Skip to content

Instantly share code, notes, and snippets.

View bwillis's full-sized avatar

Ben bwillis

View GitHub Profile
@apolzon
apolzon / resque_profiler.rb
Created March 8, 2012 18:14
Resque Profiler
def time_queue_chomping(size = 10)
if Resque.redis.llen("queue:robot_events").to_i > 0
puts "no way jose, the queue is full of junk!"
return
end
Rails.application.config.logger.level = Logger::WARN
ActiveRecord::Base.logger = ::Logger.new(StringIO.new)
t0 = Time.now.to_i
size.times { Resque.push("robot_events", :class => "RobotEventHandler", :args => [{:occurred_at => DateTime.now, :mailer => Mailer.first.attributes, :action => "fetch_top_line_data", :status => "success", :duration => "5", :response_queue => "ROBOT_EVENTS"}]) }
printed = []
@bwillis
bwillis / active_record_monkey_patch.rb
Created March 22, 2012 16:29
Fix unprecise MySQL dates for active record
class ActiveRecord::Base
DATE_FIELDS = [:created_at, :updated_at]
after_save :make_dates_less_precise
def make_dates_less_precise
DATE_FIELDS.each do |date_field|
if respond_to? date_field
time = self.send(date_field)
@sindresorhus
sindresorhus / post-merge
Last active May 2, 2024 03:18
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"