Skip to content

Instantly share code, notes, and snippets.

View szapp's full-sized avatar

Sören Zapp szapp

View GitHub Profile
@szapp
szapp / demo-contextlog.py
Created October 3, 2025 19:06
Simple context in Python's stdlib logging
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = []
# ///
import logging
import logging.config
from contextlib import contextmanager
from contextvars import ContextVar
@szapp
szapp / DaedalusStringFormatting.d
Created September 7, 2025 14:38
String formatting with %-expansion in Daedalus.
/*
* String formatting, given %s (string), %i (integer), and %f (float). The variable number of arguments are expected to
* be pushed on the stack. No error handling: If the number or order of arguments does not match, Gothic will crash.
*
* Example usage:
*
* MEM_PushStringParam("Mud");
* MEM_PushIntParam(24);
* castToIntf(1.2);
* out = STR_Format("Hello %s, give me %i ore! That is a %f % percent increase.");
@szapp
szapp / kbx_to_protonpass.py
Last active August 11, 2025 23:41
Keep tags and the hierarchical organization of nested groups when migrating from KeePassXC to ProtonPass
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "cyclopts",
# ]
# ///
import logging
import sys
@szapp
szapp / DaedalusBenchmark.d
Last active August 10, 2025 12:31
Daedalus performance benchmark (PBM) to compare two implementations (e.g. Daedalus vs. machine code) based on MEM_Benchmark.
/*
* Performance benchmark (PBM) to compare two implementations (e.g. Daedalus vs. machine code) based on MEM_Benchmark.
* Adjust the implementations `pbm_impl_A` and `pbm_impl_B` and compare their performance with `pbm_run()`.
*/
const int pbm_loop_num = 10000;
func int pbm_impl_A() {
// Example: Loop that sums all numbers (Daedalus)
var int sum; sum = 0;
repeat(i, pbm_loop_num); var int i;
@szapp
szapp / machine-code-to-daedalus.py
Created August 7, 2025 21:20
Format hexadecimal machine code bytes into Daedalus conform recipes. Run with `uv run machine-code-to-daedalus.py`.
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "cyclopts",
# ]
# ///
import logging
import re
@szapp
szapp / Filen S3 (HTTP).cyberduckprofile
Created August 6, 2025 15:30
A profile for Cyberduck for the use of a Filen S3 server including basic settings to get it working an an icon.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Protocol</key>
<string>s3</string>
<key>Vendor</key>
<string>filen-s3-http</string>
<key>Scheme</key>
<string>http</string>
@szapp
szapp / dynamic.svg
Last active August 5, 2025 19:27
Demo of dynamic SVG files that change appearance based on the presence of each other.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@szapp
szapp / restore_from_history.py
Last active August 3, 2025 14:55
Renames files copied from Windows FileHistory to match the original file names. Requires uv.
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "cyclopts",
# "pytest",
# ]
# ///
"""Usage from command line:
`./restore_from_history.py --help` or `uv run --script restore_from_history.py --help`
@szapp
szapp / quickplot.py
Created December 10, 2019 15:13
Quick plotting functions
"""
Quick plotting for testing and preliminary data visualization
"""
from matplotlib import pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
import numpy as np
__all__ = [
'imshow',
]
@szapp
szapp / smarterbounds.py
Last active December 10, 2019 15:12
Smarter bounds for matplotlib.spines.Spine
"""
Smarter bounds
This function emulates set_smart_bounds of matplotlib.spines.Spine,
but correctly sets the extent of the axes.
"""
def smarterbounds(ax, which='both'):
"""