Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created June 18, 2011 05:52
Show Gist options
  • Save ucnv/1032839 to your computer and use it in GitHub Desktop.
Save ucnv/1032839 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Redirect to the url in the server's clipboard
if defined? Rack then
Redirector = Rack::Builder.new {
use Rack::ContentLength
app = Proc.new { |env|
u = IO.popen('pbpaste', 'r+').read
[303, {'Location' => u, 'Content-Type' => 'text/plain'}, ['']]
}
run app
}.to_app
else
port = ARGV.first || '3030'
sudo = (port == '80') ? 'sudo' : ''
cmd = '%s rackup -p %s -s thin %s' % [sudo, port, $0]
system cmd
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment