Skip to content

Instantly share code, notes, and snippets.

View davidfoerster's full-sized avatar

David Foerster davidfoerster

  • Berlin, Germany
View GitHub Profile
# This is the ssh client system-wide configuration file. See
# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.
# Configuration data is parsed as follows:
# 1. command line options
# 2. user-specific file
# 3. system-wide file
# Any configuration value is only changed the first time it is set.
Migrated to https://github.com/davidfoerster/apt-remove-duplicate-source-entries
@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