Skip to content

Instantly share code, notes, and snippets.

Axel Rauschmayer rauschma

Block or report user

Report or block rauschma

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

Teaching the practically useful parts of computer science

I think the practically useful parts of computer science could easily be taught via a book (or similar).

General considerations:

  • I think I only every really learned abstract concepts when I could play with them via a programming language. For example:
    • Logic via Prolog
    • Rewrite rules via Maude
View sequential-concurrent.js
const assert = require('assert');
//========== Helper functions
* Resolves after `ms` milliseconds
function delay(ms) {
return new Promise((resolve, _reject) => {
setTimeout(resolve, ms);
View globalthis-polyfill.mjs
// Based on:
export const getGlobalThis = () => {
if (typeof globalThis !== 'undefined') return globalThis;
if (typeof self !== 'undefined') return self;
if (typeof window !== 'undefined') return window;
if (typeof global !== 'undefined') return global;
return, 'this');
export const installGlobalThis = () => {
if (typeof globalThis === 'undefined') {
View extract-methods.js
const cache = new WeakMap();
const extract = (receiver, method) => {
let cacheEntry = cache.get(receiver);
if (!cacheEntry) {
cacheEntry = new Map();
cache.set(receiver, cacheEntry);
let boundMethod = cacheEntry.get(method);
if (!boundMethod) {
boundMethod = method.bind(receiver);
View callbacks-promises-asyncfuncs.js
// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
f2(result1, (err2, result2) => {
View http-server-listen.js
async function listenRepeatedly(entity: string, server: Server, port: number) {
for (let i=0; i<10; i++) {
const currentPort = port + i;
try {
await listenOnce(server, currentPort);
console.log(`${entity}: listening at port ${currentPort}.`);
} catch (err) {
if (err.code === 'EADDRINUSE') {
console.log(`${entity}: port ${currentPort} in use, trying next port...`);

Background {#background}




View regexp-flags.js
// Add flag 'g' if it isn’t there, yet
// Solution 1
let cloneFlags = regExp.flags;
if (!cloneFlags.includes('g')) {
cloneFlags += 'g';
// Solution 2
const cloneFlags = regExp.flags.includes('g')
rauschma / demo-output.txt
Last active Jul 30, 2018
Pandoc filter: numbering parts, chapters and sections for HTML
View demo-output.txt
I. Background
1. History
2. Tips
II. Main
3. Syntax
3.1. Expressions
3.1.1. Special expressions
3.2. Statements
4. Library
You can’t perform that action at this time.