Skip to content

Instantly share code, notes, and snippets.

View garbles's full-sized avatar
🇨🇦

Gabe garbles

🇨🇦
View GitHub Profile
@garbles
garbles / SketchSystems.spec
Last active October 15, 2018 07:07
Ready*
Ready*
Unit Ready*
attack -> Select Attack
defend -> Player Defend
move -> Select Move
use item -> Select Item
done -> Waiting
Select Attack
Select Attack Type*
@garbles
garbles / get-deep-type.ts
Created May 9, 2018 23:24
TypeScript utils for 2.8
type GetDeepType1<T, A> = A extends [infer B] ? B extends keyof T ? T[B] : undefined : undefined;
type GetDeepType2<T, A> = A extends [infer B, infer C] ? B extends keyof T ? GetDeepType1<T[B], [C]> : undefined : undefined;
type GetDeepType3<T, A> = A extends [infer B, infer C, infer D] ? B extends keyof T ? GetDeepType2<T[B], [C, D]> : undefined : undefined;
type GetDeepType4<T, A> = A extends [infer B, infer C, infer D, infer E] ? B extends keyof T ? GetDeepType3<T[B], [C, D, E]> : undefined : undefined;
type GetDeepType5<T, A> = A extends [infer B, infer C, infer D, infer E, infer F] ? B extends keyof T ? GetDeepType4<T[B], [C, D, E, F]> : undefined : undefined;
type GetDeepType6<T, A> = A extends [infer B, infer C, infer D, infer E, infer F, infer G] ? B extends keyof T ? GetDeepType5<T[B], [C, D, E, F, G]> : undefined : undefined;
type GetDeepType<T, A> =
A extends [any] ? GetDeepType1<T, A> :
A extends [any, any] ? GetDeepType2<T, A> :
@garbles
garbles / README.md
Last active April 29, 2018 03:52
Why TypeScript?

Why pick TypeScript?

We are planning to standardize our JavaScript stack on TypeScript, where previously we tried Flow on several projects. You can scroll to bottom to see my "hot take" on TypeScript vs Flow.

This post is mostly a collection of references to posts where others have made strong cases for using static types and TypeScript. I've tried my best to include a TL;DR with some comments.

Why static typing?

@garbles
garbles / index.html
Created August 7, 2017 20:50
Use Phaser with Typescript + Webpack
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title></title>
</head>
<body>
@garbles
garbles / jest-axios-setup.md
Last active July 21, 2021 15:49
Setting up axios so that it doesn't use Jest's mocked XMLHttpRequest

You can set the default adapter for axios in your test setup file.

In package.json

{
  "jest": {
    "setupTestFrameworkScriptFile": "<rootDir>/test-setup.js",
  }
}
export default function append<T>(arr: T[], val: T): T[] {
return [...arr, val];
}
import {sampleOne} from 'babel-plugin-transform-flow-to-gen/api';
import type {Developer, JavaScript} from './types';
const javaScriptDevGen = Developer(JavaScript());
const dev = sampleOne(javaScriptDevGen);
console.log(dev);
// { name: 't', age: 4, preferredLanguage: { name: 'javascript' } }
import type {Person} from './types';
export default function setName(person: Person, name: string): Person {
return {
...person,
name
};
}
require('jasmine-check').install();
describe('adding numbers', () => {
check.it('the sum is always greater than the parts', [gen.int, gen.int], (a, b) => {
expect(a + b).toBeGreaterThanOrEqual(a);
expect(a + b).toBeGreaterThanOrEqual(b);
});
});
// FAIL
// ● adding numbers › the sum is always greater than the parts ( 0, -1 )
// @flow
function giveMeStrings(arr: string[]): string {
// do something with the array of strings
}
giveMeStrings('hello', 'goodbye');
/*
ERROR:
7: giveMeStrings('hello', 'goodbye');