Skip to content

Instantly share code, notes, and snippets.

@rainchen
Last active September 15, 2020 20:37
Show Gist options
  • Select an option

  • Save rainchen/3a91ef481e78ad38d51c91da0ab40e7f to your computer and use it in GitHub Desktop.

Select an option

Save rainchen/3a91ef481e78ad38d51c91da0ab40e7f to your computer and use it in GitHub Desktop.

Revisions

  1. rainchen revised this gist Aug 31, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion webrick-webify.rb
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    require 'open3'
    server = WEBrick::HTTPServer.new :Port => 8000
    server.mount_proc('/') { |req, res| res.body = Open3.capture2(ARGV[0], :stdin_data=>req.body)[0] }
    trap 'INT' do server.shutdown end
    trap('INT') { server.shutdown }
    server.start

    # server:
  2. rainchen revised this gist Aug 28, 2020. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions webrick-webify.rb
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,7 @@
    require 'webrick'
    require 'open3'
    server = WEBrick::HTTPServer.new :Port => 8000
    server.mount_proc '/' do |req, res|
    res.body = Open3.capture2(ARGV[0], :stdin_data=>req.body)[0]
    end
    server.mount_proc('/') { |req, res| res.body = Open3.capture2(ARGV[0], :stdin_data=>req.body)[0] }
    trap 'INT' do server.shutdown end
    server.start

  3. rainchen revised this gist Aug 28, 2020. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions webrick-webify.rb
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,7 @@
    require 'open3'
    server = WEBrick::HTTPServer.new :Port => 8000
    server.mount_proc '/' do |req, res|
    o, s = Open3.capture2(ARGV[0], :stdin_data=>req.body)
    res.body = o
    res.body = Open3.capture2(ARGV[0], :stdin_data=>req.body)[0]
    end
    trap 'INT' do server.shutdown end
    server.start
    @@ -12,4 +11,4 @@
    # ruby webify-webrick.rb "wc -c"

    # client:
    # curl -d 'This is a really long sentence' http://localhost:8000
    # curl -d 'This is a really long sentence' http://localhost:8000
  4. rainchen created this gist Aug 28, 2020.
    15 changes: 15 additions & 0 deletions webrick-webify.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    require 'webrick'
    require 'open3'
    server = WEBrick::HTTPServer.new :Port => 8000
    server.mount_proc '/' do |req, res|
    o, s = Open3.capture2(ARGV[0], :stdin_data=>req.body)
    res.body = o
    end
    trap 'INT' do server.shutdown end
    server.start

    # server:
    # ruby webify-webrick.rb "wc -c"

    # client:
    # curl -d 'This is a really long sentence' http://localhost:8000