Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Clayton joshuaclayton

View GitHub Profile
@joshuaclayton
joshuaclayton / 0_reuse_code.js
Created Sep 22, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@joshuaclayton
joshuaclayton / hack.sh
Created Apr 13, 2012 — forked from erikh/hack.sh
OSX For Hackers
View hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@joshuaclayton
joshuaclayton / gist:1689665
Created Jan 27, 2012 — forked from kornypoet/gist:1689638
Rspec #initialize behavior
View gist:1689665
class Foo
attr_accessor :bar
def initialize(bar, validator = BarValidator)
validator.validate!(bar)
@bar = bar
end
end
class BarValidator
@joshuaclayton
joshuaclayton / post.rb
Created Sep 14, 2011 — forked from avdi/post.rb
Just a tease...
View post.rb
class Post
include FigLeaf
include ActiveModel::Validations
# ...
end
View gist:221443
class Person
def self.region(str, &blk)
self.class_eval(&blk)
end
end
class Joe < Person
def name; "Joe"; end
region "speaking" do
View fake_geocoder.rb
module GeoKit
module Geocoders
class FakeGeocoder < Geocoder
def self.locations
@locations ||= {}
end
def self.geocode(location)
loc = GeoLoc.new
if locations.key?(location)
View git_tasks.rake
module GitCommands
class ShellError < RuntimeError; end
@logging = ENV['LOGGING'] != "false"
def self.run cmd, *expected_exitstatuses
puts "+ #{cmd}" if @logging
output = `#{cmd} 2>&1`
puts output.gsub(/^/, "- ") if @logging
expected_exitstatuses << 0 if expected_exitstatuses.empty?
View .zshrc
# autocompletion for ruby_test
# # works with tu/tf aliases
# # see also ~/bin/ruby_test.rb
_ruby_tests() {
if [[ -n $words[2] ]]; then
compadd `ruby_test -l ${words[2]}`
fi
}
compdef _ruby_tests ruby_test
alias tu="ruby_test unit"
View snippet.rb
class FilterableEnumerable
def initialize(original)
@original = original
end
def ==(value)
@original.select { |v| v == value }
end
def method_missing(sym, *args, &block)
View gist:74649
commit ed20f4dcc656ac55adbe9515466ef19d102e9ead
Author: Pratik Naik <pratiknaik@gmail.com>
Date: Thu Mar 5 22:45:04 2009 +0000
should_be_fucking_restful
diff --git a/lib/shoulda/action_controller.rb b/lib/shoulda/action_controller.rb
index 4719851..3723c72 100644
--- a/lib/shoulda/action_controller.rb
+++ b/lib/shoulda/action_controller.rb