Google Calculator
#!/usr/bin/env ruby
%w(rubygems open-uri hpricot erb).each {|lib| require lib }
doc = Hpricot(open(“http://www.google.com/search?q={ERB::Util.u(ARGV*’ ‘)}”))
puts (doc/’/html/body/div#res/p/table/tr/td[3]/h2/font/b’).inner_text
This little Ruby script requires Hpricot and uses Google to perform unit conversions & math calculations. For example, I’ve named the script ‘g’ and symlinked it in /usr/bin. Here’s how it looks:
hemingway:~ mauricio$ g 1 furlongs to feet
1 furlongs = 660 feethemingway:~ mauricio$ g 980 pesos to euros
980 Mexican pesos = 62.2061166 Euroshemingway:~ mauricio$ g “cos(0) * sqrt(64)”
cos(0) * sqrt(64) = 8
Enjoy the console math love!