just a fun exercise for learning some x86_64 nasm assembly (linux)
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
#include <stdio.h> | |
#include <stdint.h> | |
uint8_t da(uint8_t value) { | |
uint8_t lo = value & 0x0F; | |
uint8_t hi = value >> 4; | |
if (lo > 9) lo += 6; | |
if (hi > 9) hi += 6; | |
return (hi << 4) | lo; | |
} |
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
package main | |
import ( | |
"errors" | |
"math/rand" | |
"os" | |
"time" | |
) | |
// initialize rng |
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 AnyFn = (...args: any[]) => any; | |
namespace ElementExt { | |
export function addEventListener< | |
El extends Element | Document, | |
const S extends string, | |
const H extends AnyFn, | |
>(name: S, cb: H): (el: El) => void; | |
export function addEventListener< | |
El extends Element | Document, |
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
# Standard .NET and C# ignores | |
bin/ | |
obj/ | |
out/ | |
build/ | |
buildscript/ | |
*.sln.cache | |
*.suo | |
*.user | |
*.userprefs |
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 { describe, it, expect } from "bun:test"; | |
import { deepClone, deepMerge, isObject } from "./lib.ts"; | |
describe("isObject", () => { | |
it("returns false for null", () => expect(isObject(null)).toBe(false)); | |
it("returns false for undefined", () => expect(isObject(undefined)).toBe(false)); | |
it("returns false for numbers", () => expect(isObject(0)).toBe(false)); | |
it("returns false for strings", () => expect(isObject("")).toBe(false)); | |
it("returns false for booleans", () => expect(isObject(false)).toBe(false)); | |
it("returns true for objects", () => expect(isObject({})).toBe(true)); |
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 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
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 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); |
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 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({ |
NewerOlder