Skip to content

Instantly share code, notes, and snippets.

@bkimble
Created September 20, 2011 19:21
Show Gist options
  • Save bkimble/1230051 to your computer and use it in GitHub Desktop.
Save bkimble/1230051 to your computer and use it in GitHub Desktop.
ree-1.8.7-2011.03 :001 > GeoIpBlock.count
=> 6055096
ree-1.8.7-2011.03 :005 > GeoIpBlock.first.e.class.name
=> "Fixnum"
ree-1.8.7-2011.03 :006 > res = Benchmark.measure { puts GeoLocation.by_ip('74.220.125.3').location }; puts res
San Francisco, CA
0.000000 0.000000 0.000000 ( 0.003826)
@bkimble
Copy link
Author

bkimble commented Sep 20, 2011

def self.locate(decimal_ip)
if block = where(:e.gte => decimal_ip).order("e ASC").limit(1).first
return block if block.s <= decimal_ip
end
end

@bkimble
Copy link
Author

bkimble commented Sep 20, 2011

if , using mongo, I can find the first geo_ip_block that has an IP address thats end range is greater than or equal to this decimal IP
and if my geo_ip_block object has a start value that is less than or equal to this decimal IP address
return the geo ip block that I found
otherwise return null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment