Skip to content

Instantly share code, notes, and snippets.

@jtzemp
Created December 12, 2013 20:49
Show Gist options
  • Save jtzemp/7935186 to your computer and use it in GitHub Desktop.
Save jtzemp/7935186 to your computer and use it in GitHub Desktop.
http://onestepback.org/index.cgi/Tech/Ruby/WEBrick.rdoc with a change to use /usr/bin/env ruby instead of /usr/local/bin/ruby
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
dir = Dir::pwd
port = 12000 + (dir.hash % 1000)
url = "http://#{Socket.gethostname}:#{port}"
puts "URL: #{url}"
s = HTTPServer.new(
:Port => port,
:DocumentRoot => dir
)
trap("INT"){ s.shutdown }
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment