Skip to content

Instantly share code, notes, and snippets.

View vlntnwbr's full-sized avatar

Valentin Weber vlntnwbr

View GitHub Profile
@vlntnwbr
vlntnwbr / repr_dict_obj.py
Last active October 30, 2025 23:19
Method to create a string representation of any Python object that has a __dict__ attribute. The string formatting is inspired by the formatting of the Python dataclasses repr function. See docstring for details.
def repr_dict_obj(
candidate: object,
classname: str | None = None,
attr_alt_reprs: (
None | dict[str, str | Callable[[object], str] | Literal["__exclude__"]]
) = None,
) -> str:
"""
Return a dataclass inspired repr string for given object.
@vlntnwbr
vlntnwbr / setup_logging.py
Created October 23, 2025 13:21
a simple base logging function that sets up a package level logger that optionally outputs in color
def setup_logging(level: str | int, colored: bool) -> logging.Logger:
"""Set up logging for the application."""
class ColorFormatter(logging.Formatter):
"""Logging formatter for colored output."""
RESET_STYLE = "\033[0m" # ANSI code to reset all style information
LEVEL_COLOR = {
# map logging levels to colorized ansi style codes
# the string must follow this pattern "\033[<code>m"
# lookup other supported color codes here
##
# Copyright (c) 2020 Valentin Weber
#
# After some minor modifications (as marked below) this EventGhost
# Python script provides a method to send requests to devices
# registered with the Join API <https://joaoapps.com/join/api/> from
# any EventGhost Python Script or Command.
#
# EventGhost usage: `eg.globals.JoinPushDevice(text="hello_world")`
##