Skip to content

Instantly share code, notes, and snippets.

@wkettler
wkettler / multiprocess-stats.py
Last active November 22, 2022 03:36
A multiprocess stats engine example.
#!/usr/bin/env python3
from multiprocessing import Process, Pool, Manager
import random
import time
def percentile(values, percentile):
n = int(round((percentile / 100) * len(values) + 0.5))
return values[n-1]
@wkettler
wkettler / multiprocessing-logging.py
Created November 20, 2022 23:22
Python3 multiprocessing loggin example.
#!/usr/bin/env python3
import logging
import multiprocessing
def create_logger():
logger = multiprocessing.get_logger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter(\
@wkettler
wkettler / multiprocess-producer-consumer.py
Last active November 21, 2022 03:40
Python3 multiprocess producer / consumer example.
#!/usr/bin/env python3
import logging
from multiprocessing import Process, Pool, Manager
import random
import time
def init(queue):
global q
@wkettler
wkettler / ZeroFile
Last active November 9, 2022 14:29
class ZeroFile():
def __init__(self, file_size):
self.file_size = file_size
self._buf = b'\0'
self.position = 0
def tell(self):
return self.position
#!/bin/bash
if [ "$PAM_TYPE" == "close_session" ]; then
exit
fi
curl -s -X POST -H 'Content-type: application/json' SLACK_WEBHOOK \
-d @- > /dev/null << EOF
{
"attachments": [
#!/bin/bash
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/backup/$TIMESTAMP"
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
NTFY=/usr/local/bin/ntfy
mkdir -p "$BACKUP_DIR/mysql"
@wkettler
wkettler / s3share
Last active September 6, 2017 03:16
Upload a file to S3 and return a signed URL.
#!/usr/bin/env python
"""
Upload a file to S3 and return a signed URL.
William Kettler <william.p.kettler@gmail.com>
"""
import sys
import os
import subprocess
#!/usr/bin/env bash
#
# Install/update MakeMKV.
#
TMP=$(mktemp -d)
# Get current version
VERS=$(curl --silent "http://www.makemkv.com/download/" 2>&1 | \
egrep -o 'MakeMKV ([^ ]*) for' | \
@wkettler
wkettler / tree.py
Last active August 29, 2015 14:11
Autovivification removes need for horrendous nested calls to {}.setdefault() when working with trees in python. my_tree = tree() my_tree['tra']['la']['la']
from collections import defaultdict
def tree():
return defaultdict(tree)
#!/bin/bash
#
# hddcheck.sh
#
# Modified version of http://www.cyberciti.biz/files/scripts/monitor-my-hard-disk.sh.txt.
#
# Generate a warning email based on hard drive temps.
#
TO=test@test.com