Skip to content

Instantly share code, notes, and snippets.

Valentin Hilbig hilbix

Block or report user

Report or block hilbix

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hilbix
hilbix / default.conf
Created Feb 3, 2020
NginX HTTP -> HTTPS redirection with LetsEncrypt
View default.conf
server {
server_tokens off;
server_name _;
listen 80 default_server;
listen [::]:80 default_server;
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
access_log /var/log/nginx/access.log;
@hilbix
hilbix / fix-broken.sh
Last active Jul 12, 2019
Helper to fix broken "apt-get install -f", which might happen when upgrading from i386 to amd64
View fix-broken.sh
#!/bin/bash
#
# Public Domain
#
# If you follow https://wiki.debian.org/CrossGrading you might get stuck
# at the "apt-get install -f" step. Either you are doomed, or use this script here.
#
# Just run it to find out the troublesome :i386 packages.
# Then paste those packagenames to the script here to install the amd64 counterpart.
# Or press just return to run "apt-get install -f",
@hilbix
hilbix / update-yarn-key.sh
Created Mar 24, 2019
Safely update apt's yarn GPG key
View update-yarn-key.sh
#!/bin/bash
STDOUT() { local e=$?; printf '%q' "$1"; [ 1 -lt $# ] && printf ' %q' "${@:2}"; printf '\n'; return $e; }
STDERR() { STDOUT "$@" >&2; }
OOPS() { STDERR OOPS: "$@"; exit 23; }
x() { "$@"; }
o() { x "$@" || OOPS fail $?: "$@"; }
ID=72ECF46A56B4AD39C907BBB71646B01B86E50310
RING=/etc/apt/trusted.gpg.d/yarnpkg.gpg
@hilbix
hilbix / debug.inc
Created Sep 2, 2018
No-Brainer function to debug with `gdb` from shell level
View debug.inc
# This function keeps IO redirection and commandline arguments
# when you want to debug some executable.
#
# Just type "debug" in front of the call:
# "b u g" "${p[@]}" < <(in) 1> >(out) 2> >(two) 3> >(three)
# debug "b u g" "${p[@]}" < <(in) 1> >(out) 2> >(two) 3> >(three)
#
# All you need is a /dev/tty
debug()
@hilbix
hilbix / googleauth.php
Last active Jul 8, 2018
PHP RFC4648-base32 to hex conversion for Google Authenticator
View googleauth.php
# $key = hex2bin(rfc4648tohex('AAAAAAAAAAAAAAAA')); # Your secret Auth-Key
# $token = googleauth($key, floor(time()/30));
function googleauth($key, $stamp)
{
$mac = hash_hmac('SHA1', substr(chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).pack('N', floor($stamp)),-8), $key, true);
$val = unpack('N', substr($mac, (ord(substr($mac, -1)) & 15), 4));
$val = $val[1]&0x7fffffff;
return substr("000000$val", -6);
}
@hilbix
hilbix / mongoexportall.sh
Created Mar 9, 2018
Export complete MongoDB as JSON files with one record a line
View mongoexportall.sh
#!/bin/bash
#
# mongoexportall [directory [connection-options..]]
#
# This Works is placed under the terms of the Copyright Less License,
# see file COPYRIGHT.CLL. USE AT OWN RISK, ABSOLUTELY NO WARRANTY.
# (CLL is more free than Public Domain, as it disallows Copyrights.)
OOPS() { { printf 'OOPS:'; printf ' %q' "$@"; printf '\n'; } >&2; exit 23; }
@hilbix
hilbix / download-debian-netinstall.sh
Last active Jul 13, 2019
Download an verify Debian netinstall ISO
View download-debian-netinstall.sh
#!/bin/bash
VERS="$1"
OOPS() { echo "$*" >&2; exit 23; }
o() { "$@" || OOPS "exec $?: $*"; }
v() { local -n __var__="$1"; __var__="$("${@:2}")" || OOPS "exec $?: $*"; }
[ -n "$VERS" ] || read -p 'Version (like: 9.3.0): ' VERS || exit
@hilbix
hilbix / tmux.md
Created Jul 25, 2017
Fix garbled tmux
View tmux.md

https://unix.stackexchange.com/a/253369

stty sane; printf '\033k%s\033\\\033]2;%s\007' "`basename "$SHELL"`" "`uname -n`"; tput reset; tmux refresh

tmux list-windows -a | while IFS=: read -r a b c; do tmux set-window-option -t "$a:$b" automatic-rename on; done
@hilbix
hilbix / heap.h
Created Jun 23, 2017
Untested C heap include
View heap.h
/* completely untested */
struct _heap_data
#if 0
{
struct _heap_cnt cnt;
const char *cwd;
..
}
#endif
@hilbix
hilbix / fakejournal.sh
Created Dec 14, 2016
Prevent systemd-logind from spamming dmesg
View fakejournal.sh
#!/bin/bash
#
# Public Domain
#
# Prevent systemd-logind to spam dmesg
#
# Run this from something which catches the output, like
# https://github.com/hilbix/ptybuffer/blob/master/script/autostart.sh
mkdir -pm755 /run/systemd/journal
You can’t perform that action at this time.