Skip to content

Instantly share code, notes, and snippets.

@bheeshmar
Created February 7, 2012 22:28

Revisions

  1. bheeshmar revised this gist Feb 8, 2012. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions textaid.rb
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    require 'webrick'
    require 'tempfile'

    # Start gvim in foreground mode
    $EDITOR = "gvim -f"
    $EDITOR = "gvim -f "
    s = WEBrick::HTTPServer.new(:Port => 9292)
    trap("INT") { s.shutdown }
    %w(INT TERM).each { |signal| trap(signal) { s.shutdown } }

    s.mount_proc("/") do |req,res|
    File.open("textaid.txt", "wb") { |f| f.syswrite(req.body) }
    system($EDITOR + " textaid.txt")
    res.body = File.read("textaid.txt")
    t = Tempfile.open('textaid') { |f| f.write(req.body); f }
    system($EDITOR + t.path)
    res.body = File.read(t.path)
    t.unlink
    end

    s.start
  2. bheeshmar revised this gist Feb 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion textaid.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    require 'webrick'

    # Start gvim in foreground mode
    $EDITOR = "gvim --no-fork"
    $EDITOR = "gvim -f"
    s = WEBrick::HTTPServer.new(:Port => 9292)
    trap("INT") { s.shutdown }

  3. bheeshmar revised this gist Feb 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion textaid.rb
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    # Start gvim in foreground mode
    $EDITOR = "gvim --no-fork"
    s = Webrick.HTTPServer.new(:Port => 9292)
    s = WEBrick::HTTPServer.new(:Port => 9292)
    trap("INT") { s.shutdown }

    s.mount_proc("/") do |req,res|
  4. bheeshmar revised this gist Feb 8, 2012. 1 changed file with 7 additions and 25 deletions.
    32 changes: 7 additions & 25 deletions textaid.rb
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,14 @@
    require 'webrick'
    include WEBrick

    # Start gvim in foreground mode
    $EDITOR = "gvim -f"

    class FileUploadServlet < HTTPServlet::AbstractServlet
    def do_POST(req, res)
    filedata = req.body
    $EDITOR = "gvim --no-fork"
    s = Webrick.HTTPServer.new(:Port => 9292)
    trap("INT") { s.shutdown }

    # TODO: Use tempfile instead of foo.out.
    File.open("foo.out", "wb") do |f|
    f.syswrite(filedata)
    end
    system($EDITOR + " foo.out")
    res.body = File.read("foo.out")
    end
    s.mount_proc("/") do |req,res|
    File.open("textaid.txt", "wb") { |f| f.syswrite(req.body) }
    system($EDITOR + " textaid.txt")
    res.body = File.read("textaid.txt")
    end

    s = HTTPServer.new(
    :Port => 9292,
    #:Logger => Log.new(nil, BasicLog::WARN),
    :AccessLog => [],
    :DocumentRoot => Dir.pwd)

    s.mount("/", FileUploadServlet)

    trap("INT") { s.shutdown }

    puts 'Starting'
    s.start
    puts 'Bye'
  5. bheeshmar created this gist Feb 7, 2012.
    32 changes: 32 additions & 0 deletions textaid.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    require 'webrick'
    include WEBrick

    # Start gvim in foreground mode
    $EDITOR = "gvim -f"

    class FileUploadServlet < HTTPServlet::AbstractServlet
    def do_POST(req, res)
    filedata = req.body

    # TODO: Use tempfile instead of foo.out.
    File.open("foo.out", "wb") do |f|
    f.syswrite(filedata)
    end
    system($EDITOR + " foo.out")
    res.body = File.read("foo.out")
    end
    end

    s = HTTPServer.new(
    :Port => 9292,
    #:Logger => Log.new(nil, BasicLog::WARN),
    :AccessLog => [],
    :DocumentRoot => Dir.pwd)

    s.mount("/", FileUploadServlet)

    trap("INT") { s.shutdown }

    puts 'Starting'
    s.start
    puts 'Bye'