Read Yaml File in Python

$ pip install pyyaml

def read_yaml_file(path: Path) -> dict:
    def join(loader, node):
        seq = loader.construct_sequence(node)
        return "".join([str(i) for i in seq])

    yaml.SafeLoader.add_constructor("!join", join)

    with open(path, "r", encoding="utf-8") as file:
        data_dict = yaml.load(file, Loader=yaml.SafeLoader)

    return data_dict

Configure Logger in Python for color output

import logging
from colorlog import ColoredFormatter
import colorama
from pathlib import Path

colorama.init()


def setupLogging(
    name_logger: str, level: int = logging.DEBUG, path_logging_file: Path = None
):
    formatter = ColoredFormatter(
        fmt="%(asctime)s %(filename)s:%(lineno)d %(log_color)s%(levelname)-8s%(reset)s %(yellow)s%(message)s",
        datefmt="%Y-%m-%d %H:%M:%S%z",
        reset=True,
        log_colors={
            "DEBUG": "white",
            "INFO": "green",
            "WARNING": "yellow",
            "ERROR": "red",
            "CRITICAL": "red,bg_white",
        },
    )

    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)

    logger = logging.getLogger(name=name_logger)
    logger.addHandler(stream_handler)
    logger.setLevel(level)

    # Create a file handler to log to a file
    if path_logging_file:
        file_handler = logging.FileHandler(str(path_logging_file))
        file_handler.setLevel(level)
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)

    return logger


if __name__ == "__main__":
    logger = setupLogging("monitoring")
    logger.debug("This is a debug message")
    logger.info("This is an info message")
    logger.warning("This is a warning message")
    logger.error("This is an error message")
    logger.critical("This is a critical message")

Draw latex graphs


%Preamble
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%draw graphs
\usepackage {tikz}
\usetikzlibrary {positioning}
\definecolor {processblue}{cmyk}{0.96,0,0,0}

% within document environment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin {center}
\begin {tikzpicture}[latex-latex, auto ,node distance =4 cm and 5cm ,on grid ,
semithick ,
state/.style ={ circle, draw, minimum width =1 cm}]
\node[state] (A) [] {$1$};
\node[state] (B) [right =of A] {$2$};
\node[state] (C) [right =of B] {$3$};
\node[state] (D) [below =of C] {$4$};
\node[state] (E) [above =of C] {$5$};
\path (A) edge [] node[below =0.15 cm] {} (B);
\path (B) edge [] node[below =0.15 cm] {} (C);
\path (C) edge [] node[below =0.15 cm] {} (D);
\path (C) edge [] node[below =0.15 cm] {} (E);
\end{tikzpicture}
\end{center}

You can adjust the arrow heads of the edges by replacing “latex-latex” by:

latex-latex : <->
-latex : ->
latex- : ->
<-> : <-> etc…

latex-latex will generate filled balck arrows, whereas <-> produces light non filled arrows.
Not specifying a value for the argument will remove the arrow heads.

German Mac OS keyboard Mac Book Pro 14

Square brackets are very hard to write with the default key mapping option + 5,6. I changed it to shift + option + 8,9 using the tool karabiner elements. Just download and install karabiner elements, and make sure that all permissions are given. I had trouble doing so, and had to close and reopen the program several times, always prompting me other permissions that I then guaranteed. Then go to

cd ~/.config/karabiner/assets/complex_modifications/

And add a file containing

{
  "title": "[] option + 5,6 to optione + shift + 8,9",
  "rules": [
    {
      "description": "eckige klammern mit option left shift und 8 und 9 machen. Sonst machende diese Tasten ˜· (mittlerer Punkt, brauch ich nicht)",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "8",
            "modifiers": {
              "mandatory": [
                "left_option",
                "left_shift"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
                "key_code": "5",
                "modifiers": ["left_option"]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "9",
            "modifiers": {
              "mandatory": [
                "left_option",
                "left_shift"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
                "key_code": "6",
                "modifiers": ["left_option"]
            }
          ]
        }
      ]
    }
  ]
}

Finally activate the newly created rule.