Skip to content

Instantly share code, notes, and snippets.

@kerryb
kerryb / .gitconfig
Last active August 29, 2015 14:00
The non-personal bits of my git config
[color]
diff = auto
status = auto
branch = auto
[instaweb]
browser = open
[merge]
keepBackup = false
tool = diffmerge
defaultToUpstream = true
@kerryb
kerryb / application.rb
Created June 24, 2014 15:47
Simple rails example of form interacting with non-activerecord backend code
# config/application.rb
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_model/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"

Keybase proof

I hereby claim:

  • I am kerryb on github.
  • I am kerryb (https://keybase.io/kerryb) on keybase.
  • I have a public key whose fingerprint is 8DA4 4B51 5A90 D3AE 07B9 2FD2 5E07 C65F E855 9D1D

To claim this, I am signing this object:

@kerryb
kerryb / gist:66557
Created February 18, 2009 21:23
Asserting true and false (ish) in rspec
# If you want to check that something's true or false in the normal ruby sense
# (ie anything other than false or nil is true), you can use double negation
# to force it into an actual boolean (eg !!foo.should be_true). To keep this
# ugliness out of your tests, stick these matchers in your spec helper:
def be_truish
return simple_matcher do |obj, matcher|
matcher.description = 'be true(ish)'
matcher.failure_message = "Expected #{obj.inspect} to be true(ish)"
matcher.negative_failure_message = "Expected #{obj.inspect} not to be true(ish)"
#!/usr/bin/env ruby
require 'rubygems'
require 'spec'
class Foo
def self.foo
Bar.bar
rescue StandardError
end
@kerryb
kerryb / gist:274297
Created January 11, 2010 15:05
Ctags script
#!/usr/bin/ruby
#-*-ruby-*-
# A script to run ctags on all .rb files in a project. Can be run on
# the current dir, called from a git callback, or install itself as a
# git post-merge and post-commit callback.
CTAGS = '/usr/local/bin/ctags'
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'
namespace :code do
task :trailing_spaces do
grep "app", "spec"
end
def grep *file_patterns
files_found = ""
file_patterns.each do |file_pattern|
files_found << `grep -r -E '^.*[[:space:]]+$' --include '*.rb' #{file_pattern}`
end
@kerryb
kerryb / breadcrumbs.rb
Created November 11, 2010 10:43
Which is best, iteration or recursion?
# I originally refactored this method to a recursive solution, but I wonder whether
# that's really necessary. Is the alternative approach using inject easier to
# understand?
# Original method, with external iterator:
# Build breadcrumb list from an array of nested model instances, starting with the parent
# and ending with the lowest level child. Each breadcrumb needs to be created using a
# sub-array containing itself and its parents.
@kerryb
kerryb / gist:905396
Created April 6, 2011 09:36
RSpec output
$ rake spec
(in /Users/kerry/tmp/foo)
/Users/kerry/ruby/bin/ruby -S bundle exec rspec ./spec/models/foo_spec.rb
F
Failures:
1) Foo shows the line that failed
Failure/Error: false.should be_true
expected false to be true
@kerryb
kerryb / guess.sh
Created July 15, 2011 21:07
My solution to Neil's bash masterclass exercise
#/bin/bash
#
# Number guessing game.
# A simple demo of bash capabilities
#
# neil.winton@bt.com
readonly MaxGuesses=6
readonly Timeout=10