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 / enum.ts
Last active February 9, 2025 06:06
typescript enums that are compatible with the --experimental-strip-types flag introduced in node v22.6.0
// --- examples --- //
// happy path
const Priority = Enum("Low", "Normal", "High");
// ^?
type Priority = Enum<typeof Priority>;
// ^?
// invalid key starting with number
const InvalidPriority1 = Enum("1Low", "Normal", "High");
@trvswgnr
trvswgnr / grpo_demo.py
Created February 2, 2025 06:58 — forked from willccbb/grpo_demo.py
GRPO Llama-1B
# train_grpo.py
import re
import torch
from datasets import load_dataset, Dataset
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import LoraConfig
from trl import GRPOConfig, GRPOTrainer
# Load and prep dataset
@trvswgnr
trvswgnr / functor.rs
Created December 5, 2024 07:43
functor in rust
/*
[dependencies]
*/
mod sealed {
pub trait IsType<T: ?Sized> {}
impl<T: ?Sized> IsType<T> for T {}
}
@trvswgnr
trvswgnr / index.ts
Last active November 28, 2024 05:25
limit to bitwise and evaluate strings
type Op = '<<' | '&' | '|';
const Gift = {
Coal: '0',
Train: '1 << 0',
Bicycle: '1 << 1',
SuccessorToTheNintendoSwitch: '1 << 2',
TikTokPremium: '1 << 3',
Vape: '1 << 4',
Traditional: 'Train | Bicycle',
@trvswgnr
trvswgnr / partial-application.ts
Created November 27, 2024 00:32
partial application typescript
import type { Expect, Equal, IsAny, IsUnknown } from "type-testing";
import { Solution } from "./solution";
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
type AnyArray = any[];
type PartialApplicationHelper<T extends AnyArray, R> = <A extends Partial<T>>(
...args: A
) => A extends AnyArray
? A["length"] extends T["length"]
@trvswgnr
trvswgnr / distribute.ts
Created November 26, 2024 04:43
distribute workers based on ratios
interface Service {
ratio: number;
name: string;
}
function assignNumWorkers(services: Service[], maxTotalWorkers: number): Map<string, number> {
// sub 1 for the orchestrator
const availableWorkers = maxTotalWorkers - 1;
// calc total ratio sum
@trvswgnr
trvswgnr / logger.ts
Created November 21, 2024 22:43
Syslog Protocol (RFC 5424) Log to Console in TypeScript
/**
* Syslog Facility codes as defined in RFC 5424
*/
enum SyslogFacility {
KERN = 0, // kernel messages
USER = 1, // user-level messages
MAIL = 2, // mail system
DAEMON = 3, // system daemons
AUTH = 4, // security/authorization messages
SYSLOG = 5, // messages generated internally by syslogd
@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;