Skip to content

Instantly share code, notes, and snippets.

View muety's full-sized avatar

Ferdinand Mütsch muety

View GitHub Profile
muety /
Last active August 17, 2023 10:20
Script to determine the next available subuid on Linux
# Author: Ferdinand Mütsch <>
# Script to determine the next subuid / subgid for a user.
# It will consider (a) all already existing subuid / subgid ranges and (b) all "real" user ids.
# Note: When using LDAP login (e.g. with SSSD), /etc/passwd won't contain those external users.
# In the case of SSSD, you will have to enable enumeration ( to make "getent passwd" all local AD / LDAP users.
# However, on the other hand, enabling recommendation is not recommended, because it will cause high load on server and client (
# before:
# after:
# script is interactive
# it will first fetch all broken products and then ask you for confirmation before actually updating them
import re
import sys
from typing import Tuple, Set, List, Any, Dict
import requests
muety /
Created April 20, 2023 06:12
Simple script to print current power draw in Watts on Linux notebooks
import time
if __name__ == '__main__':
while True:
with open('/sys/class/power_supply/BAT0/current_now', 'r') as f:
current = float(f.readline().strip())
with open('/sys/class/power_supply/BAT0/voltage_now', 'r') as f:
voltage = float(f.readline().strip())
print(f'{current * voltage / 1000000000000} W', end='\r')
muety / webdav-fileserver.caddyfile
Created April 10, 2023 07:43
Caddy config for anonymous file uploads
http://localhost:8080 {
@get method GET
@propfind method PROPFIND
root * /tmp/data
# TODO: add basic auth for DELETE, PROPPATCH, LOCK, etc.
# TODO: add matchers so uploaded file keys must be uuids
route {
muety / shelly_wifi_reconnect.js
Last active April 12, 2024 10:07
Shelly 2. Gen device script to repeatedly check for WiFi status and reboot the device if disconnected for long enough
// Reboot after 5 minutes of disconnect
let wait_sec = 30;
let retries = 10;
let c = 0;
let timer = Timer.set(wait_sec * 1000, true, function () {'WiFi.GetStatus', null, function (result, error_code) {
if (result.status !== 'got ip') {
if (c++ < retries) {
print('wifi not connected, waiting another', (retries - c) * wait_sec, 'seconds until reboot');
muety /
Created October 24, 2022 19:51
Single FastAPI on_startup() hook with multiple Gunicorn workers (run only once for all processes combined)
# run with gunicorn:
# gunicorn --preload --workers 4 --worker-class=uvicorn.workers.UvicornWorker app.main:app
# ('preload' is the important bit here)
# alternatively, set GUNICORN_CMD_ARGS='--preload'
import ctypes
import multiprocessing as mp
from fastapi import FastAPI
import os
import stat
import time
import logging
import asyncio
from dataclasses import dataclass
muety / PGMap.php
Last active October 15, 2021 09:35
define("DSN", "host=localhost dbname=postgis_in_action user=postgis_in_action port=5432 password=whatever");
$param_format = $_REQUEST['FORMAT'];
$param_width = (int) $_REQUEST['WIDTH'];
$param_height = (int) $_REQUEST['HEIGHT'];
$param_bbox = $_REQUEST['BBOX'];
$param_schema = $_REQUEST['SCHEMA'];
-- with a couple of bugs fixed
param_format text, -- e.g. 'image/png'
param_width integer, -- e.g. 256
param_height integer, -- e.g. 256
param_srid integer, -- e.g. 'EPSG:3857'
param_bbox text, -- e.g. '660415.9243839228,3713005.085980721,665307.8941941742,3717897.0557909757' in EPSG:3857
param_schema text,
muety /
Last active September 16, 2021 13:27
A script to help you migrate your whole WhatsApp chat history with a person to Telegram
import os
import re
import shutil
# A script to help you migrate your whole WhatsApp chat history with a person to Telegram
# Instructions
# 1. Install "Backup WhatsApp Chats" extenstion to Chrome