Skip to content

Instantly share code, notes, and snippets.

Avatar

Steve Hanov smhanov

View GitHub Profile
View index.html
<!DOCTYPE html>
<html>
<body>
<h1>Hello world!</h1>
<script src="test.js"></script>
</body>
</html>
View Truetype.md

The first file

This is the first file in the gist.

@smhanov
smhanov / TrueType.ts
Last active Jul 28, 2022
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 http://stevehanov.ca/blog/index.php?id=143
View TrueType.ts
// By Steve Hanov
// steve.hanov@gmail.com
// Released to the public domain on April 18, 2020
//import { log } from "./log"
// Usage:
/*
declare let arrayBuffer:ArrayBuffer;
@smhanov
smhanov / description.md
Last active Jul 26, 2022
Pipeline multiprocessing for python with generators
View description.md

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

View copyinsert.py
#!/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: http://stevehanov.ca/blog/index.php?id=146
# 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
smhanov / dawg.py
Last active Jul 19, 2022
Use a DAWG as a map
View dawg.py
#!/usr/bin/python3
# By Steve Hanov, 2011. Released to the public domain.
# Please see http://stevehanov.ca/blog/index.php?id=115 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