#!/usr/bin/ruby # gcalc - command-line interface for Google calculator # 26aug2008 chneukirchen / revised 06aug2010, 23dec2012 / public domain require 'open-uri' q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&.unpack("C").first } html = open("http://www.google.com/search?q=#{q}").read puts (html[%r{

(.*?)

}, 1] || 'not a calculation'). gsub(%r{(.*?)}, '^\\1 '). gsub(%r{×}, '*')