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 / 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
@sepastian
sepastian / update_docker_compose.sh
Created March 19, 2019 20:47
Update docker-compose to latest version
# https://stackoverflow.com/questions/49839028/how-to-upgrade-docker-compose-to-latest-version
sudo apt remove docker-compose
VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | jq .name -r)
DESTINATION=/usr/local/bin/docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION
sudo chmod +x $DESTINATION
@sepastian
sepastian / docker_mongo_import_data.sh
Last active February 27, 2019 13:57
Docker: mongoimport data
# Assuming there's a Docker container runninng Mongo, named `mongo1`,
# fire up another container `mongo2`,
# mounting a directory containing data to import,
# and execute `mongoimport` inside `mongo2`,
# to import data into `mongo1`.
# Start `mongo2`:
# link it to the running `mongo1`;
# open a bash session;
# mount pwd to /import;
@sepastian
sepastian / count_files_by_ext.sh
Created February 6, 2019 18:07
Count files in pwd by extension
ls | rev | cut -d '.' -f 1 | rev | sort | uniq -c
@sepastian
sepastian / git_credential_store.md
Created February 5, 2019 11:18
Git credential store