Skip to content

Instantly share code, notes, and snippets.

View lawrencejones's full-sized avatar

Lawrence Jones lawrencejones

View GitHub Profile
@lawrencejones
lawrencejones / main.pro
Created November 8, 2014 15:17
Implementation of polynomial reduction
:- use_module(library(lists), [ select/3 ]).
poly_sum([], P, P).
poly_sum([(C1, E)|T], P2, Result) :-
select((C2, E), P2, P3),
Sum is C1 + C2,
poly_sum([(Sum, E) | T], P3, Result).
poly_sum([H|P1], P2, [H|Result]) :-
@lawrencejones
lawrencejones / args.js
Created November 10, 2014 12:35
Pattern for setting default js arguments
function methodWithOptionalParams(params) {
/* Assume underscore */
var options = _.extend({
first: 'First argument default',
second: undefined, // this argument is not supplied as default
third: 'Third default'
}, params || {})
doValidation(options);
@lawrencejones
lawrencejones / .gitignore
Last active August 29, 2015 14:09
Allow monkey patching of node's module loading to resolve require arguments to package local paths. Note that if you do this at work and you don't get fired, then leave- the jobs not worth keeping.
node_modules
test
/node_modules
@lawrencejones
lawrencejones / README.md
Last active August 29, 2015 14:17
Bare bones implementation of two phase commitment

Two Phase Commit

Using a hacky network abstraction, can simulate two phase commitment by having processes decide their ability to commit as a function of their process ID.

Should hold to atomic commitment axioms...

  1. All participants read the same decision
  2. If any participants decide to commit, then all do

Kingston Head

Calculates damage caused by crab+crash at kingston head, using garmin gps data

@lawrencejones
lawrencejones / -README.md
Last active August 29, 2015 14:17
Peterson's Mutex Algorithm

Peterson's Mutex Algorithm

Implements a mutex algorithm that enforces mutex, liveness and bounded waiting.

@lawrencejones
lawrencejones / prepare-commit-msg
Created April 10, 2015 16:09
Hook to append ghi output to commit message
#!/bin/bash
# Append ghi output to the commit message
if hash ghi 2>/dev/null;
then
ghi | sed 's/^ \+\([0-9]\+\)/#\tissue: #\1:\t/' >> $1
fi
@lawrencejones
lawrencejones / diffospec.zsh
Created May 6, 2015 17:04
Trigger rspec on specs that have been affected between parent and current branch
#!/usr/bin/env zsh
diffospec() {
if [[ "$1" -eq "--help" ]]; then
echo """
Desc: Runs rspec against files that have changed from a different commit
Usage: diffospec <sha?>
Examples...
@lawrencejones
lawrencejones / gh_oauth.rb
Created May 15, 2015 11:39
Create a github auth token
gem 'octokit'
require 'octokit'
print "Login: "; login = gets.chomp
print "Password: "; password = `read -s password; echo $password`.chomp
print "\nTwo factor auth: "; two_factor = gets.chomp
gh = Octokit::Client.new(
login: login,
password: password