-
-
Save practicingruby/3640112 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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