Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import base64
import os
from cryptography.fernet import Fernet, MultiFernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
psk = "superSecretPreSharedKey"
salt = os.urandom(16)
content = "Super secret data"
#!/usr/bin/env python
import os
import json
import cherrypy
import time
import threading
from cklib.graph import Graph
from cklib.graph.export import node_from_dict
from prometheus_client import Summary
from prometheus_client.exposition import generate_latest, CONTENT_TYPE_LATEST
@lloesche
lloesche / git-cleanout.sh
Created October 6, 2021 14:17
Switch to main branch and delete all local git branches
git checkout $(git branch | grep -E "(main|master)" | sed -e 's/*\s\+//') && git branch | grep -vE "(main|master)" | xargs git branch -D
@lloesche
lloesche / multicoreserver.py
Created August 15, 2023 19:24
Python async server that uses multiple CPU cores while sharing a single socket.
#!/bin/env python3
import signal
import socket
import multiprocessing
import asyncio
import logging
import argparse
from threading import Event
from asyncio import StreamReader, StreamWriter
import boto3
from datetime import datetime, timedelta
from typing import Dict, List
def cpu_usage_metrics_for_instance(
region: str, instance_id: str, start_time: datetime, duration: timedelta
) -> Dict[str, float]:
end_time = start_time + duration
metric_name = "CPUUtilization"
@lloesche
lloesche / git-contributors.sh
Created October 29, 2024 10:47
List of git contributors in `main` branch with line count
#!/bin/sh
for file in $(git ls-tree -r main --name-only); do git grep -I '^' -- "$file" >/dev/null && git blame --line-porcelain main -- "$file" | grep '^author ' | sed 's/^author //'; done | sort | uniq -c | sort -n
@lloesche
lloesche / upsmon.py
Last active June 11, 2026 19:58
Power Management Script for Raspberry PI UPS Shield Geekworm x1200
#!/usr/bin/python3
import os
import dbus
import gpiod
import time
import logging
from argparse import ArgumentParser, Namespace
from datetime import datetime
from gpiod.line import Direction, Value
@lloesche
lloesche / version2int.py
Created February 4, 2025 23:15
Convert version string to int64
#!/usr/bin/env python3.13
import pytest
import sys
import re
from packaging.version import Version
from typing import Tuple
def encode_version(
major: int,