Skip to content

Instantly share code, notes, and snippets.

View hilbix's full-sized avatar
🐢
I may be slow to respond.

Valentin Hilbig hilbix

🐢
I may be slow to respond.
View GitHub Profile
@hilbix
hilbix / kswapd-check.sh
Created March 28, 2013 15:27
Bash/AWK script to detect 100% CPU on kswapd processes, caused by a known Linux kernel issue on RHEL 5.5 (and CentOS) kernel 2.6.18-194.el5. Returns 0 if no problem, and usually 2 when the problem hits. (Note: It will return 1 on first invocation. Better safe than sorry.)
#!/bin/bash
PIDFILE=/tmp/kswapd-check.pids
scanpids()
{
cat -s /proc/[1-9]*/stat 2>/dev/null |
awk 'BEGIN {
want["(kswapd0)"]=1;
want["(kswapd1)"]=1;
@hilbix
hilbix / CopySelectedMessagesHeadersToClipboard.outlook2003.vba
Last active December 17, 2015 10:49
Outlook 2003 Macro to copy selected Mails with full Mail headers into Clipboard Needs "Microsoft Forms 2.0 Object Library" (WIN/system32/FM20.dll) und "Microsoft CDO 1.21 Library" (SHARED/system/msmapi/1031/cdo.dll)
' Source https://gist.github.com/hilbix/5597981
Public Sub CopySelectedMessagesHeadersToClipboard()
Dim sel As Outlook.Selection
Dim msg As Outlook.MailItem
Dim n As Integer
Dim all As String
Dim errcnt As Integer
Dim omsg As Object
Dim mmsg As MAPI.Message
Dim spid As String, seid As String
@hilbix
hilbix / gist:5830049
Created June 21, 2013 09:28
X11 keyboard settings
Section "InputDevice"
Identifier "Keyboard"
Driver "kbd"
# Option "XkbModel" "pc105"
Option "XkbLayout" "us,de"
Option "XKbOptions" "grp:alt_shift_toggle"
EndSection
@hilbix
hilbix / nginx.conf
Last active April 24, 2021 05:51
Example for Cookie-based Access Token with NginX HttpSecureLinkModule http://wiki.nginx.org/HttpSecureLinkModule and PHP (in this case for Typo3). Note that Typo3 needs to set the cookie as shown in token.php
# Excerpt of nginx config file
#..
#
set $ts 0;
if ($cookie_TOKEN ~ ",(.*)$") {
set $ts $1;
}
secure_link $cookie_TOKEN; # See TYPO3_ACCESSTOKEN
set $sec CHANGE_THIS_SHARED_SECRET; # See TYPO3_ACCESSKEY
secure_link_md5 $sec$ts$sec;
@hilbix
hilbix / ca.config
Created July 11, 2013 15:26
Root CA certificate which can be imported into Firefox
# see http://www.identityblog.com/?p=645
dir = .
[ ca ]
default_ca = CA_default
[ CA_default ]
serial = $dir/serial
database = $dir/certindex.txt
@hilbix
hilbix / curl.php
Created July 11, 2013 15:49
Dangerous PHP curl test script - mainly to test SSL reachability (60 means trouble with the SSL cert)
<?
# Warning, do not keep this publicly reachable, it is dangerous.
header("Content-type: text/plain");
$ch = curl_init($_SERVER["QUERY_STRING"]);
curl_exec($ch);
echo "-- errno: ";
echo curl_errno($ch);
curl_close($ch);
@hilbix
hilbix / GIT branch relation aliases
Last active December 29, 2015 17:19
GIT "relate" ALIAS to quickly show how all branches relate to HEAD (or given branch). GIT "graph" ALIAS to show the graph between two commits (from HEAD to it origin, or given branch, by default). `graph` Improved to highlight starting point (which is not always obvious).
git config --global --replace-all alias.relate '!f(){ git for-each-ref --format="%(refname:short) %(upstream:short)" refs | while read -r l r; do printf "%24s %s\\n" "$(git rev-list --cherry-mark --dense --left-right --boundary --oneline "${r:-${1:-HEAD}}...$l" -- | sed "s/^\\(.\\).*/\\1/" | sort | uniq -c | tr -d " " | tr "\\n" " ")" "$l"; done; }; f'
git config --global --replace-all alias.graph '!f(){ case "$#:$1" in 0:) r="HEAD...HEAD@{u}";; 1:*...*) r="$1";; 1:*) r="HEAD...$1";; *) r="$1...$2";; esac; git rev-list --cherry-mark --dense --left-right --boundary --pretty --graph "$r" -- | less -XFp "$(git rev-parse "${r%...*}")"; }; f'
git config --global --replace-all alias.graph1 '!f(){ case "$#:$1" in 0:) r="HEAD...HEAD@{u}";; 1:*...*) r="$1";; 1:*) r="HEAD...$1";; *) r="$1...$2";; esac; git rev-list --cherry-mark --dense --left-right --boundary --oneline --graph "$r" -- | less -XFp "$(git rev-parse "${r%...*}")"; }; f'
# THIS IS PUBLIC DOMAIN.
# Thanks to the makers of GIT for the extremely impressiv
@hilbix
hilbix / exec style aliases
Last active March 10, 2019 01:21
`git exec` to exec command within GIT directory. `git top` to exec on submodule top level directory (somewhat).
git config --global alias.exec '!exec '
git config --global alias.top '!f() { GIT_TOP="${GIT_DIR%%/.git/modules/*}"; [ ".$GIT_TOP" != ".$GIT_DIR" ] && cd "$GIT_TOP"; exec "$@"; }; f'
# THIS IS PUBLIC DOMAIN.
#
# `git exec` executes something in the current GIT module's base directory. `git exec pwd` gives this base.
# Stolen from http://stackoverflow.com/questions/957928/is-there-a-way-to-get-the-git-root-directory-in-one-command/957978#comment9747528_957978
#
# `git top` is like `git exec`, but executes in the topmost GIT directory, even from within a GIT submodule.
@hilbix
hilbix / edit-launcher.sh
Created May 25, 2014 09:31
Wrapper around desktop-file-install to edit Ubuntu launchers (`.desktop` files aka shortcuts)
#!/bin/bash
LOC="$HOME/.local/share/applications"
OOPS()
{
echo "OOPS: $*" >&2
exit 1
}
@hilbix
hilbix / _relpath.inc
Last active February 27, 2024 22:50
Calculate relative path in BASH
: relpath A B
# Calculate relative path from A to B, returns true on success
# Example: ln -s "$(relpath "$A" "$B")" "$B"
relpath()
{
local X Y A
# We can create dangling softlinks
X="$(readlink -m -- "$1")" || return
Y="$(readlink -m -- "$2")" || return
X="${X%/}/"