Skip to content

Instantly share code, notes, and snippets.

Avatar

Ashley Claymore acutmore

View GitHub Profile
@acutmore
acutmore / onSettled.js
Created Feb 17, 2022
utility function to take an array of promises and return an async iterator that yield results as promises settle
View onSettled.js
/** @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 Jun 16, 2022
DEPRECATED (FLAWED) - Proof of concept: Tuples (with symbols) as WeakMap keys in Userland
View tuples-in-weakmaps.js
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// 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 Dec 20, 2020
TypeScript presentation - use https://www.typescriptlang.org/play and load gist with the slides plugin enabled https://github.com/orta/playground-slides
View index.md

alt text


  • Erasable
  • Gradual
  • Structural
  • Generic
  • Inferable
@acutmore
acutmore / simple-tsserver-script.js
Last active Feb 22, 2020
A small wrapper around Typescript's tsserver for easier scripting
View simple-tsserver-script.js
// @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 server = tsserverAPI.start();
@acutmore
acutmore / _web-framework-render-fns.md
Last active Jul 26, 2022
Comparing web framework render functions
View _web-framework-render-fns.md
@acutmore
acutmore / focused.js
Last active Dec 10, 2019
Tracking DOM focus
View focused.js
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 Aug 5, 2022
Emulating a 4-Bit Virtual Machine in (TypeScript\JavaScript) (just Types no Script)
View README.md

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 Sep 19, 2019
logic in typescript
View tsc-logic.ts
// 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 Sep 21, 2019
Dependency Injection algorithm idea
View resolve.test.ts
import {resolve, Service, ResolvedService} from './resolve';
describe('resolve', () => {
it('resolves a single service graph', () => {
const input: Service[] = [
{
name: 'a',
requires: []
}
];
@acutmore
acutmore / index.ts
Last active Sep 21, 2019
code mod to update dependency injection annotations at YouView
View index.ts
/// <reference types="node" />
import { mod } from "riceburn";
import { TypescriptMod } from "riceburn/lib/interfaces";
import ts = require("typescript");
import cp = require("child_process");
import fs = require("fs");
const glob = require("glob");
import { getServiceDescription } from "../phoenix/tools/webpack/hatch/typescript-dependency-annotations/tsc-dep-annotations";
const { log } = console;