Skip to content

Instantly share code, notes, and snippets.

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 / 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"
@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 / blocks.rb
Created December 10, 2013 22:28
Ruby blocks, procs, map and reduce
# A proc is just a block of code that can be called later:
say_hello = -> { 2 + 2 }
say_hello.call # => 4
# Procs can take parameters:
double = ->(x) { x * 2 }
@kerryb
kerryb / Console output
Created April 29, 2012 19:28
Failing Erlang monitor
Erlang R15B (erts-5.9) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9 (abort with ^G)
1> c(doubler).
{ok,doubler}
2> c(monitor).
{ok,monitor}
3>
3> monitor:start().
new
@kerryb
kerryb / gist:2028383
Created March 13, 2012 11:56
Rubygems error
$ gem -v
<internal:lib/rubygems/custom_require>:32:in `rescue in require': undefined method `try_activate' for Gem:Module (NoMethodError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:32:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/local/bin/gem:8:in `<main>'
$ ruby -d -rubygems -e 'puts 42'
@kerryb
kerryb / chunked_average.rb
Created March 9, 2012 15:42
Reduce list to average of chunks of n items
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
chunk_size = 3
chunked_averages = (0...data.length).zip(data).group_by{|a| a.first / chunk_size}.values.map{|a| a.map(&:last).reduce(&:+) / a.size}
@kerryb
kerryb / dynamic_modules.rb
Created November 9, 2011 11:48
dynamically including a module depending on an instance property
module DynamicSetup
def dynamic_setup_complete?
@dynamic_setup_complete
end
def method_missing name, *args, &block
if dynamic_setup_complete?
super
else
perform_dynamic_setup
@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
@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