Skip to content

Instantly share code, notes, and snippets.

View ernstki's full-sized avatar

Kevin Ernst ernstki

  • Earth, Sol
View GitHub Profile
@ernstki
ernstki / getsnpcoords
Last active April 18, 2022 19:24
Fetch SNP coordinates from the UCSC MySQL server
#!/usr/bin/env bash
#
# Script to query UCSC MySQL server for SNP coordinates (but could easily be
# repurposed to query any arbitrary database/table)
#
# Author: Kevin Ernst
# Date: 2 March 2019; updated 30 August 2021
# Source: https://gist.github.com/ernstki/91b427d6714cdd4dd6560e5b4fb961f4
# License: MIT
#
@ernstki
ernstki / pywhich.py
Last active February 19, 2022 02:14
pywhich - tell me where a Python library came from
#!/usr/bin/env python
"""
pywhich - tell me where a Python package came from
Original author: Adam Anderson
Source: https://stackoverflow.com/a/42365058
License: CC-BY-SA-4.0
"""
from __future__ import print_function
@ernstki
ernstki / perlrun.md
Last active July 27, 2023 22:07
perlrun whirwind tour

[perlrun][1] whirlwind tour

Here are some [shebang (#!/path/to/interpreter) fun facts][2].

And why shebang? In music, '#' means sharp. So just shorten #! to sharp-bang. Or it might be derived from "shell bang". All this probably under the influence of the american slang idiom "the whole shebang" (everything, the works, everything involved in what is under consideration). See also the wiktionary, jargon dictionary or Merriam-Websters. Sometimes it's also called hash-bang, pound-bang, sha-bang/shabang, hash-exclam, or hash-pling (british, isn't it?).

According to Dennis M. Ritchie (email answer to Alex North-Keys) it seems it had no name originally.

And Doug McIllroy mentioned (TUHS mailing list), that the slang for # at Bell Labs most probably was "sharp" at the time.

@ernstki
ernstki / pphrases
Last active February 15, 2022 02:57
Bash script to generate a mnemonic passphrase à la https://xkcd.com/936
#!/usr/bin/env bash
##
## generate mnemonic passphrases beginning with the given letters
##
## Author: Kevin Ernst
## Date: 27 May 2021
## License: MIT
## Source: https://gist.github.com/ernstki/589bfb4adfb3869834c97bd106d58b7e
##
## Usage: pphrases a b c [...]
@ernstki
ernstki / scale.sh
Last active October 28, 2022 02:19
Detect the last screenshot on the desktop according to a pattern; scale with ImageMagick
#!/usr/bin/env bash
##
## scale the last screenshot on the desktop with ImageMagick
##
## Author: Kevin Ernst (ernstki -at- mail.uc.edu)
## Date: 25 October 2020
## Source: https://gist.github.com/ernstki/8776b3325f0a7abcc0d6080b2160a15c
## License: MIT (https://choosealicense.com/licenses/mit)
##
## Installation:
@ernstki
ernstki / dsum
Last active September 25, 2020 19:49
Aggregate-sum one column of a delimited data file based on depth in filesystem hierarchy; for use with https://github.com/erichs/composure
#!/usr/bin/bash
# shellcheck disable=SC1117
dsum ()
{
author 'Kevin Ernst'
about 'sum up column COL over DEPTH levels of hierarchy'
param '-d|--depth DEPTH - summarize this many levels of hierarchy (default: 5)'
param '-c|--column COL - add up this column (default: 2)'
param '-h|--humanize - print byte sizes in "human" figures (K, M, G, etc.)'
param '-F|--separator - field separator (default: tab)'
@ernstki
ernstki / flask-upload-download.py
Last active May 28, 2021 00:36
Minimum-viable Flask app that processes uploaded file input (and offers the result for download)
##
## Take a file uploaded by the user, process it, and offer the result for
## download
##
## For a more complete example (with better input checking), see:
## https://flask.palletsprojects.com/en/1.1.x/patterns/fileuploads/
##
## Run like this:
## $ mkdir uploads
## $ FLASK_APP=flask-upload-download.py flask run
@ernstki
ernstki / ini2assoc
Last active July 27, 2023 22:45
parse a Windows-style .ini file into a Bash associative array declaration
#!/usr/bin/sed -nf
##
## parse a Windows-style .ini file into key-value pairs that can be 'eval'd
## into a Bash associative array declaration
##
## Usage:
## $ eval "declare -A cfg=( $(ini2assoc config.ini) )"
## $ echo "section.keyname = ${cfg[section.keyname]}"
##
## Input:
@ernstki
ernstki / pdfcrunch
Last active June 14, 2022 16:42
Reduce file size of PDF documents with embedded images
#!/bin/bash
##
## Reduce a PDFs byte size by using either grayscale images and/or
## the '/ebook' output target of 'gs' (Ghostscript)
##
## Requires: Ghostscript probably 7.something or higher
##
## Author: Kevin Ernst
## Date: ages ago
##
@ernstki
ernstki / !PRETTY_PRINT_KEEPASS_XML.md
Last active November 23, 2024 18:19
Pretty-printing stylesheet for KeePass XML exports

Pretty-printing KeePass XML export files

First, create an XML export using [KeePass for Windows][kp]—not KeePassX, the export format is completely different.

Then add a line like: