Skip to content

Instantly share code, notes, and snippets.

0eNrtfWtyG8mu5l78c4K6ke9Hx8TdiKOjg5Zpm9eSqKCo7tNxohcwu5i1zUqmipStVCVQCaBEqo5V90ffY5FEPoBEIvH48O8Pn24eN/f77d3hw2///rC93t09fPjt478/PGy/3q1v+r8d/r7ffPjtw/awuf2w+nC3vu3/tV5vr/5a7zffdo8Pmw//rD5s7z5v/vXhN/3Pqv3bh4fN7aeb7d3Xq9v19bft3ebKFCTMP7+vPmzuDtvDdnOay/Eff/9x93j7abPvxvhJ6Xbzeft4e7W52Vwf9tvrq/vdzaYb53730P14d9fPoCdo4n/51Ye/P/x2ZV36L98NdbfZfv32afe47wdwqxR+7+c9GMf8HOfzZv35Znf9/epmvf+66f57ew8MY+3PQf4ByFkuuTBKznF3wbrRXdCrsEoZ2gfPnLhToxMP3Ik73WCfNqusoZlH7szHOZieRXi/PXy73Ry6SV/vbj9t79aH3R4i6IupdxPvjtdhv7v549Pm2/rPbfeT7nvPtP7oPv58/P1D/8GX7f7h8Ed1mP7c7g+P3V9+Tub0jatNd5b6Y/Sw6cn0tB4O6/5YX+Xj/60+7O43+/Vpeh/+V/f73ePh/pE9wj+nddx1TPsxU93/Z7/5XJ7WbfevXhKut/vrx+3h+G/9T8elDwb5dq6/DHEhF0y93n7e7BsscG0WPBF6nf1/3vh+9bvb+/X+OLXfPvxv8Z73hO7/7ub3eHf448t+d/vH9q4j8+G3w/5xw2BIernFZpQf1tffhhiiFfeYxdFjpjWTnh9XONqwNU4a1ThhpcMqO0jjaMuTTq8X6fwpcNpzxNNpong6rji5cXHy7GvAm/d9DUTONdAfIco9oNmGhPfjFpBZGbPSCjQlNNeW8A0lxzcmfH7XUtQfS4YUEa0JzTQnfFoU9vMms+wJl2gK23DtiaBHj5rh2hNh/AIwbHsimHHFE1amsykUaFEYpkUR/CKgP0XOsCwKn4kCyrUoQhoXKL5FEcK7vguC5twFhmhRGLZFEfL
@bterlson
bterlson / box.js
Created September 30, 2020 21:41
Source code for a useless box.
import Servo from "pins/servo";
import Timer from "timer";
import Digital from "pins/digital";
import Monitor from "pins/digital/monitor";
import NeoPixel from "neopixel";
const doorServo = new Servo({pin: 5});
const armServo = new Servo({pin: 14});
const switchMonitor = new Monitor({
mode: Digital.InputPullUp,
@bterlson
bterlson / foo.txt
Last active November 25, 2019 18:29
asdf
‎‎​
let editableThings = new WeakMap();
function finisherFor(prop) {
return function finisher(C) {
let list = editableThings.get(C);
if (!list) {
list = [];
editableThings.set(C, list);
}
list.push(prop);

Keybase proof

I hereby claim:

  • I am bterlson on github.
  • I am bterlson (https://keybase.io/bterlson) on keybase.
  • I have a public key ASCWavsVAlIX8j8m9UksFEDYdOCGjuLVELH-bE3z9KOY3wo

To claim this, I am signing this object:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bterlson
bterlson / mod.js
Last active January 26, 2017 15:25
Module export forms have subtle differences
// exporter1.js
let foo = 1;
export { foo as default }; // exports the foo binding
foo = 2;
// exporter2.js
let foo = 1;
export default foo; // creates a new binding named *default* and initializes it to 1.
foo = 2; // assigns to the foo binding which is not exported
@bterlson
bterlson / test-enumerate.md
Created January 29, 2016 19:46
for-in reconfigure

Test file

let obj = {};
Object.defineProperty(obj, 'a', { enumerable: true, configurable: true });
Object.defineProperty(obj, 'b', { enumerable: true, configurable: true });
Object.defineProperty(obj, 'c', { enumerable: true, configurable: true });

let visited = []
for(prop in obj) {
 Object.defineProperty(obj, 'c', { enumerable: false });
> eshost host --list
┌──────────────┬─────────┬────────────────────────────────────────────────────┬─────────┐
│ name │ type │ path │ args │
├──────────────┼─────────┼────────────────────────────────────────────────────┼─────────┤
│ chakra │ ch │ C:\Users\brterlso\projects\runify\hosts\ch.exe │ │
├──────────────┼─────────┼────────────────────────────────────────────────────┼─────────┤
│ node │ node │ c:\Program Files\nodejs\node.exe │ │
├──────────────┼─────────┼────────────────────────────────────────────────────┼─────────┤
│ spidermonkey │ jsshell │ C:\Users\brterlso\projects\runify\hosts\js.exe │ │
├──────────────┼─────────┼────────────────────────────────────────────────────┼─────────┤

Pattern Matching

This is a strawman proposal for adding pattern matching to ECMAScript. Pattern matching is useful for matching a value to some structure in a similar way to destructuring. The primary difference between destructuring and pattern matching are the use cases involved - destructuring is useful for binding pieces out of larger structures whereas pattern matching is useful for mapping a value's structure to data or a set of behaviors. In practice this means that destructuring tends to allow many shapes of data and will do its best to bind something out of it, whereas pattern matching will tend to be more conservative.

Additionally, the power of pattern matching is increased substantially when values are allowed to participate in the pattern matching semantics as a matcher as well as a matchee. This proposal includes the notion of a pattern matching protocol - a symbol method that can be implemented by objects that enables developers to use those values in pattern matching. A common scenario w