Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created September 5, 2012 17:07
Show Gist options
  • Select an option

  • Save practicingruby/3640112 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/3640112 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
PATTERNS = { "gg" => "http://google.com/search?q=",
"gmap" => "http://maps.google.com/maps?q=",
"wp" => "http://en.wikipedia.org/?search=",
"m" => "http://www.google.com/movies?near=" }
app = lambda do |env|
command, *args = URI.unescape(env["QUERY_STRING"]).gsub("+", " ").split
raise unless PATTERNS[command]
[302, { "Location" => "#{PATTERNS[command]}#{URI.escape(args.join(' '))}",
"Content-Type" => "text/html" }, []]
end
run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment