Skip to content

Instantly share code, notes, and snippets.

@apeckham
apeckham / gist:2918786
Created June 12, 2012 17:16
set DATABASE_URL from database.yml, in environment.rb
# because queue_classic requires DATABASE_URL in test and development
ENV["DATABASE_URL"] ||= begin
config = YAML.load(ERB.new(IO.read(Rails.root.join("config/database.yml"))).result)[Rails.env]
"#{config["adapter"]}://#{config["username"]}:@#{config["host"]}/#{config["database"]}"
end
@apeckham
apeckham / spec_helper.rb
Created June 12, 2012 17:32
run all queue_classic jobs in test
def run_queued_jobs
worker = QC::Worker.new
worker.work until QC.count.zero?
end
ActiveRecord::Base.after_create do |record|
INSTRUMENTAL.increment "#{record.class.to_s.underscore}.create"
end
@apeckham
apeckham / debugging.txt
Created June 13, 2012 22:46
running librato's statsd chef recipe on ec2 with knife-solo, and sending data from Rails
vim /etc/statsd/config.js
add console backend:
"backends": [
"./backends/graphite",
"./backends/console",
"statsd-librato-backend"
],
restart statsd
@apeckham
apeckham / gist:2957023
Created June 19, 2012 22:57
run clockwork in-process
LEFTRONIC = Leftronic.new 'leftronic key'
class Worker
def self.five_second_job
LEFTRONIC.push_number 'widget id', rand
end
end
include Clockwork
handler { |job| Worker.send(job) }
@apeckham
apeckham / gist:2960968
Created June 20, 2012 17:06
paste into the address bar and hit return to hide the orange new version ad on groupme
javascript:$("#web-nag").hide()
@apeckham
apeckham / heroku_headers.rb
Created June 22, 2012 16:19
rails metal to log heroku x-headers in request to statsd
class HerokuHeaders
def self.call(env)
$statsd.gauge('heroku.dynos_in_use', env['HTTP_X_HEROKU_DYNOS_IN_USE'])
$statsd.timing('heroku.queue_wait_time', env['HTTP_X_HEROKU_QUEUE_WAIT_TIME'])
$statsd.gauge('heroku.queue_depth', env['HTTP_X_HEROKU_QUEUE_DEPTH'])
[404, {}, []]
end
end
@apeckham
apeckham / gist:3014943
Created June 29, 2012 00:32
Keep an SSH tunnel running all the time: ~/Library/LaunchAgents/com.example.ssh-tunnel.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.ssh-tunnel</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
@apeckham
apeckham / gist:3140823
Created July 19, 2012 04:47
launchbar url for adding tasks to rememberthemilk via milkmaid gem and rbenv
# http://www.obdev.at/resources/launchbar/help/URLCommands.html
x-launchbar:execute?path=/usr/local/bin/rbenv&arguments=exec+milkmaid+task+add+%22*%22
@apeckham
apeckham / backend.js
Created July 20, 2012 21:30
simple statsd backend that prints json to /var/log/statsd.log
exports.init = function(startup_time, config, events) {
events.on('flush', function(timestamp, metrics) {
console.log(JSON.stringify(timestamp));
console.log(JSON.stringify(metrics));
});
return true;
};