Skip to content

Instantly share code, notes, and snippets.

@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
var addTwo = add(2);
addTwo; // 2
addTwo + 5; // 7
addTwo(3); // 5
addTwo(3)(5); // 10
@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));
});
@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 / 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 / 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 / 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
Worker information
hostname: e493aab3-9ebb-4ff3-bf71-74d0216e5c37@4740.wjb-1
version: v3.6.0 https://github.com/travis-ci/worker/tree/170b2a0bb43234479fd1911ba9e4dbcc36dadfad
instance: 2d2c786d-0537-48f2-96f1-2eb3fa4a1976 travis-ci-macos10.12-xcode8.3-1507738863 (via amqp)
startup: 1m6.709206302s
Download from https://build.travis-ci.com/filter/redirect_io.rb failed. Trying https://build.travis-ci.com/filter/redirect_io.rb ...
ruby: No such file or directory -- /Users/travis/filter.rb (LoadError)
@donabrams
donabrams / BetterNominal.ts
Last active August 3, 2018 18:29
Nominal typing in TypeScript
interface FooId extends String {
_fooIdBrand: string;
};
export interface Foo {
id: FooId;
color: 'yellow';
isAwesome: true;
}
interface BarId extends String {
@donabrams
donabrams / checklist.txt
Last active April 25, 2018 23:16
General JWT approach that usually isn't terrible checklist
☐ Put JWT in a cookie
☐ HTTPOnly cookie
☐ Secure cookie
☐ Domain w/ a subdomain (never root)
☐ No authorization in the JWT body (look it up serverside ya lazy asses)
☐ Userid in cookie should NOT exist anywhere but auth service
☐ Short window ( < 15 min) for JWT authentication token
☐ Ability to deauthorize a refresh token chain serverside (but long life on a refresh token is OK)
☐ Ability to monitor requests by refresh token chain