Skip to content

Instantly share code, notes, and snippets.

View tanepiper's full-sized avatar

Tane Piper tanepiper

View GitHub Profile
@tanepiper
tanepiper / settings.jsonc
Created May 15, 2023 09:29 — forked from hyperupcall/settings.jsonc
VSCode config to disable popular extensions' annoyances (telemetry, notifications, welcome pages, etc.)
// I'm tired of extensions that automatically:
// - show welcome pages / walkthroughs
// - show release notes
// - send telemetry
// - recommend things
//
// This disables all of that stuff.
// If you have more config, leave a comment so I can add it!!
{
@tanepiper
tanepiper / bookmarklet.js
Last active November 21, 2022 16:28 — forked from bramus/bookmarklet.md
Mastodon User Page Bookmarklet
javascript:(function(){
const MY_MASTO_HOST = 'tane.codes';
if (window.location.host === MY_MASTO_HOST) return;
const user = document.querySelector('meta[property="profile:username"]')?.getAttribute('content');
if (!user) return;
window.location.href = `https://${MY_MASTO_HOST}/@${user}`;
})();
@tanepiper
tanepiper / breadcrumb.integration.spec.ts
Last active February 11, 2021 21:20 — forked from LayZeeDK/breadcrumb.integration.spec.ts
Tane Piper: Auxiliary route test
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Component, Injectable, Input, OnDestroy } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ActivatedRouteSnapshot, NavigationEnd, Route, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Subject } from 'rxjs';
import { filter, map, takeUntil, tap } from 'rxjs/operators';
interface Breadcrumb {
export class ReplayControlValueChanges<T> extends Observable<T> {
constructor(control: AbstractControl | AbstractControlDirective) {
super(subscriber => {
if (!control.valueChanges) {
throw new Error('Control does not have valueChanges');
}
control.valueChanges.pipe(startWith(control.value)).subscribe(subscriber);
});
}
@tanepiper
tanepiper / validation.ts
Created February 10, 2020 14:54 — forked from busypeoples/validation.ts
Validation in TS (version 2)
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> =>
validations
.map(validation => validation(fields))
.reduce((acc, a) => Object.assign(acc, a), {});
@tanepiper
tanepiper / tuples.ts
Created September 21, 2018 14:31 — forked from hmil/tuples.ts
Well-typed variable-length tuples in TypeScript
/**
* 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
@tanepiper
tanepiper / tuple-utils.ts
Created September 12, 2018 11:23 — forked from KSXGitHub/tuple-utils.ts
Tuple generic
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
@tanepiper
tanepiper / ng-serve-docker-nginx-proxy.md
Created September 5, 2018 23:48 — forked from markstuart/ng-serve-docker-nginx-proxy.md
Running Angular CLI in local dev behind docker nginx reverse proxy

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 / example.js
Created September 6, 2017 10:29 — forked from millermedeiros/example.js
execute multiple shell commands in series on node.js
// USAGE ------
// ============
var shell = require('./shellHelper');
// execute a single shell command
shell.exec('npm test --coverage', function(err){
console.log('executed test');
}});
@tanepiper
tanepiper / index.js
Last active July 11, 2017 14:50 — forked from zkat/index.js
npx is cool
#! /usr/bin/env node
const fs = require('fs');
const http = require('http');
const home = process.env.HOME;
const options = {
host: 'example.com',
path: '/',