const identity = x => x
const withIndex = fn => (_, i) => fn(i);
const getIndex = withIndex(identity);
const positiveIntegers = (length) => Array.from({ length }).map(getIndex);
const isEven = n => n % 2 === 0;
const isOdd = n => !isEven(n);
const odd = (...numbers) => numbers.filter(isOdd);
const reciprocal = n => 1 / n;
const inverse = (...numbers) => numbers.map(reciprocal);
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 searchParamsToObject(params: URLSearchParams) { | |
const uniqueKeys = [...new Set(params.keys())]; | |
return Object.fromEntries(uniqueKeys.map(key => [ | |
key, | |
params.getAll(key).length > 1 ? params.getAll(key) : params.get(key), | |
])); | |
} |
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 TypedResponse<TJson> extends globalThis.Response { | |
json: () => Promise<TJson>; | |
} | |
async function typedFetch<T>(...args: Parameters<typeof fetch>) { | |
const response = await fetch(...args); | |
if (!response.ok) throw response; | |
return response as TypedResponse<T>; | |
} |
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
defaults write com.apple.screencapture location ~/Screenshots/ |
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
class IndexedObjectArray extends Array { | |
#map; | |
constructor(length) { | |
super(length); | |
} | |
toMap() { | |
return this.#map; | |
} |
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 squares(n: number) { | |
return (n * (n + 1) * (2 * n + 1)) / 6; | |
} |
Curated by Joe Maffei
This document outlines key considerations for determining when a feature can be considered "done." It's crucial to address these points as early as possible in the development process and continue to revisit them at each stage. By doing so, we can ensure higher quality, reduce rework, and streamline our development pipeline. Consider these points at the following stages:
- When drafting requirements documents
- During the design and wireframing phase
- While writing user stories or bug tickets
- Throughout the development process
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
/** | |
* Converts an iterable to an object, keeping only key/value pairs that are both strings. | |
*/ | |
function pickStringKeysAndValues< | |
T extends { entries(): IterableIterator<[unknown, unknown]> }, | |
>(iterable: T): Record<string, string> { | |
let result: Record<string, string> = {}; | |
for (let [key, value] of iterable.entries()) { | |
if (typeof key === 'string' && typeof value === 'string') { | |
result[key] = value; |
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
/** | |
* Module-level variable where all of the global dependency injection | |
* overrides are stored. | |
*/ | |
const provisions = new Map<unknown, unknown>(); | |
/** | |
* Adds an override to the global dependency injection context. | |
* TypeScript ensures that the signature of the override is the same | |
* as that of the dependency being overridden. |
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 keyMirror<Obj>(...args: (keyof Obj)[]): Readonly<{ [Key in keyof Obj]: Key }> { | |
let obj = {}; | |
for (let arg of args) { | |
Object.defineProperty(obj, arg, { | |
configurable: false, | |
enumerable: true, | |
value: arg, | |
writable: false, | |
}); | |
} |
NewerOlder