Skip to content

Instantly share code, notes, and snippets.

Avatar

David Foerster davidfoerster

  • Berlin, Germany
View GitHub Profile
@davidfoerster
davidfoerster / fetch_benchmarks.py
Created Apr 17, 2019
Fetch author citation benchmarks from Google Scholar
View fetch_benchmarks.py
#!/usr/bin/python3 -OO
import sys
import operator
import scholarly
import urllib.parse
DEFAULT_ATTRIBUTES = (
'citedby', 'citedby5y',
'hindex', 'hindex5y',
'i10index', 'i10index5y'
View filter-timestamps.py
#!/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 Jul 24, 2018
Test expansion inside the value of the "PATH" environment variable by glibc
View test-path-tilde-expansion.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
if (argc <= 0)
View replace-dict.py
#!/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))
View screenshot-and-postprocess.sh
#!/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"
View decrypt-pdf2ps.sh
#!/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"
View find-test.sh
#!/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 Aug 6, 2017
Crop random regions from a series of PDF documents (https://askubuntu.com/q/932193/175814)
View crop-calc.py
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 Dec 7, 2016
Family Search for Linux patch set for any JVM ≥ 1.6
View Indexing_unix.sh.patch
--- 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
View rename-videos.py
#!/usr/bin/python3
import sys, os, os.path
for original_name in sys.argv[1:]:
original_name_noext, extension = os.path.splitext(original_name)
new_name = original_name_noext[:-11] + extension
print('{0!r} => {1!r}'.format(original_name, new_name))
if os.path.exists(new_name):
reply = None
You can’t perform that action at this time.