Skip to content

Instantly share code, notes, and snippets.

View karlvr's full-sized avatar

Karl von Randow karlvr

View GitHub Profile
karlvr /
Last active November 3, 2022 08:06
Download and update OpenSceneryX from
#!/bin/bash -eu
# Download and update OpenSceneryX from
if [ -z "$target" ]; then
echo "usage: $0 <target dir>" >&2
exit 1
if [ ! -d "$target" ]; then
karlvr /
Last active October 29, 2021 05:03
Delete tags from a git repository that reference commits that aren't part of the named branch.
#!/bin/bash -eu
# Delete tags from a git repository that reference commits that aren't part of the named branch
# This is useful if you've split a branch out of a repository and want to remove all of the commits
# that referenced activity in other branches.
usage() {
echo "usage: $0 [-d] [-p <remote>] <branch>" >&1
echo " -d dry run" >&1
karlvr / main.css
Created September 2, 2021 02:43
Webpack asset naming ENAMETOOLONG bug
body {
karlvr / Dynamic Ansible
Last active September 20, 2023 13:25
Ansible playbook example of running roles dynamically by including a list of role names in a host's vars

I have a heterogenous set of hosts and a mix of different roles that I want to apply to each host. Using groups would mean creating a group for nearly every role, which felt like overkill.

This combination of a playbook and two task scripts runs the roles specified in the host's required_roles variable, in order. It supports a tag named after the role, to run the specific role, and a tag role-partial to activate the role but to require other tags to activate specific tasks in the role (helpful when debugging roles).

karlvr / ob-search.js
Created March 23, 2021 19:42
Search a JavaScript object for a string
function search(ob, needle, path = [], seen = new Map()) {
if (seen.has(ob)) {
seen.set(ob, true)
for (const key of Object.keys(ob)) {
if (typeof ob[key] === 'string') {
if (ob[key].indexOf(needle) !== -1) {
const pathDesc = [...path, key].map(pathKey => Number(pathKey) == pathKey ? `[${pathKey}]` : `.${pathKey}`).join('').substring(1)
karlvr /
Created November 12, 2020 00:06
A bash script to search and replace git remotes in multiple git repositories
#!/bin/bash -eu
# Update the git remotes on git working copies contained in the given parent folder.
# usage: <path containing git repo(s)> <remote search> <remote replace>
# e.g. ~/git
while getopts ":n" opt; do

Migrate from hosted GitLab to GitHub

In order to migrate from hosted GitLab to GitHub, I decided to use command-line git to mirror each repository from within the GitLab storage on our server.

The script uses the GitHub API to create a new private repository, and then uses the git command-line tool to mirror the repository.

The script keeps track of which repositories have been migrated by creating hidden .migrated-github-<repository> files. If you run the script again, these repositories will be skipped. This means you can re-run the script to recover from errors, such as a repository containing a file larger than 100MB (see for a solution to that).

If you choose to remove those files, you can still run the script multiple times as it mirrors the repository to GitHub. This approach could be used to pick up any changes made in GitLab before the final changeover to GitHub. But see the next paragraph...

karlvr /
Last active October 25, 2023 12:20
A small bash script to migrate Maven packages from Sonatype Nexus to GitHub Packages

Migrate Maven packages from Sonatype Nexus to GitHub Packages

This gist describes the process we've used to migrate our Maven package repository from Sonatype Nexus to GitHub Packages. The same process could be used for migrating any Maven package repo that is in the standard layout.

We created a special repository on GitHub to hold all of our Maven packages. You might decide to migrate packages to different repositories, in which case invoke the script multiple times.

The script uses find to look for all of the folders containing poms and upload them. You specify the folder

karlvr / mopidy-alsamixer-patch.diff
Last active August 11, 2018 22:04
mopidy-alsamixer 1.0.3 patch for logarithmic volume
diff --git a/mopidy_alsamixer/ b/mopidy_alsamixer/
index 8f4312a..8916efa 100644
--- a/mopidy_alsamixer/
+++ b/mopidy_alsamixer/
@@ -22,6 +22,9 @@ class Extension(ext.Extension):
schema = super(Extension, self).get_config_schema()
schema['card'] = config.Integer(minimum=0)
schema['control'] = config.String()
+ schema['min_volume'] = config.Integer(minimum=0, maximum=100)
+ schema['max_volume'] = config.Integer(minimum=0, maximum=100)
karlvr / immutable-typescript-attempt.ts
Last active June 27, 2018 04:41
Immutable-js Typescript 2.8 attempt
import { Map, fromJS } from 'immutable'
function toImmutable<T>(array: T[]): ImmutableList<T>
function toImmutable<T extends object>(obj: T): ImmutableObject<T>
function toImmutable<T>(value: T): ImmutableObject<T> | ImmutableList<T> {
return fromJS(value)
type Diff<T, U> = T extends U ? never : T