Skip to content

Instantly share code, notes, and snippets.

View sepastian's full-sized avatar
💭
\_ . |‾‾‾| o-`o

Sebastian Gassner sepastian

💭
\_ . |‾‾‾| o-`o
View GitHub Profile
@sepastian
sepastian / jupyter_remote_via_ssh_tunnel.txt
Last active October 26, 2022 09:25
Jupyter notebook on remote host via SSH tunnel
# SSH into remote host "R", startup Jupyter on port XXXX.
ssh user@remotehost.com
jupyer notebook --no-browser --port=XXXX
# On the localhost "L", accessing jupyter via the browser:
# create a reverse tunnel, forwarding YYYY (L) to XXXX (R).
ssh -N -L YYYY:localhost:XXXX user@remotehost.com
---- --------- ----
| | |
| | ` port on remote where Jupyer is listening
@sepastian
sepastian / img2pdf.sh
Created November 12, 2019 17:23
Recursively perform OCR on images, output searchable PDFs
#!/bin/bash
# Current directory contains a folder named 'img',
# which contains images nested in subfolders, e.g.
#
# img
# folder1
# img1.jpg
# img2.jpg
# folder2
@sepastian
sepastian / go_install_imports.sh
Last active November 8, 2019 14:24
Golang: install all packages imported in src
# Using go get can be confusing, here's what I learned.
#
# When go get ./... failed in a Dockerfile on Dockerhub, I listed and installed dependencies manually.
# Inspired by https://dave.cheney.net/2014/09/14/go-list-your-swiss-army-knife
#
# Recursively search for dependencies in $GOPATH/src; install dependencies using go get.
find "${GOPATH}/src" -type d \
-exec go list -f '{{ join .Imports "\n" }}' -e {} + \
| sort -u \
| xargs go get -v
@sepastian
sepastian / eduroam_uni_passau_cert_file.sh
Last active October 15, 2019 14:27
Connect to eduroam with personal certificate using wpa_supplicant or wicd
# First, install certificate with https://www.zim.uni-passau.de/dienstleistungen/netzwerk-und-server/netzwerkzugang/eduroam/fuer-uniangehoerige/linux/
# This will created ~/.cat_installer/user.p12 and ~/.cat_installer/ca.pem, which are the certificates required to connect.
# Create eduroam config for wpa_supplicant.
# ZIMID is your ZIM identifier, e.g. abcdef99
cat > /tmp/eduroam.conf <<EOF
network={
ssid="eduroam"
key_mgmt=WPA-EAP
pairwise=CCMP
@sepastian
sepastian / magic_sysrq_keys.txt
Created October 5, 2019 17:42
Magic SysRq keys
https://en.wikipedia.org/wiki/Magic_SysRq_key
# Prerequisites:
# - gdal2tiles.py (https://gdal.org/)
# - map.tit, a GeoTIFF file generated, for example, by QGIS
$ sudo apt install gdal-bin
$ gdal2tiles.py map.tif tiles
$ cd tiles && python -m http.server
# Go to http://localhost:8000/leaflet.html;
# place tiles/ on a web server and create a L.tileLayer using the tiles.
@sepastian
sepastian / mongo_index_hint.js
Created June 28, 2019 10:37
Mongo DB Index Hint
// Extract is a nested document, which exists in some documents only.
//
// Collection data defines a partial index on extract.created_at.
//
// Finding documents which have extract set takes long, if the collection is large.
//
// Use hint() to search the index extarct.created_at in determining, if extract exists.
db.data.getIndices()
/*
{
@sepastian
sepastian / pdftk_rotate_even_odd_pages_differently.sh
Created June 18, 2019 15:19
PDFTK: rotate even/odd pages differently
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# From https://unix.stackexchange.com/a/18631/56290
# Rotate even pages by 180 degrees, don't rotate odd pages.
pdftk A=infile.pdf shuffle Aoddnorth Aevensouth output outfile.pdf
@sepastian
sepastian / git_self_signed_cert_file.sh
Created April 18, 2019 10:17
git: use (self-signed) certificate from file
# Touch a file containing self-signed certificates to be used by git.
touch ~/.git-certs
chmod 600 ~/.git-certs
# Append the certificate to the file created aboe.
# https://stackoverflow.com/questions/7885785/using-openssl-to-get-the-certificate-from-a-server#comment26410932_7886248
echo \
| openssl s_client -connect my.server.com:443 2>&1 \
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \
>> ~/.git-certs
@sepastian
sepastian / jq.sh
Last active April 16, 2019 09:10
jq recipies
# Match .msg against case-insensitive regex;
# output .name and .time of matching documents.
jq 'select(.msg|test("aggregating variable";"i")) | .name,.time' input.json
# Output single line, as CSV.
jq -c 'select(.msg|test("aggregating variable";"i")) | .name,.time' input.json | tr -d '[]'
# Output value, default to 0, if field is missing.
jq '.value // 0' input.json