Skip to content

Instantly share code, notes, and snippets.

{ "_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" : "test@test.com", "newsletter_signup" : true, "first_name" : null, "remind_timezone" : null, "sms_processed" : false }
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)
@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)
def a; nil; end; def b; 'wee'; end;
c = [:a,:b].map{|m| send(m)}
@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"]
}
@bkimble
bkimble / gist:1365005
Last active May 2, 2024 01:27
List local memcached keys using Ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@bkimble
bkimble / param_spec.rb
Created December 16, 2012 04:49
Typhoeus URL testing
require 'spec_helper'
#Ethon param test
describe Ethon::Easy::Params do
before do
@dataset =
[
#basics
["http://a.com", {:foo => '1'}, "http://a.com?foo=1"],
["http://a.com", {:foo => 1}, "http://a.com?foo=1"],
//= require foo.js
(function($, _, Backbone){
Backbone._ = _;
Backbone.$ = $;
})
//= require bar.js
($.noConflict(), _.noConflict(), Backbone.noConflict());
#!/usr/bin/ruby
puts "hello"
require 'tempfile'
puts ARGV[1]
filename,lines,prefix = ARGV
unless filename && lines
#!/usr/bin/ruby
puts "hello"
require 'tempfile'
puts ARGV[1]
filename,lines,prefix = ARGV
unless filename && lines