{{ message }}

Instantly share code, notes, and snippets.

# Tom Stuart tomstuart

Created Jan 19, 2020
Setting up macOS
View setting-up-macos.md
Last active Jun 15, 2017
Approximate substring matching with Levenshtein distance
View levenshtein.rb
 module Levenshtein def self.substring_distance(needle, haystack) distances = Array.new(haystack.length.succ, 0) needle.each_char.with_index do |needle_char, needle_index| next_distances = [needle_index.succ] haystack.each_char.with_index do |haystack_char, haystack_index| deletion, insertion, substitution = distances[haystack_index.succ].succ,
Last active Oct 7, 2016
A bit more algebra
View a-bit-more-algebra.md

By working with polynomials we can justify these definitions purely algebraically without doing any differentiation, which I hand-waved away as “a bit more algebra” in the post.

For example, from the angle sum identity

sin(ɑ + β) = sin ɑ cos β + cos ɑ sin β

we know that

sin(a + bε) = sin a cos bε + cos a sin bε

Created Jul 22, 2016 — forked from tuzz/combinations_spec.rb
Generates combinations from an array
View combinations_spec.rb
 require "rspec" def combinations(array, length) if length.zero? [[]] else array.each_index.map { |i| array.drop(i) }.flat_map do |head, *tail| combinations(tail, length - 1).map do |combination| [head] + combination end
Last active Dec 14, 2015
Ruby script to open latest Codeship build for current commit
View codeship
 #!/usr/bin/env ruby require 'json' require 'net/https' require 'time' API_ENDPOINT = 'https://codeship.com/api/v1/projects.json' API_KEY = ENV['CODESHIP_API_KEY'] || raise('set CODESHIP_API_KEY first! get it from https://codeship.com/user/edit#user_api_key') TRIES = 5
Last active Aug 29, 2015 — forked from richardjpope/free-prescriptions.feature
View free-prescriptions.feature
 #http://www.nhs.uk/NHSEngland/Healthcosts/Pages/Prescriptioncosts.aspx Given a user who is 60 or older When they collect a prescription Then it should be free Given a user who is younger than 16 When they collect a prescription Then it should be free
Created Apr 12, 2015
View calling-convention.txt
 before function call: at start of function call: ARG: args for caller args for caller saved state for caller saved state for caller LCL: locals for caller locals for caller stack for caller stack for caller args for callee --> ARG: args for callee SP: saved state for callee LCL: locals for callee SP:
Created Aug 9, 2014
An implementation of the Burrows–Wheeler transform that satisfies https://github.com/zetter/burrows-wheeler-transform
View bwt.rb
 class BWT def encode(string) chars = string.chars + ['\$'] chars.each_index.map(&chars.method(:rotate)).sort.map(&:last).join end def decode(string) chars = string.chars chars.inject([]) { |table| chars.zip(table).sort }. map(&:join).detect { |s| s.end_with?('\$') }.chop
Last active Aug 29, 2015
Rules for auto-explaining FreeAgent transactions
View rules.json
 [ { "textToMatch": "HISCOX", "description": "Liability & indemnity insurance", "vat": "0", "category": "Insurance", "shouldHaveAttachment": false, "ecStatus": "Non-EC" }, {
Created Jul 17, 2014
View gist:d9ce295b89c73a4b69ff
 \$ cat Gemfile source 'https://rubygems.org/' \$ time ruby -e 'puts "Hello world"' Hello world real 0m0.197s user 0m0.117s sys 0m0.073s