Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Created December 1, 2012 02:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/4180325 to your computer and use it in GitHub Desktop.
Save jc00ke/4180325 to your computer and use it in GitHub Desktop.
Get Lat:Long from IP Info Database
#!/usr/bin/env ruby
require 'open-uri'
class IpInfoDb
attr_reader :source
URI = "http://ipinfodb.com"
def initialize
@source = open(URI).read
end
def self.get_lat_long
new.get_lat_long
end
def latitude
@latitude ||= get("Latitude")
end
def longitude
@longitude ||= get("Longitude")
end
def get_lat_long
"#{latitude}:#{longitude}"
end
private
def get(which)
source.match(%r{<li>#{which} : (.*)</li>}) && $1
end
end
puts IpInfoDb.get_lat_long
gtk-redshift -l $(get_lat_long) &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment