Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / defaultdict.ts
Last active April 30, 2022 22:35
Wannabe defaultdict for typescript. Not really tested.
class DefaultDict<T, Q> extends Map<T, Q> {
defaultFactory: () => Q
constructor(defaultFactory: () => Q) {
super()
this.defaultFactory = defaultFactory
}
get(name: T): Q {
if (this.has(name)) {
return super.get(name)!
} else {
@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
@sveitser
sveitser / nixos-install-encrypted-root.sh
Last active May 30, 2021 09:28
Installs nixos on encrypted root from live CD.
#!/usr/bin/env bash
#
# Installs nixos with full disk encrypted root partition.
#
# - Prompts for password initially, after that no interaction should
# be required.
# - At the end it will prompt for a root password, could not make
# echo-ing it into nixos-install work.
# - Reserves 550MB for boot partition, rest for the root volume.
# - After booting, log in as root user and set password for normal user.

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]