Skip to content

Instantly share code, notes, and snippets.

View bradstewart's full-sized avatar

Brad Stewart bradstewart

View GitHub Profile
@cblunt
cblunt / Gemfile
Created October 21, 2011 08:55
Configure Carrierwave for Amazon S3 Storage and Heroku
# ...
gem 'carrierwave'
gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
@chetan
chetan / yardoc_cheatsheet.md
Last active May 10, 2024 02:53
YARD cheatsheet
@aseemk
aseemk / url.coffee
Created April 27, 2012 05:51
Simplified wrapper around Node's native 'url' module
# url.coffee
# by Aseem Kishore ( https://github.com/aseemk ), under MIT license
#
# A simplified wrapper around the native 'url' module that returns "live"
# objects: updates to properties are reflected in related properties. E.g.
# updates to the `port` property will be reflected on the `host` property.
#
# The public API and behavior are pretty close to the native 'url' module's:
# http://nodejs.org/docs/latest/api/url.html Currently lacking / known issues:
#
@krisleech
krisleech / booking.rb
Created August 10, 2012 11:11
separating persistance and domain, DCI-ish.
# app/models/booking.rb
class Booking < AR::Base
# ...
end
# app/models/booking/create.rb
class Booking::Create
def initialize(attributes)
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active May 28, 2024 17:41
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@kylemanna
kylemanna / connmanctl.md
Last active June 27, 2023 23:12
Connmanctl Cheat Sheet
@justinweiss
justinweiss / filterable.rb
Last active January 11, 2024 07:28
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
@BiggerNoise
BiggerNoise / assign_case_command.rb
Created March 3, 2014 21:10
Command Pattern at work
class AssignCaseCommand < Command
attribute :case, Case
attribute :owner, User
attribute :created_by, User
attribute :comments, String
attribute :distribute_at, DateTime
attribute :distribute_rule_name, String
attribute :require_initial, Boolean
# MODEL
class Case < ActiveRecord::Base
include Eventable
has_many :tasks
concerning :Assignment do
def assign_to(new_owner:, details:)
transaction do
@danott
danott / view.coffee
Created July 24, 2014 23:38
How to propogate events up the batman view tree, similar to EventBinding
class App.BehavesLikeEventBindingView extends Batman.View
fireOnSelfAndNearestAncestor: (event, args...) ->
@[event]?.apply(@, args)
if target = @superview?.targetForKeypath(event)
target[event].apply(target, args)