Skip to content

Instantly share code, notes, and snippets.

@mayjs
mayjs / Numbers
Created November 17, 2014 22:57
Useful regular expressions
\d+ Checks for positive (unsigned) integers
-?\d+ Checks for positive and negative (signed and unsigned) integers
-\d+ Checks for negative (signed) integers
-?\d*(\.\d+)? Checks for positive and negative decimals.
-?\d*(\.\d{n})? Checks for positive and negative decimals with precision n.
-?\d*(\.\d{n,m})? Checks for positive and negative decimals with a precision between n and m
-?\d*(\.\d{n,})? Checks for positive and negative decimals with a precision greater then or equal to n
@mayjs
mayjs / System Properties
Created November 23, 2014 17:24
Java stuff
List all Properties and values in the console:
System.getProperties().list(System.out);
@mayjs
mayjs / preprocessor_fun.h
Created December 15, 2015 11:27 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
// ==UserScript==
// @name HideFBMainPage
// @namespace thekemiren@googlemail.com
// @include https://www.facebook.com/?*
// @include https://www.facebook.com/*
// @version 1
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle("#contentCol.newsFeedComposer #contentArea{opacity:0.0000001 !important;}");
@mayjs
mayjs / watchfile.sh
Created May 1, 2016 17:52 — forked from swarminglogic/watchfile.sh
watchfile - monitor file(s) and execute a command when files are changed
#!/bin/bash
version=1.0.1
versionDate="2014-02-14"
function showHelp() {
echo "watchfile - monitor file(s)/command and perform action when changed
Possible ways of usage
----------------------------------------
@mayjs
mayjs / extract_labels.py
Last active November 23, 2016 12:13
Extract LaTeX labels from .aux files generated by pdflatex
import argparse
import sys
import re
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Extract LaTeX labels")
parser.add_argument("file", metavar="FILE", type=argparse.FileType("r"))
parser.add_argument("-o", "--output", metavar="OUTPUT_FILE", default=sys.stdout, type=argparse.FileType("w"))
args = parser.parse_args()
@mayjs
mayjs / convert.py
Created January 3, 2017 18:55
Generate ASCII art from bitmaps in python
from PIL import Image
"""Credit: https://www.hackerearth.com/notes/beautiful-python-a-simple-ascii-art-generator-from-images/
One change: the scaled images width is doubled to create better ASCII art.
"""
ASCII_CHARS = [ '#', '?', '%', '.', 'S', '+', '.', '*', ':', ',', '@']
def scale_image(image, new_width):
"""Resizes an image preserving the aspect ratio.
@mayjs
mayjs / Readme.md
Created July 12, 2017 10:50
Wekan Systemd unit file

Place wekan.service in /etc/systemd/system, then use sudo systemctl start wekan to start the service.

#!/bin/bash
bottoken=<INSERT TOKEN>
chatid=<INSERT CHAT>
matrikel=<INSERT MATRIKEL>
# USE curl https://api.telegram.org/bot$bottoken/getUpdates to get the chatID!
telegrambase=https://api.telegram.org/bot$bottoken/sendMessage?chat_id=$chatid
if [[ $(curl -vs -F "matrikel=$matrikel" http://dekanat.cs.uni-dortmund.de/web/de/cgi-bin/zqueryBA.cgi 2>&1 | grep Zeugnis_Nicht_Vorhanden) ]]; then
@mayjs
mayjs / convert_xoj.sh
Created December 21, 2017 18:08
Recursively convert all recently changed *.xoj files in a directory to pdf (requires a patched version of xournal)
#!/bin/bash
# This script converts all xournal xoj files in subdirectories of the current working directories to pdf files
# It also checks if the file was recently changed.
# To do this, it compares modification timestamps of these files with the modification timestamp of the script files itself.
# The script will also update its own modification timestamp afterwards.
SCRIPT="$(realpath "$0")"
# Converts a single xoj file to pdf.
function convertXoj {