Skip to content

Instantly share code, notes, and snippets.

View karlvr's full-sized avatar

Karl von Randow karlvr

View GitHub Profile
@karlvr
karlvr / apologies.text
Last active December 17, 2015 00:49 — forked from NZKoz/apologies.text
Dear [First Name],
We're really sorry but our systems were compromised and the attackers
managed to take a copy of your passwords.
The passwords were stored as:
[ ] Bcrypt hashes with a cost factor of X
[ ] PBKDF2 hashes with an iteration count of X
[ ] scrypt because I am Colin Percival
@karlvr
karlvr / jstack-grep
Last active December 20, 2015 13:18
A pattern matching tool for jstack output. Can search for a pattern in the stacktraces, then show details of just the matching threads, either showing all of the stacktrace or just lines matching the search pattern, or matching any other patterns.
#!/usr/bin/perl
#
# A pattern matching tool for jstack output. Can search for a pattern in the stacktraces,
# then show details of just the matching threads, either showing all of the stacktrace or
# just lines matching the search pattern, or matching any other patterns.
#
# For example, to see which threads are currently accessing the database and show the
# stacktrace lines containing your own classes:
# jstack-grep postgres <pid> -i com.xk72
#
diff -r bb795f69be65 src/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java
--- a/src/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java Sun May 29 14:03:11 2016 +1200
+++ b/src/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java Sun May 29 16:09:37 2016 +1200
@@ -71,6 +71,17 @@
initialize(1024, null);
}
+ private static void checkKeySize(int keysize)
+ throws InvalidParameterException {
+
@karlvr
karlvr / 00README.md
Last active April 2, 2017 20:53
init.d startup script for spotify-connect-web
apt-get install -y avahi-utils
@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
@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)

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 / 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
@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 / main.css
Created September 2, 2021 02:43
Webpack asset naming ENAMETOOLONG bug
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