Skip to content

Instantly share code, notes, and snippets.

View bencrouse's full-sized avatar

Ben Crouse bencrouse

View GitHub Profile
(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
@bencrouse
bencrouse / .gitconfig
Created January 19, 2012 21:40
gitconfig
[user]
name = bcrouse
email = bcrouse@weblinc.com
[core]
[color]
ui = true
[merge]
tool = opendiff
[core]
editor = /usr/bin/vim
@bencrouse
bencrouse / tire.rb
Created June 4, 2012 16:49
putting data into an index
data = { id: 'id', name: 'something' }
index = Tire::Index.new('index_name')
index.store(data)
index.refresh #(optionally)
@bencrouse
bencrouse / rails_rescues.rb
Created July 9, 2012 20:58
ActionDispatch::ShowExceptions.rescue_responses
{"ActionController::RoutingError"=>:not_found,
"AbstractController::ActionNotFound"=>:not_found,
"ActionController::MethodNotAllowed"=>:method_not_allowed,
"ActionController::NotImplemented"=>:not_implemented,
"ActionController::InvalidAuthenticityToken"=>:unprocessable_entity,
"ActiveRecord::RecordNotFound"=>:not_found,
"ActiveRecord::StaleObjectError"=>:conflict,
"ActiveRecord::RecordInvalid"=>:unprocessable_entity,
"ActiveRecord::RecordNotSaved"=>:unprocessable_entity
}