Skip to content

Instantly share code, notes, and snippets.

@kasima
Created May 21, 2010 07:46
Show Gist options
  • Save kasima/408595 to your computer and use it in GitHub Desktop.
Save kasima/408595 to your computer and use it in GitHub Desktop.
sinatra suggester
require 'rubygems'
require 'sinatra'
require 'json'
input = 'suggestions.txt'
suggestions = []
File.open(input, 'r').each { |line| suggestions << line.strip }
get '/:q' do
matches = suggestions.find_all{ |s| s.match(params[:q]) }[0..9]
halt 200, {'Content-Type' => 'text/json'}, matches.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment