This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
require 'tempfile' | |
class File | |
def File.open_safely(path) | |
result, temp_path = nil, nil | |
Tempfile.open("#{File.basename($0)}-#{path.hash}") do |file| | |
result = yield file | |
temp_path = file.path | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP_ERRORS = [Timeout::Error, | |
Errno::EINVAL, | |
Errno::ECONNRESET, | |
EOFError, | |
Net::HTTPBadResponse, | |
Net::HTTPHeaderSyntaxError, | |
Net::ProtocolError] | |
SMTP_SERVER_ERRORS = [TimeoutError, | |
IOError, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# straight Test::Unit | |
# one GET | |
# one failure message to address if something goes wrong | |
# six lines of code | |
# two db records created | |
# no string programming | |
def test_index | |
2.times { Factory(:user) } | |
get :index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Making RSpec concise: | |
# http://opensoul.org/2008/11/10/making-rspec-concise | |
describe Company do | |
it { should have_many(:classifications) } | |
it { should have_many(:events) } | |
it { should have_many(:interests) } | |
it { should have_many(:jobs) } | |
it { should have_many(:leads) } | |
it { should have_many(:locations) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH=/usr/local/bin:/usr/local/mysql/bin/:/opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin:/usr/local/apache2/bin:${HOME}/bin:$PATH | |
export PS1='\W \$ ' | |
export EDITOR='vim -w' | |
export SVN_EDITOR='vim -wd' | |
export CDPATH=.:~:~/dev | |
# ALIASES | |
alias myip='ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_bold=$(tput bold) | |
_normal=$(tput sgr0) | |
__vcs_dir() { | |
local vcs base_dir sub_dir ref | |
sub_dir() { | |
local sub_dir | |
sub_dir=$(stat -f "${PWD}") | |
sub_dir=${sub_dir#$1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
http.get query | |
rescue *HTTP_ERRORS => error | |
notify_hoptoad error | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test | |
require File.dirname(__FILE__) + '/../test_helper' | |
class XMLRendererTest < ActiveSupport::TestCase | |
context "A class with XMLRenderer mixed in" do | |
setup do | |
class ::DummyClass | |
include XMLRenderer | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Originally by Xavier Noria and posted to the Rails Core list here: | |
# http://groups.google.com/group/rubyonrails-core/browse_thread/thread/7554c8c5a25b4765?hl=en | |
# Output has been aggregated at: | |
# http://gist.github.com/20721 | |
require 'rubygems' | |
require 'grit' | |
$KCODE = 'u' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example < ActiveRecord::Base | |
# includes: mixed in behavior | |
# properties: attributes, associations | |
# lifecycle: validations, callbacks | |
# instance methods | |