Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'eventmachine'
- require 'evma_httpserver'
- require 'json'
- INPUT = 'suggestions.txt'
- class Handler < EventMachine::Connection
- include EventMachine::HttpServer
- def process_http_request
- resp = EventMachine::DelegatedHttpResponse.new( self )
- matches = @@suggestions.find_all{ |s| s.match(@http_request_uri[1..-1]) }[0..9]
- resp.status = 200
- resp.content_type 'text/json'
- resp.content = matches.to_json
- resp.send_response
- end
- end
- @@suggestions = []
- File.open(INPUT, 'r').each { |line| @@suggestions << line.strip }
- puts "#{@@suggestions.size} suggestions..."
- EventMachine::run {
- EventMachine.epoll
- EventMachine::start_server("0.0.0.0", 8080, Handler)
- puts "Listening..."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement