Skip to content

Instantly share code, notes, and snippets.

View jphenow's full-sized avatar
💻
👋🏻 :octocat:

Jon Phenow jphenow

💻
👋🏻 :octocat:
View GitHub Profile
@jphenow
jphenow / resque-patches.rb
Created June 11, 2013 13:38
Necessary resque/resque-scheduler patches
require 'resque'
require 'resque_scheduler'
require 'resque/scheduler'
module ResqueSchedulerPatches
extend ActiveSupport::Concern
included do
class << self
alias_method_chain :delayed_timestamp_peek, :rescue
end
@jphenow
jphenow / deploy.rake
Last active December 18, 2015 00:09 — forked from njvitto/deploy.rake
#Deploy and rollback on Heroku in staging and production
%w[staging production].each do |app|
desc "Deploy to #{app}"
task "deploy:#{app}" => %W[deploy:set_#{app}_app deploy:push deploy:restart deploy:tag]
desc "Deploy #{app} with migrations"
task "deploy:#{app}:migrations" => %W[deploy:set_#{app}_app deploy:push deploy:off deploy:migrate deploy:restart deploy:on deploy:tag]
desc "Rollback staging"
@jphenow
jphenow / block_params.rb
Created May 20, 2013 21:26
Something interesting about block params
nested_arrays = [[:a,:b,[:c,:d]],[:w,:x,[:y,:z]]]
nested_arrays.each do |(first, second, (inner_first, inner_last))|
puts first
puts inner_first
end
# =>
# a
# c
@jphenow
jphenow / aliased_attributes.rb
Last active December 17, 2015 13:09
Get the attributes of a mongoid object with their aliased names as the keys
class Game
include Mongoid::Document
def aliased_attributes
attributes.inject({}) { |attrs, (raw_key, raw_value)|
attrs[Game.aliased_fields.invert.fetch(raw_key) { raw_key }] = raw_value
attrs
}
end
end
module HeroAttributes
def self.included(base)
base.extend(ClassMethods)
end
def abilities
self.class.abilities
end
module ClassMethods
@jphenow
jphenow / case.rb
Last active December 16, 2015 15:59
Case statements
def base_finalizer_class
return GameFinalizer unless game.sport
case game.sport.class_name
when "IceHockey"
Sports::IceHockey::GameFinalizer
when "Baseball"
Sports::Baseball::GameFinalizer
when "Lacrosse"
Sports::Lacrosse::GameFinalizer
when "RugbyUnion"
@jphenow
jphenow / rspec_filters.rb
Last active December 16, 2015 14:19
Fancy RSpec handling of filters
RSpec.configure do |config|
config.before do
Rails.cache.clear unless self.class.metadata[:cache]
end
end
describe "doing stupid stuff" do
#...
end
@jphenow
jphenow / hash_split.rb
Created April 14, 2013 16:16
I wish this were standard, I want this often
class Hash
def split_by(&block)
[select(&block), reject(&block)]
end
end
@jphenow
jphenow / .gitconfig
Last active December 16, 2015 01:28
Show some nice output of the most recently committed to branches
[alias]
recent-asc = for-each-ref --sort=committerdate refs/heads/ --format='%(refname:short)\n%(committerdate)\t%(authorname)\n'
recent-desc = for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)\n%(committerdate)\t%(authorname)\n'
@jphenow
jphenow / local_variable.rb
Created April 9, 2013 16:31
A local variable is still setup and nil'd, even `if false`.
class Foo
attr_accessor :bar
def initialize
self.bar = "bar"
end
def baz
bar = "baz" if false
bar