Skip to content

Instantly share code, notes, and snippets.

View trvswgnr's full-sized avatar
:octocat:
hardly workin'

Travis Wagner trvswgnr

:octocat:
hardly workin'
View GitHub Profile
@trvswgnr
trvswgnr / map.ts
Last active June 26, 2024 11:45
custom ts map with eq and cmp
export enum Ordering {
Less = -1,
Equal = 0,
Greater = 1,
}
export interface Eq<T> {
eq(other: T): boolean;
}
@trvswgnr
trvswgnr / partial-application.ts
Last active July 26, 2024 17:55
partial application in typescript
export default function createPartialApplication<T extends any[], R>(
fn: (...args: T) => R,
): PartialApplication<T, R> {
return function accumulator(...args1: any[]): any {
return args1.length >= fn.length
? fn(...(args1 as T))
: (...args2: any[]) => accumulator(...args1.concat(args2));
};
}
@trvswgnr
trvswgnr / lc.rs
Last active June 19, 2024 01:16
λ-calc interpreter cramb
use std::collections::HashSet;
use std::iter::Peekable;
use std::str::Chars;
#[derive(Debug, PartialEq, Clone)]
enum Token {
Lambda,
Dot,
Variable(String),
LParen,
@trvswgnr
trvswgnr / lc.rs
Last active June 5, 2024 16:16
λ-calc interpreter in crablang
use std::collections::HashSet;
use std::iter::Peekable;
use std::str::Chars;
#[derive(Debug, PartialEq, Clone)]
enum Token {
Lambda,
Dot,
Variable(String),
LParen,
@trvswgnr
trvswgnr / sub-add.c
Created April 19, 2024 06:48
sub and add repr in c
#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;
}
@trvswgnr
trvswgnr / README.md
Last active April 17, 2024 20:13
fizzbuzz in nasm assembly
@trvswgnr
trvswgnr / getSixRandomFiles.go
Last active April 17, 2024 03:31
get 6 random files from a directory
package main
import (
"errors"
"math/rand"
"os"
"time"
)
// initialize rng
@trvswgnr
trvswgnr / fp.ts
Last active April 10, 2024 23:00
functional programming typescript extensions
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,
@trvswgnr
trvswgnr / .gitignore
Created April 6, 2024 04:10
c# gitignore
# Standard .NET and C# ignores
bin/
obj/
out/
build/
buildscript/
*.sln.cache
*.suo
*.user
*.userprefs
@trvswgnr
trvswgnr / deep.test.ts
Last active February 5, 2024 21:39
typescript deep merge and deep clone
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));