Skip to content

Instantly share code, notes, and snippets.

Tane Piper tanepiper

View GitHub Profile
View replay-control-value-changes.ts
export class ReplayControlValueChanges<T> extends Observable<T> {
constructor(control: AbstractControl | AbstractControlDirective) {
super(subscriber => {
if (!control.valueChanges) {
throw new Error('Control does not have valueChanges');
tanepiper / validation.ts
Created Feb 10, 2020 — forked from busypeoples/validation.ts
Validation in TS (version 2)
View validation.ts
type ValidationResult<T, U> = Partial<{ [Key in keyof T]: U }>;
type Validation<T, U> = (fields: T) => ValidationResult<T, U>;
const validate = <T, U = boolean | string>(
validations: Validation<T, U>[],
fields: T
): ValidationResult<T, U> =>
.map(validation => validation(fields))
.reduce((acc, a) => Object.assign(acc, a), {});
tanepiper / tuples.ts
Created Sep 21, 2018 — forked from hmil/tuples.ts
Well-typed variable-length tuples in TypeScript
View tuples.ts
* Arbitrary-length tuples
* =======================
* Working with tuples of unknown length in TypeScript is a pain. Most library authors fall back on enumerating all possible
* tuple lengths up to a threshold (see an example here )
* In this gist, I'm attempting to leverage recursion to provide support for arbitrary length tuples. This has the potential
* to make some kinds of declarative APIs nicer and enhance type inference in some cases.
* This example shows how to take a variable-length tuple as an input, transform each of its types and use the resulting
View tuple-utils.ts
export namespace TupleUtils {
* Get type of first element
* @example `First<[0, 1, 2]>` → `0`
export type First<Tuple extends [any, ...any[]]> = Tuple[0]
* Get type of last element


Run task npm:install:app after this

cd env/api && npm install --silent


tanepiper /
Created Sep 5, 2018 — forked from markstuart/
Running Angular CLI in local dev behind docker nginx reverse proxy


Angular app talking to multiple microservices using Cookie authentication on ajax requests. Cookies are not passed over cross domain ajax requests, so we need to be able to have the Angular app and microservices running on same-domain in local dev as well as in production.

We have a Docker nginx proxy running on localhost:8000:

  • proxying to multiple microservices on localhost:8000/api/<microservice>
  • proxying other requests to Angular CLI (ng serve) on en0 inet ( for instance) port 4200
  • using a python script to get the correct en0 IP and write it to the nginx config at proxy startup
tanepiper / TypeInference.ts
Created Apr 12, 2018
Type inference in typescript
View TypeInference.ts
const foo = function <T>(a: T, b: T[]): any {
return { a, b }
foo(6, 'di')
foo(6, [9])
foo<string>(6, 'di')
foo<string>('foo', 'di')
foo<string>('foo', ['di'])
foo<object>({}, [{}]) 
View KillTheBrowser.js
function handleKill1() {
setInterval(createModal, 1000);
View HijackEscapeKey.js
const open = document.querySelector(".open");
function createModal() {
open.addEventListener("click", createModal);
document.addEventListener("keyup", event => {
tanepiper / AnnoyingButton.js
Created Jan 31, 2018
Creates an annoying button it's hard to close with a mouse
View AnnoyingButton.js
function createModal() {
// ...
const button = document.createElement("button");
button.innerText = "Close Me";
function moveModal() {
button.setAttribute("disabled", true);
button.innerText = 'LOL';
lastX = || 0;
lastY = || 0;
You can’t perform that action at this time.