This file contains hidden or 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
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( | |
# 4/5/9 | |
:mdy => proc { |t| t.strftime('%m/%d/%y').gsub /(\b)0/, '\1' } | |
) |
This file contains hidden or 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
value = | |
10.times do |i| | |
if i == 5 | |
break "found five!" | |
end | |
end | |
value # => "found five!" |
This file contains hidden or 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 FilterableEnumerable | |
def initialize(original) | |
@original = original | |
end | |
def ==(value) | |
@original.select { |v| v == value } | |
end | |
def method_missing(sym, *args, &block) |
This file contains hidden or 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 reindent(data, base) | |
lines = data.split("\n") | |
smallest_indentation = lines.collect { |l| l =~ /\w/ }.min | |
lines.each do |line| | |
line.gsub!(/^\s{#{smallest_indentation}}/, ' ' * base) | |
end | |
lines.join("\n") | |
end |
This file contains hidden or 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 FilterableEnumerable | |
def initialize(original) | |
@original = original | |
end | |
def >(value) | |
@original.select { |v| v > value } | |
end | |
def >=(value) |
This file contains hidden or 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
88888! |
This file contains hidden or 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 make_class(klass) | |
::Object.class_eval " | |
class #{klass} < #{self} | |
end | |
" | |
end |
This file contains hidden or 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 /some/rails/project/script/runner | |
# Shows every class that contains capitalized method names and the "offending" methods. | |
methods = {} | |
ObjectSpace.each_object(Class) do |klass| | |
capitalized_methods = klass.methods.select { |m| m =~ /[A-Z]/ } | |
unless capitalized_methods.empty? | |
methods[klass] = capitalized_methods | |
end |
This file contains hidden or 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
# Nginx cache busting rewriter, best used on assets that have long-lived expires. | |
# | |
# Rewrites like so: | |
# blah.com/release_ab2ea212312.../file.css => blah.com/file.css | |
# | |
location ~ ^/release_(.*?)/ { | |
rewrite ^/release_(.*?)/(.*)$ /$2 last; | |
} |
This file contains hidden or 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/ruby | |
files = {} | |
Dir.glob('**/*').each do |file| | |
basename = File.basename(file).downcase | |
if File.file?(file) | |
files[basename] ||= [] | |
files[basename] << file | |
end | |
end |