This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e -u -o pipefail | |
# Open a new pull request in github from the current branch | |
open_pr() { | |
local base_branch=${1:-"development"} | |
local merge_organisation_opt=${2:-} | |
local browser="xdg-open" | |
local repo current_branch merge_organisation merge_branch url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AllKeysOfUnion<U> = U extends any ? keyof U : never; | |
type NonCommonKeysOfUnion<U> = Exclude<AllKeysOfUnion<U>, keyof U>; | |
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | |
type UnionWithKeys<U, K extends keyof any> = U extends any | |
? { [Key in K]: Key extends keyof U ? U[Key] : never } | |
: never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.getElementById("tutorial"); | |
const context = canvas.getContext("2d"); | |
function drawBackground() { | |
context.beginPath(); | |
context.fillStyle = "rgb(200, 200, 200)"; | |
context.rect(0, 0, 640, 480); | |
context.fill(); | |
context.closePath(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Naturals using Peano numbers. See https://ostro.ws/2019/12/09/taking-types-too-far/ */ | |
type Zero = { prev: never }; | |
type Nat = { prev: Nat }; | |
type Succ<N extends Nat> = { prev: N }; | |
type Prev<N extends Nat> = N["prev"]; | |
type Nats = { | |
0: Zero; | |
1: Succ<Zero>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Length<T extends any[]> = T["length"]; | |
type Head<T extends any[]> = T[0]; | |
type Tail<T extends any[]> = ((...xs: T) => any) extends (x: any, ...t: infer T) => any ? T : never; | |
type Last<T extends any[]> = { | |
0: never; | |
1: T[0]; | |
">1": Last<Tail<T>>; | |
}[Length<T> extends 0 ? 0 : Length<T> extends 1 ? 1 : ">1"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renderJoin(nodes: ReactNode[], separator: ReactNode): ReactNode { | |
return nodes.flatMap((node, idx) => | |
idx < nodes.length - 1 ? [node, separator] : [node] | |
).map((node, idx) => <React.Fragment key={idx}>{node}</React.Fragment>); | |
} | |
// Usage | |
const myComponent: React.FC = props => { | |
return <div>{renderJoin([<p>item1</p>, <p>item2</p>], <br />)}</div>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Matcher<KindField extends string, Kind extends string, Obj, Result> = { | |
[K in Kind]: (obj: Extract<Obj, { [F in KindField]: K }>) => Result; | |
}; | |
export function match<KindField extends string>(field: KindField) { | |
return function< | |
Obj extends { [K in KindField]: Kind }, | |
Result, | |
Kind extends string = Obj[KindField] | |
>(obj: Obj, matcher: Matcher<KindField, Kind, Obj, Result>): Result { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
function idOf(idx: number): string { | |
const quotient = Math.floor(idx / letters.length); | |
const remainder = idx % letters.length; | |
return (quotient > 0 ? idOf(quotient - 1) : "") + letters[remainder]; | |
} | |
function cell(colIdx: number, rowIdx: number): string { | |
return idOf(colIdx) + (rowIdx + 1).toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Metric { | |
timestamp: Date; | |
temperature: number; | |
pressure: number; | |
humidity: number; | |
rain: number; | |
sun: number; | |
windDirection: number; | |
windVelocity: number; | |
dew: number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* SelectedPick<T, Selector> | |
An extended version of Pick<T, Key> where, instead of a union of keys, | |
you pass an object with the properties to get from a type. */ | |
type Extends<T1, T2> = [T1] extends [T2] ? true : false | |
type OmitNever<T> = Pick<T, { [K in keyof T]: T[K] extends never ? never : K }[keyof T]> | |
export type Selector<Model> = { | |
[Key in keyof Model]?: boolean | NestedSelectorValue<Model[Key]> |