Skip to content

Instantly share code, notes, and snippets.

@sveitser
sveitser / nixos-luks-zfs-pool-import.org
Last active January 1, 2024 21:03
NixOS, Broken ZFS pool import on LUKS Recovery

NixOS, Broken ZFS pool import on LUKS Recovery

Below are the steps I used to recover the system, this is nixos running on ZFS on LUKS, where the LUKS volume is encrypted with a GPG key on a yubikey.

During a docker image build my system looked up and I had to reset my desktop by holding the power button. After that importing the zfs root pool hung on startup.

Some steps are from memory.

  • Create a bootable USB drive with gpg, etc.: example
[{"inputs": [{"internalType": "uint64", "name": "nRoots", "type": "uint64"}, {"internalType": "address", "name": "verifierAddr", "type": "address"}, {"internalType": "address", "name": "recordsMerkleTreeAddr", "type": "address"}], "stateMutability": "nonpayable", "type": "constructor"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "address", "name": "erc20Address", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "assetDefinitionCode", "type": "uint256"}], "name": "AssetSponsored", "type": "event"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "uint64", "name": "height", "type": "uint64"}, {"indexed": false, "internalType": "uint256[]", "name": "depositCommitments", "type": "uint256[]"}, {"indexed": false, "internalType": "bytes", "name": "minerAddr", "type": "bytes"}, {"indexed": false, "internalType": "bytes", "name": "noteTypes", "type": "bytes"}, {"indexed": false, "internalType": "bytes", "name": "transferNotes", "type": "bytes"}, {"inde
@sveitser
sveitser / install-nixos-luks-yubikey-zfs.sh
Last active January 1, 2024 21:03
Install nixos on luks, zfs and encrypt passphrase with yubikey
#!/usr/bin/env bash
#
# 1. boot from live cd, with programs.gpg enabled
# 2. gpg --import /your/public/key
# 3. edit GPG_ID, DISK below
# 4. run script
#
set -euo pipefail
GPG_ID="foo@bar.com"
DISK="/dev/disk/by-id/..."
@sveitser
sveitser / colab-ssh-ide.md
Last active August 27, 2021 09:49
SSH into colab, use vscode remote extension

Using Editor or IDE with colab

Note: worked in 2020, may no longer work exactly as described.

Idea: conveniently work with github repo and notebook on colab.

  1. Sign up for ngrok
  2. Install colab_ssh in colab notebook
  3. Start tunnel
  4. Provide ngrok token from https://dashboard.ngrok.com/auth/your-authtoken

Drop other columns with pandas pivot_table

Problem: would like to use pivot_table [1] to pivot and ignore irrelevant columns in the DataFrame.

Given the DataFrame

df = pd.DataFrame(
    {
#!/usr/bin/env bash
#
# Usage
#
# python2nix my_pypi_package > my_package.nix
#
# TODO
# - accept 'format' as arg
# - prepopulate dependencies?
set -euo pipefail
@sveitser
sveitser / click-config-file-example.py
Last active September 24, 2020 08:20
Python CLI arguments preference: CLI > Env Var > config file > default
import click
import click_config_file
import yaml
def myprovider(file_path, cmd_name):
with open(file_path) as config_file:
return yaml.safe_load(config_file)
@click.command()
@sveitser
sveitser / resize.py
Last active July 12, 2020 13:13
Resize and center crop a directory of images.
#!/usr/bin/env python
"""Resize and crop images to square.
Install dependencies: pip install click Pillow
Usage: python resize.py [OPTIONS] --directory /my/image/dir --convert_directory /my/output/dir
Options:
--directory TEXT Directory with original images. [required]
--convert_directory TEXT Where to save converted images. [required]
# /etc/udev/rules.d/20-bt-auto-enable-a2dp.rules
# hxss
SUBSYSTEM=="bluetooth", ACTION=="add", RUN+="/home/hxss/.config/scripts/xorg/bt-auto-enable-a2dp.sh"
@sveitser
sveitser / filter.py
Last active April 9, 2019 13:41
pydub de-esser / bandstop filter
# pip install pydub scipy
import pydub.scipy_effects
from pydub import AudioSegment
from pydub.playback import play
raw = AudioSegment.from_wav("blah.wav")
six = pydub.scipy_effects.low_pass_filter(raw, 6000, order=1)
play(raw)
play(six)