Skip to content

Instantly share code, notes, and snippets.

@reox
reox / multiprocessing_stub.py
Created February 9, 2016 13:05
A Stub for multiprocessing, also handles Ctrl+C correctly and kills childs
import sys
from argparse import ArgumentParser
from multiprocessing import Queue, Array
import multiprocessing
import signal
import os
import time
# this signal handler terminates the child-process on SIGINT or SIGTERM event
@reox
reox / git-pull.sh
Created November 25, 2015 15:37
Cozy way to wait for a fellow to push the changes... just play jeopardy music until git pull succed!
#!/bin/sh
# Get jeopardy.mp4 from:
# clive https://www.youtube.com/watch?v=0Wi8Fv0AJA4
# ffmpeg -i <file> -vn -acodec copy "jeopardy.mp"
mpv -loop $(dirname $0)/jeopardy.mp4 >/dev/null 2>&1 &
PID=$!
while [ "$(git pull)" = "Already up-to-date." ]; do
echo -n "."
@reox
reox / downloader.sh
Last active February 11, 2017 23:28
Download Alpha Centauri Episodes
# first get all xml files with the download link
for url in $(curl http://www.br.de/fernsehen/ard-alpha/sendungen/alpha-centauri/alle-videos/index.html | egrep -o 'href="(.*[^"])" .* title="zur Übersicht' | awk -F "\"" '{ print $2 }'); do
for videourl in $(curl http://www.br.de/$url | egrep -o 'href="(.*[^"])" .* title="zum Video' | awk -F "\"" '{ print $2 }'); do
xmlfile=$(curl http://www.br.de/$videourl | egrep -o "dataUrl:'(.*[^'])'" | awk -F "'" '{ print $2 }')
wget http://www.br.de/$xmlfile
done
done
# second get the actual file
for file in *.xml; do
@reox
reox / testmydisk.sh
Last active August 29, 2015 14:15
testmydisk
#!/bin/bash
# written by reox 2015
# test the read speed of your disk.
# this script will test random access, you can remove the shuf command in the for loop to have linear access too.
# after you run the script, plot the data with your favourite plotting lib.
set +x
set +e
sectors=$(fdisk -l $1 | egrep -o "[0-9]+ sectors" | cut -f 1 -d " ")
@reox
reox / spiral.ngc
Last active August 29, 2015 14:13
Mill a spiral for a hole
G21 ;mm
G90 ; absolute coordinates
G64 ; continuous mode for corners
G0 Z40.000000
F1800
M3 S6000
G54
G17
@reox
reox / ldr.py
Last active August 29, 2015 14:13 — forked from electronut/ldr.py
"""
Display Random Data using matplotlib's animation function
forked from:
Author: Mahesh Venkitachalam
Website: electronut.in
"""
import sys
import numpy as np
@reox
reox / format_time.py
Created January 8, 2015 12:54
Format seconds to human readable format
import time
def format_time(time):
m, s = divmod(time, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
# could be extended here to weeks, months, years, ...
# but the exact calculation of months, weeks and years is a little bit
# more difficult... so we leave it as it is.
@reox
reox / show_valid_certs.sh
Created October 19, 2014 12:49
Print out information about non valid certificates and certificates that will run out in less than 30 days.
#!/bin/bash
# Show the validity of certificate files
# If the certificate will run out in less than one month, a warning is shown
# If the certificate is not valid anymore, an error message is shown
# Valid certificates are not printed out
for cert in /etc/nginx/ssl/*.crt; do
d1=$(date -d "$(openssl x509 -noout -dates -in $cert | grep notAfter | cut -d '=' -f 2)" +%s)
d2=$(date +%s)
@reox
reox / check_multiple_startswith.py
Last active August 29, 2015 14:07
Check if string starts with multiple substrings
words = ["foo", "bar", "blafoo"]
check_list = lambda x, y: map(lambda z: not x.startswith(z), y)
if not all(check_list("foobarfoo", words)):
print("String starts with one of the substrings")
else:
print("String does not start with one of the substrings")
@reox
reox / logger.py
Created July 18, 2014 11:30
Sample Logger - return a pretty straight forward and configured logger
import logging
import logging.handlers
def get_logger(name, logfile=""):
"""
Get a logger with a given name.
The logger will be configured to match other loggers.
Keyword arguments: