Skip to content

Instantly share code, notes, and snippets.

View caugner's full-sized avatar

Claas Augner caugner

View GitHub Profile
@caugner
caugner / latex-bracket-depth.rb
Created February 22, 2017 22:41
Visualise bracket depth of a LaTeX document.
# Usage:
# $ cat file.tex | ruby latex-bracket-depth.rb
# $ echo "\textbf{ \textit{foobar} }" | ruby latex-bracket-depth.rb
# \textbf{1\111111{222222}1}
content = STDIN.read
len = content.size
level = 0
@caugner
caugner / git-cac.sh
Created February 9, 2017 11:22
A git commit alias to commit at time of last change.
#!/bin/bash
# cac = commit-at-changetime
alias git-cac=git commit --date="$(git ls-files --modified | xargs stat | grep "Modify: " | sort | tail -1 | awk '{gsub("Modify: ", "", $0); print $0}')"
@caugner
caugner / backup-ftp.sh
Created November 20, 2016 20:54
Secured parallel mirroring using lftp.
#!/bin/bash
if (( $# != 3 )); then
echo "Usage: $0 ftp.example.com ftp-user ftp-password"
exit 1
fi
SERVER=$1
USER=$2
PASS=$3
@caugner
caugner / nightly.desktop
Created July 31, 2016 00:06
A simple application menu entry for Mozilla Firefox Nightly.
[Desktop Entry]
Version=1.0
Name=Nightly
Exec=/opt/nightly/firefox %u
Icon=/opt/nightly/browser/icons/mozicon128.png
Terminal=false
Type=Application
MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=true
Categories=Network;WebBrowser;
@caugner
caugner / nightly-updater
Last active February 7, 2017 08:19
A simple updater for Mozilla Firefox Nightly in Linux multi-user environments.
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# A simple updater for Mozilla Firefox Nightly in Linux multi-user environments.
#
# Choose your OS, architecture and destination here:
NIGHTLY_OS='linux'
@caugner
caugner / postsuper-delete-recipient.sh
Created May 20, 2015 11:58
Remove messages from mail queue by recipient
# Adapted from `man postsuper` (in earlier tail versions, one could write the shortcut `tail +2` to skip the first line)
mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" }
# $7=sender, $8=recipient1, $9=recipient2
{ if ($8 == "[email protected]" && $9 == "")
print $1 }
' | tr -d '*!' | postsuper -d -
@caugner
caugner / pdfnup-2x4.sh
Created February 16, 2015 17:22
pdfnup-2x4
# Take slides pdf and convert them to a nice 2x4 overview.
#
# Usage: pdfnup-2x4 FILE [PAGES]
# pdfnup-2x4 slides.pdf | all pages
# pdfnup-2x4 slides.pdf '1-8' | only pages 1 to 8
#
# Configuration:
# --nup 2x4 | 2x4 input pages per output page (i.e. 2 columns with 4 pages each)
# --column true | top to bottom, left to right
# --paper a4paper | force A4
@caugner
caugner / .htaccess
Created November 20, 2014 21:00
Force HTTPS in Apache HTTPD
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
@caugner
caugner / simple-lexer.rb
Created November 11, 2014 10:18
Simple Lexer for arithmetic expressions
DIGIT = /[0-9]/
LETTER = /[a-z]/i
class Lexer
def self.lex(input)
output = []
it = CharIterator.new(input)
peek = it.next
@caugner
caugner / dump-and-load.py
Created November 11, 2014 10:15
Dump/load to/from JSON and Pickle
import json, pickle
def dump_data(data, path):
"""
Stores an object in a json or pickle file.
"""
if path.endswith('.json'):
t = 'json'
elif path.endswith('.pickle'):