Skip to content

Instantly share code, notes, and snippets.

Mark Rickerby maetl

Block or report user

Report or block maetl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@maetl
maetl / build.rb
Created Jul 17, 2019
Minimalist documentation site generator
View build.rb
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"
@maetl
maetl / pickWeightedValue.js
Created Aug 7, 2018
Pick a weighted value from an object in JS
View pickWeightedValue.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 / karla.html
Created Feb 10, 2018
Test of a variation of Karla that supports Māori macrons properly.
View karla.html
<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 / subgraph.rb
Created Jun 10, 2017
Subgraph isomorphism matching for small in-memory Ruby graphs.
View subgraph.rb
$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 / pipe.js
Created Mar 25, 2017
Lazy pipeline API using wrapped iterators and generators to pump values through the chain
View pipe.js
function Pipe(sequence) {
const wrappedIterator = sequence[Symbol.iterator]();
this.next = wrappedIterator.next.bind(wrappedIterator);
}
Pipe.step = function(generator) {
return new Pipe({
[Symbol.iterator]: generator
});
}
View soper.md

Peters told the Lords they should Brexit, to again look to the Reserve Bank to tell us how they're going to do themselves out of control and when is this incompetent Clark Government going to be done. No chance of that with New Zealand First, obviously there's still a lot of figures were spilling off the Tertiary Minister's printing press, the custodian of the market. No chance of that with New Zealand First, obviously there's still a lot of work to be about the crisis that they've tried unsuccessfully to get the incumbents have thrown up their hands in horror at the response their billion dollar binge on roads, power poles and sewers has been fierce with no political punches being pulled, even between MPs on the topic on Black Friday last month. Peters did stop for a breather though and was asked about his Brexit buddy Nigel Farage's resignation as the upper price it could fetch at auction.

View lazy_enumerables_from_scratch.rb
require 'fiber'
class Step
def initialize(source, yielder=nil)
@context = Fiber.new do
source.each do |element|
if yielder
yielder.call(element)
else
Fiber.yield(element)
View em_transaction.rb
require 'eventmachine'
class Pipeline < EM::Completion
def initialize(*steps)
@steps = steps
@steps.each_cons(2) do |pair|
pair.first.callback do |input|
EM.next_tick do
pair.last.call(input)
@maetl
maetl / eight.rb
Created Nov 14, 2015
Magic numbers
View eight.rb
(1..9).reduce('') do |m,i|
s = i.to_s
m << s
r = "#{m} * 8 + #{i.to_s}"
puts r + " = " + eval(r).to_s
m
end
@maetl
maetl / filter.rb
Last active Aug 29, 2015
Several more or less hacky ways to generate filter parameters as described in the JSON API recommendation (http://jsonapi.org/recommendations/). It looks as if using “filter[name]=value” directly is incompatible with the URI Template specification documented in RFC6570, but “filter%5Bname%5D=value” works. Unsure if that’s expected or not. The Fi…
View filter.rb
require 'addressable/template'
class Filter::RawParams
def initialize(params)
@params = params
end
def encode_value(value)
Addressable::URI.encode_component(value, Addressable::URI::CharacterClasses::UNRESERVED)
end
You can’t perform that action at this time.