Skip to content

Instantly share code, notes, and snippets.

View chrismo's full-sized avatar

chrismo chrismo

View GitHub Profile
@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
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 / 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)))))
)
module Car
def vroom
'<car noise>'
end
end
module Boat
def vroom
'<boat noise>'
end
@chrismo
chrismo / method_logger_test.rb
Created September 13, 2012 15:33 — forked from nhance/method_logger.rb
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
# converted to stand-alone script
require 'minitest/autorun'
require 'minitest/unit'
require 'stringio'
# fake out the logger
class Rails
@@logger = StringIO.new
@chrismo
chrismo / gist:3800936
Created September 28, 2012 16:55
Non-merging copying over of changes from branch to branch
If file exists in both places:
git diff target_branch source_branch relative_path_to_file | git apply
If file is new on other branch:
git checkout source_branch relative_path_to_file
The checkout will work even if the file exists, and will stomp it,
@chrismo
chrismo / howto.txt
Created November 1, 2012 17:09
How to spelunk code in RubyMine with git
Open git history for the file.
In annotate view, find the line of code and the sha.
Select history view and start typing the sha until it's selected.
Type 'esc', then down arrow.
Right-click and select "Annotate" - this will open the prior rev in the editor in annotate view.
Find that line of code and repeat.
@chrismo
chrismo / child_at_exit.rb
Created November 7, 2012 15:44
Using at_exit with fork
child = fork do
at_exit { $stderr.puts "Child one is done." }
exit # superfluous
end
Process.wait
$stderr.puts "Parent is done waiting for child one #{child}."
child = fork do
at_exit { $stderr.puts "This won't get hit." }
exit!
@chrismo
chrismo / output.txt
Created November 27, 2012 22:25
all(?) things at_exit and otherwise
18930: Parent
18933: Child A
18934: Child B
18933: END in child if only exit called
18933: at_exit in child if only exit called
18933: parent END (only one)
18933: parent at_exit (2 times)
18933: parent at_exit (2 times)
18930: parent: child died
18930: parent trap(0)