Skip to content

Instantly share code, notes, and snippets.

@croaky
croaky / .ruby-version
Created April 10, 2013 21:54
Development (.ruby-version) / CI (config/tddium.yml) / production (https://devcenter.heroku.com/articles/ruby-support) parity of Ruby versions down to patch level.
1.9.3-p392
class Customer
def initialize(attrs = {})
@id = attrs[:id]
@country = attrs[:country]
end
def tax_code
TaxCodes[@country].call(@id)
rescue
raise "Tax codes for #{@country} not supported"
@croaky
croaky / thank-you.md
Created November 9, 2012 22:44 — forked from anonymous/thank-you.md
This Week in Open Source

This Week in Open Source

Thanks to this week's contributors to thoughtbot projects.

Test your Ruby gem against different versions of its dependencies.

avatar Joe Ferris

module DelayedJob
module Matchers
def enqueue_delayed_job(handler)
DelayedJobMatcher.new handler
end
class DelayedJobMatcher
def initialize(handler)
@handler = handler
@attributes = {}
@croaky
croaky / bid_offered_job.rb
Created July 27, 2012 06:28
Delayed::Job example
class BidOfferedJob < Struct.new(:bid_id)
PRIORITY = 1
def self.enqueue(bid)
Delayed::Job.enqueue new(bid.id), priority: PRIORITY
end
def perform
Mailer.bid_offered(owner, bid).deliver
Activity.create activity_type: 'bid_offered', subject: bid, user: aide
@croaky
croaky / migration.rb
Created July 27, 2012 04:00
Adding indexes CONCURRENTLY in Rails
class AddIndexToUsersSubscriptionToken < ActiveRecord::Migration
def self.up
change_column_null :users, :subscription_token, false
if ENV['NO_DDL_TRANSACTION']
execute <<-eosql
CREATE UNIQUE INDEX CONCURRENTLY index_users_on_subscription_token
ON users (subscription_token)
eosql
else
@croaky
croaky / _activity_feed.html.haml
Created June 26, 2012 17:26
Activity Feed pattern
%ul
- activities.each do |activity|
%li
.activity{ data: { role: activity.activity_type } }
= render_activity activity
@croaky
croaky / gist:2957583
Created June 20, 2012 01:32
Getting a production dump from Heroku backups
curl -o latest.dump `heroku pgbackups:url --app project-production`
pg_restore --verbose --clean --no-acl --no-owner -d project_development latest.dump
rm latest.dump