Skip to content

Instantly share code, notes, and snippets.

View billhorsman's full-sized avatar

Bill Horsman billhorsman

View GitHub Profile
@billhorsman
billhorsman / circle.yml
Created September 2, 2012 22:35
Circle CI Config for deployment to Heroku with 10 min timeout
deployment:
staging:
branch: master
commands:
- git push [email protected]:yakify-ci.git:
timeout: 600
dependencies:
pre:
@billhorsman
billhorsman / twice.rb
Created June 22, 2012 08:03
Two simple queries instead of one complex (or impossible) one.
# Problem: the query you want to build to bring back the right objects is complicated. When
# you try and eagerly load the objects you need it all breaks and goes to shit. This often
# happens if you are using "group" or "count", for instance. If you don't eagerly load the
# objects you need then you have an n+1 (or worse) problem as you make an additional query
# for each object you use.
# So try doing the query in two parts: 1) get the primary key for each object you need,
# 2) eagerly load all the objects that match.
# Grab the ids. Don't worry about eagerly loading. The important thing is that it doesn't
@billhorsman
billhorsman / descriptive_sql_load_log.rb
Created July 20, 2011 14:35 — forked from JackDanger/descriptive_sql_load_log.rb
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Turn:
# User Load (6.3ms) SELECT * FROM "users"
# Into:
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users"
<%= stylesheet_link_tag :global, :cache => (Rails.env == 'development' ? nil : 'global') %>