Skip to content

Instantly share code, notes, and snippets.

@bkimble
bkimble / gist:1346429
Created November 7, 2011 22:35
Association Helper Methods with .fields for MongoMapper
# Module to allow us to query listings and get back a Plucky object so we can
# continue to form the query before firing it off to mongo. Include this in
# any model that has many :listings. This is to get around MongoMapper
# not allowing us to use methods on the association helper methods it adds to
# the classes. Billy Kimble 2011-05-01
module ListingsFinder
FIELDSETS = {
'homepage' => ["id","title","description"]
}
def a; nil; end; def b; 'wee'; end;
c = [:a,:b].map{|m| send(m)}
@bkimble
bkimble / gist:1282088
Created October 12, 2011 18:25
Reproduction process for Typhoeus max concurrency issues with zlib
#!/usr/bin/env ruby
require 'rubygems'
require 'typhoeus'
hydra = Typhoeus::Hydra.new(:max_concurrency => 1)
hydra.disable_memoization
typh_options = {:headers => {"Accept-Encoding" => "deflate, gzip"}, :method => :get, :verbose => false}
r1 = Typhoeus::Request.new("http://www.yahoo.com/", typh_options)
ree-1.8.7-2011.03 :001 > GeoIpBlock.count
=> 6055096
ree-1.8.7-2011.03 :005 > GeoIpBlock.first.e.class.name
=> "Fixnum"
ree-1.8.7-2011.03 :006 > res = Benchmark.measure { puts GeoLocation.by_ip('74.220.125.3').location }; puts res
San Francisco, CA
0.000000 0.000000 0.000000 ( 0.003826)
{ "_id" : { "$oid" : "4e711ac4d413190fcc0000c2" }, "popularids" : [], "listing_ids" : [], "email_optin" : true, "sms_age_verification" : null, "created_at" : { "$date" : 1316035268000 }, "sms_alert" : false, "updated_at" : { "$date" : 1316035268000 }, "categoryids" : [ 5118494, 5118936, 5118495, 5118487, 5118492, 5118924, 5118993, 5118498, 5118497, 5118521 ], "email_processed" : false, "mobile_number" : null, "email_alert" : true, "last_name" : null, "storeid" : 2395871, "email_age_verification" : true, "remind_time" : null, "sms_optin" : true, "brandids" : [ -2099999884, -2099997271, -2099998575 ], "email" : "[email protected]", "newsletter_signup" : true, "first_name" : null, "remind_timezone" : null, "sms_processed" : false }