Skip to content

Instantly share code, notes, and snippets.

View Casper64's full-sized avatar

Casper Küthe Casper64

View GitHub Profile
@Casper64
Casper64 / pipe.ts
Last active September 27, 2025 12:11
Type safe async pipe function in typescript
type SingleArgFunc = (arg: any) => any;
type Pipe<T extends SingleArgFunc[], M = T> = M extends [
infer F extends SingleArgFunc,
infer S extends SingleArgFunc,
...infer Rest extends SingleArgFunc[],
]
? Awaited<ReturnType<F>> extends Parameters<S>[0]
? Pipe<T, [S, ...Rest]>
: never
@Casper64
Casper64 / BPlusTree.java
Last active April 13, 2025 16:04
B+ tree implementation in Java with iterator and stream support.
/*
* Copyright (c) 2025. Casper Küthe
* All rights reserved.
*/
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@Casper64
Casper64 / switch-theme.sh
Created November 3, 2024 18:34
Bash script to switch between light and dark theme in Linux Mint Cinnamon
#!/bin/bash
theme=$1
if [ -Z $theme ]; then
current_theme=$(gsettings get org.cinnamon.desktop.interface gtk-theme)
if [[ "$current_theme" == "'Mint-Y-Dark'" ]]; then
theme="light"
else
@Casper64
Casper64 / DynamicTag.tsx
Last active September 16, 2024 22:39
Dynamic react tags
// Use dynamic React tags, kinda like Styled Components.
// e.g. <CustomTag.H1 === <h1>
import React from 'react'
// All JSX defined html elements
type Tag = keyof React.JSX.IntrinsicElements
// Convert tags longer than a length of 1 to its Capitalized version for fun
type ReactifyTag<T extends Tag> = T extends `${string}${infer Rest}`
? Rest extends ''
@Casper64
Casper64 / db_pool.v
Created April 22, 2023 16:53
Vweb Database pool test
module main
import vweb
import db.pg
struct App {
vweb.Context
vweb.Controller
db_handle vweb.DatabasePool[pg.DB]
mut:
@Casper64
Casper64 / theme_reflection.v
Last active April 15, 2023 13:34
Convert struct fields as seperate rows in a database. Used for Vaunt theming.
// Made by Casper Küthe
module vaunt
import db.pg
import json
// Why do I use this reflection?
// Well, in the frontend editor i need to have the option type available for
// rendering the options. Plus now each options is stored as single row in the
// database. No need to pass the whole json theme to the api only 1 update.
@Casper64
Casper64 / tictactoe.asm
Last active March 6, 2023 09:46
Tic tac toe written in x86 nasm assembly
; This program simulates the text-based version of tictactoe in assembly
;
; compile with: nasm -f elf tictactoe.asm -o out.o
; and: ld -m elf_i386 -s -o out out.o
; run with ./out
;
; Made by Casper Kuethe 2023
;
; some constants
@Casper64
Casper64 / htmlparser.py
Last active September 2, 2022 15:58
A parser for html I wrote to better understand parsers and tokenizers. With the intention to convert it from python to V
"""
© Casper Kuethe 2022
htmlparser.py
This script parses a html page and can format it
usage:
> python htmlparser.py [file]
this writes the formatted html file at the path ./out.html
"""
@Casper64
Casper64 / animate.py
Last active May 15, 2022 21:25
Converts frames to video (mp4) and plays the resulted video in a loop. Also this script detects if a new frame was added and then updates the video.
import cv2
import glob
import os
import re
from datetime import datetime
"""
Script that turns the images in the input folder into a video.
The frames must be placed inside "path/{input_folder}/frames/*".
The video will be saved in "./animation.mp4".
@Casper64
Casper64 / https.ts
Last active December 30, 2020 22:58
Typescript async wrapper for Nodejs https module, get and post functions
import https from 'https'
export interface GetOptions {
data: (chunk: any) => void;
end: (data: any) => void;
error: (err: Error) => void;
}
export async function get(url: string, options: Partial<GetOptions> = {}): Promise<any> {
const p = new Promise((resolve, reject) => {