Skip to content

Instantly share code, notes, and snippets.

@jmccartie
jmccartie / system.mdml
Created January 15, 2011 16:13
New System install
Keeping track of items to install with a fresh system.
Textmate
HAML bundle: https://github.com/phuibonhoa/handcrafted-haml-textmate-bundle
if (![self check]) { [self wreck]; }
def leppard(shotgun)
shotgun ? shoot : !shoot
end
@jmccartie
jmccartie / idip.js
Created January 21, 2011 20:55
(courtesy of @nathansmith)
my.hand = function (upon(your_hip)) {
while (i.dip) {
you.dip();
we.dip();
}
}
@jmccartie
jmccartie / grades.yml
Created March 29, 2011 03:12
attempt to compare difficulties of rock climbing (YDS, Hueco, French). Not equality, but level of difficulty/reward.
0:
yds: <5.5
hueco: VB
french: <2+
1:
yds: 5.5
hueco: VB
french: 3-
2:
yds: 5.6
@jmccartie
jmccartie / migration.rb
Created March 30, 2011 16:13
Migrating from a has_one relationship to a has_and_belongs_to_many
class RemoveCategoryIdFromItem < ActiveRecord::Migration
def self.up
# Migrate items from has_many
Item.all.each do |item|
CategoriesItems.create(:item_id => item.id, :category_id => item.category_id)
end
remove_column :items, :category_id
end
# How I might do it 3 months ago in a different language
n = 0
item.categories.each do |category|
puts category.title
break if n == item.categories.count
puts ", "
n += 1
end
# How I tried it first in ruby
@jmccartie
jmccartie / helper_spec.rb
Created April 1, 2011 04:19
simple helper with cookie and it's test that won't work
# helper
# Set first_time? cookie
def set_first_time_cookie
cookies[:first_time] = {
:value => 'false',
:expires => 30.years.from_now,
}
end
# spec
@jmccartie
jmccartie / notifications.rb
Created April 25, 2011 20:42
Rails 3 error warning for slow queries
# config/initializers/notifications.rb
# created by @JEG2
if Rails.env == "development"
ActiveSupport::Notifications.subscribe(
"sql.active_record"
) do |_, start, finish, _, details|
time = finish - start
if time >= 0.5
raise "Slow query (#{time}s): #{details[:sql]}"
@jmccartie
jmccartie / tiger-commit.sh
Created April 26, 2011 21:31
tiger-commit
$ gem install tigerblood
$ tiger-commit
$ git log
commit 395ced32f5bedc29e5002f4b787cc20c497bea1a
Author: Charlie Sheen <[email protected]>
Date: Tue Apr 26 16:30:28 2011 -0500
testing