Skip to content

Instantly share code, notes, and snippets.


Dave Herman dherman

View GitHub Profile
* buffer.region(4, 16).into::<JsUint32Array>
* buffer.from(4).to(16).into::<JsUint32Array>
* buffer[4..16].to_typed_array::<u32, _>(&mut cx)
* JsUint32Array::from_region(&mut cx, buffer[4..16])
* buffer.region(4..16).to_typed_array::<u32, _>(&mut cx)
* JsUint32Array::from_region(&mut cx, buffer.region(4..16))
* JsUint32Array::from_buffer_region(&mut cx, buffer, 4, 16))
trait TypedArrayExt {
fn set_info<'cx, C: Context<'cx>>(&self, cx: &mut C, info: Handle<'cx, JsObject>) -> NeonResult<()>;
fn get_info<'cx, C: Context<'cx>>(&self, cx: &mut C) -> JsResult<'cx, JsObject> {
let info = cx.empty_object();
self.set_info(cx, info)?;
dherman / ab.js
Created Jul 15, 2022
failed experiment to monkey-patch ArrayBuffer.prototype
View ab.js
"use strict";
let abp = ArrayBuffer.prototype;
const VIEW = Symbol('view');
function getView(receiver) {
return receiver[VIEW] ||
(receiver[VIEW] = new Uint8Array(receiver));

In penance for cracking stupid jokes on Twitter, here's my Emacs cheat sheet. Emacs has a steep learning curve, so I've tried to order them by importance so you could learn them in stages.

One overall rule of thumb: pay attention to the minibuffer (the line at the bottom of the editor). It will often guide you through a process, and also gives you hints about what state you're in, such as the middle of a multi-chord sequence.

The other rule of thumb: when in doubt, C-g it out.

Basics (mandatory)

You simply can't get by without having these at your fingertips.

flowchart TB
    subgraph primitives [Primitive Types]
dherman /
Last active May 30, 2022
ES6 Realms API

Notational Conventions

This section describes the conventions used here to describe type signatures.

A [T] is an array-like value (only ever used read-only in this API), i.e., one with an integer length and whose indexed properties from 0 to length - 1 are of type T.

A type T? should be read as T | undefined -- that is, an optional value that may be undefined.


dherman / ssa-cps-anf.txt
Created Nov 20, 2012
links on SSA, CPS, and A-normal form
View ssa-cps-anf.txt
Original paper on A-normal form:
A high-level intro to ANF:
One of the earlier attempts to relate SSA and CPS:
dherman /
Last active Sep 1, 2021
fine-grained borrowing (read-write) and sharing (read-only) of buffers


Typed arrays can be copied or transferred between workers, but it's not possible for multiple workers to work with a buffer in parallel without copies. This document describes two ways to improve this without introducing data races: transferring read-write access to disjoint regions of buffers, and transferring read-only access to shared buffers/regions.

This variant of the API enables fine-grained borrowing and sharing, where a single ArrayBuffer can have multiple disjoint regions parceled out. This way individual workers can work with their regions at their original indices. This makes the API more amenable to being a compilation target.


Here is an example that demonstrates sharing a read-only segment and multiple read-write segments with four separate workers.

dherman /
Last active Jul 4, 2021
What can you do with ES6 string template literals?

DOM selectors

var elements = query`.${className}`;


var message = l10n`Hello ${name}; you are visitor number ${visitor}:n!


  • expression-oriented programming one of the great advances of FP
  • expressions plug together like legos, making more malleable programming experience in-the-small


Write in an expression-oriented style, scoping variables as locally as possible: