Skip to content

Instantly share code, notes, and snippets.

View mperham's full-sized avatar

Mike Perham mperham

View GitHub Profile
@mperham
mperham / retries.rb
Created October 19, 2012 22:15
Sidekiq retry management API
require 'sidekiq'
module Sidekiq
# Encapsulates a single job awaiting retry
class Retry
attr_reader :score, :item
def initialize(score, item)
@score = score
@item = Sidekiq.load_json(item)
@mperham
mperham / gist:3667520
Created September 7, 2012 16:20
Campfire in 10 lines
##
# Broadcast a message to Campfire
#
# campfire = Campfire.new(options)
# campfire.say("#{self.class.name} finished successfully!")
# campfire.say("trombone", :Sound)
#
def say(msg, type=:Text)
http = Net::HTTP.new("#{options[:subdomain]}.campfirenow.com", 443)
http.use_ssl = true
@mperham
mperham / gist:3651105
Created September 6, 2012 04:11
Campfire's SSL cert doesn't verify with Ruby 1.9.3 p194
# This works for me in 1.9.3-p125 but not in p194.
# Can anyone explain why?
require 'net/http'
http = Net::HTTP.new("theclymb1.campfirenow.com", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new("/login")
response = http.request(request)
raise response.inspect if response.code != '200'
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@mperham
mperham / gist:2485051
Created April 25, 2012 00:58
YAML parsing bug in Ruby 1.9.3?
YAML.parse(BELOW) fails, I believe due to the shipCompany line below which contains a single backtick.
```
--- !ruby/object:Delayed::PerformableMethod
args: []
method_name: :push_to_wh
object: !ruby/ActiveRecord:Cart
attributes:
split_to:
DEPRECATION WARNING: Layout found at "admin/customer_service" for Admin::CustomerServiceController but parent controller set layout to "admin/customer_service". Please explicitly set your layout to "admin/customer_service" or set it to nil to force a dynamic lookup. (called from realtime at /Users/mperham/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/1.8/benchmark.rb:308)
@mperham
mperham / gist:2187468
Created March 24, 2012 20:20
blpop not accurate
redis 127.0.0.1:6379> blpop a, 1
(nil)
(1.49s)
redis 127.0.0.1:6379> blpop a, 1
(nil)
(1.02s)
redis 127.0.0.1:6379> blpop a, 1
(nil)
(1.51s)
redis 127.0.0.1:6379> blpop a, 1
@mperham
mperham / gist:2166351
Created March 23, 2012 02:46
Dalli benchmarks: MRI 1.9.3 vs JRuby 1.6.7
> rake bench
Testing with Rails 3.2.1
Using standard socket IO (jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java])
Run options: --seed 22292
# Running tests:
Testing 2.0.0 with jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
Found memcached 1.4.13 in PATH
user system total real
@mperham
mperham / gist:2165749
Created March 23, 2012 00:21
jruby + dalli = unhappy
src/dalli> JRUBY_OPTS=--1.9 ruby test/benchmark_test.rb
Testing with Rails 3.2.1
/Users/mperham/.rvm/gems/jruby-1.6.7@dalli/gems/minitest-2.11.4/lib/minitest/unit.rb:647 warning: already initialized constant VERSION
/Users/mperham/.rvm/gems/jruby-1.6.7@dalli/gems/minitest-2.11.4/lib/minitest/unit.rb:1021 warning: already initialized constant PASSTHROUGH_EXCEPTIONS
/Users/mperham/.rvm/gems/jruby-1.6.7@dalli/gems/minitest-2.11.4/lib/minitest/unit.rb:1024 warning: already initialized constant SUPPORTS_INFO_SIGNAL
Using standard socket IO (jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java])
Run options: --seed 40696
# Running tests:
@mperham
mperham / gist:2047504
Created March 15, 2012 23:03
Encoding issue
ArgumentError: invalid %-encoding (Men's Advance Lightweight Zip Tee
Channeled construction increases performance, decreases weight. 100% polyester wicks, breathes and dries quickly. Chitosan anti-microbial finish controls odor.
**break**
Wicking, fast drying, antimicrobial fabric is lightweight and comfortable
Flat-lock seams are rotated away from abrasion areas for comfort
2" stand-up collar and 8" front zip for thermoregulation