Skip to content

Instantly share code, notes, and snippets.

@dvliman
Created August 19, 2012 17:20
Show Gist options
  • Save dvliman/3396439 to your computer and use it in GitHub Desktop.
Save dvliman/3396439 to your computer and use it in GitHub Desktop.
file:// to http://. simple http server on your root directory
#!/usr/bin/env ruby
# thanks to jim weirich
# run ./servefiles from the root directory
require 'webrick'
include WEBrick
dir = Dir::pwd
port = (ARGV.first || (12000 + (dir.hash % 1000))).to_i
url = "http://#{Socket.gethostname}:#{port}"
puts "Opening #{url}"
`open #{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