Skip to content

Instantly share code, notes, and snippets.

View bencrouse's full-sized avatar

Ben Crouse bencrouse

View GitHub Profile
# starting point (line is too long)
def send_mail(source)
Mailer.deliver(to: 'bob@example.com', from: 'us@example.com', subject: 'Important message', body: source.text)
end
# bad (double indent)
def send_mail(source)
Mailer.deliver(
to: 'bob@example.com',
from: 'us@example.com',
Dragonfly[:weblinc].job(:small_thumb) do
encode :jpg, '-quality 85'
process :thumb, '60x'
process :optim
end
Dragonfly[:weblinc].job(:large_thumb) do
encode :jpg, '-quality 85'
process :thumb, '195x'
process :optim
@bencrouse
bencrouse / keybase.md
Created May 19, 2015 15:21
keybase.md

Keybase proof

I hereby claim:

  • I am bencrouse on github.
  • I am bencrouse (https://keybase.io/bencrouse) on keybase.
  • I have a public key whose fingerprint is 0233 2681 1928 59F1 4206 1808 0580 67E2 ED88 1F84

To claim this, I am signing this object:

(function($) {
// Arrays
$.inject = function(array, memo, fn) {
for(var i = 0; i < array.length; i++)
memo = fn(memo, array[i]);
return memo;
};
#Files (not deleted) in the index
files=$(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
if [ "$files" != "" ]
then
for f in $files
do
# Only examine known text files
if [[ "$f" =~ [.](conf|css|erb|html|js|json|log|properties|rb|ru|txt|xml|yml)$ ]]
then
# Add a linebreak to the file if it doesn't have one
@bencrouse
bencrouse / gist:1126643
Created August 5, 2011 00:16
DDDish Rails
#
# Controller - Application service layer until a separation has clear value
#
#
class CartController < ApplicationController
before_filter :find_variant
rescue_from Model::InvalidOperation, with: :domain_error
def add_item
Sunspot.session = CoreShardingSessionProxy.new(Sunspot.config)
# Causes error
# /Users/bcrouse/.rvm/gems/ruby-1.9.2-p0@solr_plexus/gems/sunspot-1.2.1/lib/sunspot/session_proxy/abstract_session_proxy.rb:21:in `config': Sunspot::SessionProxy::ShardingSessionProxy does not support :config (Sunspot::SessionProxy::NotSupportedError)
@bencrouse
bencrouse / lion_logic.sh
Created September 3, 2011 22:22
Open Logic 8 Pro on Lion
#!/bin/bash
open /Applications/Logic\ Pro.app/Contents/MacOS/Logic\ Pro
@bencrouse
bencrouse / capybara.rb
Created December 15, 2011 16:35
Region Select
select 'Pennsylvania', from: 'shipping_address[region]'
class AddItemToCartCommand
include Command
validate :sku, presence: true
validate :quantity, presence: true, numericality: { greater_than_or_equal_to: 1 }
def cart
Cart.from_session(params[:session_id])
end