Skip to content

Instantly share code, notes, and snippets.

@mperlet
mperlet / change_none_unique_minidlna_title.sh
Created August 18, 2015 13:38
Problem: minidlna use the title from the metadata, sometimes its better when the title = the filename. This script change the title from "'HERE THE NONE UNIQUE TITLE'" to the filename.
for line in $(sqlite3 /root/minidlna/files.db "SELECT ID,PATH FROM DETAILS WHERE TITLE='HERE THE NONE UNIQUE TITLE';");
do
id=$(echo $line | cut -d"|" -f1);
path=$(echo $line | cut -d"|" -f2);
echo $id;
echo $path;
sqlite3 /root/minidlna/files.db "UPDATE DETAILS SET TITLE='$(basename $path)' WHERE ID=$id;";
done;
@mperlet
mperlet / django_list_to_queryset.py
Created June 26, 2014 13:54
Converts a list to a django queryset
def list_to_queryset(model_list):
if len(model_list) > 0:
return model_list[0].__class__.objects.filter(
pk__in=[obj.pk for obj in model_list])
else:
return []
@mperlet
mperlet / check_iban.py
Created April 5, 2017 08:28
Python IBAN Checker
# Based on http://codereview.stackexchange.com/questions/135366/python-iban-validation
import string
def is_iban(unchecked_iban):
LETTERS = {ord(d): str(i) for i, d in enumerate(string.digits + string.ascii_uppercase)}
def _number_iban(iban):
@mperlet
mperlet / python_port_open.sh
Created March 24, 2017 15:49
python port check one line bash
python -c "import socket;print(True) if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('127.0.0.1',8000)) else False"
@mperlet
mperlet / parentHeight.js
Created December 17, 2020 07:28
jQuery calculate parent height by sum up childrens height
var parentHeight = $.map($('.parent > *'), function (i) {
return ($(i).height())
}).reduce(function (accumulator, currentValue) {
return accumulator + currentValue;
}, 0);
$('.parent').height(parentHeight);
@mperlet
mperlet / ostseezeitung-plus.sh
Created December 10, 2020 13:19
Shell function to read Ostsee-Zeitung Plus articles
function oz {
# bash> oz "https://www.ostsee-zeitung.de/Nachrichten/MV-aktuell/MV-plant-kompletten-Corona-Lockdown-in-wenigen-Tagen"
echo "{ $(curl -s "$1" | grep -o '\"description\":\".*')" | jq .articleBody
}
@mperlet
mperlet / Google Meet Focus And Toggle Mic
Created May 26, 2020 10:54
I use that script for a gnome keyboard shortcut
xdotool search --name 'Meet' | xargs xdotool windowactivate;sleep 0.2; xdotool key Ctrl+d
# record from soundcard
parec -d 1 | lame -r -V0 - my.mp3
# split file by silence
ffmpeg -i my.mp3 -af silencedetect=noise=-30dB:d=0.5 -f null - 2>&1 | grep silence_end | cut -d" " -f 5 | xargs -L 2 | nl | xargs -l bash -c 'ffmpeg -i my.mp3 -acodec copy -ss $1 -to $2 my$0.mp3'
@mperlet
mperlet / pycheck.sh
Created January 4, 2019 11:29
Check python files in pwd
function pycheck() {
echo
echo
echo
find . -name "*.py" | xargs mypy --ignore-missing-imports
echo
echo
@mperlet
mperlet / imagediff.sh
Created September 6, 2018 10:32
Diff two images with imagemagick without saving them
#!/bin/bash
# TODO: Add Readme
# TODO: Add Example
# TODO: Check if imagemagick is installed
IMG_A="$1"
IMG_B="$2"
convert "$IMG_A" "$IMG_B" <(compare "$IMG_A" "$IMG_B" -) +append - | display