Skip to content

Instantly share code, notes, and snippets.

View caugner's full-sized avatar
💭
I may be slow to respond.

Claas Augner caugner

💭
I may be slow to respond.
  • Mozilla
  • Paris, France
  • 01:49 (UTC +02:00)
  • X @ClaasAug
View GitHub Profile
@caugner
caugner / getmx.sh
Created February 19, 2013 22:41
Get mail domain of a given domain
#!/bin/bash
if [ -n "$1" ]
then
host -t mx $1 | awk '{print $7}' | sed 's/.$//'
fi
@caugner
caugner / ruby-re-german.rb
Created July 22, 2013 14:37
Ruby regular expression for German texts
#!/bin/ruby
# uppercase characters
uchar = 'A-ZÄÖÜÁÀÉÈ'
# lowercase characters
lchar = 'a-zäöüßáàéè'
# all characters
char = uchar + lchar
# whitespace characters
@caugner
caugner / libreoffice41-install.sh
Last active August 29, 2015 14:08
Install LibreOffice 4.1 under Ubuntu 14.04
sudo add-apt-repository -y ppa:libreoffice/libreoffice-4-1
sudo apt-get install \
libreoffice=1:4.1.6-0ubuntu1~trusty1~ppa1 \
libreoffice-base=1:4.1.6-0ubuntu1~trusty1~ppa1 \
libreoffice-base-core=1:4.1.6-0ubuntu1~trusty1~ppa1 \
libreoffice-core=1:4.1.6-0ubuntu1~trusty1~ppa1 \
libreoffice-calc=1:4.1.6-0ubuntu1~trusty1~ppa1 \
libreoffice-draw=1:4.1.6-0ubuntu1~trusty1~ppa1 \
libreoffice-impress=1:4.1.6-0ubuntu1~trusty1~ppa1 \
@caugner
caugner / date_difference.js
Created October 31, 2014 14:26
Determine intuitive difference between two dates
function date_difference(from_date, to_date) {
if (to_date < from_date) {
return date_difference(to_date, from_date);
}
var DAY_IN_MS = 1000 * 60 * 60 * 24;
// count first day
from_date = new Date(from_date.getTime() - DAY_IN_MS);
@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'):
@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 / .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 / 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 / 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 == "someone@example.com" && $9 == "")
print $1 }
' | tr -d '*!' | postsuper -d -
@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'