Skip to content

Instantly share code, notes, and snippets.

View cookrn's full-sized avatar
👻

Ryan Cook cookrn

👻
View GitHub Profile
@cookrn
cookrn / 00_usage.md
Created April 10, 2012 02:27
A Reasonable `to_map` for `ActiveRecord::Base`

to_map

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

Installation

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

Example Models

@cookrn
cookrn / 00_desc.md
Created April 3, 2012 07:03
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
cookrn / fix.rb
Created March 14, 2012 15:42
Ruby Script to Remove File FOREVER From Git Repo
# 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(
you.r
list.of
@cookrn
cookrn / terms_of_service.markdown
Created March 12, 2012 17:16 — forked from devver/terms_of_service.markdown
Antiqua, Ltd. Terms of Service

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
cookrn / privacy_policy.markdown
Created March 12, 2012 17:16 — forked from devver/privacy_policy.markdown
Antiqua, Ltd. Privacy Policy

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..

@cookrn
cookrn / question_1.js
Created March 4, 2012 03:27
dojo4 quiz #2
// QUESTION
// 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');
};
Foo.bar = function(){
console.log('Foo::bar');
@cookrn
cookrn / rake.zsh
Created February 19, 2012 20:43
Run rake with environment properly loaded
#!/usr/bin/env zsh
rvm-shell "ruby-1.9.3-p0" -c "foreman run bundle exec rake "$argv
@cookrn
cookrn / app.js
Created December 26, 2011 20:18
Push to Resque Queue from Node
require( './boot' );
var DbItem = require( './db_item' )
, item = new DbItem( '123456abcdefg' );
item.queue( function( error , response ){
console.log( 'Response: ' + response );
process.exit();
} );
@cookrn
cookrn / Gemfile
Created December 12, 2011 22:29
Sample RBX Error Output
source :rubygems
gem "sinatra"
group :development do
gem "foreman"
end