Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import decimal
import math
from decimal import Decimal
from fractions import Fraction
# In response to https://www.reddit.com/r/mildlyinteresting/comments/1hcb9ce/not_a_single_person_at_my_2000_student_high/
# and, in particular, some sloppy math in https://www.reddit.com/r/mildlyinteresting/comments/1hcb9ce/comment/m1mzfgh/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
@bsidhom
bsidhom / powerset.hs
Created November 5, 2024 05:49
Powerset construction for comparing runtime and memory performance characteristics between Rust, Haskell, and Python
module Main where
main :: IO ()
main = do
mapM_ print xs where
xs = powerset [(1 :: Integer)..24]
powerset :: [a] -> [[a]]
powerset = pset [] where
pset :: [a] -> [a] -> [[a]]
@bsidhom
bsidhom / fixfit.py
Last active October 10, 2024 03:48
Inspect and strip fields from FIT activity files
#!/usr/bin/env python3
# This tool operates on CSV files as created (and read) by the FitCSVTool.jar
# tool included in the FIT SDK. Input is always read from stdin, and output is
# written to stdout.
#
# Example usage:
# java -jar FitCSVTool.jar -b original_activity.fit original_activity.csv
# ./fixfit.py detect <original_activity.csv
# ./fixfit.py strip --field=accumulated_power --field=avg_power --field=functional_threshold_power --field=max_power --field=normalized_power --field=power --field=power_zone_high_boundary --field=threshold_power --field=time_in_power_zone <original_activity.csv >fixed_activity.csv
@bsidhom
bsidhom / update-beryl-tailscale.sh
Created September 27, 2024 04:56
Update GL.iNet Beryl AX (GL-MT3000) tailscale version
#!/usr/bin/env bash
set -euo pipefail
function main() {
if [[ $# -ne 1 ]] ; then
echo "usage: $0 <router ip>" >&2
exit 2
fi
local router_ip="$1"
@bsidhom
bsidhom / spin.go
Last active June 23, 2024 03:45
Burn CPU cycles by running AES encryption in a loop. Useful for draining battery quickly and doing power tests.
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"io"
"sync"
)
@bsidhom
bsidhom / rewrite-pdf-outline.py
Last active November 15, 2024 02:11
Write an outline specified in JSON format into a PDF document using qpdf
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
import sys
def main():
@bsidhom
bsidhom / vanguard-unrealized-lots.js
Created March 22, 2024 02:41
Extract unrealized lot data from Vanguard accounts
let main = async (account, units) => {
const scrapeAccount = (accountWidget) => {
const accountId = accountWidget.id;
const accountName = accountWidget
.querySelector("span.c11n-accordion__heading")
.innerText.trim();
const holdingsLinks = [
...accountWidget.querySelectorAll(
`app-holdings tr[app-holdings-row] div.holdings-link`
),
@bsidhom
bsidhom / vanguard-lots-to-beancount.js
Created March 21, 2024 22:12
Convert Vanguard realized lots to the legs of a Beancount transaction. Mostly useful for establishing opening balances given a large set of lots.
let main = () => {
const datePattern = new RegExp(`(\\d{2})/(\\d{2})/(\\d{4})`);
const extractDate = (s) => {
const m = s.match(datePattern);
const month = m[1];
const day = m[2];
const year = m[3];
return `${year}-${month}-${day}`;
};
const extractLot = (row) => {
@bsidhom
bsidhom / migrate-links.py
Last active February 26, 2024 14:49
Update symlinks under a directory root after moving from one location to another
@bsidhom
bsidhom / dump-links.py
Last active February 26, 2024 11:06
Dump FS symlinks as JSON