Skip to content

Instantly share code, notes, and snippets.

View bencrouse's full-sized avatar

Ben Crouse bencrouse

View GitHub Profile
@bencrouse
bencrouse / gateway.rb
Last active June 16, 2020 12:03
Custom shipping gateway
module ActiveShipping
class MyBuild < ActiveShipping::Fedex
def find_rates(*args)
results = super
# some code to customize the results
return results
end
end
end
@bencrouse
bencrouse / brands.rb
Last active May 29, 2020 12:07
Brand aggregation
module Workarea
module Search
class Brands
include ProductDisplayRules
def all_results
buckets = Array.wrap(response.dig('aggregations', 'all_brands', 'buckets'))
buckets.map { |b| b['key'] }
end
@bencrouse
bencrouse / current.rb
Created October 19, 2016 14:09
Mongoid Criteria merging fixes
_key == '$in' ? new_val & old_val : old_val | new_val
@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:

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
# 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',
@bencrouse
bencrouse / gist:6767822
Created September 30, 2013 18:14
Delete multiple keys from Redis
redis-cli keys 'query*' | awk '{ gsub("\"", "*", $1); print "\"" $1 "\"" }' | xargs redis-cli DEL
@bencrouse
bencrouse / paranoia_probs.rb
Created August 2, 2012 16:47
Mongoid 3.0 Paranoia Problems
1.9.3p194 :006 > Catalog::Product.last
=> #<Catalog::Product _id: PROD9990094, _type: nil, deleted_at: nil, version: 1, created_at: 2012-07-31 20:43:50 UTC, updated_at: 2012-07-31 20:43:50 UTC, slug: "test-product-211", display_starts_at: 2012-07-31 20:43:50 UTC, display_ends_at: nil, purchase_starts_at: 2012-07-31 20:43:50 UTC, purchase_ends_at: nil, site_id: 1, name: "Test Product 211", sale_starts_at: nil, sale_ends_at: nil, display_price_range: false, packaged_product_ids: []>
1.9.3p194 :007 > Catalog::Product.last.destroy
=> 0
1.9.3p194 :008 > Catalog::Product.last
=> #<Catalog::Product _id: PROD9990094, _type: nil, deleted_at: 2012-08-02 16:46:50 UTC, version: 1, created_at: 2012-07-31 20:43:50 UTC, updated_at: 2012-07-31 20:43:50 UTC, slug: "test-product-211", display_starts_at: 2012-07-31 20:43:50 UTC, display_ends_at: nil, purchase_starts_at: 2012-07-31 20:43:50 UTC, purchase_ends_at: nil, site_id: 1, name: "Test Product 211", sale_starts_at: nil, sale_ends_at: nil, display_price_range: false, p
@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
}
@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)