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 / reborder
Last active August 31, 2024 11:58
Use ImageMagick to trim extra pixels from an image and replace with a uniform border (default 10 pixels); good for screenshots
#!/usr/bin/env bash
##
## Trim extra pixels from around an image, e.g., a screenshot, and replace
## with a border of uniform width, of a color sampled from the four image
## corners, using ImageMagick 6.x (or above?)
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## Date: 29 August 2024
## License: WTFPL or ISC at your option
## Homepage: https://gist.github.com/ernstki/74aba058622a9cea43bebc4028aba5cd
@ernstki
ernstki / bash-version-has-shopt.sh
Last active August 23, 2024 01:00
Determine if a given version of Bash has a specific 'shopt' option using all available 'bash' image tags on Docker Hub
#!/bin/bash
#
# old version that may not work anymore; see docker-image-test.sh instead
#
# source: http://www.googlinux.com/list-all-tags-of-docker-image/index.html
# maybe API documentation?
# shellcheck disable=SC2086
REGISTRY=https://registry.hub.docker.com/v2/repositories/library
@ernstki
ernstki / Makefile_with_built_in_help
Last active August 18, 2024 02:17
Auto-generated 'make help' from comments on Makefile targets
TITLE = A Makefile that makes its own 'make help' target
ME = $(lastword $(MAKEFILE_LIST))
HOMEPAGE = https://gist.github.com/ernstki/982edcfbf93c357bdb09878f7c724389/edit
help: # prints this help
@bash -c "$$AUTOGEN_HELP_BASH" < $(ME)
define AUTOGEN_HELP_BASH
declare -A targets; declare -a torder
targetre='^([A-Za-z]+):.* *# *(.*)'
@ernstki
ernstki / gitlapi
Last active August 17, 2024 23:37
Query GitLab v4 API endpoints with curl and jq; handles record pagination
#!/usr/bin/env bash
##
## Query a GitLab v4 API endpoint, with pagination
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## License: WTFPL
## Date: 22 May 2024
## Requires: jq (https://github.com/jqlang/jq)
## Homepage: https://gist.github.com/ernstki/3707675c8a4ddb06d128154947c49e29
##
@ernstki
ernstki / dot-bashrc-essentials.sh
Last active May 1, 2024 14:19
Bash login essentials: stuff I always add to my login scripts, but never had all in one place
# .bashrc essentials
# copy and paste any parts that you need into your own ~/.bashrc
# you may get a nicer one by default from your *nix distro; uncomment this
# only if you have an ugly default "bash-x.y$" prompt string
#PROMPT="[\u@\h:\w]$ "
# trim the display of '\w' to just the last three path elements
PROMPT_DIRTRIM=3
@ernstki
ernstki / fc-reject.pl
Last active April 30, 2024 10:19
Easily disable fonts that aren't in your language, for Debian and derivatives (and possibly other Linux distros)
#!/usr/bin/env perl
##
## Usage: fc-reject.pl > ~/.config/fontconfig/conf.d/88-reject.conf
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## License: MIT or CC-BY-SA-4.0, at your option
## Source: https://gist.github.com/ernstki/2ae279ad89888e4099c9852bf0ba5d11
##
use v5.12;
use warnings;
use autodie;
@ernstki
ernstki / README.md
Last active April 24, 2024 21:46
screenrc with a decent-looking caption / hardstatus line, including LSF job status

A classy .screenrc with LSF support

Screenshot of what you get

Here's a sensible .screenrc that does the following:

  • gives you a useful and hip-looking status line
  • tries really hard to enable 256 color support for programs that support it, like Vim
  • disables the visual bell and splash screen
  • remaps window #0 to be Ctrl+A, `, which feels more natural to me
@ernstki
ernstki / pkgutil-list-files
Created April 19, 2024 16:58
Wrapper script for macOS's `pkgutil` to list full pathnames of files in all packages, or packages matching a pattern
#!/bin/sh
pkgutil --packages \
| if [[ "$1" ]]; then grep -i "$1"; else cat; fi \
| perl -nE '
#line 5 "pkgutil-list-files"
chomp;
print STDERR "# scanning $_…\n";
$location = `pkgutil --pkg-info $_`;
$location =~ s/.*location: (.*?)\n.*/$1/s;
print STDERR "# location: $1\n";
@ernstki
ernstki / README.md
Last active April 8, 2024 12:12
List the ABI versions of all detected libc and libstdc++'s (GNU/Linux only)

Linker error messages related to libc and libstdc++

We run into the dreaded

/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found

error messages a lot around here. This article is an attempt to explain what's going on with that.

@ernstki
ernstki / jdtt
Last active January 17, 2024 01:34
jdtt - accept command line arguments for 'yum', 'apt', or 'port' and just do the thing based on the platform
#!/usr/bin/env bash
##
## Accept arguments from popular package management tools (except Homebrew)
## and just do the right thing, based on the platform.
##
## Created out of frustration at typing `yum` on Macs and `port` on Linux
## boxes, and `apt` on RHEL/CentOS boxes all too often.
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## Date: 16 Januar 2024