Skip to content

Instantly share code, notes, and snippets.

@evilstreak
evilstreak / baker.hx
Last active April 16, 2016 13:58
State Machine robot scripts
// BAKER BOT
//
// This bot will bake bread and then drop it all
// off in the beacon. Build an oven and give the
// bot lots of grain and wood.
// go to the oven
moveto(oven);
// bake bread until we run out of ingredients
@evilstreak
evilstreak / benchmark.rb
Last active August 29, 2015 14:19
Performance improvement from adding caching when rendering mustache partials for GOV.UK search results
$:.unshift "lib"
require "mustache"
require "benchmark/ips"
BASE_TEMPLATE = <<end_of_template
<h2>Names</h2>
{{#names}}
{{> user}}
{{/names}}
@evilstreak
evilstreak / gist:0d61ef17eea4f3dcbd1a
Created September 16, 2014 07:15
Enumerator#concat
class Enumerator
def concat(other)
new_size = size && other.size && size + other.size
Enumerator.new(new_size) do |yielder|
each { |element| yielder << element }
other.each { |element| yielder << element }
end
end
end
function ssh-govuk-dev {
if [[ $PWD = ~/code/gds/* ]]; then
ssh dev -t "cd /var/govuk/$(basename $PWD); bash --login"
else
ssh dev
fi
}
@evilstreak
evilstreak / gist:aa51c55e3799a2f5d47f
Created July 4, 2014 14:02
Misleading RSpec expectation failure messages
require 'rspec'
RSpec.describe Object do
subject { Object.new }
before do
# Stub a method so we can spy on it
allow(subject).to receive(:a_method)
# Call it twice with alpha and once with beta
@evilstreak
evilstreak / gist:7097e6f0cd6b4a93d996
Last active August 29, 2015 14:02
New govspeak syntax for ordered lists with custom markers
$LegislativeList
1. The
quick
2. Brown fox
a) Jumps
over
ii) Foo
iv) Bar
viii) Baz
b) The lazy
{
"title": "Immigration Rules Updates",
"slug": "guidance/immigration-rules/updates",
"kind": "manual-change-notes",
"details": {
"manual_slug": "guidance/immigration-rules",
"updates": [
{
"published_at": "2014-04-01T12:30:00",
"slug": "guidance/immigration-rules/document-slug",
@evilstreak
evilstreak / .gitconfig
Created March 14, 2014 15:56
Git aliases
[alias]
amend = commit --amend -C HEAD
c = commit
cm = commit -m
co = checkout
d = diff --no-prefix
dc = diff --no-prefix --cached
f = fetch --prune
ff = merge --ff-only
ignore = !([ ! -e .gitignore ] && touch .gitignore) | echo $1 >> .gitignore
require 'rspec/autorun'
module DominicRecursion
def self.letters(haystack, needles, index = 0)
# base case: if the letters to match are empty, we've succeeded
return [[]] if needles.empty?
# base case: if the word to match in is empty, we've failed
return [] if haystack.empty?
class Bezier
TOLERANCE = 0.5 ** 8
def initialize(control_points)
@control_points = control_points
end
def points
@points ||= build_points
end