Skip to content

Instantly share code, notes, and snippets.

View bsidhom's full-sized avatar

Ben Sidhom bsidhom

View GitHub Profile
@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 July 16, 2024 15:34
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
@bsidhom
bsidhom / extract-gemcraft-levels.js
Last active January 7, 2024 00:34
Extract Gemcraft: Chasing Shadows level metadata
// Extract level metadata from https://gemcraft.fandom.com/wiki/GemCraft_Chapter_2:_Chasing_Shadow_Fields
let extractLevels = () => {
const extractGemTypes = (cell) => {
const anchors = [...cell.querySelectorAll("a")];
return anchors.map((a) => a.title);
};
const extractText = (cell) => {
const s = cell.innerText.trim();
if (s.length == 0) {
@bsidhom
bsidhom / partitions.py
Last active May 20, 2024 23:04
Generate integer partitions and compositions
#!/usr/bin/env python3
def main():
print("partitions of 5:")
for p in partitions(5):
print(p)
print()
print("compositions of 5:")
for c in compositions(5):
@bsidhom
bsidhom / babynames.py
Created November 4, 2023 06:50
Merge SSA baby names dataset into a flat CSV
#!/usr/bin/env python3
# Baby names zip can be downloaded from https://www.ssa.gov/oact/babynames/names.zip
import argparse
import csv
import io
import re
import sys
import zipfile
@bsidhom
bsidhom / stolen_rubies.py
Created October 29, 2023 04:32
Stolen Rubies riddle
#!/usr/bin/env python3
# Solves the stolen rubies riddle: https://www.youtube.com/watch?v=2QJ2L2ip32w
import itertools
def main():
configs = unique_configs(gen_chests())
# For each "reasonable" strategy (possibly assigning a different number to