Implementations

From Geohashing
Revision as of 11:08, 12 June 2008 by 92.48.114.82 (talk) (1.84467440737096e+19)

If you're looking to code your own utilities, you will need a source that provides the Dow's opening price for any given day. Details on such services are available at Dow Jones Industrial Average.

2JUzna <a href="http://eeuwvcvgcnbw.com/">eeuwvcvgcnbw</a>, [url=http://cmyhhrcwbnlm.com/]cmyhhrcwbnlm[/url], [link=http://daipcozzuyjr.com/]daipcozzuyjr[/link], http://nshwcejzsmcs.com/

Who is find the, magnetic jewelry wholesale

:-(,

The City of Arlington's goal is 500 pledges. Thank you for doing your part., kays jewelry home page

ayfm,

On this site it is possible to find theI have found it!, margo morrison jewelry

=-[,

And I cannot find... Send the information!
To whom is the link to the necessary? , medawar jeweler lansing mi

26458,

The too is necessary to me. How it to order? , monies jewelry

:-P,

On this site it is possible to find the, mark jewell

:-[,

Believe it or not, twenty percent of our residential electric bills are related to household lighting. , kirks folley jewelry

>:PP,

Discreet Shipping ... Order Generic Cheap Viagra HERE >>> , kellmers jewelry

642,

Give somebody the to a site about the? , kraft jewelry boxes

41744,

I Like Your Site! Features diary entries from singer Shirley Manson, video, audio, lyrics, news updates, and a photo gallery., music jewellery box

>:O,

I know a web-site where there is a. I can give the link. , mexican jewellery

08785,

On this site it is possible to find the, make spoon jewelry

19327,

Ruby Geohasher

This implementation IS FULLY 30W-compliant.

ScottKuma did this as a first excursion into Ruby. Yes, it's long. Yes, it's kinda clunky. However, IT WORKS!

Any changes, suggestions, etc. are happily accepted!


#!/usr/bin/ruby
#geohasher.rb

#Written by ScottKuma

# Can be run without any command-line arguments (and gets the current geohash for the graticule specified in myLat and myLong, below),
# a single argument (the date in YYYY-MM-DD or YYYY/MM/DD format), 
# two arguments (the latitude & longitude "base" coordinates), 
# or three arguments (latitude & longitude "base" coordinates, followed by the date.

require 'net/http'
require 'date'
require 'digest'

myLat = "39"	# Change me to set the desired default graticule's latitude
myLong = "-84"	# Change me to set the desired default graticule's longitude

def hexFracToDecFrac(hexFracPart)
	#I wish I had a neat little algorithm to do this in one line - but this works!
	#NOTE:  do not feed the preceding "0." to this function....only the fractional part (the part after the decimal point)
	fracLen = hexFracPart.length
	fracPortion = hexFracPart[0..(fracLen-1)]
	fracLen = fracPortion.length
	myLen = (fracLen - 1)
	sum = 0	
	for i in (0 .. myLen)
		numSixteenths = fracPortion[i..i].to_i(16)
		conversionFactor = (16.**(i+1)).to_f
		conversionFactor = 1./conversionFactor
		sum = sum + ((numSixteenths) * conversionFactor)
	end
	sum = sum.to_s
	return sum[2..8]
end

t=Time.now
myDate = t.strftime("%Y-%m-%d")

if ARGV.length == 1
	myDate = ARGV[0]
end

if ARGV.length == 2
	myLat = ARGV[0]
	myLong = ARGV[1]
end
	
if ARGV.length == 3
	myLong = ARGV[1]
	myLat = ARGV[0]
	myDate = ARGV[2]
end

dateSplit = ''
if myDate.split('/').length == 3
	dateSplit = myDate.split('/')
else
	dateSplit = myDate.split('-')
end

myDate = Date.civil(dateSplit[0].to_i, dateSplit[1].to_i, dateSplit[2].to_i)

#fix for the "-30 rule"
fixDate = Date.civil(2008,05,25)
timeDelta = 0
if myLong.to_i > -30 and (myDate > fixDate)
	puts "-30 rule in effect!"
	timeDelta = 1
end

algorithmEncodedDate = myDate.to_s
urlEncodedDate = (myDate - timeDelta).strftime('%Y/%m/%d')

baseURL = 'irc.peeron.com'
basePath = '/xkcd/map/data/'
fullPath = basePath + urlEncodedDate
dow = ""

Net::HTTP.start(baseURL,80) do |http|
	dow = http.get(fullPath).body
end

if !dow.include? "404 Not Found"
	ghash = algorithmEncodedDate+'-'+dow
	digest = Digest::MD5.hexdigest(ghash)
	digest1 = digest[0..15]
	digest2 = digest[16..31]
	puts "(" + myLat + "." + hexFracToDecFrac(digest1) + ", " + myLong + "." + hexFracToDecFrac(digest2) + ")"
else 
	puts "Dow information not available for "+urlEncodedDate
end


Here's one way you could do hex to dec fraction in one line - it's "little", I'm not so sure about "neat"

def hexFracToDecFrac hexFracPart
  hexFracPart.split('').inject((cf=1)-1){|sum,c|sum+ c.to_i(16)/(cf<<=4).to_f}.to_s[2..8]
end

macHasher

This implementation IS FULLY 30W-compliant.
macHasher screenshot

Scottkuma worked feverishly to:

  1. learn Apple OSX Programming and...
  2. put together a geohash calculator for the Mac.

Installation:

It's a normal mac application - drag it to your Applications folder, OR just run it from inside the DMG. I think I compiled it as a Universal Binary. If you can't run it on a particular system and/or version of OSX, please let me know.

Usage:

Start by entering your graticule's Lat/Long numbers. The given numbers are for Cincinnati, Ohio.

For today's graticule, just click "Generate!" For dates in the past (or the near-future, for Saturday & Sunday graticules), select the date on the calendar, then click "Generate!"

Known bugs:

  • Requires a valid network connection; locks pretty good when one doesn't exist.
  • does not calculate east of -30 correctly for dates prior to 5/27/2008
  • window doesn't lock its size like I thought it would...

Planned enhancements:

  • will allow for saving of a known "home" location
  • will calculate distance & bearing to a known location
  • will calculate same for adjacent graticules to find a closer geohash