View monitor-usage.py
#!/usr/bin/env python3 | |
""" | |
simple server usage monitoring, writing json to stdout. | |
usage: nohup python3 monitor_usage.py 3 > /var/log/usage.log & | |
""" |
View die-hard.py
from hypothesis import given, settings | |
from hypothesis.strategies import lists, sampled_from | |
def new_state(): | |
return {'big': 0, 'small': 0} | |
def desired_state(state): | |
return state['big'] != 4 | |
def empty_big(state): |
View retry.sh
#!/bin/bash | |
# define the retry fn | |
retry() { | |
e=0 | |
if [[ $- =~ e ]]; then | |
e=1 | |
fi | |
set +e | |
max_tries=10 |
View log-watcher.py
#!/usr/bin/env python3 | |
import functools | |
import sys | |
import time | |
import collections | |
import threading | |
import queue | |
email_to = '_@_.com' | |
email_subject = 'error' |
View new-password.py
#!/usr/bin/env python3 | |
import secrets | |
import string | |
import sys | |
import tty | |
import termios | |
import functools | |
import math | |
import operator |
View aws-rotate-access-key.py
#!/usr/bin/env python3 | |
import boto3 | |
import os | |
import pprint | |
import sys | |
import termios | |
import tty | |
""" |
View pip-upgrade.py
#!/usr/bin/env python3 | |
""" | |
check for updates and optionally upgrade packages via pip | |
""" | |
import os | |
import subprocess | |
import sys | |
import termios |
View license.txt
All public gists https://gist.github.com/nathants | |
Copyright 2020-present, Nathan Todd-Stone | |
MIT License, http://www.opensource.org/licenses/mit |
View rotate-logs.sh
#!/bin/bash | |
set -euo pipefail | |
# usage: myprogram.py | rotate-logs /tmp/myprogram.log [1000000] | |
file=$1 | |
max_lines=${2:-1000000} | |
touch $file | |
line_count=$(cat $file | wc -l) |
View auto-restart.sh
#!/bin/bash | |
set -eou pipefail | |
# usage: auto-restart.sh python program.py | |
trap 'exit 1' SIGINT | |
count=$(ps -eo args | grep ^/bin/bash | grep "auto-restart $*"$ | grep -v grep | wc -l) | |
if (($count > 2)); then | |
echo already running: auto-restart $@ >&2 |
OlderNewer