Skip to content

Instantly share code, notes, and snippets.

@MaartenBaert
MaartenBaert / .asoundrc-jack
Last active February 22, 2016 01:16
ALSA configuration for recording with JACK.
# Some of this may look redundant, but this was carefully written to
# work around various bugs in alsa-plugins, so don't mess with it :).
# override default
pcm.!default {
type plug
slave {
pcm "rjack"
}
}
@MaartenBaert
MaartenBaert / gast.sh
Last active February 22, 2016 01:23
A script that automates the process of configuring JACK, PulseAudio and ALSA for recording with SSR. It's used to record game audio, microphone audio and Skype/TeamSpeak audio simultaneously. This script only works when combined with the right config files. Also, this is completely unsupported, don't expect it to 'just work'.
#!/bin/bash
# IMPORTANT: READ THIS BEFORE RUNNING THIS SCRIPT!
# This script only works when the system is configured correctly. Do these things first:
#
# Step 1:
# - If you have an ~/.asoundrc file, rename it to ~/.asoundrc-default. If you don't have one, create an empty file named ~/.asoundrc-default.
# - Create ~/.asoundrc-jack with the contents found here: https://gist.github.com/MaartenBaert/3630a1863969ba344704
# The script will create a symlink from .asoundrc to .asoundrc-jack when started, and from .asoundrc to .asoundrc-default when stopped.
#
from pylab import *
def segment_intersects_rectangle(x1, y1, x2, y2, cx, cy, w, h):
return (fabs(x1 + x2 - 2.0 * cx) < fabs(x1 - x2) + w and
fabs(y1 + y2 - 2.0 * cy) < fabs(y1 - y2) + h and
2.0 * fabs((x1 - cx) * (y1 - y2) - (y1 - cy) * (x1 - x2)) < w * fabs(y1 - y2) + h * fabs(x1 - x2))
def test_intersect(plot_line, plot_rect):
for line in plot_line:
(x1, x2) = line.get_xdata()
@MaartenBaert
MaartenBaert / PKGBUILD
Created October 8, 2017 21:51
PKGBUILD for mingw-w64-harfbuzz 1.5.1
# Maintainer: Schala <schalaalexiazeal "at" gmail {dot} com>
# Contributor: calegria <calegria+al "at" gmail {dot} com>
pkgbase=mingw-w64-harfbuzz
pkgname=(mingw-w64-harfbuzz mingw-w64-harfbuzz-icu)
pkgver=1.5.1
pkgrel=1
pkgdesc="OpenType text shaping engine (mingw-w64)"
arch=(any)
url="http://www.freedesktop.org/wiki/Software/HarfBuzz"
@MaartenBaert
MaartenBaert / gist:e9c94f8c57cdb2913fe21102b9a6293d
Created October 9, 2017 18:32
QProgressDialog with separate worker thread. Note that there's a possible reentrancy problem since setValue calls QApplication::processEvents.
QProgressDialog dialog("Parameter sweep ...", "Cancel", 0, (int) sweep_values.size(), this);
dialog.setWindowTitle(MainWindow::WINDOW_CAPTION);
dialog.setWindowModality(Qt::WindowModal);
dialog.setMinimumDuration(0);
dialog.setValue(0);
std::atomic<bool> worker_canceled(false), worker_stopped(false);
std::exception_ptr worker_exception;
std::thread worker_thread([&]() {
try {
for(size_t i = 0; i < sweep_values.size(); ++i) {
@MaartenBaert
MaartenBaert / glinject.py
Created January 27, 2018 14:54
GLInject to Python (numpy)
import ctypes
import glob
import mmap
import operator
import os.path
import time
import numpy
import matplotlib.pyplot as plt

Manually fixing bit flips in BTRFS

Somehow my BTRFS file system became corrupted by what appears to be a single bit flip in a metadata field. Rather than copying all the data and reformatting the file system, which would have required another disk at least as large as the original, I decided to try to fix this manually, which appears to have worked. I've documented the procedure I've used here, in case I need it again or someone else runs into a similar issue and finds it useful.

The first thing you should do is run btrfs check. For me this produced the following output:

Opening filesystem to check...
Checking filesystem on /dev/nvme0n1p1
UUID: ec7afe1c-8478-450a-82fc-d17b32d8ca3d