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 / 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 / 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 / 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 / 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 / _web-framework-render-fns.md
Last active May 6, 2024 16:31
Comparing web framework render functions
@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 / 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