Page 1 of 1 [ 1 post ] 

Aaron_Mason
Veteran
Veteran

User avatar

Joined: 3 Jul 2005
Age: 39
Gender: Male
Posts: 511
Location: Bathurst, Australia

07 Aug 2008, 11:01 pm

Hey all,

For those who haven't a clue of what I'm on about, here's the rundown:

Image

To translate - one combines the Atom date (without the time) with today's Dow Jones opening score, and creates an MD5 hash of it. You then split it in half, and turn the two halves into a decimal number, then prefix them both with "0." to make them a decimal. Add the two decimal numbers to your current coordinates, pop those into Google Maps and you have a completely random location every day, determined by the stock market.

Geeky? Hell yes. But it does make life interesting.

Here's the Bash script I wrote to calculate it. Note that you will need a version of Unix installed on your system. It also works under Cygwin - though UnxUtils and MinGW don't agree with it. You will also need wget installed. To make it work for you, get your current location, remove the decimal part (i.e. 25.398964 becomes 25) and run the script like this:

# ./xkcd-coord 28 141

In tests it worked on OpenBSD 4.3, Linux From Scratch 6.3 (with Bash 3.2.17(1), bc 1.0.6 and wget 1.10.2) and Cygwin

Code:
#!/usr/bin/env bash

if [ ! $2 ]; then
        echo "Syntax: $0 latitude longitude" >&2
        echo "Ex. $0 88 104" >&2
        exit 1
fi

get_dj() {

        wget -O .dj.$$ "http://au.quote.com/us/stocks/quote.action?s=%24INDU&ref=0" -o .debug.$$
        sed -n "$(expr $(grep -n Open .dj.$$ | cut -d : -f 1) + 1)p" .dj.$$ | sed -e 's/.*td.*">//' -e 's/<.td>//' -e 's/,//'
        rm .dj.$$
   rm .debug.$$
}

hex2dec () {
        bc <<EOF
ibase=16
$(tr a-f A-F <<<$1)
quit
EOF
}

if [ ! $MD5PRG ]; then
        (which md5 2>/dev/null >/dev/null) && MD5PRG=md5
        (which md5sum  2>/dev/null >/dev/null) && MD5PRG=md5sum
        if [ ! $MD5PRG ]; then
                echo "Please run this program specifying your md5 checksumming program like this:" >&2
                echo "  MD5PRG=<path to your MD5 program> $0"
                exit 2
        fi
fi

if [ ! $AWKPRG ]; then
        (which gawk 2>/dev/null >/dev/null) && AWKPRG=gawk
        (which awk 2>/dev/null >/dev/null) && AWKPRG=awk
        if [ ! $AWKPRG ]; then
                echo "Please run this program specifying your awk processor like this:" >&2
                echo "  AWKPRG=<path to your awk program> $0"
                exit 3
        fi
fi

djopen=$(get_dj)

sum=$($MD5PRG <<<"$(date +%Y-%m-%d)-$djopen")

first=${sum:0:16}
second=${sum:16:32}

first=$(hex2dec $first)
second=$(hex2dec $second)

lati=$1
long=$2

lati=$(echo $lati $first | $AWKPRG '{printf "%s.%s", $1, $2}')
long=$(echo $long $second | $AWKPRG '{printf "%s.%s", $1, $2}')

echo "Next meetup is at $lati,$long"


EDIT: Whoops, left my proxy in there :S Also a few other bug fixes.


_________________
We are one, we are strong... the more you hold us down, the more we press on - Creed, "What If"

AS is definitive. Reality is frequently inaccurate.

I'm the same as I was when I was six years old - Modest Mouse