Skip to content

Instantly share code, notes, and snippets.

View maetl's full-sized avatar

Mark Rickerby maetl

View GitHub Profile
@maetl
maetl / pipe.js
Created March 25, 2017 12:09
Lazy pipeline API using wrapped iterators and generators to pump values through the chain
function Pipe(sequence) {
const wrappedIterator = sequence[Symbol.iterator]();
this.next = wrappedIterator.next.bind(wrappedIterator);
}
Pipe.step = function(generator) {
return new Pipe({
[Symbol.iterator]: generator
});
}
@maetl
maetl / subgraph.rb
Created June 10, 2017 13:22
Subgraph isomorphism matching for small in-memory Ruby graphs.
$LOAD_PATH << "./lib"
require 'mementus'
# Prototype of subgraph isomorphism search using Ullmann’s original 1976
# algorithm [1] as the foundation for a depth-first scan that moves forward
# through each possible outgoing edge, then attempts to confirm the match by
# doing a reverse edge lookup, comparing the query to the target graph.
#
# This is known to be a NP-complete problem but despite being exponential in
# theory, in practice it’s possible to achieve reasonable results by using
@maetl
maetl / karla.html
Created February 10, 2018 13:40
Test of a variation of Karla that supports Māori macrons properly.
<html>
<head>
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/karmilla" type="text/css"/><style>
h1, h2, p {
font-family: 'Karmilla', sans-serif;
}
</style>
</head>
<body>
<h1>te ao māori</h1>
@maetl
maetl / pickWeightedValue.js
Created August 7, 2018 02:49
Pick a weighted value from an object in JS
const rules = {
'90%': 0.9,
'10%': 0.1
}
function pickWeightedValue(rules) {
const productions = Object.keys(rules)
const weights = Object.values(rules)
let maxIndex = 0
@maetl
maetl / build.rb
Created July 17, 2019 00:57
Minimalist documentation site generator
require "kramdown"
require "mustache"
require "fileutils"
WEB_DIR = "./public"
DOCUMENT_TPL = ".site/templates/document.html"
INDEX_TPL = ".site/templates/index.html"
HOME_TPL = ".site/templates/homepage.html"
Mustache.template_path = ".site/templates/partials"