Skip to content

Instantly share code, notes, and snippets.

View skwp's full-sized avatar

Yan Pritzker skwp

View GitHub Profile
Fixture.class_eval do
def find
if model_class
if model_class.respond_to?(:find_with_deleted)
model_class.find_with_deleted(self[model_class.primary_key])
else
model_class.find(self[model_class.primary_key])
end
else
raise FixtureClassNotFound, "No class attached to find."
class ThreadFactory
if ENV['RAILS_ENV'] == 'development'
class FakeThread
def initialize(&block)
block.call
end
end
def initialize(&block)
FakeThread.new(&block)
# A fast, clean grep for code in a rails directory
function g {
grep -nwrsI --color $1 app/ config/ vendor/ script/ test/ db/ public/
# The version below shows two lines of context around the match
# grep -nwrsIC1 --color $1 app/ config/ vendor/ script/ test/ db/ public/
}
# Prerequisites
# 1. Your commit messages contain ticket numbers such as "Ticket #1234"
# 2. Your collaborators create branches named exactly for the ticket number. So for example, bob/1234
#
# Usage: merged_branches [remote_name]
# Output: A list of branches (tickets) that have already been merged (can be found in your log)
#
function merged_branches {
for branch in `git branch -a | grep $1 | awk '{ print $1 }' | awk -F"/" '{print $2}'`
do
@skwp
skwp / gist:173952
Created August 24, 2009 16:22
Lazy decorator pattern for ruby
# Creates the ability to lazily initialize
# a class. This means the instance will not
# be created until a method is called on it.
# Useful for objects that create connections or
# use other expensive resources.
#
# example:
#
# class ExpensiveObject
# def initialize
#!/bin/bash
cvs -z3 -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy co -P tidy
cd tidy
sh build/gnuauto/setup.sh
./configure --prefix=/usr
make && sudo make install
[user]
name = yan
email = yan@pritzker.ws
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = auto
log = auto
# debugging from console...parse calendar
# note the #first call at the end, because the calendar seems to come
# in a one element array (not sure why)
cal = RiCal.parse_string(File.read("tmp/feeds/1_revolution_cafe/1f66991912759009fd90a29331e4a3f1")).first
# grab the first event
event = cal.events.first
# load your libs
Dir[File.join(File.dirname(__FILE__),"../gems/*/lib")].each { |f| $LOAD_PATH << f }
# add all my app files to the load path so I can require 'app_file_name'
# note that this assumes all your code lives in dirs one level up from test
# if you have many subdirectories you can use a glob like "../**/*" to get all subdirs
Dir[File.join(File.dirname(__FILE__),"../*")].each {|f| $LOAD_PATH << f }
require 'test/unit'
# Load gems so we can load the shoulda tasks
Dir[File.join(File.dirname(__FILE__),"gems/*/lib")].each { |f| $LOAD_PATH << f }
require 'rake'
require 'rake/testtask'
require 'shoulda/tasks'
task :default => [:test_units]
desc "Run basic tests"