Skip to content

Instantly share code, notes, and snippets.

@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

Common performance symptoms

The two most common performance symptoms are with throughput or timeouts.

An application's maximum throughput can be measured by how many requests per second it serves; New Relic reports this number as "rpm," which means "requests per minute." Throughput will be limited by how long the average request takes to process and how may servers are available to handle processes. Heroku calls these servers "dynos."

class BidAcceptedJob < Struct.new(:bid_id)
PRIORITY = 1
def self.enqueue(bid)
Delayed::Job.enqueue new(bid.id), priority: PRIORITY
end
def perform
Mailer.bid_accepted(aide, bid).deliver
Activity.create activity_type: 'bid_accepted', subject: bid, user: aide
@croaky
croaky / single_recipient_smtp.rb
Created June 15, 2012 21:52
SingleRecipientSmtp
class SingleRecipientSmtp < ::Mail::SMTP
def initialize(_)
self.settings = {
address: 'smtp.sendgrid.net',
authentication: :plain,
domain: 'myapp.com',
password: ENV['SENDGRID_PASSWORD'],
port: '587',
user_name: ENV['SENDGRID_USERNAME']
}
#!/bin/sh
# Downloads the Twelve-Factor App guide from http://www.12factor.net/ and
# converts it to plain text for easy reading
# Credit to Dan Choi
twelve-factor() {
base=www.12factor.net
out=twelve-factor.txt
rm $out
wget -r http://$base
#!/bin/sh
load-production() {
backup-production
get-backup | restore-from-backup
}
backup-production() {
heroku pgbackups:capture --expire `heroku-production`
}
@croaky
croaky / mentor-playbook.md
Created May 22, 2012 12:22
From Techstars' Mentor Manifesto & other sources
  • Ask tons of questions. Be Socratic.
  • Be authentic. Mentoring is a human interaction.
  • Be challenging but never destructive.
  • Be direct. Tell the truth, however hard.
  • Be optimistic.
  • Be responsive.
  • Clearly commit to mentoring, or do not be a mentor.
  • Clearly separate opinion from fact.
  • Clearly state what is an interruption for you and what isn’t.
  • Communicate with other mentors.