Skip to content

Instantly share code, notes, and snippets.

@leahneukirchen
Created August 26, 2008 14:02

Revisions

  1. leahneukirchen revised this gist Aug 26, 2008. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion goog
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    require 'open-uri'
    n = ARGV[0] =~ /^\d+$/ ? ARGV.shift : 5
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    open("http://www.google.com/search?q=#{q}&num=#{n}").read.
    open("http://www.google.com/search?ie=utf-8&oe=utf-8&q=#{q}&num=#{n}").read.
    scan(%r{<h3 class=r><a href="(.*?)" class=l>(.*?)</a>}) { |url, desc|
    puts url
    puts " " + desc[0..70].gsub(%r{</?em>}, '') unless $q
  2. @invalid-email-address Anonymous revised this gist Aug 26, 2008. 2 changed files with 11 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion gcalc
    Original file line number Diff line number Diff line change
    @@ -4,5 +4,5 @@ require 'open-uri'
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    html = open("http://www.google.com/search?q=#{q}").read
    puts (html[%r{<font size=\+1><b>(.*?)</b></h2>}, 1] || 'not a calculation').
    gsub(%r{\240|<font size=-2> </font>}, "").gsub("&#215;", "x").
    gsub(%r{\240|<font size=-2> </font>}, "").gsub("×", "x").
    gsub(%r{<sup>(.*?)</sup>}, '^\\1 ')
    10 changes: 10 additions & 0 deletions goog
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/usr/bin/env ruby -s
    # goog [-q] [num] <string> / 26aug2008 chneukirchen / public domain
    require 'open-uri'
    n = ARGV[0] =~ /^\d+$/ ? ARGV.shift : 5
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    open("http://www.google.com/search?q=#{q}&num=#{n}").read.
    scan(%r{<h3 class=r><a href="(.*?)" class=l>(.*?)</a>}) { |url, desc|
    puts url
    puts " " + desc[0..70].gsub(%r{</?em>}, '') unless $q
    }
  3. @invalid-email-address Anonymous revised this gist Aug 26, 2008. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gcalc
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,5 @@ require 'open-uri'
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    html = open("http://www.google.com/search?q=#{q}").read
    puts (html[%r{<font size=\+1><b>(.*?)</b></h2>}, 1] || 'not a calculation').
    delete("\240").gsub("&#215;", "x").gsub(%r{<sup>(.*?)</sup>}, '^\\1 ')
    gsub(%r{\240|<font size=-2> </font>}, "").gsub("&#215;", "x").
    gsub(%r{<sup>(.*?)</sup>}, '^\\1 ')
  4. @invalid-email-address Anonymous revised this gist Aug 26, 2008. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gcalc
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #!/usr/bin/env ruby
    # gcalc <google calculator string> / 26aug2008 chneukirchen / public domain
    require 'open-uri'
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    html = open("http://www.google.com/search?q=#{q}").read
  5. @invalid-email-address Anonymous revised this gist Aug 26, 2008. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gcalc
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,5 @@
    require 'open-uri'
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    html = open("http://www.google.com/search?q=#{q}").read
    puts (html[%r{<font size=\+1><b>(.*?)</b></h2>}, 1] || 'not a calculation').delete("\240")
    puts (html[%r{<font size=\+1><b>(.*?)</b></h2>}, 1] || 'not a calculation').
    delete("\240").gsub("&#215;", "x").gsub(%r{<sup>(.*?)</sup>}, '^\\1 ')
  6. @invalid-email-address Anonymous revised this gist Aug 26, 2008. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gcalc
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,4 @@
    require 'open-uri'
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    html = open("http://www.google.com/search?q=#{q}").read
    puts html[%r{<font size=\+1><b>(.*?)</b></h2>}, 1] || 'not a calculation'
    puts (html[%r{<font size=\+1><b>(.*?)</b></h2>}, 1] || 'not a calculation').delete("\240")
  7. @invalid-email-address Anonymous created this gist Aug 26, 2008.
    5 changes: 5 additions & 0 deletions gcalc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #!/usr/bin/env ruby
    require 'open-uri'
    q = ARGV.join(" ").gsub(/./m) { "%%%02X" % $&[0] }
    html = open("http://www.google.com/search?q=#{q}").read
    puts html[%r{<font size=\+1><b>(.*?)</b></h2>}, 1] || 'not a calculation'