Skip to content

Instantly share code, notes, and snippets.

@tongyul
tongyul / subshell.sh
Created March 3, 2025 17:40
Script for launching a subshell with modified PATH and LD_LIBRARY_PATH
#!/bin/bash -e
ENVNAME='CMU 15-213'
START="$PWD"
cd "$(dirname "$0")"
BIN="$PWD/bin"
LIB="$PWD/lib"
mkdir -p "$BIN" "$LIB"
cd "$START"
@tongyul
tongyul / proxied.sh
Created March 3, 2025 15:38
Shell script that runs command with network proxy variables
#!/bin/bash -e
HELP_STR="\
Usage:
proxied # prints this message
proxied _proxy_ # prints sh snippet that sets _proxy_
proxied _proxy_ _cmd_... # runs _cmd_ with _proxy_
Environment variables that are affected:
- ALL_PROXY
- http_proxy
@tongyul
tongyul / main.py
Created May 19, 2024 16:42
Inconsistent resize behavior w.r.t. pygame.SCALED
from __future__ import annotations
from typing import Final, NoReturn
import dataclasses, logging, sys
import pygame
from pygame import Surface
logging.basicConfig(level=logging.DEBUG)
DEFAULT_WIDTH: Final = 1280
DEFAULT_HEIGHT: Final = 720
@tongyul
tongyul / enum.ts
Last active July 30, 2023 10:08
TypeScript discriminated union & a poor man's match statement | Rust-like enum | Haskell data | SML datatype
type EnumLike<K extends string> = { kind: K, value: any };
type EnumMatchTable<E extends EnumLike<string>, T> = {
[Variant in E as Variant["kind"]]: (_: Variant["value"]) => T;
}
export type Case<K extends string, T> = { kind: K, value: T };
export const caseConstructor =
<K extends string>(kind: K) =>
<T,>(value: T) : Case<K, T> => ({ kind, value });