Skip to content

Instantly share code, notes, and snippets.

View acutmore's full-sized avatar

Ashley Claymore acutmore

View GitHub Profile
@acutmore
acutmore / immutability-supports-equality.md
Last active September 23, 2022 22:31
When considering the design of the Record & Tuple proposal a core driver in much of the design stems primarily from equality rather than immutability.

Immutability is Equality's support act [hackmd]

When considering the design of the Record & Tuple proposal a core driver in much of the design stems primarily from equality rather than immutability.

Categorizing equality

There are many ways to think about equality but one way to divide up the design space is two dimensions.

pure impure
@acutmore
acutmore / onSettled.js
Created February 17, 2022 17:40
utility function to take an array of promises and return an async iterator that yield results as promises settle
/** @param promises {Array<Promise<unknown>>} */
export async function * onSettled(promises) {
let wake;
let wait = new Promise(_ => wake = _);
let pending = promises.length;
const queue = [];
for (const p of promises) {
Promise.allSettled([p]).then(([result]) => {
queue.push(result);
@acutmore
acutmore / tuples-in-weakmaps.js
Last active June 16, 2022 09:27
DEPRECATED (FLAWED) - Proof of concept: Tuples (with symbols) as WeakMap keys in Userland
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// this approach fails to handle cycles
// next attempt: https://gist.github.com/acutmore/d1aaaff27c898fdd26b2e15de5c2f7c6
const {Tuple, FakeSymbol} = ToyTupleLib();
const Box = BoxLib(FakeSymbol);
const TupleWeakMap = TupleWeakMapLib(Tuple, FakeSymbol, v => FakeSymbol.isFakeSymbol(v));
const wm = new TupleWeakMap();
@acutmore
acutmore / index.md
Last active December 20, 2020 14:02
TypeScript presentation - use https://www.typescriptlang.org/play and load gist with the slides plugin enabled https://github.com/orta/playground-slides

alt text


  • Erasable
  • Gradual
  • Structural
  • Generic
  • Inferable
@acutmore
acutmore / simple-tsserver-script.js
Last active October 18, 2022 15:34
A small wrapper around Typescript's tsserver for easier scripting
// @ts-check
const childProcess = require('child_process');
const path = require('path');
const TTL_MS = 5000;
/**
* @description Start a connection to tsserver
* @param {{debug?: boolean}} options
* @example
const chat = tsserverAPI.start();
@acutmore
acutmore / _web-framework-render-fns.md
Last active December 7, 2023 00:59
Comparing web framework render functions
@acutmore
acutmore / focused.js
Last active December 10, 2019 13:55
Tracking DOM focus
function updateFocus(elm) {
const focusedClass = 'focused';
const currentlyFocused = document.querySelector('.' + focusedClass);
if (currentlyFocused != null) {
currentlyFocused.classList.remove(focusedClass);
}
if (elm) {
elm.classList.add(focusedClass);
}
}
@acutmore
acutmore / README.md
Last active January 21, 2024 20:30
Emulating a 4-Bit Virtual Machine in (TypeScript\JavaScript) (just Types no Script)

A compile-time 4-Bit Virtual Machine implemented in TypeScript's type system. Capable of running a sample 'FizzBuzz' program.

Syntax emits zero JavaScript.

type RESULT = VM<
  [
    ["push", N_1],         // 1
    ["push", False],       // 2
 ["peek", _], // 3
@acutmore
acutmore / tsc-logic.ts
Last active September 19, 2019 11:51
logic in typescript
// ASHEMBLER
type B = 1 | 0;
type BITS_4 = [B,B,B,B];
// note: 'assert' interfaces function as unit tests
interface assert {
true: 1;
false: 0;
}
@acutmore
acutmore / resolve.test.ts
Last active September 21, 2019 09:05
Dependency Injection algorithm idea
import {resolve, Service, ResolvedService} from './resolve';
describe('resolve', () => {
it('resolves a single service graph', () => {
const input: Service[] = [
{
name: 'a',
requires: []
}
];