Skip to content

Instantly share code, notes, and snippets.

@kayakaya
Created April 15, 2010 12:57
Show Gist options
  • Save kayakaya/367055 to your computer and use it in GitHub Desktop.
Save kayakaya/367055 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'webrick'
require 'tempfile'
$EDITOR = '/Users/kayakaya/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'
$PORT = 9292
server = WEBrick::HTTPServer.new(:Port => $PORT)
trap('INT') { server.shutdown }
server.mount_proc('/status') do |req, res|
res.status = 200
end
server.mount_proc('/edit') do |req, res|
temp = Tempfile.new('editwith_')
if req.body
temp << req.body
end
temp.close false
system $EDITOR, temp.path
temp.open
res.body = temp.read
temp.close
res.status = 200
res['Content-Type'] = 'text/plain'
res['Content-Length'] = res.body.bytesize
end
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment