Skip to content

Instantly share code, notes, and snippets.

View cb109's full-sized avatar
💭
🍴 🐘

Christoph Bülter cb109

💭
🍴 🐘
View GitHub Profile
@cb109
cb109 / stop_recursion.py
Created July 19, 2022 09:16
Stop infinite recursion
import inspect
import traceback
from typing import Callable
def stop_recursion(function: Callable):
"""Decorator to stop recursion of given function early.
Avoids 'RecursionError: maximum recursion depth exceeded' if
preventing the cause of the recursion is not possible.
@cb109
cb109 / gunicorn.sh
Created June 15, 2022 08:50
Set gunicorn workers based on available cores
# https://docs.gunicorn.org/en/stable/design.html#how-many-workers
let num_workers=2*$(nproc --all)+1
gunicorn --workers $num_workers
@cb109
cb109 / on_change_rerun_relevant_tests.sh
Last active July 25, 2022 12:26
On file changed, re-run relevant pytests only
pip install pytest-watch pytest-testmon
# Build db on first run.
pytest --testmon
# Watch for changes, rerun tests.
ptw -- <pytest-options>
# Together: Watch for changes, rerun tests relevant with changed file(s) only!
ptw -- --testmon <pytest-options>
@cb109
cb109 / conftest.py
Last active February 4, 2022 13:07
Allow pytest -k to match against tests with @pytest.mark.extra_keywords("match these", "as", "well")
def pytest_itemcollected(item):
"""Implement custom marker: @pytest.mark.extra_keywords
Using this we can assign extra keywords to match via the -k CLI
option, so that the test module/class/functionname are not the only
things matched. This makes sense if e.g. certain features should be
matched by name without having to change the test name necessarily.
"""
if not item.own_markers:
@cb109
cb109 / obs_beep_when_replay_buffer_saved.lua
Last active January 23, 2022 10:12
Beep when OBS replay buffer has been saved
-- Beep when the OBS (https://obsproject.com) replay buffer has been saved.
--
-- Slightly edited version of:
-- https://gist.github.com/upgradeQ/b2412242d76790d7618d6b0996c4562f
-- as mentioned in:
-- https://obsproject.com/forum/threads/id-love-some-feedback-when-a-replay-is-saved.129807/
-- with a less annoying sound and a different event.
--
-- Add to OBS via: Tools > Scripts > + Button
--
@cb109
cb109 / visualize_django_template_include_hierarchy_with_graphviz.py
Last active May 20, 2025 07:33
Visualize Django Template Include Hierarchy with Graphviz
"""Point script at Django template name and output DOT text describing the includes.
Use like:
cat visualize_django_template_include_hierarchy_with_graphviz.py | python manage.py shell
Starting template name must be something relative like
'myapp/mysubfolder/template_1.html'. The script will follow the inputs
and output a text like:
@cb109
cb109 / localize.sh
Last active December 3, 2021 12:29
Localize remote file to this machine
# Download remote file to same location on this machine.
#
# Helper is meant to be copied to your own dot files,
# then updated to the remote you use all the time.
#
# Folders are created as needed.
#
# Use like:
# localize /var/log/nginx/access.log
#
  1. Lege diese Datei auf deinem Desktop an: RisingDumbnessValheim.txt
  2. Öffne die Datei z.B. in Notepad und füge den folgenden Code ein (passe bei Bedarf den Pfad zur Steam.exe an):
echo|set/p=RisingDumbness123|clip > nul
"C:\Program Files (x86)\Steam\Steam.exe" -applaunch 892970 +connect 49.12.229.23:2456
  1. Speicher die Datei, schließe sie und benenne sie um in: RisingDumbnessValheim.bat (dafür müssen Dateiendungen im Windows Explorer angezeigt werden, siehe Ansicht > Dateiendungen anzeigen)
  2. Führ die Datei per Doppelklick aus (falls du die Standardanwendung für .bat Dateien geändert hast, bitte korrigier das vorher). Valheim startet, wähle deinen Charakter, es erscheint das Passwort-Eingabefeld. Das Password (RisingDumbness123) ist bereits in der Zwischenablage, füge es einfach per Strg+V ein. Fertig!
@cb109
cb109 / pytest_django_assert_between_num_queries.py
Created November 4, 2021 12:34
pytest-django django_assert_between_num_queries
from contextlib import contextmanager
from datetime import timedelta
from functools import partial
from typing import Generator
@contextmanager
def _assert_between_num_queries(
config,
min_num: int,
max_num: int,