Skip to content

Instantly share code, notes, and snippets.

@Vftdan
Vftdan / slice.c
Last active January 16, 2024 11:57
Slice types in C as anonymous struct types
// Copyright (c) 2024, vftdan
// SPDX-License-Identifier: MIT
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#define DEBUG_PRINT_VALUE(x, fmt) fprintf(stderr, #x " = " fmt "\n", x); fflush(stderr)
@Vftdan
Vftdan / owncast-chat2ass.sh
Created July 16, 2023 21:17
Owncast chat log to ASS/SSA subtitles
#! /bin/sh
# owncast-chat2ass.sh
# Copyright (c) 2023 vftdan (https://github.com/Vftdan)
TimeToSeconds() {
date -d "$1" +'%s.%N'
}
TimespanSeconds() {
printf '%s\n' "$(TimeToSeconds "$2") - $(TimeToSeconds "$1")" | bc
@Vftdan
Vftdan / sunskribo.vim
Created October 24, 2022 20:00
Vim keymap for https://bouncepaw.github.io/sunskribo (breaks in my version of NeoVim, but works in vim.gtk3)
scriptencoding utf-8
let b:keymap_name = "sunskribo"
lmapclear <buffer>
function! s:get_any_var(name, default)
let l:g = get(g:, a:name, a:default)
let l:b = get(b:, a:name, l:g)
return get(w:, a:name, l:b)
endfunction
@Vftdan
Vftdan / cue_to_flac_cmd.py
Last active August 14, 2022 14:54 — forked from Theldus/cue_to_flac.py
CUE splitter using ffmpeg (to flac)
#! /usr/bin/env python3
import sys
def unquote(s):
if len(s) < 2:
return s
if s[0] == '"' and s[-1] == '"':
return s[1:-1]
return s
@Vftdan
Vftdan / treecopy_flac2m4a.sh
Last active July 23, 2023 07:05
Script for copying file trees while converting files with some extension. Extensions to convert and conversion commands can be easily added or changed.
#! /bin/sh
# Should work both in bash and dash + GNU coreutils. Probably works in other POSIX shells & coreutils.
if [ $# -ne 2 ]; then \
echo "Usage: $0 <old_dir> <new_dir>" >&2
exit 1
fi
# Output dir must not be descendor of input dir!
in_dir="$(realpath "$1")"
@Vftdan
Vftdan / Makefile
Created April 27, 2022 13:39
Comparison of float parsing with istream & other methods in native & emscriptens compilers.
run: main main.js
@echo "=== Native ==="
./main
@echo
@echo "=== Emscripten ==="
node ./main.js
main: main.cpp
g++ -std=c++11 main.cpp -o main
main.js: main.cpp
em++ -std=c++11 main.cpp -o main.js
@Vftdan
Vftdan / hide-nixbuild-accounts.sh
Created January 15, 2022 14:18
Hide nixbuild accounts from lighdm in Linux Mint / Ubuntu Bionic.
#! /bin/sh
for i in $(seq 32); do \
cat > /var/lib/AccountsService/users/nixbld"$i" <<EOF
[User]
SystemAccount=true
EOF
done
@Vftdan
Vftdan / minecraft-keycodes.tsv
Last active September 13, 2021 13:19
Minecraft old (1.12) & new (1.16) keycodes
Key Old Code New Code
BUTTON0 -100 key.mouse.left
BUTTON1 -99 key.mouse.right
BUTTON2 -98 key.mouse.middle
BUTTON3 -97 key.mouse.4
BUTTON4 -96 key.mouse.5
BUTTON5 -95 key.mouse.6
BUTTON6 -94 key.mouse.7
BUTTON7 -93 key.mouse.8
NONE 0 key.keyboard.unknown
@Vftdan
Vftdan / alglib.py
Created September 3, 2021 14:42
Some algebraic types for making calculations
from fractions import Fraction, gcd
from itertools import product as cartprod
def memo(f):
cache = {}
def g(*argv, **kwargs):
args = (argv, tuple(sorted(kwargs.items())))
if args in cache:
#print("Using {0} |-> {1}".format(args, cache[args]))
return cache[args]
else:
@Vftdan
Vftdan / catcolored.vim
Last active August 7, 2021 18:27
NeoVim script to pretty print the file to terminal
function! s:color_to_ansi(cstr, is_bg)
let l:car=a:is_bg ? 40 : 30
let l:cdr=[]
if a:cstr[0] == '#'
let l:car+=8
let l:cdr=[2] + map(split(a:cstr[1:], '\v..\zs'), 'str2nr(v:val, 16)')
elseif a:cstr > 15
let l:car+=8
let l:cdr=[5, a:cstr]
else