Skip to content

Instantly share code, notes, and snippets.

@wernersbacher
wernersbacher / random_in_intervals.py
Created December 21, 2022 10:27
Generate a random integer from several intervals
def random_in_intervals(allowed_intervals: Iterable):
""" generate a radnom int from a selection of several intervals.
intervals have to be in the format a, b where b > a"""
sum_of_ranges = sum(b-a for a, b in allowed_intervals)
random_float = random.random()
relative_number = random_float*sum_of_ranges
# now we have to get the actual value from the interval
@wernersbacher
wernersbacher / table.html
Created December 13, 2022 18:58
Resolve a HTML table's rowspan attributes (table normalizing) in Javascript
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>
function normalize(tagname){
var newTable = $(tagname).clone(true);
$(tagname).empty();
@wernersbacher
wernersbacher / extractMkvSubtitles.sh
Last active December 13, 2022 19:00 — forked from cinatic/extractMkvSubtitles.sh
Extract Subtitles from mkv
#!/bin/bash
# Extract SRT subtitles from each MKV file in the given directory
# call script.sh <path> <language-searchtag>
# If no directory is given, work in local dir
if [ "$1" = "" ]; then
DIR="."
else
DIR="$1"
fi
@wernersbacher
wernersbacher / check.sh
Created March 31, 2020 08:43
Bash: Check if IP-Address is valid
function valid_ip()
{
local ip=$1
local stat=1
regexv6='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)