This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from typing import Any | |
# Custom formatter class | |
class CustomFormatter(logging.Formatter): | |
green = "\x1b[32m" | |
bold_green = "\x1b[1;32m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import logging | |
from typing import Any, Awaitable, Callable, TypeVar | |
logger = logging.getLogger(__name__) | |
# Define a TypeVar to capture the function's return type | |
R = TypeVar("R") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib | |
from litestar import Litestar, get | |
from litestar.response import File | |
@get(path='/favicon.ico') | |
async def handle_favicon_get() -> File: | |
icon_path = pathlib.Path(__file__).parent / 'crylaugh2.ico' | |
return File( | |
path=icon_path, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyramid.view import notfound_view_config | |
@notfound_view_config(renderer='string') | |
def notfound_view(request): | |
request.response.status = 404 | |
return f"""Page not found: path is {request.path} | |
``..:/oydhhMMhsyhdy+/::/. | |
:sddhyo+/:-. -NN :mMMMMMy` | |
`.-:/oyNMmhyyso+/-.` `NMN`-yMMMm+-+yms. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inspiration from https://github.com/themotte/rDrama/commit/9da3451ed97ec62cf4dc403e2863ae7d2fdfba98 | |
# import pprint | |
import logging | |
import subprocess | |
from collections.abc import Callable | |
LOGGER = logging.getLogger(__name__) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import abc | |
BASIC_TYPES = (int, float, complex, bool, str, bytes) | |
# modified off https://stackoverflow.com/a/15836901 | |
def dict_merge(a, b): | |
""" | |
merges b into a and return merged result | |
NOTE: tuples and arbitrary objects are not handled as it is totally ambiguous what should happen | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Lock, Thread | |
from pathlib import Path | |
from typing import Optional, Union | |
import os | |
import logging | |
class SingletonMeta(type): | |
""" | |
This is a thread-safe implementation of Singleton. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def truncate_float(f: float, n: int): | |
""" | |
Truncate float `f` to at most `n` decimal points. | |
- truncate_float(1.9333, 2) -> 1.93 | |
- truncate_float(1.9373, 2) -> 1.93 | |
- truncate_float(1.9, 2) -> 1.9 | |
https://stackoverflow.com/questions/29246455/python-setting-decimal-place-range-without-rounding | |
Parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import socket | |
import struct | |
import time | |
import json | |
class ZabbixSender: | |
''' | |
Sender to Zabbix |