Skip to content

Instantly share code, notes, and snippets.

View chrismo's full-sized avatar

chrismo chrismo

View GitHub Profile
@chrismo
chrismo / copr.md
Last active April 9, 2021 18:15
Git: Checkout PR

Greg Vaughn posted this cool alias the other day:

copr = "!f() { git fetch -fu origin refs/pull/$1/head:pr-$1; git checkout pr-$1; } ; f"

Preferring to be a stock-tools person, I wanted to deconstruct this to see how I'd use it off-the-shelf without the alias.

git fetch     -- I'm already familiar with this command
-fu           -- these two flags I'm not sure are necessary, esp. -u since the help says, 
 "unless you are implementing your own Porcelain you are not supposed to use 
@chrismo
chrismo / quote.txt
Created March 11, 2014 18:37
ActiveRecord limitations in PoEAA
As the domain logic gets more complicated and you begin moving toward a
rich Domain Model (116), the simple approach of an Active Record (160)
starts to break down. The one-to-one match of domain classes to tables
starts to fail as you factor domain logic into smaller classes.
Relational databases don't handle inheritance, so it becomes difficult
to use strategies [Gang of Four] and other neat OO patterns. As the
domain logic gets feisty, you want to be able to test it without having
to talk to the database all the time.
Fowler, Martin (2002-11-05). Patterns of Enterprise Application
@chrismo
chrismo / test.rb
Created April 22, 2013 22:47
elsif
irb(main):001:0> a = 2
=> 2
irb(main):002:0> if a == 0
irb(main):003:1> puts 'zero'
irb(main):004:1> elsif a < 2
irb(main):005:1> puts 'less than 2'
irb(main):006:1> else
irb(main):007:1* puts 'greater than or equal to 2'
irb(main):008:1> end
greater than or equal to 2
require 'tmpdir'
def setup
dir = Dir::tmpdir
%w(system.log 20130330.log 20130329.log).each do |fn|
File.open(fn, 'w') { |f| f.print 'fake contents' }
end
end
def rotate_logs
@chrismo
chrismo / .ruby-version
Last active December 15, 2015 09:59
parley IO question
1.9.3-p385
@chrismo
chrismo / .ruby-version
Last active December 14, 2015 20:40
private method refactor
1.9.3-p385
@chrismo
chrismo / fixture.rb
Created March 5, 2013 05:11
DIY fixture base class
class BaseFixture
def self.create(opts={})
fixture = self.new(opts)
fixture.save!
fixture
end
end
class UserFixture < BaseFixture
def self.new(opts={})
@chrismo
chrismo / README.md
Last active October 19, 2016 20:32
Bundler 1.3 --binstubs vs. Rails 4

On a clean Rails 4 install with Bundler 1.3.0, using --binstubs causes competition between Rails and Bundler for the contents of bin/rails (and bin/rake).

Just running bundle will rewrite the Rails version of bin/rails to a version that doesn't work.

The fix is to use the new bundle binstubs <gemname> command.

(see rails/rails#8974)

@chrismo
chrismo / loop_zip.rb
Last active December 11, 2015 14:58
loop_zip
require 'minitest/autorun'
def loop_zip(a, b)
b = b * ((a.length / b.length) + 1) if a.length > b.length
a.zip(b)
end
class TestLoopZip < MiniTest::Unit::TestCase
def test_2_and_3
assert_equal [['a', 1], ['b', 2]], loop_zip(%w(a b), [1, 2, 3])
@chrismo
chrismo / .gitignore
Created December 7, 2012 18:38
idempotent alias_method_chain
.bundle
.rbenv-version
zz_gems
bin