Skip to content

Instantly share code, notes, and snippets.

@cupakromer
cupakromer / gist:6072860
Last active December 20, 2015 04:39
CFP Proposal: Cooking Code

Cooking Code

Using Refactorings as Smells to Cook Aromatic Code

Refactoring is a huge part of the programming workflow. Over the past year there has been a resurgence of the refactoring practice. With so much emphasis on the process and techniques of refactoring, the bigger picture is often missed.

When you refactor, you should stop and ask: "Why do I need to do this? What's different now? Did a perception change, was something missed, etc.? How can I prevent this the next time?"

Remember, not all smells are "bad" and it's a subjective scale.

@cupakromer
cupakromer / gist:5760066
Last active December 18, 2015 09:19
Magic Hashes All The Way Down
turtles_all_the_way_down = ->{ Hash.new{ |h, k| h[k] = turtles_all_the_way_down.call } }
magic_hash = Hash.new{ |h, k| h[k] = turtles_all_the_way_down.call }
magic_hash
# => {}
magic_hash['1']
# => {"1"=>{}}
magic_hash['1'] = 2
@cupakromer
cupakromer / Gemfile
Last active December 17, 2015 19:19
Custom Rails Config
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Run the puma server
gem 'puma'
# Mock all calls through .find on an ActiveRecord model
# or its chained scopes
def expect_find(model)
@scope ||= model.scoped
model.stub!(:scoped).and_return @scope
@scope.should_receive(:find).ordered
end
@cupakromer
cupakromer / gist:4719800
Created February 6, 2013 02:47
How to require all .rb in sub-dirs
Dir[File.expand_path('../formulas/**/*.rb', __FILE__)].each{|f| require f}
require "money"
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(name, *args, &block)
@coreyhaines
coreyhaines / .rspec
Last active August 15, 2024 15:13
Active Record Spec Helper - Loading just active record
--colour
-I app
@jstorimer
jstorimer / hilong.rb
Last active February 18, 2025 18:20
hilong -- A simply utility to show character counts for each line of input and highlight lines longer than 80 characters.
#!/usr/bin/env ruby
# A simply utility to show character counts for each line of input and
# highlight lines longer than 80 characters.
#
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html
#
# Examples:
#
# $ hilong Gemfile