Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓

Ferdinand Mütsch muety

🤓
View GitHub Profile
View leihlokal_product_descriptions_fix.py
# before: https://anchr.io/i/1NQ3x.png
# after: https://anchr.io/i/iMkiK.png
# 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
muety / current_power.py
Created April 20, 2023 06:12
Simple script to print current power draw in Watts on Linux notebooks
View current_power.py
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
muety / webdav-fileserver.caddyfile
Created April 10, 2023 07:43
Caddy config for anonymous file uploads
View webdav-fileserver.caddyfile
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
muety / rclone_sync.txt
Last active December 20, 2022 20:32
Automated Google Drive sync for Linux using rclone
View rclone_sync.txt
Script that will trigger a local to remote sync when any changes below your local Google Drive folder occur - but at max. every 10 minutes - and a remote to local sync every x (e.g. 30 minutes) via a cron job.
0. Install rclone and configure it for Google Drive
1. Create files listed below
2. Configure rclone_watch_local.sh to be run on startup (e.g. using a systemd service unit)
3. Add a cron job that runs rclone_remote2local.sh every x (e.g. 30) minutes
----------------------
rclone_local2remote.sh
----------------------
@muety
muety / shelly_wifi_reconnect.js
Last active November 28, 2022 17:39
Shelly 2. Gen device script to repeatedly check for WiFi status and reboot the device if disconnected for long enough
View shelly_wifi_reconnect.js
// 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 () {
Shelly.call('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
muety / main.py
Created October 24, 2022 19:51
Single FastAPI on_startup() hook with multiple Gunicorn workers (run only once for all processes combined)
View main.py
# 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
View qcartpole_gridsearch.py
import time
import multiprocessing
import numpy as np
from sklearn.model_selection import ParameterGrid
import qcartpole
N_RUNS = 10
grid_params = {
@muety
muety / track.php
Last active May 31, 2022 13:56
OwnTracks receiver script
View track.php
<?php
$data = file_get_contents('php://input');
$json = json_decode($data);
header("Content-type: application/json");
if ($json->_type !== 'location') {
return;
}
View mouse_tracker.py
#!/usr/bin/python
# TODO: https://stackoverflow.com/a/58840987/3112139
import os
import stat
import time
import logging
import asyncio
from dataclasses import dataclass
View dqn_cartpole.py
# Inspired by https://keon.io/deep-q-learning/
import random
import gym
import math
import numpy as np
from collections import deque
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam