Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
a-recknagel / docs.conf.py
Created October 29, 2020 12:32
MCVE to reproduce sphinx's classvar appending
import sys
sys.path.append('src')
project = "sphinx_test"
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
]
@a-recknagel
a-recknagel / setup.py
Created November 7, 2020 16:07
Minimal packaging requirements
from setuptools import setup
setup(
name="my_package",
version="0.1.0",
packages=["my_package"],
install_requires=[],
)
@a-recknagel
a-recknagel / logging_setup.py
Last active November 23, 2020 12:19
log to a fluentd
import logging.config
workstation_IP = "?"
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"fluent_fmt": {
@a-recknagel
a-recknagel / client.py
Created March 25, 2021 22:28
Simple socket communication
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('0.0.0.0', 5000))
s.send(b'Hello, world\r\n')
print(f"Received {s.recv(1024)}")
@a-recknagel
a-recknagel / annotation_extension.py
Created April 3, 2021 00:07
How to include property annotations as if they were attributes
from dataclasses import dataclass
def annotate_properties(_cls=None):
def wrap(cls):
properties = [(x, getattr(cls, x)) for x in dir(cls) if type(getattr(cls, x)) == property]
for name, property_ in properties:
cls.__annotations__[name] = property_.fget.__annotations__["return"]
return cls
@a-recknagel
a-recknagel / logging_setup.py
Last active June 2, 2021 18:35
logging to stdout and file
import logging.config
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"oneline": {
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
},
@a-recknagel
a-recknagel / Dockerfile
Last active April 12, 2021 15:01
ubuntu 18.04 with poetry
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget curl
RUN wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
RUN tar -xf Python-3.9.4.tgz
RUN cd Python-3.9.4 && ./configure && make install
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -
ENV PATH "$PATH:/root/.poetry/bin"
@a-recknagel
a-recknagel / .gitigore
Created May 7, 2021 10:24
poetry inclusion demo
src/dlls
venv
.idea
*.egg-info
poetry.lock
dist
@a-recknagel
a-recknagel / Dockerfile
Created May 14, 2021 12:22
If your workstation and your Dockerfile have different archs
FROM python:slim
COPY wheelhouse/* wheelhouse/
RUN pip install wheelhouse/*
@a-recknagel
a-recknagel / foo.py
Last active May 18, 2021 12:08
qlog test
from logging import getLogger, config
from colorama import Fore, Back, Style
log = getLogger(__name__)
config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,