Skip to content

Instantly share code, notes, and snippets.

View chrismo's full-sized avatar

chrismo chrismo

View GitHub Profile
@chrismo
chrismo / .ruby-version
Last active December 14, 2015 20:40
private method refactor
1.9.3-p385
@chrismo
chrismo / .ruby-version
Last active December 15, 2015 09:59
parley IO question
1.9.3-p385
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 / 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
@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 / 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 
Coloured fox fur production, HOPEDALE, Labrador, 1834-1842
#Source: C. Elton (1942) "Voles, Mice and Lemmings", Oxford Univ. Press
#Table 17, p.265--266
29
22
2
16
12
35
8
@chrismo
chrismo / bundle editor.sh
Last active December 12, 2022 02:13
Sequel Pro Format Sql Bundle
ruby formatsql.rb "$(cat)"
@chrismo
chrismo / gist:809e901313061c0358a5
Created February 19, 2015 16:35
4clojure #33
(fn [coll x]
(apply concat
(map
(fn [item]
(map
(fn [_] identity item)
(range x)))
coll)))
(fn [x coll]
(keep #(if (= (count %) x) % nil)
(map #(map last %)
(vals
(group-by
#(quot (first %) x)
(map-indexed #(vector % %2) coll)))))
)