Skip to content

Instantly share code, notes, and snippets.

View nicholasjhenry's full-sized avatar

Nicholas Henry nicholasjhenry

View GitHub Profile
@nicholasjhenry
nicholasjhenry / gist:1362299
Created November 13, 2011 16:33
Recycle App with Module #railsisnotyourapp
# RecycleApp
module RecycleApp
class << self
attr_accessor :can_store
def config
yield self
end
end
end
@nicholasjhenry
nicholasjhenry / AssetFile
Created January 4, 2012 00:42
AssetFile for Rake Pipeline for use with ember.js/handlebars
require "json"
require "rake-pipeline-web-filters"
input "assets"
output "public"
class HandlebarsFilter < Rake::Pipeline::Filter
def initialize(&block)
block ||= proc { |input| input.sub(/\.handlebars$/, '.js') }
super(&block)
@nicholasjhenry
nicholasjhenry / gist:1601567
Created January 12, 2012 16:51
Sproutcore Statechart
TwitterBrowser.EnterUserNameView = SC.TextField.extend({
insertNewline: function() {
TwitterBrowser.statechart.sendEvent('searchForUser', this.get('value'));
}
});
TwitterBrowser.statechart = SC.Statechart.create({
searchForUser: function(userName) {
var recordArray = TwitterBrowser.store.find(
SC.Query.local(TwitterBrowser.User, "userName ='" + userName + "'", {userName: userName}));
@nicholasjhenry
nicholasjhenry / gist:1780623
Created February 9, 2012 15:17
Installing ruby-debug with ruby-1.9.3-p0-falcon
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1780623)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@nicholasjhenry
nicholasjhenry / gist:3024550
Created June 30, 2012 16:34
Hexagonal Rails Example
class AddComment
attr_reader :observer, :store, :success, :fail
def initializer(observer, store)
@observer, @store = observer, store
yield self if block_given?
return self
end
def call(post_id, comment_attrs)
@nicholasjhenry
nicholasjhenry / gist:3025421
Created June 30, 2012 20:37
Inspired by "Making ActiveRecord Thin"
customer = Shop::Directory.new(repository: User).find(1001)
product = Shop::Warehouse.new(repository: Product).find(1002)
transaction = Shop::Transaction.new(customer: customer, product: product, orders: Orders.new(repository: Order))
transaction.commit
module Shop
class Warehouse
attr_reader :repository
def index
@stockist_countries = StockistCountry.active_stockists
end
@nicholasjhenry
nicholasjhenry / gist:3034867
Created July 2, 2012 18:50
More ideas on SRP with Rails and ActiveRecord
module MyApp
BusinessException = Class.new(StandardError)
class Post
attr_reader :record
def initialize(args)
@record = args[:record]
@nicholasjhenry
nicholasjhenry / gist:3035215
Created July 2, 2012 19:40
Streamlined ActiveRecord
class Post < ActiveRecord::Base
has_many :comments
# SERVICES
def comment(attributes)
create_comment(attributes)
end
@nicholasjhenry
nicholasjhenry / gist:3035546
Created July 2, 2012 20:35
Simplified Persistence Separation
class MyApp::Post
attr_reader :record
def initialize(args)
@record = args[:record]
end
def comment(attributes)
create_comment(attributes)