Skip to content

Instantly share code, notes, and snippets.

Avatar
👻

Ryan Cook cookrn

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

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 Apr 3, 2012
Ruby Object Constructors
View 00_desc.md

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 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(
you.r
list.of
@cookrn
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..

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

View question_1.js
// 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 Feb 19, 2012
Run rake with environment properly loaded
View rake.zsh
#!/usr/bin/env zsh
rvm-shell "ruby-1.9.3-p0" -c "foreman run bundle exec rake "$argv
@cookrn
cookrn / app.js
Created Dec 26, 2011
Push to Resque Queue from Node
View app.js
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 Dec 12, 2011
Sample RBX Error Output
View Gemfile
source :rubygems
gem "sinatra"
group :development do
gem "foreman"
end