Skip to content

Instantly share code, notes, and snippets.

View acutmore's full-sized avatar

Ashley Claymore acutmore

View GitHub Profile
@acutmore
acutmore / proxy.js
Created September 7, 2016 17:24
Basic es5 proxy
console.clear();
function isFunction(o){
return typeof o === (typeof isFunction);
}
/**
* Wraps up an object replacing methods with an interceptor
* @param obj - the obj to wrap
* @param interceptor {(obj, methodName, args) => any}
@acutmore
acutmore / chaos-promise.ts
Last active April 7, 2019 12:10
Promise Implementation where callbacks resolve in random order - To help catch race conditions
const OriginalPromise = Promise;
const enum State {
PENDING,
RESOLVED,
REJECTED
}
const emptyFn = () => {};
const FUDGE_FACTOR_MS = 100;
@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 / index.ts
Last active September 21, 2019 09:04
code mod to update dependency injection annotations at YouView
/// <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;
@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: []
}
];
@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 / 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 / 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 / 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