Skip to content

Instantly share code, notes, and snippets.

@elct9620
Created May 24, 2018 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elct9620/98c6dc0b4cdfc02a5f93d160bd0c3125 to your computer and use it in GitHub Desktop.
Save elct9620/98c6dc0b4cdfc02a5f93d160bd0c3125 to your computer and use it in GitHub Desktop.
# Start Command: rackup
require 'socket'
# Initialize Socket -> Pure Data
pd = TCPSocket.new 'localhost', 3000
# Create HTTP Server
app = Proc.new do |env|
# /?Do=1&Re=0
query = env['QUERY_STRING']
# [['Do', 1], ['Re', 0]]
params = URI.decode_www_form(query)
# ['Do 1', 'Re 0']
# "Do 1;\nRe 0"
# "Do 1;\nRe 0;\n"
pd.send(params.map { |param| param.join(' ') }.join(";\n") + ";\n",0)
[200, {'Content-Type' => 'text/plain'}, ['Success']]
end
run app
# Don't pd.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment