Skip to content

Instantly share code, notes, and snippets.

/**
* A simple Time travel machine to the future.
*
* A theoretical time-traveling to the future
* (a very-very-very simplified explanation/application
* of the General relativity).
*
* .allgemeine Relativitätstheorie
*
* by Dmitry Soshnikov <[email protected]>
@DmitrySoshnikov
DmitrySoshnikov / reg-vm.js
Last active June 15, 2018 20:38
A simple educational Register-based VM, Assembler, and Disassembler.
// "Fetch, decode, eval!"
// A simple Register-based VM, Assembler, and Disassembler.
// by Dmitry Soshnikov <[email protected]>
// This virtual machine (VM) consists of registers (data storage),
// and operations (instructions) which operate on the registers.
// --------------------------------------------------------------
// Registers.
// --------------------------------------------------------------
"use strict";
const slice = [].slice;
/**
* A user callback function that is raised when the result of an async function
* is available.
*
* @param Any error
* If truthy, indicates an error result. Will be thrown from the

List comprehensions

Basic idea in theoretical programming: a notation for Set builders from math.

Basic idea in practical programming: syntactic sugar for "map + filter" functional methods:

Example of map and filter, ES6

let x = N.filter(x => x > 10).map(x => x * x);
@DmitrySoshnikov
DmitrySoshnikov / stop-copy-gc.js
Last active February 13, 2018 19:23
Stop and Copy GC technique.
/**
* Stop and Copy Garbage Collection technique.
*
* See also previous lessons on
*
* - Mark and Sweep GC: https://gist.github.com/DmitrySoshnikov/4391763
* - Reference Counting (ARC) https://gist.github.com/DmitrySoshnikov/4646658
*
* by Dmitry Soshnikov <[email protected]>
* MIT Style License
@DmitrySoshnikov
DmitrySoshnikov / reference-counting-gc.js
Last active September 30, 2022 00:19
Reference counting GC
/**
* Automatic Reference Counting (ARC) Garbage Collection technique.
*
* This diff describes Reference counting GC technique.
* See also previous lesson on Mark and Sweep GC:
* https://gist.github.com/4391763
*
* by Dmitry Soshnikov <[email protected]>
* MIT Style License
*/
@DmitrySoshnikov
DmitrySoshnikov / reference-counting-gc.js
Last active December 11, 2015 17:09
Automatic Reference Counting (ARC) Garbage Collector
/**
* Automatic Reference Counting (ARC) Garbage Collection technique.
*
* This diff describes Reference counting GC technique.
* See also previous lesson on Mark and Sweep GC:
* https://gist.github.com/4391763
*
* Covered topics:
*
* 1. Reference value in ECMAScript (JS specific)
/**
* Mark and Sweep Garbage Collection technique.
* MIT Style License
* by Dmitry Soshnikov
*/
// This diff describes the simplest version of mark and sweep
// GC in order to understand the basic idea. In real practice the
// implementation can be much tricker and optimized.
@DmitrySoshnikov
DmitrySoshnikov / no-such-method-analysis.js
Created December 15, 2011 13:01
Analysis of current noSuchMethod situation
// by Dmitry Soshnikov <[email protected]>
// on "noSuchMethod" hook via proxies
// written on December 15, 2011
// Below is tl;dr
// but if you want really never-ending tl;dr, try this
// original old thread from 2010 on es-discuss:
// https://mail.mozilla.org/pipermail/es-discuss/2010-October/011929.html
// Small disclaimer and note:
@DmitrySoshnikov
DmitrySoshnikov / r-proto-class-current-class.js
Created November 15, 2011 17:27
R-Proto-Class-Current-Class.js
// https://mail.mozilla.org/pipermail/es-discuss/2011-November/018440.html
// see original lib here:
// https://gist.github.com/1366953
// https://gist.github.com/1330574
var Class = {
/**
*allocate