Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
a-recknagel / deepchecks-config.yaml
Created August 15, 2024 11:15
deepchecks-monitoring v1 openAPI spec
plugin: openapi
specFile: deepchecks-openapi-spec.json
@a-recknagel
a-recknagel / timeout.py
Last active February 27, 2024 17:17
generic timeout construct
import signal
import contextlib
import os
from threading import Thread
from time import sleep
from datetime import datetime
class CustomInterrupt(Exception):
SIG = 63
@a-recknagel
a-recknagel / pip_plugin.py
Last active January 15, 2024 12:11
Pseudo installer fixture for pytest
from __future__ import annotations
import shutil
import sys
from pathlib import Path
from typing import Union
import pytest
SourceFileTree = dict[str, Union[str, Path, "SourceFileTree"]]
@a-recknagel
a-recknagel / extends.py
Last active October 17, 2023 20:04
bootleg inheritance
from inspect import signature
from contextvars import ContextVar
from typing import Callable
from unittest.mock import sentinel
SENTINEL = sentinel.UNSET
ctx: ContextVar[dict] = ContextVar('extends_ctx')
ctx.set({})
@a-recknagel
a-recknagel / implode_csv.py
Last active September 22, 2023 09:28
csv imploder w/ example
from pathlib import Path
from csv import DictReader
from collections import defaultdict
class DupelessDict(dict):
"""Duplicate entries may not pass silently."""
def __setitem__(self, key, value):
if key in self:
raise ValueError(f"Duplicate {key=} encountered.")
@a-recknagel
a-recknagel / foo.py
Created September 18, 2023 09:29
flat vs nested
nested_representation = {
5: {
"0-100": {
12: {
"new": 0.123,
"old": 0.321,
},
24: {
"new": 0.1234,
"old": 0.4321,
@a-recknagel
a-recknagel / popmap_deduplicator.py
Created August 2, 2023 20:35
popmap_deduplicator
from collections import defaultdict
from os import path
def split_off_duplicate_individuals(mapping):
current = {}
dupes = {}
seen = set()
for group, (idv_a, idv_b) in mapping.items():
if idv_a not in seen and idv_b not in seen:
import numpy as np
def plot(scenario: Scenario):
print(scenario.data)
class Scenario:
def __init__(
self,
some_modifier=2
data=None
@a-recknagel
a-recknagel / parse_package_metadata.py
Created May 12, 2023 14:57
w00t, switch/case does something useful
from collections import defaultdict
import importlib.metadata
from typing import Any
from pprint import pp
from packaging.requirements import Requirement
from packaging.markers import Op, Value, Variable
def group_deps_by_extra(pkg: str) -> dict[str, list[str]]:
@a-recknagel
a-recknagel / griffe.md
Last active May 10, 2023 07:31
plot cyclic python imports

griffe