Skip to content

Instantly share code, notes, and snippets.

Avatar

Ashley Claymore acutmore

View GitHub Profile
@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 Aug 24, 2020
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 Nov 19, 2020
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;
@acutmore
acutmore / chaos-promise.ts
Last active Apr 7, 2019
Promise Implementation where callbacks resolve in random order - To help catch race conditions
View chaos-promise.ts
const OriginalPromise = Promise;
const enum State {
PENDING,
RESOLVED,
REJECTED
}
const emptyFn = () => {};
const FUDGE_FACTOR_MS = 100;
@acutmore
acutmore / proxy.js
Created Sep 7, 2016
Basic es5 proxy
View proxy.js
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}
You can’t perform that action at this time.