Skip to content

Instantly share code, notes, and snippets.

View abebus's full-sized avatar
:shipit:
exceeding limits of corporate world by contributing to OSS during work hours💅

Albert N abebus

:shipit:
exceeding limits of corporate world by contributing to OSS during work hours💅
View GitHub Profile
from typing import Any
from collections import deque
from collections.abc import Generator
def multiplex_generators(
*generators: Generator[Any, Any, Any],
) -> Generator[Any, Any, Any]:
"""Run multiple generators 'concurrently', yielding their results as they come."""
active_generators = deque(generators)
@abebus
abebus / json_to_orjson_monkeypatch.py
Created May 3, 2025 12:19
This script replaces Python's built-in json.dumps() and json.loads() with faster orjson implementations while automatically falling back to the standard library when unsupported features are used.
import json as std_json
from typing import TYPE_CHECKING, Any
import orjson
# Mapping json kwargs to orjson options
JSON_TO_ORJSON_OPTIONS = {
"indent": orjson.OPT_INDENT_2, # maps indent to OPT_INDENT_2 (note: no control over indent size)
"sort_keys": orjson.OPT_SORT_KEYS,
"default": "default", # handle separately
@abebus
abebus / logo_deleter.py
Last active September 21, 2024 16:53
Python OpenCV delete multiple logos (templates) from image. Used in my image processing pipeline
from __future__ import annotations
import atexit
from multiprocessing.pool import ThreadPool
from pathlib import Path
from typing import TYPE_CHECKING
import cv2
import numpy as np
from PIL import Image