Skip to content

Instantly share code, notes, and snippets.


Ryan Cook cookrn

View GitHub Profile
cookrn / minitest_integration.rb
Created May 18, 2012
Changes that allow the Draper MiniTest/Integration tests to pass
View minitest_integration.rb
require 'minitest/unit'
require 'minitest/spec'
module MiniTest
class DecoratorSpec < Spec
before do
Draper::ViewContext.current.controller.request ||=
Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request
Draper::ViewContext.current.params ||= {}
cookrn /
Last active Mar 29, 2017
Named Screen -- Inspired by @ahoward

Named Screen

A utility inspired by @ahoward that allows screens to be the name of the directory they were spawned from. This is mainly helpful for Terminal/iTerm tabs.

Executing this should rejoin sessions with the same name if they already exist or otherwise create them.


  1. Place or symlink into your path (I symlink as ns)
  2. Ensure the script is executable
View stable_marriage.rb
class Person
def initialize(name)
@name = name
@fiance = nil
@preferences = []
@proposals = []
attr_reader :name, :proposals
attr_accessor :fiance, :preferences
cookrn /
Created Apr 10, 2012
A Reasonable `to_map` for `ActiveRecord::Base`


A to_map function is very useful when you want to convert models to PLAIN OLD DATA. Think presenters, conductors, APIs, JSON, etc...


Add this monkey-patch to your Rails project and call it on your model instances.

Example Models

cookrn /
Created Apr 3, 2012
Ruby Object Constructors

What the what?!

Ruby objects can be built in a way such that they are easier to use/test/debug from the point of view that if you do not automatically run their intended functionality from the constructor, potential side-effects and bugs can be better examined.

In general, I find it helpful to consider a constructors' purpose constrained only to setting instance-level attributes based on the passed arguments or using pre-defined defaults. Anything outside of that, I would consider setting up a class-level factory method.

Consider creating semantically-named factory style class methods that create an object and then call a specific method.

I find this especially helpful for hand-rolled presenters and worker classes (e.g. for Resque).

cookrn /
Created Mar 20, 2012
How to Create and Apply a Patch w/ Git Across Similar Repositories
cookrn / fix.rb
Created Mar 14, 2012
Ruby Script to Remove File FOREVER From Git Repo
View fix.rb
# Make a backup first!
# Place at the root of the desired git repo
# Run w/ commit SHA as first argument e.g. ruby fix.rb 57415b9c864e4128dca805b4a8ad7b7e59281ac6
# All files in your list will be forever removed from the filesystem and git repo from given
# commit up to HEAD
files = %w(
cookrn / terms_of_service.markdown
Created Mar 12, 2012 — forked from devver/terms_of_service.markdown
Antiqua, Ltd. Terms of Service
View terms_of_service.markdown

Terms of Service

Last revised on 03-12-2012

The Gist

Antiqua, Ltd. operates the Antiqua.IO service, which we hope you use. If you use it, please use it responsibly. If you don't, we'll have to terminate your account.

For paid accounts, you'll be charged on a monthly basis. You can cancel anytime, but there are no refunds.

cookrn / privacy_policy.markdown
Created Mar 12, 2012 — forked from devver/privacy_policy.markdown
Antiqua, Ltd. Privacy Policy
View privacy_policy.markdown

Privacy Policy

Last revised on 03-12-2012

The Gist

Antiqua, Ltd. will collect certain non-personally identify information about you as you use our sites. We may use this data to better understand our users. We can also publish this data, but the data will be about a large group of users, not individuals.

The only personal information required to use the service is your email. This will never be sold, disclosed, or otherwise transferred without explicit advance notification (a minimum of 30 days) and the ability to opt out. The only likely scenario where this would be the case is an acquisition of Antiqua, Ltd..

View question_1.js
// write a javascript class, called 'Foo', with a class method 'bar' and an
// instance method 'bar'
var Foo = function Foo(){
console.log('new Foo instance');
}; = function(){