Skip to content

Instantly share code, notes, and snippets.

View krisleech's full-sized avatar

Kris Leech krisleech

View GitHub Profile
krisleech / comp-fails
Created February 24, 2014 10:56
Get list of cukes failing in one branch but not another using output from CI
#!/usr/bin/env bash
# manual steps
# Download raw output of master cuke to master-cuke-ci.raw as plain text
# Download raw output of another cuke branch to branch-cuke-js.raw as plain text
set -e
krisleech / grab
Created February 25, 2014 15:23
screenshot webpages
#!/usr/bin/env bash
webkit2png -F -o page1 "http://${HOST}/..."
webkit2png -F -o page2 "http://${HOST}/..."
webkit2png -F -o page3 "http://${HOST}/..."
krisleech / 01-initial-server-side-render.html
Created March 6, 2014 16:43
Instead of javascript templates reuse the DOM as a template
<div id="results">
<div class="result" data-result-id='1'>
<div data-attr="title">Result 1</div>
<div class="result" data-result-id='2'>
<div data-attr="title">Result 2</div>
<div class="result" data-result-id='3'>
krisleech / double.rb
Created May 22, 2014 14:02
Simple Ruby double
class Double < Hash
def initialize(attrs)
attrs.each { |k,v| store(k,v) }
def method_missing(_name, *args, &block)
has_key?(_name) ? fetch(_name) : super(_name, *args, &block)
krisleech / gbr
Created June 24, 2014 14:07
git branch with autocomplete
#!/usr/bin/env bash
# quickly find a branch, using the team name as the first argument and autocomplete
# to narrow it down further.
# requires "selecta" (garybernhardt/selecta) installable via brew on MacOS
set -e
if [[ -z "$1" ]]; then
krisleech / repo.rb
Created October 22, 2014 23:10
entiry and repo
## App
require 'bundler'
### Entity
class Person
include Virtus.model
krisleech / events.rb
Last active August 29, 2015 14:09
EventSourcing in Ruby Spike / Notes
# Thoughts on Event Sourcing in Ruby.
# Idea is to have commands which record events in an event store.
# A denormalizer listens to the EventStore for new events and creates highly denormalized record(s) in a relational database.
# Entities are then populated by querying the relational database, since it it totally denormalized no JOIN's are required.
# The relational tables serve the same purpose as relation views, the event data might be persisted to multiple tables.
# For example a command might create an event from which the denormalizer will create record in tables which are used for
# persistance of entities and for aggregate reporting.
# The relational data can be recreated using the event store.
krisleech /
Last active August 29, 2015 14:09
Notes on SOA
  • Each service represents a bounded context, it is the authority for a business concept and contains the business rules.
  • The service has business behaviour and data, exposing one or more resources.
  • Services which talk to other services are coupled, instead services should have all the data they need, even if it duplicates of what is contained in other services.
  • They must have autonomy, the network and service availability is not reliable.
  • Trying to treat services like data sources means using distributed transactions and locks, which are, putting it mildly, difficult.
  • Use an event bus to communicate between services:
    • decoupled, no need to know about other services
    • events are async so can be retried
    • events are writtern in past tense
  • When a canonical resource has been updated an event is published. The event includes the resource, or an id, or a URL from which it can be retrived. Subscribed services can then update their copy of the data.
krisleech / events.rb
Created November 29, 2014 00:36
Notes on an event sourcing API
# initializer
$event_store =
event_store.subscribe(, prefix: ‘on’)
# controller
# push a new event (write database)
uuid =
event_store.push(aggregate_id: uuid, event: ‘StudyCreated’, data: { … })
krisleech / gist:8c56096946dc02a192a1
Created December 5, 2014 09:31
kris.leech public SSH key
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq/9WdnAcWFW720c/kK2Kyo21SD0z2U0xm11cLKdPofxwKvb97H0m+URLAZhsbJ232R7sfQuUfgGSM6Spg+iv5qyo2nEY3ksyGYn5xMfkS1tIkmP+Q69XoEmNjBh3Pon0X0AITi9QGbRdQ/pYoYpNTcjePPC/1dOqnl/HWNuUyx/DglnFnUoedQAufTLsnTV3eySc9tYFUEjYUGrX+EDcAD+Fg2VmHLhGItRe4lnCy2MSbDFeGI8N7te4ZnwuXp6fHIPSDn74UdDRWAdcrtu99ZEvieMA1ONf3p21w/T2QdiWBUokXv6kmkq8BMucmGXxtl7tZt3QMYoL8D8PxNcM7Q== kris