Skip to content

Instantly share code, notes, and snippets.

View mara004's full-sized avatar
🎆

mara004

🎆
View GitHub Profile
@mara004
mara004 / git_net_additions.py
Last active August 28, 2026 20:37
Analyze net additions with git
# SPDX-FileCopyrightText: 2026 geisserml <geisserml@gmail.com>
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
# This is essentially a copy of https://github.com/pypdfium2-team/pypdfium2/blob/11c67012f256abd3c402c47e9abe26bfbc3d182e/utils/dev/git_net_additions.py
# Please check pypdfium2's main branch for possible updates.
# Augment `git diff --numstat` with a delta column (net additions, i.e. additions-deletions), and sort the output by that column.
# This helps maintainers analyze net growth (or degrowth) between refs on a per file basis, ordered by relevance, with the highest net additions shown first. (Author's note: AOTW, neither git itself, nor GitHub, nor any other tool I'm aware of seemed to offer that functionality.)
# For completeness, this script also adds a churn column (absolute additions+deletions) as in `git diff --stat`. Validates the final result against `git diff --shortstat`.
@mara004
mara004 / regextract.py
Last active August 8, 2026 16:35
`grep -o` substitute for pythoneers
import re, sys
pattern = sys.argv[1]
out_pattern = sys.argv[2]
string = sys.argv[3]
match = re.search(pattern, string)
result = out_pattern % match.groups()
print(result, end="")
@mara004
mara004 / layereddict.py
Last active August 28, 2026 20:33
Layered dictionary (__missing__ hook)
class layereddict (dict):
def __init__(self, layer, **kwargs):
super().__init__(**kwargs)
self._layer = layer
def __missing__(self, key):
return self._layer[key]
@mara004
mara004 / class_kit.py
Last active July 26, 2026 18:05
Cached properties with slots, via metaclass (Clean, declarative variant)
# SPDX-FileCopyrightText: 2026 geisserml <geisserml@gmail.com>
# SPDX-License-Identifier: MPL-2.0
import stl # local
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from functools import cached_property as cached_prop_typehint
else:
def cached_prop_typehint(func):
@mara004
mara004 / .XCompose
Last active July 18, 2026 14:56
Custom compose sequences
# Dump your /usr/share/X11/locale/en_US.UTF-8/Compose below and save as ~/.XCompose
<Multi_key> <minus> <numbersign> : "‑" U2011 # NONBREAKING HYPHEN
@mara004
mara004 / run_with_args.py
Last active January 26, 2026 23:58
Wrap a python module's CLI entrypoint with argfiles support
#! /usr/bin/env python3
# SPDX-FileCopyrightText: 2026 mara004 <geisserml@gmail.com>
# SPDX-License-Identifier: BSD-2-Clause
import sys
import shlex
from pathlib import Path
from importlib import import_module
from importlib.metadata import entry_points
@mara004
mara004 / ghostscript_ffi.py
Last active April 14, 2025 01:06
PDF rendering with Ghostscript, revisited (ABI bindings, in-memory approach)
# Four lines intentionally left blank
# SPDX-FileCopyrightText: 2025 geisserml <geisserml@gmail.com>
# SPDX-License-Identifier: MPL-2.0 OR GPL-3.0-or-later
# Note that Ghostscript is AGPL-licensed, so this code is altogether affected by copyleft
# Written with Ghostscript 9.56.1 on Fedora.
@clausecker
clausecker / README.md
Last active December 25, 2025 23:33
prepare()-ing for execution

UNIX famously uses fork+exec to create processes, a simple API that is nevertheless quite tricky to use correctly and that comes with a bunch of problems. The alternative, spawn, as used by VMS, Windows NT and recently POSIX, fixes many of these issues but it overly complex and makes it hard to add new features.

prepare() is a proposed API to simplify process creation. When calling prepare(), the current thread enters “preparation state.” That means, a nascent process is created and the current thread is moved to the context of this process, but without changing memory maps (this is similar to how vfork() works). Inside the nascent process, you can configure the environment as desired and then call prep_execve() to execute a new program. On success, prep_execve() leaves preparation state, moving the current thread back to the parent's process context and returns (!) the pid of the now grownup child. You can also use prep_exit() to abort the child without executing a new process, it similarly returns the pid

@mara004
mara004 / dvd_rip.sh
Last active March 24, 2025 22:28
DVD ripping
# see also https://wiki.ubuntuusers.de/DVDs_manuell_rippen/#Komplette-Spur-rippen
lsdvd /dev/sr0 # to show available tracks and their length
mplayer dvd://n -dvd-device /dev/sr0 # to preview a track -- where n is the track number (1-based)
mplayer dvd://n -dvd-device /dev/sr0 -v -dumpstream -dumpfile filename.vob # to rip track
@mara004
mara004 / interesting_windows.md
Last active April 14, 2026 17:49
Interesting Windows(-only) software