So, Ben, you're saying that Google sucks rocks? (=
*ducking*
On 8/10/06, Ben Bleything <[EMAIL PROTECTED]> wrote:
On Thu, Aug 10, 2006, Caleb Phillips wrote:
> Getting back on point, the real question should be:
>
> Can you write tiny ruby program (one liner?) that works like this:
Oh man, you had to ask. It's not one line, but it's small. Disclaimer,
I know nothing about math so this is all guesswork and crap. If it's
wrong, please tell me :D
------------------
require 'net/http'
puts "Usage: google_sucks_rocks.rb <term>" and return if ARGV.empty?
options = %w(sucks rocks)
results = {}
options.each do |option|
results[option] =
Net::HTTP.get_response(URI.parse("http://www.google.com/search?q=#{ARGV[0]}+#{option}")).body.match(/of
about <b>(.*?)<\/b> for/)[1].gsub(/,/,'').to_f
end
print "Ratio of sucks to rocks for #{ARGV[0]} is "
if results['rocks'] > results['sucks']
puts "1:#{(results['rocks'] / results['sucks'])}"
else
puts "#{(results['sucks'] / results['rocks'])}:1"
end
------------------
> $ ./google-rocks-sucks-o-meter.rb "DreamHost Rocks"
> 1:2
./google_sucks_rocks.rb dreamhost
Ratio of sucks to rocks for dreamhost is 1:1.48104265402844
Ben
_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby
_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby