Skip to content

Instantly share code, notes, and snippets.

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

Travis A. Wagner trvswgnr

:octocat:
hardly workin'
View GitHub Profile
@trvswgnr
trvswgnr / traits.ts
Last active November 10, 2024 22:28
typescript traits
export const Traits = _Traits as unknown as (new <T>(...args: any[]) => T) & typeof _Traits;
function _Traits(): Mixed<unknown, unknown>;
function _Traits<M1>(m1: M1): Mixed<unknown, M1>;
function _Traits<M1, M2>(m1: M1, m2: M2): Mixed<unknown, M1 & M2>;
function _Traits<M1, M2, M3>(m1: M1, m2: M2, m3: M3): Mixed<unknown, M1 & M2 & M3>;
function _Traits<M1, M2, M3, M4>(m1: M1, m2: M2, m3: M3, m4: M4): Mixed<unknown, M1 & M2 & M3 & M4>;
function _Traits<M1, M2, M3, M4, M5>(m1: M1, m2: M2, m3: M3, m4: M4, m5: M5): Mixed<unknown, M1 & M2 & M3 & M4 & M5>;
function _Traits(...args: any[]) {
return args.reduce((c, m) => m(c));

VPS Setup Script for Bun Applications

An automated setup script for deploying Bun applications on a VPS with Nginx reverse proxy, SSL, and PM2 process management.

Features

  • 🚀 One-command setup for Bun applications
  • 🔒 Automatic SSL certificate configuration via Let's Encrypt
  • 🔄 Nginx reverse proxy with optimized settings
  • 📊 PM2 process management
@trvswgnr
trvswgnr / get_tree.sql
Created October 30, 2024 17:17
query that returns a tree in json (full tree from root or subtree from node n) with RCTE
CREATE OR REPLACE FUNCTION build_tree(parent_id INTEGER DEFAULT NULL)
RETURNS JSONB AS $$
DECLARE
result JSONB;
count INTEGER;
BEGIN
SELECT COUNT(*)
INTO count
FROM nodes n
WHERE n.parent_id IS NOT DISTINCT FROM $1;
@trvswgnr
trvswgnr / mod.ts
Last active October 23, 2024 19:58
real modulo operation in typescript
/**
* Real modulo operation that works correctly with negative numbers.
*
* JavaScript's `%` operator returns the remainder of a division operation,
* which may be negative. This function corrects that by adding the base before
* taking the remainder.
*/
export function mod(dividend: number, modulus: number): number {
return ((dividend % modulus) + modulus) % modulus;
}
@trvswgnr
trvswgnr / index.pug
Created October 23, 2024 02:08
Snowfall WebGL Shader
// img#snowflake(src="https://cdn.jsdelivr.net/gh/trvswgnr/cdn/snowflake.png")
#snow
@trvswgnr
trvswgnr / index.pug
Created October 23, 2024 01:32
Snowfall WebGL Shader
#snow
@trvswgnr
trvswgnr / script.js
Created October 23, 2024 01:26
WebGL Shader
class ShaderProgram {
constructor( holder, options = {} ) {
options = Object.assign( {
antialias: false,
depthTest: false,
mousemove: false,
autosize: true,
side: 'front',
@trvswgnr
trvswgnr / exit-signal.ts
Last active October 22, 2024 09:32
typescript linux exit signals
/**
* Unix/POSIX Signal implementation with architecture-specific handling.
* @module Signal
*/
type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
type IsNever<T> = [T] extends [never] ? true : false;
@trvswgnr
trvswgnr / gen-commit-msg.ts
Created October 9, 2024 18:39
ai generate git commit message from diffs of staged files
#!/usr/bin/env bun
import { exec } from "child_process";
/*
Generate a commit message for the staged changes.
*/
import Anthropic from "@anthropic-ai/sdk";
@trvswgnr
trvswgnr / levenshtein.ts
Last active September 27, 2024 03:56
levenshtein distance ts
export function levenshteinDistance(a: string, b: string): number {
if (typeof a !== "string" || typeof b !== "string") {
throw new TypeError("Arguments must be of type `string`");
}
if (arguments.length > 2) {
throw new RangeError("Too many arguments");
}
if (a === b) {