Skip to content

Instantly share code, notes, and snippets.

View keithort's full-sized avatar

Keith Ort keithort

View GitHub Profile
@scottjehl
scottjehl / whichones.js
Created August 21, 2020 15:40
which elements are wider than the viewport?
var list = [];
document.querySelectorAll("body *")
.forEach(function(elem){
if(elem.getBoundingClientRect().width > document.body.getBoundingClientRect().width){
list.push(elem.outerHTML.split('>')[0] + '>');
}
});
confirm( "these elements are wider than the viewport:\n\n " + list.join("\n") )
@nth-commit
nth-commit / VariadicPipe.ts
Last active September 29, 2022 21:47
Function composition in TypeScript 4.1 (on top of ixjs's pipe)
import { OperatorFunction } from 'ix/interfaces';
import { pipe } from 'ix/iterable';
import { map } from 'ix/iterable/operators';
/**
* Creates a new type which is the first element of a non-empty tuple type.
*
* @example type T = Head<[string, number, Object]>; // string
*/
export type Head<Ts extends [any, ...any[]]> = Ts extends [infer T, ...any[]] ? T : never;
@jamiebuilds
jamiebuilds / tradeoffs-in-value-derived-types-in-typescript.md
Last active December 16, 2022 17:21
Value-derived types in TypeScript are super powerful, but you should be thoughtful in how/when you use them

Tradeoffs in value-derived types in TypeScript

Many of the more "advanced" typescript features can be used for creating "value-derived" types.

At its simplest form:

let vehicle = { name: "Van", wheels: 4 }
@chaance
chaance / example.ts
Created August 12, 2021 03:39
Merge discriminated union props for better easier destructuring
type SomeProps =
| { action: "START" }
| { action: "STOP"; time: number }
| { action: "PAUSE"; time: number; ref: { current: any } };
function useExample(props: SomeProps) {
let {
action, // "START" | "STOP" | "PAUSE"
time, // number | undefined,
ref // { current: any } | undefined