Skip to content

Instantly share code, notes, and snippets.

View patbenatar's full-sized avatar

Nick Giancola patbenatar

View GitHub Profile
class Foo
attr_reader :adapter
def initialize
@adapter = if Rails.env.production?
Foo::RealAdapter.new
else
Foo::StubAdapter.new
end
@patbenatar
patbenatar / polymorphic_query_helper.rb
Created January 30, 2013 00:20
Simple utility for working with polymorphic associations in ActiveRecord where queries.
module PolymorphicQueryHelper
class << self
def expand_polymorphic_hash(hash)
{}.tap do |expanded_hash|
for name, object in hash
expanded_hash.merge!({
"#{name}_id".to_sym => object.id,
"#{name}_type".to_sym => object.class.name
})
class Order
include Stats::Host
# The above would mix this in:
has_one :stat, class_name: "Order::Stat"
after_commit :create_stat, on: :create
def create_stat
stat.create!
class Analyzer
class << self
include ActionView::Helpers::NumberHelper
end
CACHE_NAMESPACE = "analyzer"
CACHE_LIFESPAN = 10.minutes
class_attribute :items_to_analyze

not brew

  • xcode cli tools
  • brew
  • $ brew tap homebrew/dupes

brew

  • apple-gcc42
  • mysql
  • postgres
  • redis
export HEROKU_STG_APP=stg-app-name
export HEROKU_PROD_APP=prod-app-name
@patbenatar
patbenatar / media.scss
Created October 24, 2012 21:27
Nifty mixins for responsive Sass. Requires Sass >= 3.2
/*
* Usage:
* h1 {
* font-size: 2em;
* @include media(small) {
* font-size: 1.5em;
* }
* }
*/
@mixin media($media) {
@patbenatar
patbenatar / gist:3900776
Created October 16, 2012 17:38
After oauth login, return user to URL they came from with Devise + Omniauth
# link_to path
user_omniauth_authorize_path(:facebook, origin: request.fullpath)
# in ApplicationController
def after_sign_in_path_for(resource)
stored_location_for(resource) || request.env['omniauth.origin'] || root_path
end
@patbenatar
patbenatar / gh_issues_string.js
Created October 12, 2012 23:39
Format GitHub issues as a simple newline separated string
// GitHub already has jQuery loaded, so we can use it for free!
titles = []; $(".info-wrapper h3 a").each(function () { number = $(this).closest("td").prev("td.number").text().match(/\d+/)[0]; titles.push("#" + number + " " + $(this).text()) }); titles.join("\n");
@patbenatar
patbenatar / gist:3836827
Created October 4, 2012 22:16
Bash script for git pull rebase shorthand
# Git pull and rebase
# Show git log if rebasing finds new changes
# You can optionally pass in a remote and branch
function gpr {
output=`git pull --rebase $1 $2`
echo $output
if [[ $output != *is\ up\ to\ date\.* ]] then
git log -n 3
fi
}