Skip to content

Instantly share code, notes, and snippets.

View justindossey's full-sized avatar

Justin Dossey justindossey

  • Laudable Labs
  • San Francisco, CA
View GitHub Profile
@justindossey
justindossey / default.rb
Created October 16, 2014 23:14
Chef recipe showing order of lazy evaluation
node.default.bar.tags = ['tag1-bar']
file "/tmp/bar.txt" do
content lazy { node.bar.tags.join(',') }
end
ruby_block 'update second tag' do
block { node.default.bar.tags << 'tag2-bar' }
only_if { node.default.bar.tags << 'tag3-bar' }
notifies :create, 'file[/tmp/bar.txt]', :delayed
@justindossey
justindossey / test_fd_subscribe_memleak.rb
Created November 15, 2013 20:33
Non-leaking version of bunny logger memory leak test
require 'bunny'
require 'logger'
class TestLoggerSubscribeMemleak
def initialize(msg_count=10_000)
@messages_to_write = msg_count
@message_count = msg_count
@connection = Bunny.new(:user=>"jbd_dev_reader", :pass=>"123456", :host=>"localhost", :vhost=>"jbd", :port=>5672)
@connection.start
@channel = @connection.create_channel
@justindossey
justindossey / gist:7490942
Last active December 28, 2015 11:08
ruby 187 memory leak with logger in Bunny::Queue#subscribe
require 'bunny'
require 'logger'
class TestLoggerSubscribeMemleak
def initialize(msg_count=10_000)
@message_count = msg_count
@messages_to_write = msg_count
@connection = Bunny.new(:user=>"test_user", :pass=>"123456", :host=>"localhost", :vhost => "test", :port => 5672)
@connection.start
@channel = @connection.create_channel
@justindossey
justindossey / gist:2255384
Created March 30, 2012 21:40
Flip read_secondary via MongoMapper
trap('USR2') do
# reconnect to MongoDB with read_secondary reversed
result=MongoMapper.connection.instance_eval('@read_secondary = !@read_secondary')
logger.notice("#{Time.now}: now reading from #{result ? 'secondary' : 'primary'}")
end
@justindossey
justindossey / gist:2063267
Created March 17, 2012 17:38
MongoMapper-- check that replicas are within a minute of primary
def all_replicas_in_sync?(verbose=false)
in_sync = true
# connect to the primary
mongo = Mongo::Connection.new(*MongoMapper.connection.primary)
db = mongo.db('local')
last_op=db.collection('oplog.rs').find.sort([['$natural',-1]]).limit(1).to_a[0]
db.collection('slaves').find().to_a.each do |slave|
opdiff = last_op['ts'].increment - slave['syncedTo'].increment
diff = (last_op['ts'].seconds - slave['syncedTo'].seconds)/1000.0
in_sync = false if diff > 60