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
View es2019-edition.md

Update of “JavaScript for impatient programmers”

This update completes the ES2019 edition of this book. In addition to many small improvements, it brings the following changes:

  • Chapter “The big picture”
    • New section “Polyfills: new features on older platforms”
  • Chapter “Variables and assignment”:
    • Rewritten section “Global variables and the global object”
  • Chapter ”Booleans”:
    • Major rewrite of section “Falsy and truthy values”
View ts-cjs.md

TypeScript bug when compiling to CommonJS?

tsconfig.json:

{
  "compilerOptions": {
    "rootDir": "ts",
    "outDir": "dist",
    "target": "es2018",
View medium-paywall.md
View teaching-practical-cs.md

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: https://mathiasbynens.be/notes/globalthis
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 eval.call(undefined, '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) {
console.error(err1);
callback(err1);
return;
}
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}.`);
return;
} catch (err) {
if (err.code === 'EADDRINUSE') {
console.log(`${entity}: port ${currentPort} in use, trying next port...`);
You can’t perform that action at this time.