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 / sehnenlänge.R
Created March 4, 2016 09:13
Kreissegment Verhalten von Sehnenlänge und Segmenthöhe
radius <- function(h, s){
# Abbruchbedingung
h <- ifelse(h > s/2, NaN, h)
n <- ((4 * h^2) + s^2) / (8 * h)
return( n )
}
library(ggplot2)
@reox
reox / make_backup.sh
Created March 28, 2016 11:58
Bup Backup using a remote BUP_DIR
#!/bin/bash
# creake a backup of several folders using bup
# Using $TARGET as $BUP_DIR
TARGET=/mnt/backup
FOLDERS="/etc /root /home /srv /var"
LOGFILE="$TARGET/logs/$(date +%Y%m%d_%H%M%S).log"
(
flock -n 200
@reox
reox / latestversion.py
Last active March 28, 2016 12:01
Get the latest version of folders named like v23.42.1337
versions = filter(lambda x: re.match(r"^v[0-9]+\.[0-9]+\.[0-9]+$", x), os.listdir(path))
# The short form for:
# Take the version code like 1.2.197 and create a number out of it: 100020197 (every code part has 4 digits)
# Then sort it numerically and take the last one, which should be the largest number
last_version = sorted(versions, key=lambda x: sum(map(lambda x: 10 ** ((2-x[0]) * 4) * x[1], enumerate(map(int, x[1:].split("."))))))[-1]
@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

Keybase proof

I hereby claim:

  • I am reox on github.
  • I am reox (https://keybase.io/reox) on keybase.
  • I have a public key whose fingerprint is 0A30 1C5A 5C2A 80EC 1C55 F02B 0860 1DFA 423D CC9B

To claim this, I am signing this object:

@reox
reox / virt-import-win7-from-virtualbox.sh
Created March 10, 2017 13:12
Import a Windows 7 VM from Virtualbox
# Unfortunately virtio seems to not work with win8 (it seems to work with windows 10)
virt-install --import --memory 4096 --vcpus 1 --name win8 --os-variant win8 --disk ~/VirtualBox\ VMs/Windows/Windows-disk1.vmdk,format=vmdk
@reox
reox / bottleclass.py
Created May 9, 2017 08:21
Bottle as a class. Need to define the routing yourself, then you are fine
from bottle import Bottle
# From http://stackoverflow.com/a/21112077
def routemethod(route, **kwargs):
def decorator(f):
f.route = route
for arg in kwargs:
setattr(f, arg, kwargs[arg])
return f
return decorator
@reox
reox / linear.py
Created July 11, 2017 07:37
Linear Algebra with scipy
import numpy as np
from itertools import combinations
import scipy.linalg
x = [1.2, 1.3, 1.6, 2.5, 2.3, 2.8]
y = [167.0, 180.3, 177.8, 160.4, 179.6, 154.3]
z = [-0.3, -0.8, -0.75, -1.21, -1.65, -0.68]
f = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6]).transpose()
G = np.c_[x, y, z]
@reox
reox / ReplaceNonNullPlacements.FCMacro
Last active November 2, 2017 21:17
FreeCAD Macro to replace all placements with Nullplacements. This is important when using Assembly2 Workbench, to allow correct placement there.
print("Checking replacing all placements with default.")
print("===============================================")
for b in App.activeDocument().findObjects("PartDesign::Body"):
if not b.Placement.isNull():
print("!!! Body {} has a non null placement --> resetting!".format(b.Label))
b.Placement.Base = FreeCAD.Base.Vector()
b.Placement.Rotation = FreeCAD.Base.Rotation()
else:
print("Body {} looks fine...".format(b.Label))