Skip to content

Instantly share code, notes, and snippets.

@tomstuart
tomstuart / codeship
Last active December 14, 2015 17:17
Ruby script to open latest Codeship build for current commit
#!/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
@tomstuart
tomstuart / combinations_spec.rb
Created July 22, 2016 14:39 — forked from tuzz/combinations_spec.rb
Generates combinations from an array
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
@tomstuart
tomstuart / a-bit-more-algebra.md
Last active October 7, 2016 11:37
A bit more algebra

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ε

@tomstuart
tomstuart / levenshtein.rb
Last active May 26, 2023 23:12
Approximate substring matching with Levenshtein distance
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,
@tomstuart
tomstuart / setting-up-macos.md
Created January 19, 2020 15:43
Setting up macOS
@tomstuart
tomstuart / backtrace-limit-fixes.diff
Created June 25, 2023 14:33
Read `--backtrace-limit` from `RUBYOPT`, default it to 5 and allow it to be set to -1
diff --git a/error.c b/error.c
index 8aa081c198..d51ea349e0 100644
--- a/error.c
+++ b/error.c
@@ -66,7 +66,7 @@ VALUE rb_iseqw_local_variables(VALUE iseqval);
VALUE rb_iseqw_new(const rb_iseq_t *);
int rb_str_end_with_asciichar(VALUE str, int c);
-long rb_backtrace_length_limit = -1;
+long rb_backtrace_length_limit = 5;