Static site development
When developing a static site, or editing an existing one, its a bitch to try and remember things like relative and absolute paths, etc etc. I didn’t want to have to mess with that and I certainly didn’t want the hassle of setting up apache or lighty just to serve files from the directory I had mirrored the site.
So, Ruby to the rescue! 2 minutes later and I had this serving my files for me:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<code class='ruby'>#!/usr/local/bin/ruby require 'webrick' include WEBrick def webserve(port, directory) server = HTTPServer.new( :Port => port, :DocumentRoot => directory ) trap("INT"){ server.shutdown } server.start end port = ARGV[0] || 3000 directory = ARGV[1] || Dir::pwd webserve(port, directory)</code> |
Just run it in the directory that has your files in, or call it like:
|
1 2 |
<code>webserver 3000 /path/to/my/files </code> |
and voila, instant server.
I don’t know how people live without this stuff.