Skip to content

Instantly share code, notes, and snippets.

@donabrams
donabrams / 1-Goals.md
Last active November 1, 2018 16:17
Usable git (lets)

Goals:

  • Promote small commits
  • Promote rebasing (fewer merge commits)
  • Sensible defaults
  • Better merge conflict resolution and avoidance
  • Less git knowledge to know
@donabrams
donabrams / Omit.ts
Last active November 8, 2018 15:29
Typesafe omit typescript (TS 3.1.6)
// This doesn't support map over union types individually
type SimpleOmit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
// The below type, MappedRemoveKey, only works with discrimated unions!
// Otherwise the intersection of the types ALSO passes (submiting a TS bug now-- in typescript-3.1.6)
// example union type WITHOUT a discriminator
type Foo = { foo: string };
type FooBar = { foo: string, bar: string };
type Yay = { yay: true };
@donabrams
donabrams / argsType.ts
Last active November 14, 2018 22:58
ArgsType.ts
type ArgsType<T> = T extends (...args: infer R) => any ? R : never;
type Func1 = (a: string, b: boolean) => boolean;
type Func2 = () => void;
const pass1: ArgsType<Func1> = ["yay", true];
const fail1: ArgsType<Func1> = ["yay"];
const fail2: ArgsType<Func1> = [true, true];
const fail3: ArgsType<Func1> = [];
const fail4: ArgsType<Func1> = ["yay", true, "boo"];
@donabrams
donabrams / get.ts
Created May 27, 2019 16:23
Typesafe get(obj, [keys...]
interface Example {
a: {
b: {
aNumber: number;
}
}
}
interface HasB {
b: {
@donabrams
donabrams / channel.js
Created December 7, 2019 08:40
Async Produce/Consume Channel
function channel() {
const buffer = [];
const wait = [];
let lastSignal;
const consume = function() {
return buffer.length > 0
? Promise.resolve(buffer.shift())
: new Promise((resolve) => {
wait.push((val) => resolve(val));
});
var addTwo = add(2);
addTwo; // 2
addTwo + 5; // 7
addTwo(3); // 5
addTwo(3)(5); // 10
@donabrams
donabrams / Godzilla brew list
Created July 21, 2022 18:27
Godzilla brew list 2022-07-21
$ brew list
==> Formulae
awscli fontconfig icu4c libmpc libxext oniguruma postgis webp
boost freetds isl libnghttp2 libxml2 opam postgresql wget
brotli freetype jpeg libpng libxrender openblas proj xerces-c
ca-certificates freexl jq libpq little-cms2 openjdk protobuf xorgproto
cairo gcc json-c libpthread-stubs lz4 openjpeg protobuf-c xz
cfitsio gdal krb5 librttopo lzo openldap python@3.10 yarn
cgal gdbm lastpass-cli libspatialite m4 openssl@1.1 python@3.8 zlib
cloc geos leiningen libssh2 minizip openssl@3 python@3.9 zstd