Skip to content

Instantly share code, notes, and snippets.

@gsharp
Created June 6, 2010 22:14
Show Gist options
  • Save gsharp/427958 to your computer and use it in GitHub Desktop.
Save gsharp/427958 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
# web.rb
# to be run with apache, as long as apache is setup to parse .rb and can execute the file
puts "Content-Type: text/html" # has to happen before output to browser
puts
begin # wrap page in exception to avoid 500 errors
param = ARGV[0]
if ARGV[0]
puts <<-end
<h1>your param is #{param}</h1>
<pre>
groovy!
the
script
worked
</pre>
end
else
puts "you should put a param on this url: http://yourserver/web.rb?YOURPARAM"
end
bogusFunction # this is a bogus function to test errors
rescue Exception # output errors to browser
puts "<div style='border: 1px dashed #000; background-color: #fcc; padding: 10px; margin: 10px'>"
puts "<em>#{$!.backtrace}</em>: <strong>#{$!.message}</strong>"
puts "</div>"
end # end exception wrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment