Skip to content

Instantly share code, notes, and snippets.

View joshuaclayton's full-sized avatar

Josh Clayton joshuaclayton

View GitHub Profile

There's ways to do cleaner SRP that allow moving email delivery out of a model and controller and still be flexible for emailing different things based on type of user, etc.; it's merely a matter of how you solve the problem. simple.rb is the simplest thing that'll do basically the same exact thing that the original author intended - separate object, fast to test, blah blah blah. Introducing DI to override delivery is super simple and can be a lambda/Proc or method; WithDeliveryEmail doesn't give a shit, as long as it has a call method accepting the user to deliver the email to.

Is the solution of moving email delivery outside the callback of the user sensible? Can other developers figure out what the side effects of saving a user from the controller immediately? Does creating a user always ensure that an email is delivered? If the system does what it needs to do and all those can be answered with yes, I think it

@joshuaclayton
joshuaclayton / hack.sh
Created April 13, 2012 20:17 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
window "AppName" do
root "~/dev/thoughtbot/app"
vpane 75, "vim ."
vpane 25 do
hpane 75
hpane 25 do
vpane 50, "guard"
vpane 50, "evergreen serve"
end
To get Tmux + pbcopy/pbpaste working:
brew install reattach-to-user-namespace
IIRC this only works on OS X 10.7, but check out https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard to read more.
At the very top of your ~/.tmux.conf (assuming you're using zsh as your shell)
set-option -g default-command "reattach-to-user-namespace -l zsh"
@joshuaclayton
joshuaclayton / .rspec
Created January 31, 2012 14:04
RSpec + Cucumber + Spork
--colour --drb
@joshuaclayton
joshuaclayton / gist:1689665
Created January 27, 2012 16:38 — forked from kornypoet/gist:1689638
Rspec #initialize behavior
class Foo
attr_accessor :bar
def initialize(bar, validator = BarValidator)
validator.validate!(bar)
@bar = bar
end
end
class BarValidator
@joshuaclayton
joshuaclayton / benchmark.rb
Created January 13, 2012 19:50
Factory Girl benchmarks
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require "rubygems"
require "active_record"
require "factory_girl"
require "benchmark"
module DefineConstantMacros
def define_class(path, base = Object, &block)
namespace, class_name = *constant_path(path)
require "money"
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(name, *args, &block)
@joshuaclayton
joshuaclayton / gh-delete.js
Created December 16, 2011 15:39
Github notification delete scriptlet
javascript:jQuery("a[title='delete thread']").trigger("click"); setTimeout(function() { window.location.reload(); }, 500);
class FakeResque
extend Resque::Helpers
cattr_accessor :queue
self.queue = []
def self.enqueue(klass, *args)
raise Resque::NoQueueError unless ((eval("klass.queue") rescue false) || klass.instance_variables.include?("@queue"))
self.queue << [klass, encode(args)]
end