Skip to content

Instantly share code, notes, and snippets.

View davidfoerster's full-sized avatar

David Foerster davidfoerster

  • Berlin, Germany
View GitHub Profile
@davidfoerster
davidfoerster / keytransformdict.py
Last active June 16, 2021 12:07
A Python dictionary class that transforms its keys for https://stackoverflow.com/a/68002134/2461638
import abc
import collections.abc
class KeyTransformDictionaryBase(dict, abc.ABC):
__slots__ = ()
@abc.abstractmethod
def __key_transform__(self, key):
@davidfoerster
davidfoerster / fetch_benchmarks.py
Created April 17, 2019 10:07
Fetch author citation benchmarks from Google Scholar
#!/usr/bin/python3 -OO
import sys
import operator
import scholarly
import urllib.parse
DEFAULT_ATTRIBUTES = (
'citedby', 'citedby5y',
'hindex', 'hindex5y',
'i10index', 'i10index5y'
#!/usr/bin/python3
import sys
import locale
import functools
from datetime import datetime
timefmt = '%b %d %H:%M:%S'
def parse_arg_time(s):
@davidfoerster
davidfoerster / test-path-tilde-expansion.c
Created July 24, 2018 12:21
Test expansion inside the value of the "PATH" environment variable by glibc
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
if (argc <= 0)
#!/usr/bin/python3
import sys
with open(sys.argv[1]) as dict_file:
dictionary = dict(line.rstrip('\n').split(None, 1) for line in dict_file)
with sys.stdin:
for line in sys.stdin:
line = line.rstrip('\n')
print(dictionary.get(line, line))
@davidfoerster
davidfoerster / screenshot-and-postprocess.sh
Last active April 21, 2018 22:19
Screenshot & Post-process
#!/bin/bash
set -eu -o noclobber
outfile_format='Screenshot %(%F %T)T'
imgext=png
screenshot='gnome-screenshot -f'
postprocessor=gimp
# Discover user picture directory
user_dirs="${XDG_CONFIG_HOME:-"$HOME/.config"}/user-dirs.dirs"
[ ! -e "$user_dirs" ] || source "$user_dirs"
@davidfoerster
davidfoerster / decrypt-pdf2ps.sh
Last active January 1, 2018 12:08
Decrypt PDF to PS
#!/bin/sh
INPUT=doc.pdf
OUTPUT=doc.ps
PASSWORD=foobar
gs -sDEVICE=pswrite -dSAFER -dBATCH -dNOPAUSE \
-dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false \
-dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false \
-dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode -dPassThroughJPEGImages=true \
-sPDFPassword="$PASSWORD" -sOutputFile="$OUTPUT" "$INPUT"
@davidfoerster
davidfoerster / find-test.sh
Last active November 15, 2017 13:36
find test
#!/bin/bash
set -eu
declare -r TMP="${1:-"${TMP:-/tmp}/find-test"}"
declare -ri file_count="${2:-1000000}" pad="${3:-255}"
declare -ar find=( find "$TMP" -mount -mindepth 1 )
# Preparation
mkdir -p -- "$TMP"
declare -i free_inodes="$(stat -f -c %d -- "$TMP")"
if [ "$free_inodes" -gt 0 ]; then
@davidfoerster
davidfoerster / crop-calc.py
Last active August 6, 2017 11:44
Crop random regions from a series of PDF documents (https://askubuntu.com/q/932193/175814)
import sys, random
if len(sys.argv) < 3:
sys.argv.append(input())
cropsize = float(sys.argv[1])
llx, lly, urx, ury = map(float, sys.argv[2].split(None, 3))
width = urx - llx
height = ury - lly
@davidfoerster
davidfoerster / Indexing_unix.sh.patch
Last active December 7, 2016 19:54
Family Search for Linux patch set for any JVM ≥ 1.6
--- Indexing_unix.sh 2016-10-04 10:38:56.804167702 +0200
+++ Indexing_unix.sh 2016-10-04 10:48:30.712992854 +0200
@@ -105,16 +105,16 @@
fi
fi
- if [ "$ver_major" = "" ]; then
- return;
- fi
- if [ "$ver_major" -gt "1" ]; then