Skip to content

Instantly share code, notes, and snippets.

Tane Piper tanepiper

Block or report user

Report or block tanepiper

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tanepiper
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 https://github.com/pelotom/runtypes/blob/fe19290d375c8818d2c52243ddc2911c8369db37/src/types/tuple.ts )
*
* 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
View takeoff.md

npm:install:api

Run task npm:install:app after this

cd env/api && npm install --silent

npm:install:app

@tanepiper
tanepiper / ng-serve-docker-nginx-proxy.md
Created Sep 5, 2018 — forked from markstuart/ng-serve-docker-nginx-proxy.md
Running Angular CLI in local dev behind docker nginx reverse proxy
View ng-serve-docker-nginx-proxy.md

Setup

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 (192.168.1.5 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
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 => {
event.preventDefault();
@tanepiper
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 = newModal.style.top || 0;
lastY = newModal.style.left || 0;
@tanepiper
tanepiper / mm-keyboard.html
Created Dec 19, 2017
Example of how to declare a keyboard with Music Markup
View mm-keyboard.html
<mm-keyboard oscillator-type="sawtooth">
<mm-key class-name="white b" frequency="174.614" time="1"></mm-key>
<mm-key class-name="black as" frequency="184.997" time="1"></mm-key>
<mm-key class-name="white a" frequency="195.998" time="1"></mm-key>
<mm-key class-name="black gs" frequency="200.000" time="1"></mm-key>
<mm-key class-name="white g" frequency="207.652" time="1"></mm-key>
<mm-key class-name="black fs" frequency="233.082" time="1"></mm-key>
<mm-key class-name="white f" frequency="246.942" time="1"></mm-key>
<mm-key class-name="white e" frequency="261.626" time="1"></mm-key> <!-- Middle c -->
<mm-key class-name="black ds" frequency="277.183" time="1"></mm-key>
View code-example.js
const e = document.createDocumentFragment('div');
const sleep = (ms, caller, ...args) => new Promise(resolve => setTimeout(caller || resolve, ms, ...args));
const waitForHello = async(timeout, elm) => {
console.log('checking');
if (elm.innerHTML === 'Hello world') {
console.log('Value found');
return;
} else if ((timeout -= 100) <= 0) {
You can’t perform that action at this time.