Skip to content

Instantly share code, notes, and snippets.

View vanstee's full-sized avatar
💭
🛠

Patrick Van Stee vanstee

💭
🛠
View GitHub Profile
@vanstee
vanstee / app.rb
Created November 30, 2010 17:28
redis chat app
require 'sinatra'
require 'redis'
require 'json'
require 'sanitize'
redis = Redis.new
get '/' do
@index = redis.llen 'messages'
erb :index
<script type="text/javascript" src="./jquery/jquery.js"></script>
<script type="text/javascript">
function verifyLogin() {
$.post('./verify_login.php',
{username: $("#username").val(), password: $("#password").val() },
function(output) {
if (output == "") {
window.location="index.php";
}
alert(output);
if top_score = top_hits.map(&:score).max
- top_hits.detect { |h| h.score == top_score }.result
+ sid = top_hits.detect { |h| h.score == top_score }.stored(:demandbase_sid)
+ Company.find_by_demandbase_sid(sid)
elsif not options.keys.include?(:country)
# There's no location information or no matches based on location
# revert to a search with no scope
- solr_hits(q, options, nil).first.try(:result)
+ sid = solr_hits(q, options, nil).first.stored(:demandbase_sid)
+ Company.find_by_demandbase_sid(sid)
def reindex_companies_since(timestamp)
conditions = ["updated_at >= ?", timestamp]
total = Company.count(:conditions => conditions)
indexed = 0
companies = Queue.new
indexing = true
Thread.abort_on_exception = true
def self.build_fuzzy_query(name, options = {})
[].tap do |q|
subq = [].tap do |subq|
Normalizer.short_name(name).split.uniq.each do |token|
subq << "short_name_text:#{token}^5" # exact match
subq << "short_name_text:#{token}~^3" # fuzzy match
subq << "marketing_alias_text:#{token}^5" # exact match
subq << "marketing_alias_text:#{token}~^3" # fuzzy match
end
setup do
@company = Factory(:company, :company_name => "Highgroove Studios", :marketing_alias => "Genius Wolf Brains", :state => "GA")
@top = Factory(:company, :company_name => "Company HQ", :state => "GA", :company_search_weight => '1', :company_sort_order => '5')
@middle = Factory(:company, :company_name => "Company", :state => "GA", :company_search_weight => '1', :company_sort_order => '5')
@bottom = Factory(:company, :company_name => "Company", :state => "GA", :company_search_weight => '5', :company_sort_order => '1')
Company.solr_index_batch!({})
end
require 'sinatra'
get '/' do
"hello world"
end
$('.signin .options ul li').hover(function() {
$('.signin .options ul li').removeClass('hover');
$(this).addClass('hover');
}), function() {
$('.signin .options ul li').removeClass('hover');
})
$('.signin .options li').hover( ->
$('.signin .options li').removeClass('hover')
$(this).addClass('hover')
true
, ->
$('.signin .options li').removeClass('hover')
true
)
less_encoded = crazy_encoded_stuff.gsub("\\", "")
JSON.parse(less_encoded[1, less_encoded.length - 1])