Skip to content

Instantly share code, notes, and snippets.

@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
@coreyhaines
coreyhaines / .rspec
Last active August 15, 2024 15:13
Active Record Spec Helper - Loading just active record
--colour
-I app
require "money"
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(name, *args, &block)
@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}
# 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 / 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'
@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 / 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.

@elefontpress
elefontpress / gist:6159651
Last active June 12, 2024 22:48
This is the contract Bearded uses for client work on a time and materials basis. It's worked for us, but I am not a lawyer, so please run it by yours before you use it! Regardless, do whatever you like with it. Use it, share it, change it ... go nuts. Our original contract from 2008 was for fixed-price projects and was based on Andy Clark'e Cont…

Bearded's Hourly Contract

Date: [[Date of Document]] Between [Our Company] and [Your Company]

Summary

We’re not big on formality, but sometimes it’s best to have a few simple things written down so that we’re all on the same page. In this contract you won’t find complicated legal terms or large passages of unreadable text. We have no desire to trick you into signing something that you might later regret. We do want what’s best for the safety of both parties, now and in the future.

@cupakromer
cupakromer / books_controller.rb
Last active May 19, 2020 10:20
Rails 4 Standard CRUD Controller
# No flash messages are set with this controller.
#
# This is a fairly basic / bare controller which does only the basic CRUD.
class BooksController < ApplicationController
respond_to :html, :xml, :json
before_action :set_book, only: [:show, :edit, :update, :destroy]
def index
respond_with @books = Book.all