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 / reduce.md
Last active August 28, 2026 20:40
Explore `functools.reduce()` & `operator.getitem` as sort key
>>> from functools import reduce, partial
>>> from operator import getitem
>>>
>>> # First, let's get an understanding of how reduce and partial actually work:
>>> # reduce() comes in two variants: the first variant takes a single iterable
>>> # featuring the initial value followed by the arguments to be applied on the previous value
@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 / class_kit_old.py
Last active July 23, 2026 07:22
Cached properties with slots, via metaclass (Hacky variant)
# SPDX-FileCopyrightText: 2026 geisserml <geisserml@gmail.com>
# SPDX-License-Identifier: MPL-2.0
from typing import TYPE_CHECKING
from stl import cached_property
if TYPE_CHECKING:
from functools import cached_property
def _func_visitor(cp_map):
@mara004
mara004 / cached_property.py
Last active July 23, 2026 12:57
Custom cached property implementation (backward compatible)
# SPDX-FileCopyrightText: 2026 geisserml <geisserml@gmail.com>
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
# See also
# https://github.com/pypdfium2-team/pypdfium2/blob/950aeb49b8aa1b5e9bc248b1ff293d4e586bf41b/src/pypdfium2_stl/shared/stl.py
# https://stackoverflow.com/a/78825819/15547292
# https://gist.github.com/mara004/076e3110aba8e8a3f8a6f2c84af350ee
class cached_property:
"""
@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 / at_function_exit.py
Created August 8, 2025 13:45
Exit hanlder for function
# SPDX-FileCopyrightText: 2025 geisserml <geisserml@gmail.com>
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
import functools
class finally_decorator:
def __init__(self, callback):
self._callback = callback
@mara004
mara004 / yt_revanced.md
Last active June 13, 2025 22:20
On Procuring YouTube ReVanced

In the course of this process, you will download several apps from external sources. To be on the safe side, you'll want to check each APK with https://www.virustotal.com/ before installation. You are also encouraged to use Firefox with uBlockOrigin and the Badware Risks filter list enabled, as a precaution against scamming sites.

  1. Install ReVanced Manager from https://github.com/ReVanced/revanced-manager/releases/latest or https://revanced.app/download
  2. Open ReVanced Manager (grant permission to install apps when asked for). Tap Patches -> Select an app. Look for YouTube and the Suggested: version. It should be in the 3rd line. (Do not use the 1st line, that's your installed version of YouTube.)
  3. Go to https://www.apkmirror.com/ and search for YouTube $VERSION, where $VERSION is the suggested version you have determined in (2). (Alternatively, tap on the Suggested: ... field to do a browser search that may lead you to the apkmirror site in question.) Once you've found the right APK, downlo