Skip to content

Instantly share code, notes, and snippets.

View nalanj's full-sized avatar
🌴
On vacation

nalanj nalanj

🌴
On vacation
  • Greenville, SC
View GitHub Profile
# Testing exception_notifier the easy way:
class ActionController::Base
alias :rescue_action_locally :rescue_action_in_public
end
# Cycling Through A Set of Strings With Sequency
#
# It's pretty easy to use Sequency (http://github.com/commondream/sequency) to cycle through a set of
# strings when creating factories.
#
# I got this data from the US Social Security Administration website (http://www.ssa.gov/OACT/babynames/)
Sequence.define(:first_name) do |i|
names = %w( Jacob Emily Michael Isabella Ethan Emma Joshua Ava Daniel Madison Christopher
Sophia Anthony Olivia William Abigail Matthew Hannah Andrew Elizabeth )
-- Script to display the names of files that are missing from your iTunes Library
-- Adapted from the script at http://www.macosxhints.com/article.php?story=2007031309145927
tell application "iTunes"
set thePlaylist to library playlist 1
set musicFiles to the file tracks of thePlaylist
repeat with mf in musicFiles
--the name of mf as string
set hasLoc to ""
# Getting postgres gem to install on OS X requires that you have the ARCHFLAGS environment variable set
# correctly
sudo env ARCHFLAGS="-arch i386" gem install postgres
# Reusable mocking of ActiveResource
#
# I use this technique when I need to mock ActiveResource in several tests and it gets a bit too keyboard
# heavy to use the default mechanism.
# Shortcut for typing ActiveResource::HttpMock.respond_to
def ar_mock(&block)
ActiveResource::HttpMock.respond_to(&block)
end
I'm thinking that the syntax for Industrial Revolution will be something like this:
Defining a Factory
==================
Factory.for Cat do
defaults do
cat = Cat.new
cat.name = "Mr. Whiskers"
cat.color = "Yellow"
# My my.cnf file on my local system. Keeps me from having to type in -u root every time I run MySQL
[client]
user=root
# My command prompt, ripped from someone online that I don't have a link for. Sorry!
function git_current_branch {
git branch 2>/dev/null | awk '/^\* /{print " " $2}'
}
function git_dirty {
git status 2>/dev/null | wc -l | awk '{if ($1 > 2) print "*"}'
}
export PS1="[\w\$(git_current_branch)\$(git_dirty)]: "
# Using mk-table-checksum
# Setting up the checksums from the master
mk-table-checksum --replicate maatkit.checksum localhost
# Checking the checksums on the slave
mk-table-checksum --replicate maatkit.checksum --replcheck localhost
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:-7];
NSDate *weekAgo = [calendar dateByAddingComponents:comps toDate:self.currentDate options:0];