Skip to content

Instantly share code, notes, and snippets.

View key-container.ts
* This module contains two data structures:
* - `KeyContainerMap` lets us use “key containers” as Map keys.
* - `KeyContainerSet` lets us use “key containers” as Set elements.
* A “key container” is an object that has a method `.getMapKey()`. Two key
* containers are considered equal if `.getMapKey()` returns the same value
* (often a string).
View gist-toc.mjs
#!/usr/bin/env node
// Usage:
// cat | ./gist-toc.mjs
// pbpaste | ./gist-toc.mjs | pbcopy # clipboard -> clipboard (macOS)
function createSlug(str) {
str = str.replace(/[?%:`]/g, '');
str = str.replace(/ +/g, '-');
return str.toLowerCase();
View fork-join.mjs
import * as assert from 'assert/strict';
async function forkJoin(objOrArrOfPromises) {
let promises;
if (Array.isArray(objOrArrOfPromises)) {
promises = objOrArrOfPromises;
} else {
promises = Object.values(objOrArrOfPromises);
const settled = await Promise.allSettled(promises);
View caused-error.mjs
// Code moved here:

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']

Brief an die Politik bzgl. COVID-19


  • Die deutsche Politik scheint nicht zu verstehen, dass eine Mehrheit der Deutschen härtere Maßnahmen gegen COVID-19 mittragen würde, wenn dahinter eine Strategie stünde.
  • Um das zu kommunizieren, sind die Abgeordneten des eigenen Wahlkreises wahrscheinlich die besten Ansprechparter*innen. Hier kann man sie finden:
  • Den folgen Text werde ich ihnen per E-Mail schicken.

( Lizenz: )


Dual mode code (that works both synchronously and asynchronously)

My use case: a Markdown parser that should work both synchronously and asynchronously. The latter forces the invoking code to switch to async, which is overkill when parsing simple strings.

Currently the parser is based on async generators.

Potential solution 1: CSP (communicating sequential processes) and generators

I did some experiments with CSP.

rauschma /
Last active May 17, 2021
ES2021 edition of “JavaScript for impatient programmers”

What is new in the ES2021 edition of “JavaScript for impatient programmers”?

Free to read online:

  • The exercises now run as native ESM modules on Node.js. Previously, they were run via the esm package.
  • Material on new ES2021 features:
    • String.prototype.replaceAll()
    • Promise.any()
    • Logical assignment operators
    • Underscores (_) as separators in number literals and bigint literals

Using the “JS for impatient programmers” exercise setup with latest language features


  • Replace the existing package.json with the file shown here.
  • Execute in the shell:
    cd impatient-js-code*
    rm -rf node_modules
    npm install
rauschma /
Last active Jan 25, 2021
Table: RegExp flags `/g` and `/y`

Table: RegExp flags /g and /y

The following table was generated by the Node.js script:

/ /g /y /yg
r.exec(s) {i:0} {i:1} {i:1} {i:1}
.lI unch .lI upd .lI upd .lI upd
r.test(s) true true true true
.lI unch .lI upd .lI upd .lI upd