Skip to content

Instantly share code, notes, and snippets.

View miraculixx's full-sized avatar
💭
working on https://github.com/omegaml

miraculixx

💭
working on https://github.com/omegaml
  • Switzerland
View GitHub Profile
@miraculixx
miraculixx / util.py
Created April 5, 2024 10:27
drop-in replacmement for time.sleep (python)
def wait(s, delay=1):
"""
drop-in for time.sleep() with status updates and Ctrl-C support
Usage:
for delay in wait(seconds):
print(f'waiting for {delay} seconds')
"""
import time
@miraculixx
miraculixx / example.MD
Last active February 29, 2024 16:34
Python multiprocess parallel selenium web scraping with improved performance

How to run this

(output as of September 29, 2023)

$ python scraper.py
Does flying slower actually save fuel?
Is non-consented video recording admissable evidence in a civil trial in Maryland?
Iteration counts of AMG solver changes in parallel

Two switch flyback converter MOSFETs voltage stress

@miraculixx
miraculixx / LICENSE.md
Last active February 27, 2024 22:50
Python Plotting Interaktive Beispiel

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit

Thinkfan Configuration for Lenovo X-Series

Why?

X-Series seems to have an issue with the fan control on suspend. In particular when thinkfan is active during suspending, the fan will continue to run indefinitely, even in suspended state.

@miraculixx
miraculixx / example.py
Created January 11, 2024 13:45
trace manipulations to os.environ in python
# to investigate which code is manipulating os.environ
class trace(dict):
def __delitem__(self, k):
self._trace(k)
super().__delitem__(k)
def _trace(self, k):
import inspect
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
@miraculixx
miraculixx / barrier-suspend.sh
Last active September 26, 2023 14:29
fix barrier issue on suspend/resume on linux mint
#!/bin/bash
# run this from /usr/lib/systemd/system-sleep/pre-suspend.sh
# adopted from https://www.addictivetips.com/ubuntu-linux-tips/run-scripts-and-commands-on-suspend-and-resume-on-linux/
USER=$(ls /home | grep -v root | tail -n1)
if [ "${1}" == "pre" ]; then
killall barrier barrierc
elif [ "${1}" == "post" ]; then
# need to run in background to ensure other post resume processing happens first
sudo su - $USER -c "nohup bash -c 'sleep 10; env DISPLAY=:0 /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=barrier com.github.debauchee.barrier' &"
fi
@miraculixx
miraculixx / .bash_k8s.rc
Last active August 12, 2023 07:34
useful kubectl shortcuts
# put in $HOME/.bash_k8s.rc
# . $HOME/bash_k8s.rc
# podlog <any pod name substring>
function podlog() {
pod=`kubectl get pods --all-namespaces | grep " $1" | tr -s ' ' | cut -d ' ' -f 2 | head -n1`
ns=`kubectl get pods --all-namespaces | grep " $1" | tr -s ' ' | cut -d ' ' -f 1 | head -n1`
shift 1
kubectl logs --namespace $ns $pod $*
}
@miraculixx
miraculixx / greplogs.sh
Created July 22, 2023 16:07
grep all docker logs
#!/bin/bash
# Get a list of running container IDs
container_ids=$(docker ps -q)
# Loop through each container and retrieve its logs
for container_id in $container_ids; do
container_name=$(docker inspect -f '{{ .Name }}' "$container_id" | cut -d'/' -f2)
echo "Container: $container_name"
docker logs "$container_id" 2>&1 | grep "$1" # Replace "SEARCH_PATTERN" with your desired pattern
@miraculixx
miraculixx / warp.sh
Last active June 24, 2023 21:49
CloudFlare WARP toggle and desktop notification
#!/bin/bash
# cloudflare warp
# https://developers.cloudflare.com/warp-client/get-started/linux/
# see https://1.1.1.1/
# Panel Icon: /bin/bash -ic ".$HOME/.bashrc.ext;warp toggle"
warp() {
case $1 in
on)
warp-cli connect
;;
@miraculixx
miraculixx / markup.py
Last active April 12, 2023 17:13
an extensible multi-markup reader in less than 100 lines of python code
# (c) miraculixx, licensed as by the terms of WTFPL, http://www.wtfpl.net/txt/copying/
# License: DO WHATEVER YOU WANT TO with this code.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
from io import StringIO
from contextlib import contextmanager