Skip to content

Instantly share code, notes, and snippets.

View karlvr's full-sized avatar

Karl von Randow karlvr

View GitHub Profile
@karlvr
karlvr / opensceneryx.sh
Last active November 3, 2022 08:06
Download and update OpenSceneryX from https://www.opensceneryx.com
#!/bin/bash -eu
# Download and update OpenSceneryX from https://www.opensceneryx.com
target="${1:-}"
if [ -z "$target" ]; then
echo "usage: $0 <target dir>" >&2
exit 1
fi
if [ ! -d "$target" ]; then
@karlvr
karlvr / git-delete-tags-not-part-of-branch.sh
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
karlvr / main.css
Created September 2, 2021 02:43
Webpack asset naming ENAMETOOLONG bug
body {
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNyIgdmlld0JveD0iMCAwIDE2IDE3Ij4KICA8cGF0aCBmaWxsPSIjRkZGRkZGIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNiw4IEwxNiw0LjAwNjg0NTQ3IEMxNiwzLjQ0OTk0ODc2IDE1LjU1MTg5NDUsMyAxNC45OTkxMjgzLDMgTDEzLDMgTDEzLDUuMDAwMTkyNTEgQzEzLDUuNTUyMzcwOTQgMTIuNTU2MTM1Miw2IDEyLDYgQzExLjQ0NzcxNTMsNiAxMSw1LjU1NjI4MzM1IDExLDUuMDAwMTkyNTEgTDExLDMgTDUsMyBMNSw1LjAwMDE5MjUxIEM1LDUuNTUyMzcwOTQgNC41NTYxMzUxOCw2IDQsNiBDMy40NDc3MTUyNSw2IDMsNS41NTYyODMzNSAzLDUuMDAwMTkyNTEgTDMsMyBMMS4wMDA4NzE2NiwzIEMwLjQ0NDYzMDg2MSwzIDAsMy40NTA3ODAwNyAwLDQuMDA2ODQ1NDcgTDAsOCBMMTYsOCBaIE0xNiw5IEwxNiwxNS45OTMxNTQ1IEMxNiwxNi41NDkyMTk5IDE1LjU1NTM2OTEsMTcgMTQuOTk5MTI4MywxNyBMMS4wMDA4NzE2NiwxNyBDMC40NDgxMDU1MDUsMTcgMCwxNi41NTAwNTEyIDAsMTUuOTkzMTU0NSBMMCw5IEwxNiw5IFogTTQsMiBDMy40NDc3MTUyNSwyIDMsMS41NTIyODQ3NSAzLDEgQzMsMC40NDc3MTUyNSAzLjQ0NzcxNTI1LDAgNCwwIEM0LjU1MjI4NDc1LDAgNSwwLjQ0NzcxNTI1IDUsMSBDNSwxLjU1MjI4NDc1IDQuNTUyMjg0NzUsMiA0LDIgWiBNMTI
@karlvr
karlvr / Dynamic Ansible Roles.md
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
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)) {
return
}
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
karlvr / bulk-update-git-remotes.sh
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: bulk-update-git-remotes.sh <path containing git repo(s)> <remote search> <remote replace>
#
# e.g. bulk-update-git-remotes.sh ~/git github.com/foo gitlab.com/bar
dryrun=0
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 https://rtyley.github.io/bfg-repo-cleaner/ 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
karlvr / migrate-nexus-to-github-packages.md
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
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/__init__.py b/mopidy_alsamixer/__init__.py
index 8f4312a..8916efa 100644
--- a/mopidy_alsamixer/__init__.py
+++ b/mopidy_alsamixer/__init__.py
@@ -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
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