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 String | |
def escape_single_quotes | |
self.gsub(/'/, "\\\\'") | |
end | |
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
array.inject{|sum,x| sum + x } |
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
# Courtesy http://www.allerin.com/blog/?p=186 | |
class ActiveRecord::Base | |
def self.skip_callback(callback, &block) | |
method = instance_method(callback) | |
remove_method(callback) if respond_to?(callback) |
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
# Taken from http://codesnippets.joyent.com/posts/show/1812 | |
# takes a number and options hash and outputs a string in any currency format | |
def currencify(number, options={}) | |
# :currency_before => false puts the currency symbol after the number | |
# default format: $12,345,678.90 | |
options = {:currency_symbol => "$", :delimiter => ",", :decimal_symbol => ".", :currency_before => true}.merge(options) | |
# split integer and fractional parts | |
int, frac = ("%.2f" % number).split('.') |
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
You can use | |
git add -u | |
To add the deleted files to the staging area, then commit them | |
git commit -m "Deleted files manually" | |
Delete a branch on Github |
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
def format_time_difference(start_time, end_time) | |
difference = end_time.to_i - start_time.to_i | |
hours = difference/3600.to_i | |
minutes = (difference/60 - hours * 60).to_i | |
seconds = (difference - (minutes * 60 + hours * 3600)) | |
sprintf("%02d:%02d:%02d\n", hours, minutes, seconds) | |
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
#!/usr/bin/env ruby | |
# From my blog post at http://www.postal-code.com/binarycode/2009/06/06/better-range-intersection-in-ruby/ | |
class Range | |
def intersection(other) | |
raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range) | |
my_min, my_max = first, exclude_end? ? max : last | |
other_min, other_max = other.first, other.exclude_end? ? other.max : other.last |
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
Time.now.in_time_zone("Eastern Time (US & Canada)") |
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
for i in 1..5 | |
begin | |
do_something_that_might_raise_exceptions(i) | |
rescue | |
next # do_something_* again, with the next i | |
end | |
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
# created by Nathan Broadbent (http://madebynathan.com/2011/03/31/thanks-first-council-of-nicaea/) | |
def easter(year) | |
c=year/100 | |
n=year-19*(year/19) | |
k=(c-17)/25 | |
i=c-c/4-(c-k)/3+19*n+15 | |
i-=30*(i/30) | |
i-=(i/28)*(1 -(i/28)*(29/(i+1))*((21-n)/11)) | |
j=year+year/4+i+2-c+c/4 |
OlderNewer