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
import { expect, test, describe } from "bun:test"; | |
import { | |
retry, | |
stopAfterAttempt, | |
stopAfterDelay, | |
stopBeforeDelay, | |
waitCombine, | |
waitExponential, | |
waitExponentialJitter, | |
waitFixed, |
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 function* enumerate<T>( | |
iterable: Iterable<T>, | |
start = 0, | |
): Generator<[number, T]> { | |
let index = start; | |
for (const value of iterable) { | |
yield [index, value]; | |
index++; | |
} | |
} |
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 function range( | |
end: number, | |
config?: { step?: number; direction?: "asc" | "desc" }, | |
): Generator<number>; | |
export function range( | |
start: number, | |
end: number, | |
config?: { step?: number; direction?: "asc" | "desc" }, | |
): Generator<number>; | |
export function* range( |
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 async function wait(ms: number): Promise<void>; | |
export async function wait<T>(ms: number, value: T): Promise<T>; | |
export async function wait<T>( | |
ms: number, | |
value?: T | undefined, | |
): Promise<T | undefined> { | |
return new Promise<T | undefined>((resolve) => | |
setTimeout( | |
() => (value === undefined ? resolve(undefined) : resolve(value)), | |
ms, |
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 function log(): undefined; | |
export function log<T>(arg: T): T; | |
export function log<T extends readonly unknown[]>(...args: T): T; | |
export function log<T>(...args: T[]): T[] | T | undefined { | |
console.log(...args); | |
if (args.length === 0) return undefined; | |
if (args.length === 1) return args[0]; | |
return args; | |
} | |
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
import redis from "redis"; | |
const { REDIS_PASSWORD } = process.env; | |
async function makeDisposable<T extends object>( | |
resource: T, | |
{ | |
onDispose, | |
onInit, | |
}: { | |
onDispose?: (resource: T) => Promise<void>; |
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 | |
# Default text and settings | |
custom_text="⏱️" | |
keep_last=false | |
show_done=true | |
done_text="✅" | |
# Parse arguments | |
while [[ $# -gt 0 ]]; do |
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 class Completer<T = unknown, E = unknown> { | |
private _promise: Promise<T>; | |
private _resolve!: (value: T | PromiseLike<T>) => void; | |
private _reject!: (reason?: E) => void; | |
constructor() { | |
this._promise = new Promise<T>((resolve, reject) => { | |
this._resolve = resolve; | |
this._reject = reject; | |
}); |
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
from __future__ import annotations | |
import asyncio | |
from typing import List, Any, Coroutine, TypeVar, Generic, TypeAlias | |
from dataclasses import dataclass | |
T = TypeVar('T') | |
@dataclass | |
class Fulfilled(Generic[T]): | |
value: 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
export function asyncComponent<T>( | |
fn: (props: T) => Promise<JSX.Element> | |
): React.FC<T> { | |
return fn as any; | |
} |
NewerOlder