Skip to content

Instantly share code, notes, and snippets.

View Fitzsimmons's full-sized avatar

Justin Fitzsimmons Fitzsimmons

View GitHub Profile
@Fitzsimmons
Fitzsimmons / rich_domain_models2.md
Created September 24, 2012 17:05 — forked from vsavkin/rich_domain_models2.md
Building Rich Domain Models in Rails (revision 2)

Building Rich Domain Models in Rails

Part 1. Decoupling Persistence

Abstract

Domain model is an effective tool for software development. It can be used to express really complex business logic, and to verify and validate the understanding of the domain among stakeholders. Building rich domain models in Rails is hard. Primarily, because of Active Record, which doesn't play well with the domain model approach.

One way to deal with this problem is to use an ORM implementing the data mapper pattern. Unfortunately, there is no production ready ORM doing that for Ruby. DataMapper 2 is going to be the first one.

Another way is to use Active Record just as a persistence mechanism and build a rich domain model on top of it. That's what I'm going to talk about here.

@Fitzsimmons
Fitzsimmons / gist:3548815
Created August 31, 2012 03:41
Passing context in javascript
var that = this;
this.player.on("audio-ended", function() {
that.next();
});
//-------VERSUS-----------
this.player.on("audio-ended", function() {
this.next();
}, this);
@Fitzsimmons
Fitzsimmons / block_test.rb
Created June 4, 2012 17:16
Local Jump Errors
class T
def initialize(&block)
self.class.send(:define_method, :runner, &block)
end
def do_stuff
self.runner do |thing|
puts thing
end
end
@Fitzsimmons
Fitzsimmons / spark.md
Created April 25, 2012 15:00 — forked from jesperfj/spark.md
Spark on Heroku

This guide will get you started using Spark on Heroku/Cedar. Spark is basically a clone of Sinatra for Java. 'Nuff said.

Create your app

Create a single Java main class in src/main/java/HelloWorld.java:

import static spark.Spark.*;
import spark.*;
tm22-s00334 rabbitmq # ls -l
total 59624
-rw-r--r-- 1 rabbitmq rabbitmq 0 Mar 27 03:10 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 94393 Mar 27 03:10 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 0 Mar 26 03:10 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 51897 Mar 26 03:10 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 20 Mar 27 03:10 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 34326652 Mar 27 11:00 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 32088122 Mar 27 03:10 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 0 Mar 26 03:10 [email protected]
@Fitzsimmons
Fitzsimmons / rabbitbench.rb
Created February 27, 2012 20:09
Bunny benchmarking
require 'benchmark'
require 'rubygems'
require 'bunny'
m = "<event>
<string1>123456790123456790123456790123456790</string1>
<string2>123456790123456790123456790123456790</string2>
<string2>123456790123456790123456790123456790</string2>
<string2>123456790123456790123456790123456790</string2>
nulogy@tm22-s00081 ~ $ sudo /usr/sbin/passenger-status
----------- General information -----------
max = 4
count = 4
active = 4
inactive = 0
Waiting on global queue: 2
----------- Application groups -----------
/data/nulogy/current:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16965 nulogy 18 0 2372m 1.5g 100 D 17 41.8 267:41.66 Rack: /data/nulogy/current
1466 nulogy 18 0 667m 527m 392 R 9 14.0 3:45.65 Rack: /data/nulogy/current
1457 nulogy 18 0 659m 523m 420 R 18 13.9 3:32.19 Rack: /data/nulogy/current
1460 nulogy 18 0 585m 451m 680 R 18 12.0 3:14.81 Rack: /data/nulogy/current
1407 nulogy 24 0 522m 344m 336 S 0 9.1 0:33.26 Passenger ApplicationSpawner: /data/nulogy/current
1463 nulogy 18 0 554m 316m 336 D 13 8.4 1:56.39 Rack: /data/nulogy/current
11549 nulogy 18 0 789m 178m 84 R 14 4.7 55:40.76 Rack: /data/nulogy/curren
@Fitzsimmons
Fitzsimmons / gist:1288255
Created October 14, 2011 20:34
bundle exec helper for zsh
# Customize to your needs...
be() {
if [[ -a Gemfile ]]; then
bundle exec $*
else
command $*
fi
}
@Fitzsimmons
Fitzsimmons / gist:1207304
Created September 9, 2011 20:54
Dev review helper functions
### ZSH
### Add one of these to your .zshrc
# Outputs a github link that you can click on to see the diff
devreview() {
if [[ -n $1 ]]; then
git log --pretty=oneline | egrep "Merge branch '${1}.*' into (dev|release|rails_3)" | awk '{print "https://github.com/nulogy/packmanager/commit/" $1}'
fi
}