Skip to content

Instantly share code, notes, and snippets.

@migane
Created September 6, 2012 21:24
Show Gist options
  • Save migane/3660478 to your computer and use it in GitHub Desktop.
Save migane/3660478 to your computer and use it in GitHub Desktop.
Sorting file lines with rackup and curl
# Alpha.txt is supposed to be a text file with multiple lines
# my_sort_file.rb
class MySortFile
def call(env)
req = Rack::Request.new(env)
initial_file = req.params['file']
Rack::Response.new.finish do |res|
res['Content-Type'] = 'text/plain'
res.status = 200
if(req.params['file'].class==NilClass)
res.write("Sorry the file does not exist.\n")
else
initial_file.split(/\n/).sort.each do |word|
res.write(word.chomp<<"\n")
end
end
end
end
end
# config.ru
require './my_sort_file'
run MySortFile.new
# To use it:
# rackup confi.ru in a Terminal
# Then in another Terminal:
# curl --data-urlencode [email protected] localhost:9292
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment