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
| # This is not the best example, but imagine a Rails project with lots of complex logic and methods and stuff... | |
| # Imagine that Base is an 500 line ActiveRecord model... :) | |
| require 'rubygems' | |
| require 'active_support/core_ext' | |
| Customer = Struct.new(:id, :first_name, :last_name, :company_name) | |
| ## Implementation directly in the class | |
| # Pros: |
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 ruby | |
| `git diff --cached --name-only --diff-filter=AM`.lines.each do |filename| | |
| path = File.join(Dir.pwd, filename.strip) | |
| puts "Checking syntax of #{ filename.strip }" | |
| case filename | |
| when /.haml$/ | |
| exit 1 unless system('haml', '--check', path) | |
| when /.scss$/ | |
| exit 1 unless system('scss', '--check', path) |
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 CaseComparator | |
| def initialize(object, operator) | |
| @object = object | |
| @operator = operator | |
| end | |
| def ===(other) | |
| other.send(@operator, @object) | |
| 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
| require 'formula' | |
| class Vim < Formula | |
| homepage 'http://www.vim.org/' | |
| url 'ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2' | |
| head 'https://vim.googlecode.com/hg/' | |
| sha256 '5c5d5d6e07f1bbc49b6fe3906ff8a7e39b049928b68195b38e3e3d347100221d' | |
| version '7.3.294' | |
| def features; %w(tiny small normal big huge) 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
| ZSH_THEME_GIT_PROMPT_PREFIX=" %F{208}❨%F{220}" | |
| ZSH_THEME_GIT_PROMPT_SUFFIX="%F{208}❩%{$reset_color%}" | |
| ZSH_THEME_GIT_PROMPT_DIRTY="%F{196}✻%{$reset_color%}" | |
| ZSH_THEME_GIT_PROMPT_CLEAN="" | |
| PROMPT=$'%F{196}%M %F{202}%~%{$reset_color%}$(git_prompt_info)%{\e[%(?.32.31);1m%} ➔%{$reset_color%} ' |
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
| require 'rspec-expectations' | |
| class RSpec::Expectations::Differ | |
| def diff_as_object(a, b) | |
| if a.is_a?(Time) && b.is_a?(Time) | |
| minutes, seconds = (b - a).divmod(60) | |
| hours, minutes = minutes.divmod(60) | |
| Kernel.format(" %dh %dm %ds \nactual: %s\nexpected: %s", hours, minutes, seconds % 60, b.utc.to_s, a.utc.to_s) | |
| else | |
| super |
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 ruby | |
| if match = `git symbolic-ref HEAD 2> /dev/null`.split('/').last.to_s.match(/^(?:t|s)-?(\d+)$/) | |
| message = File.read(ARGV.first) | |
| message.gsub!("STORYID", "[##{ match[1] }]") | |
| File.open(ARGV.first, 'w') do |f| | |
| f.puts(message) | |
| 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 ruby | |
| require 'rubygems' | |
| require 'pivotal-tracker' | |
| class String | |
| ANSI_COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white] | |
| def colorize(color) | |
| num = ANSI_COLORS.index(color) or raise("Bad color #{ color }") | |
| "\e[3#{ num }m" + self + "\e[0m" |
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 Multibench | |
| def initialize | |
| @benches = Hash.new { 0 } | |
| end | |
| def bench(title) | |
| start = Time.now | |
| yield.tap do | |
| @benches[title] += Time.now - start | |
| 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 ruby | |
| # Usage: | |
| # runonupdate "spec spec/models/cat_spec.rb -O spec/spec.opts" app/models/cat.rb app/models/dog.rb | |
| # | |
| # This will run cat-specs whenever cat.rb or dog.rb is updated. | |
| class RunOnUpdate | |
| attr_reader :cmd | |
| attr_reader :files |