Skip to content

Instantly share code, notes, and snippets.

View thermistor's full-sized avatar
🏠
Working from home

Weston Triemstra thermistor

🏠
Working from home
View GitHub Profile
alias dewip="sed -E -i '' -e '/^[[:blank:]]*@wip$/d;s/,[[:blank:]]*@wip//g;s/@wip,[[:blank:]]*//g' features/*.feature"

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@thermistor
thermistor / assets.rake
Created October 20, 2011 13:55 — forked from shedd/assets.rake
Check asset encoding for valid UTF-8
namespace :assets do
desc "Check that all assets have valid encoding"
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
extensions = ["js", "coffee", "css", "scss"]
paths.each do |path|
dir_path = Rails.root + path
@thermistor
thermistor / delayed_job.rb
Created November 19, 2011 19:38
have failed jobs report via airbrake as well
# have failed jobs report via airbrake as well
# save it as config/initializers/delayed_job.rb
class Delayed::Worker
protected
def handle_failed_job_with_airbrake(job, error)
Airbrake.notify_or_ignore(error)
handle_failed_job_without_airbrake(job, error)
end
@thermistor
thermistor / deploy.rb
Created June 26, 2012 23:47 — forked from ryanb/deploy.rb
Check to see if you have changes in head which have not been pushed before deploying
namespace :deploy do
desc "Make sure there is something to deploy"
task :check_revision, :roles => :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
@thermistor
thermistor / chef_solo_bootstrap.sh
Last active October 6, 2015 13:28 — forked from wadtech/chef_solo_bootstrap.sh
Bootstrap Chef Solo for Ubuntu 12.04 LTS
#!/usr/bin/env bash
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.bz2
tar -xvjf ruby-2.0.0-p195.tar.bz2
cd ruby-1.9.3-p327/
./configure --prefix=/usr/local
make
@thermistor
thermistor / gist:3107339
Created July 13, 2012 20:44 — forked from ericbeland/gist:846482
Slow Down webdriver in Capybara (Monkeypatch for 0.1.3)
# This is a total hack to slow down webdriver in Capybara
# so you can more easily watch what is happening.
# paste this above the top of a Capybara Webdriver RSpec test if you need to debug something in slo-mo
require 'selenium-webdriver'
module ::Selenium::WebDriver::Remote
class Bridge
def execute(*args)
set :user, 'application'
set :application, 'nayada'
set :deploy_to, "/#{user}/rails/#{application}-git"
ssh_options[:paranoid] = false
ssh_options[:port] = 389
role :app0, "94.127.68.83", :primary => true
namespace :deploy do
@thermistor
thermistor / index.html
Created August 17, 2012 04:52 — forked from anonymous/index.html
This is just an experiment! There are certainly better ways to show an image of a MacBook, but none as fun as this :)
<i class="macbook"></i>
@thermistor
thermistor / OPTIONS.rb
Created September 18, 2012 17:10 — forked from ajturner/OPTIONS.rb
make Rails respond to an HTTP OPTIONS method request
# Add to routes.rb
# Needed for responding to OPTIONS http method
map.connect '*path',
:controller => 'home',
:action => 'options_for_mopd',
:conditions => {:method => :options}
# in home_controller.rb