Skip to content

Instantly share code, notes, and snippets.


Steve Hanov smhanov

View GitHub Profile
View index.html
<!DOCTYPE html>
<h1>Hello world!</h1>
<script src="test.js"></script>
smhanov /
Last active January 4, 2021 19:44
Test page

The first file

This is the first file in the gist.

smhanov / OpenType.ts
Last active December 9, 2022 09:50
Here is my implementation of a TrueType font reader in Typescript. You can read a font directly from an ArrayBuffer, and then call drawText() to draw it. See my article The second file, OpenType.ts is the same thing but it handles more TrueType files. It is also more coplex
View OpenType.ts
// To see this run, you first stub out these imports. Then put the file in a Uint8Array.
// let slice = new Slice(array);
// let font = new OTFFont(slice);
// Then you can call methods like font.drawText(canvasContext, )
import { ICanvasContext } from "./ICanvasContext"
import { log as Log } from "./log"
const log = Log.create("OPENTYPE");
smhanov /
Last active July 26, 2022 12:40
Pipeline multiprocessing for python with generators

Pipeline multiprocessing in Python with generators

Similar to mpipe, this short module lets you string together tasks so that they are executed in parallel.

The difference is that it lets you use generators, functions which yield results instead of returning them. Each yielded item gets passed to the next stage.

You can specify that one or more copies of the workers operate on the input queue.

Things that can be in a stage

#!/usr/bin/env python3
import time
import sys
# Python by Steve Hanov
# Suffix array construction from:
# From Ge Nong, Sen Zhang and Wai Hong Chan, Two Efficient Algorithms for Linear Suffix Array Construction, 2008
# longestMatches from:
# Released to the public domain.
class SuffixArray:
View Heap.js
// By Steve Hanov (2014)
// Released to public domain
// Minimum element is always on top.
// You can pass in an optional lessThan(a, b) function to the constructor.
// You may use .length to retrieve the length. Try not to set it though.
function Heap()
if (arguments.length) {
smhanov /
Last active March 6, 2023 18:23
Use a DAWG as a map
# By Steve Hanov, 2011. Released to the public domain.
# Please see for the accompanying article.
# Based on Daciuk, Jan, et al. "Incremental construction of minimal acyclic finite-state automata."
# Computational linguistics 26.1 (2000): 3-16.
# Updated 2014 to use DAWG as a mapping; see
# Kowaltowski, T.; CL. Lucchesi (1993), "Applications of finite automata representing large vocabularies",
# Software-Practice and Experience 1993