Difference between revisions of "Implementations"

From Geohashing
imported>Tjtrumpet2323
m (Reference Implementation)
imported>Tjtrumpet2323
m
Line 1: Line 1:
== Official Interactive Coordinate Calculator ==
+
== Official Implementations ==
{{30w compliant|yes=1}}
+
{{30w compliant}}
 
The original sample interactive coordinate calculator can be found at [http://irc.peeron.com/xkcd/map http://irc.peeron.com/xkcd/map].  The common URL, [http://xkcd.com/geohashing http://xkcd.com/geohashing], redirects here.
 
The original sample interactive coordinate calculator can be found at [http://irc.peeron.com/xkcd/map http://irc.peeron.com/xkcd/map].  The common URL, [http://xkcd.com/geohashing http://xkcd.com/geohashing], redirects here.
  
 
=== Reference Implementation ===
 
=== Reference Implementation ===
{{30w compliant}}
+
{{30w compliant|no=1}}
 
A reference implementation is available: [http://irc.peeron.com/xkcd/map/sample.pl.html view] [http://irc.peeron.com/xkcd/map/sample.pl download]
 
A reference implementation is available: [http://irc.peeron.com/xkcd/map/sample.pl.html view] [http://irc.peeron.com/xkcd/map/sample.pl download]
  
 +
=== MediaWiki Implementation ===
 +
{{30w compliant|no=1}}
 
[[MediaWiki Implementation|MediaWiki half-implementation]] (for use by template creators).
 
[[MediaWiki Implementation|MediaWiki half-implementation]] (for use by template creators).
  
 
== Python Implementation ==
 
== Python Implementation ==
{{30w compliant}}
+
{{30w compliant|no=1}}
 
<pre>import md5, datetime, struct, urllib, re, sys
 
<pre>import md5, datetime, struct, urllib, re, sys
 
date = datetime.date.today()
 
date = datetime.date.today()
Line 21: Line 23:
  
 
== Shell Script Implementation ==
 
== Shell Script Implementation ==
{{30w compliant}}
+
{{30w compliant|no=1}}
 
<pre>#!/bin/zsh
 
<pre>#!/bin/zsh
 
DOW=$(wget -qO- http://irc.peeron.com/xkcd/map/data/$(date +%Y/%m/%d))
 
DOW=$(wget -qO- http://irc.peeron.com/xkcd/map/data/$(date +%Y/%m/%d))
Line 31: Line 33:
  
 
== Alternative geohash location suggester ==
 
== Alternative geohash location suggester ==
{{30w compliant}}
+
{{30w compliant|no=1}}
 
[http://geohashing.electronicwar.net/ Geohash Recommender]
 
[http://geohashing.electronicwar.net/ Geohash Recommender]
  
Line 43: Line 45:
  
 
== GeoRSS feed ==
 
== GeoRSS feed ==
{{30w compliant}}
+
{{30w compliant|no=1}}
 
You can subscribe to a feed (in GeoRSS format) that will give you updates on a daily basis{{fact}}.  Updates include the "best guess" address of the location as well as the specific latitude/longitude coordinates.
 
You can subscribe to a feed (in GeoRSS format) that will give you updates on a daily basis{{fact}}.  Updates include the "best guess" address of the location as well as the specific latitude/longitude coordinates.
 
<pre>http://atlas.freshlogicstudios.com/Features/Experiments/Xkcd/Xkcd.ashx?Latitude=38&Longitude=-91</pre>
 
<pre>http://atlas.freshlogicstudios.com/Features/Experiments/Xkcd/Xkcd.ashx?Latitude=38&Longitude=-91</pre>
Line 52: Line 54:
  
 
== Atom feed ==
 
== Atom feed ==
{{30w compliant}}
+
{{30w compliant|no=1}}
 
You can subscribe to a feed that will give you updates on a daily basis:
 
You can subscribe to a feed that will give you updates on a daily basis:
 
<pre>http://staticfree.info/geohash/atom/LAT,LON</pre>
 
<pre>http://staticfree.info/geohash/atom/LAT,LON</pre>
Line 61: Line 63:
  
 
== k4 implementation ==
 
== k4 implementation ==
{{30w compliant}}
+
{{30w compliant|no=1}}
 
Here's an implementation in [http://kx.com/developers/license2.php k4], a vector-programming (i.e., self-obfuscating) language that seems to me to be very true to the spirit of xkcd. The following shell script takes the graticule as an argument, uses standard standard unix tools to retrieve the current Dow opening price, and returns a URL for a Google map to the the upcoming Saturday's meetup. It assumes the q executable is in your PATH.
 
Here's an implementation in [http://kx.com/developers/license2.php k4], a vector-programming (i.e., self-obfuscating) language that seems to me to be very true to the spirit of xkcd. The following shell script takes the graticule as an argument, uses standard standard unix tools to retrieve the current Dow opening price, and returns a URL for a Google map to the the upcoming Saturday's meetup. It assumes the q executable is in your PATH.
 
<pre>
 
<pre>

Revision as of 05:29, 24 May 2008

Official Implementations

This implementation's 30W-compliance IS UNKNOWN.

The original sample interactive coordinate calculator can be found at http://irc.peeron.com/xkcd/map. The common URL, http://xkcd.com/geohashing, redirects here.

Reference Implementation

This implementation IS NOT 30W-compliant.

A reference implementation is available: view download

MediaWiki Implementation

This implementation IS NOT 30W-compliant.

MediaWiki half-implementation (for use by template creators).

Python Implementation

This implementation IS NOT 30W-compliant.
import md5, datetime, struct, urllib, re, sys
date = datetime.date.today()
djia = urllib.urlopen(date.strftime("http://irc.peeron.com/xkcd/map/data/%Y/%m/%d")).read()
if djia.find('404 Not Found') >= 0: sys.exit(sys.stderr.write("Dow Jones not available yet.\n"))
sum = md5.new("%s-%s" % (date, djia)).digest()
print struct.unpack(">Q", sum[0:8])[0] / (2.**64), struct.unpack(">Q", sum[8:16])[0] / (2.**64)

There is also a Python package xkcd.geohash which is independent of the interactive coordinate calculator (but uses Google Finance as well).

Shell Script Implementation

This implementation IS NOT 30W-compliant.
#!/bin/zsh
DOW=$(wget -qO- http://irc.peeron.com/xkcd/map/data/$(date +%Y/%m/%d))
[[ "$DOW" != +([0-9.]) ]] && echo "DOW not available yet." && exit 1
MD5=$(echo -n "$(date +%Y-%m-%d)-$DOW"|md5sum|cut -d' ' -f 1|tr a-f A-F)
echo "$1$(echo 10k16i0.${MD5:0:16}p|dc), $2$(echo 10k16i0.${MD5:16}p|dc)"

If you're looking to code your own utilities and need a source for the Dow Jones Industrial Average for a day, NuclearDog has set up a mySQL backed page to query the value that automatically updates hourly. Details on this service (and others) is available at Dow Jones Industrial Average.

Alternative geohash location suggester

This implementation IS NOT 30W-compliant.

Geohash Recommender

Yet another implementation in Python is here as well. It does the same as the ones above but also gives "validation" information. Lets you know if the geohash location is under water and thus if its a valid place to go party. Using this it attempts to suggest the "best" alternative geohash by checking all neighbouring grid locations. I'll add more terrain recognition if people like it. A webservice to access it can be found JSON Web Service. The code is over here Source Code

All the errors seem to be fixed now. Doesn't try giving you locations if there is no DOW and made the image recognition stuff work a bit better too, enjoy! :)

Bugs: There are a few, it needs a few refreshes to get the whole tagging right.[citation needed] It also has trouble guessing the terrain type occationally. Refreshing it makes it work but its a problem im looking into, have a look at the code and help if you can :)

-- SinJax

GeoRSS feed

This implementation IS NOT 30W-compliant.

You can subscribe to a feed (in GeoRSS format) that will give you updates on a daily basis[citation needed]. Updates include the "best guess" address of the location as well as the specific latitude/longitude coordinates.

http://atlas.freshlogicstudios.com/Features/Experiments/Xkcd/Xkcd.ashx?Latitude=38&Longitude=-91

For example, here's the GeoRSS geohash for St. Louis.

This GeoRSS feed is used to power the Atlas geohash implementation.

Atom feed

This implementation IS NOT 30W-compliant.

You can subscribe to a feed that will give you updates on a daily basis:

http://staticfree.info/geohash/atom/LAT,LON

For example, here's the Atom Geohash for Boston.

Just put your coordinates in, subscribe and you'll be ready to go!

k4 implementation

This implementation IS NOT 30W-compliant.

Here's an implementation in k4, a vector-programming (i.e., self-obfuscating) language that seems to me to be very true to the spirit of xkcd. The following shell script takes the graticule as an argument, uses standard standard unix tools to retrieve the current Dow opening price, and returns a URL for a Google map to the the upcoming Saturday's meetup. It assumes the q executable is in your PATH.

#!/bin/sh

test $# -eq 2 || exit 1
dow=`curl -s 'http://finance.google.com/finance?cid=983582'| \
 egrep -o '<span id="ref_983582_op">[^<]+</span>'| \
 sed -r 's/.*>(.*)<.*/\1/'|tr -d ,`

q -lat $1 -lon $2 -dow $dow<<"EOF"
\
(.q.set').(!:;,/)@\:.Q.opt .z.x;
h:.Q.n,6#.Q.A;c:16 xexp'-:'1+!16
u:"http://maps.google.com/maps?q="
d:.q.ssr[$.z.D+7-.q.mod[.z.D]7;".";"-"]
s:0N 16#,/$-15!"-"/:(d;dow);l:(lat;lon)
-1@u,"+"/:l,'1_'$sum'(h?/:.q.upper s)*\:c;
\\
EOF

For example, here's New York as of 2008-05-23:

% gh 40 -74
http://maps.google.com/maps?q=40.126648+-74.5475331

N.B., this was written on a Friday; I make no guarantee that it will produce useful results when run on any other day of the week (though Saturdays will probably work).

Adavies42 20:50, 23 May 2008 (UTC)