Skip to content

Instantly share code, notes, and snippets.

View fnkr's full-sized avatar
🐧
cat /dev/urandom | aplay -c 2 -r 24000

Florian Kaiser fnkr

🐧
cat /dev/urandom | aplay -c 2 -r 24000
View GitHub Profile
@fnkr
fnkr / heidisql_password.py
Created February 18, 2019 20:17
Python implementation of HeidiSQL password hash functions.
# Original implementation is written in Pascal:
# https://github.com/HeidiSQL/HeidiSQL/blob/10.1/source/apphelpers.pas#L456-L506
from itertools import zip_longest
from random import randint
def decode(hash):
def grouper(n, iterable, padvalue=None):
return zip_longest(*[iter(iterable)] * n, fillvalue=padvalue)
@fnkr
fnkr / mysql-db-stats.sql
Created February 20, 2018 09:44
Human readable overview of MySQL/MariaDB database size
SELECT table_schema "Database",
Round(Sum(data_length) / 1024 / 1024, 0) "Data size (in MB)",
Round(Sum(data_length) / 1024 / 1024 / 1024, 3) "Data size (in GB)",
Round(Sum(index_length) / 1024 / 1024, 0) "Index size (in MB)",
Round(Sum(index_length) / 1024 / 1024 / 1024, 3) "Index size (in GB)",
Round(Sum(data_length + index_length) / 1024 / 1024, 0) "Total size (in MB)",
Round(Sum(data_length + index_length) / 1024 / 1024 / 1024, 3) "Total size (in GB)"
FROM information_schema.tables
GROUP BY table_schema;
@fnkr
fnkr / simple_mysql_backup.sh
Last active May 30, 2018 06:45
MySQL/MariaDB server backup in 147 chars
echo 'show databases;' | sudo mysql | tail -n+2 | grep -v _schema$ | grep -v ^mysql$ | xargs -n 1 -I _ bash -c 'sudo mysqldump _ | gzip > _.sql.gz'
@fnkr
fnkr / ascii_table.py
Created May 12, 2016 09:08
ASCII Tables with Python 3
# Python 3
def pprinttable(rows):
if len(rows) > 1:
headers = rows[0]._fields
lens = []
for i in range(len(rows[0])):
lens.append(len(max([x[i] for x in rows] + [headers[i]],key=lambda x:len(str(x)))))
formats = []
hformats = []
for i in range(len(rows[0])):
@fnkr
fnkr / imagemagick-print-width-height.sh
Last active May 12, 2016 09:21
Print width and height with ImageMagick's identify tool.
identify -format '%wx%h' image.png
@fnkr
fnkr / kirby-subdir.nginxconf
Created May 12, 2016 09:05
Nginx configuration for Kirby A) in domain's root directory (e.g. example.com) B) in subdirectory named /kirbycms/ (e.g. example.com/kirbycms/).
# e.g. for example.com/kirbycms/
location /kirbycms/ {
if (!-e $request_filename) {
rewrite ^/kirbycms/(.*)$ /kirbycms/index.php last;
break;
}
}
@fnkr
fnkr / random-string.sh
Last active March 31, 2017 08:00
Generate random, alphanumeric strings in Bash.
#!/bin/bash
RANDSTR="$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 40)"
@fnkr
fnkr / gist:cdccb6681aaefab42c43
Last active February 27, 2016 19:16
httpd reloader. Tells nginx (or any other httpd) to reload configuration if file has been created.
#!/bin/bash
reload_command="/usr/sbin/nginx -s reload"
watchfile="/tmp/please_reload_httpd"
while read file; do
if [ "$file" = "$(basename "$watchfile")" ]; then
$reload_command
rm "$watchfile"
fi
done < <(exec inotifywait -e create --format '%f' --quiet --monitor "$(dirname "$watchfile")")
@fnkr
fnkr / gist:51f0a92b9f0c658287ec
Last active May 12, 2016 09:23
This code allows you to configure phpPgAdmion to automatically login to a particular server and database with a particular default password.
<?php
/*
Automatic Login
(c) 2008 Tim Wood
contact via: tmwood (at) datawranglers (dot) com
You are free to use this code as long as this notice is retained
Description