Tag: Ruby
Ruby gem geoip and Rack::GeoIPCountry
by Samson on Feb.25, 2010, under Ruby, Technique
wikipedia上对于geolocation的解释是这样的:
Geolocation is the identification of the real-world geographic location of an Internet-connected computer, mobile device, website visitor or other.
检测的方法貌似也有很多:
Geolocation can be performed by associating a geographic location with the Internet Protocol (IP) address, MAC address, RFID, hardware embedded article/production number, embedded software number (such as UUID, Exif/IPTC/XMP or modern steganography), invoice, Wi-Fi connection location, or device GPS coordinates, or other, perhaps self-disclosed information.
(班门弄斧一下先,呵呵呵呵)
ruby里面取到geo信息的一个相对方便的办法是使用rubygem geoip,虽然本质上还是使用maxmind的data,但是免去了编译和安装其c library的麻烦。
(continue reading…)
List performance: ruby 1.8 and 1.9 (Part 2)
by Samson on Feb.22, 2010, under Ruby, Technique
接上篇: List performance: ruby 1.8 and 1.9 (Part 1)
有了之前的准备和热身,真正跑起步来似乎轻松不少,先贴上我们用来benchmark的code:
n = ARGV.empty? ? 10 ** 6 : 10 ** ARGV[0].to_i
puts "n=#{n}"
Benchmark.bmbm do |x|
x.report do
list = []
n.times do
list < < 0
end
end
end
和之前用来benchmark loop performance的code结构上基本没有区别,这里不再赘述,具体的解释亦可参照前文。
(continue reading…)
List performance: ruby 1.8 and 1.9 (Part 1)
by Samson on Feb.22, 2010, under Ruby, Technique
(本文数据较多,在rss reader里面可能可读性不是很好,可考虑直接在线阅读)
昨天看到pipitu的这篇blog,觉得蛮有意思,文章比较了python和java的list performance,只可惜没有include ruby 1.8和ruby 1.9,不然结论会更有悬念一点,呵呵.
由于无法营造一致的软硬件环境,也不愿意重复pipitu关于python和java部分的工作,这里就只好先简单benchmark(如果可以算是的话)一下ruby 1.8和1.9里的list (array) performance了,也许pipitu以后有空更新include ruby也说不定:)
先看一下我们用的ruby的版本:
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin9]
还有os:
Darwin macbook.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386
ruby’s “python -m SimpleHTTPServer”
by Samson on Feb.21, 2010, under Minds, Ruby, Technique
If I remembered right, the command below used to be the most voted one on commandlinefu.com:
the “SimpleHTTPServer” module is written in python and it maybe called “the python way”, but that’s not our topic today. what we really want to do here is just making a ruby equivalent for this popular command, using rack.
first, make sure you have rack gem installed on your system (if you’ve installed rails 2.x before, you may already have it):
confirm installation (Rack 1.0 should also work for our example):
Rack 1.1
alright, preparation is done, let’s start cooking. only a rackup file will be sufficient, for consistency, let’s just call it simple_http_server.ru .
#\ -E deployment
use Rack::ContentLength
app = Rack::Directory.new Dir.pwd
run app