some simple but cool text spinners, mostly taken from https://wiki.tcl-lang.org/page/Text+Spinner
npm i -S gist:2b5607fd9aadc827f46f48ce979a6864
function isDST(date: Date, timeZone: string = 'America/New_York'): boolean { | |
const year = date.getFullYear(); | |
const startDST = getNthDayOfMonth(2, 0, 2, year); // sec sun in mar | |
const endDST = getNthDayOfMonth(1, 0, 10, year); // first sun in nov | |
const localDate = new Date(date.toLocaleString('en-US', { timeZone })); | |
const utcOffset = localDate.getTimezoneOffset() * 60000; // in milliseconds | |
const utcDate = new Date(localDate.getTime() + utcOffset); | |
return utcDate >= startDST && utcDate < endDST; | |
} |
some simple but cool text spinners, mostly taken from https://wiki.tcl-lang.org/page/Text+Spinner
npm i -S gist:2b5607fd9aadc827f46f48ce979a6864
export type pipe<T> = { | |
<U>(x: T, id?: string): pipe<U>; | |
map: <U>(fn: (x: T) => U) => pipe<U>; | |
unwrap: () => NonNullable<T>; | |
unwrapOr: (defaultValue: NonNullable<T>) => NonNullable<T>; | |
unwrapOrElse: <T>(fn: () => T) => NonNullable<T>; | |
unwrapOrDefault: () => NonNullable<T>; | |
}; | |
export const pipe = <T>(x: T): pipe<T> => _pipe(x, x); |
export type Enum<T> = { | |
[key in keyof T]: T[key] extends (...args: any[]) => any ? ReturnType<T[key]> : T[key]; | |
}[keyof T]; | |
export const Enum = <const T>(obj: T) => obj; | |
export function EnumVariant<const F extends (...args: any[]) => T, const T>(fn: F): F; | |
export function EnumVariant<const T>(arg: T): T; | |
export function EnumVariant(arg: unknown) { | |
return arg; | |
} | |
const DataTypes = Enum({ |
import sqlite3 from "sqlite3"; | |
export class Database { | |
private db: sqlite3.Database; | |
constructor(path: string) { | |
this.db = new sqlite3.Database(path); | |
} | |
public static open(path: string): Database { | |
return new Database(path); | |
} |
class TrackablePromise<T> extends Promise<T> { | |
private _status: PromiseStatus = "pending"; | |
private _promise: Promise<T>; | |
private _value: T | undefined; | |
constructor( | |
executor: ( | |
resolve: (value: T | PromiseLike<T>) => void, | |
reject: (reason?: any) => void, |
export function escapeHtml(str: string) { | |
let html = ''; | |
let matchIndex: number | undefined; | |
let lastIndex = 0; | |
let char: string; | |
while (true) { | |
matchIndex = regex.exec(str)?.index; | |
if (matchIndex === undefined) break; | |
html += str.slice(lastIndex, matchIndex); | |
char = str[matchIndex]; |
import type * as _htmx from "htmx.org"; | |
declare global { | |
var htmx: typeof _htmx; | |
} | |
declare module "htmx.org" { | |
interface HtmxExtension { | |
init(apiRef: HtmxInternalApi): void; | |
} |
<label for="modal1">clicky boi</label> | |
<input id="modal1" class="peer" type="checkbox" hidden /> | |
<label for="modal1" class="hidden peer-checked:block bg-black bg-opacity-25 fixed h-full w-full top-0 left-0"></label> | |
<dialog class="hidden peer-checked:block"> | |
<p>lgtm ¯\_(ツ)_/¯</p> | |
<label for="modal1">close</label> | |
</dialog> |
use std::{ | |
hash::Hasher, | |
io::{self, BufReader, Read}, | |
}; | |
/// The size of the buffer used when reading the file. | |
const BUFFER_SIZE: usize = 8 * 1024; // 8 KB | |
/// Hashes the contents of the given readable object (e.g. a file). | |
#[inline] |