Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / .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 / blockchain.txt
Created January 12, 2016 14:18
Blockchain verification
Verifying that +kerryb is my blockchain ID. No, me neither. https://onename.com/kerryb
class RomanNumerals
NUMBERS = {
1000 => "M",
900 => "CM",
500 => "D",
400 => "CD",
100 => "C",
90 => "XC",
50 => "L",
40 => "XL",
@kerryb
kerryb / ytd.bash
Last active February 23, 2017 21:45
Year-to-date running stats
ytd() {
ytd=$(find ~/Dropbox/Apps/tapiriik -name $(date +%Y)-*_Running*.tcx -print0 | xargs -0 -n1 awk '/DistanceMeters/ {a=$0} END {gsub(/\s*<[^>]*>/, "", a); print a}' | paste -sd+ - | sed 's/\(.*\)/0.000621371 * (\1)/' | bc | sed 's/\(\..\).*/\1/')
proj=$(echo "$ytd * 365 / $(date +%j)" | bc)
echo "YTD: $ytd. Projected: $proj"
}
@kerryb
kerryb / child.ex
Last active July 2, 2018 10:53
Supervised task, with timeout
defmodule Child do
def task(parent) do
Process.sleep(:timer.seconds(2))
send(parent, :finished)
end
end
@kerryb
kerryb / README.md
Last active May 19, 2019 19:00
Basic given/when/then macros for ExUnit

README

A spike looking at adding basic given-when-then steps to ExUnit tests.

Features

  • define tests as sequences of calls to given_, when_ and then_ (unfortunately when is a reserved word)
  • match steps by calling defwhen etc with a string matching the one used in the step
  • interpolate values into step descriptions using {braces}
  • placeholder variable names are available as methods on the magic args variable