Skip to content

Instantly share code, notes, and snippets.

View distributedlife's full-sized avatar

Ryan Boucher distributedlife

View GitHub Profile
@distributedlife
distributedlife / runjob_if_not_running.sh
Created November 2, 2011 00:40
Run a script if a process is not running
#!/bin/bash -e
#$1 = the regex to identify the job; should use the pattern "[m]y job"
#$2 = the script to run
REGEX=$1
SCRIPT=$2
#try and get the PID
PSID=`ps -ef | grep "$REGEX" -m 01 | awk '{print $2}'`
@distributedlife
distributedlife / with_object.rb
Created April 11, 2012 12:51
Is this necessary?
def with object
yield(object)
end
#so I can do this:
with Project.create do |project|
Task.create(:project_id => project.id)
end
Feature: Who cares?
Scenario: valid user accounts can log in
When I have a valid user account
Then I can login
@distributedlife
distributedlife / coverage_100p_bhahaha.rb
Created May 9, 2012 01:50
You fool, you foolish fool. 100% code coverage is dumb.
def reciprocal integer
1.0 / integer
end
describe 'reciprocal' do
it 'should return 1 over the integer' do
reciprocal(2).should == 0.5
end
end
@distributedlife
distributedlife / specaroony.rb
Created June 28, 2012 02:54
tapestry specs
describe "a photo" do
it "should have a resource location"
it "should have EXIF data"
it "can include one or more people"
end
describe "a stack" do
it "should have at least one photo"
it "should have at least one bubbled photo"
it "can have zero or more sub stacks"
@distributedlife
distributedlife / tagtastic.rb
Created June 28, 2012 05:53
tagtastic specs
describe "tagtastic" do
it "should recurse all the folders lazily"
describe "in preparation mode" do
it "should remove images"
it "should calculate the musicbrainz poid"
it "should store the poid as originalfilename.poid"
it "should look up the musicbrainz data for the poid and store it in originalfilename.json"
it "should log all files with no poid"
end
@distributedlife
distributedlife / rspec_include.rb
Created July 1, 2012 06:42
rspec include files in lib path
Dir["lib/*.rb"].each {|f| require File.join(File.dirname(__FILE__), "../", f)}
@distributedlife
distributedlife / exhibit_a.js
Created July 16, 2012 09:37
How best to model thi
draw = function() {
painter.clear();
things.forEach(function(thing) {
if(thing.active) {
painter.draw(thing);
}
});
};
@distributedlife
distributedlife / bullet_view.js
Created August 1, 2012 11:49
How do I mock the dependency of the things under test?
define(["game/thing_view"], function(ThingView) {
return function(THREE, bullet) {
var _this = new ThingView(THREE, bullet, "/public/img/tank_bullet.png")
return _this;
}
});
@distributedlife
distributedlife / require_js_unbind.coffee
Created August 21, 2012 11:24
what to do when you are unsure of what mocked requirejs AMD modules you need to unbind
unbind_all_the_things = (requirejs) ->
defined = requirejs.s.contexts._.defined
requirejs.undef(module) for module in Object.keys(defined)