Skip to content

Instantly share code, notes, and snippets.

@bsidhom
bsidhom / counting_unique_coupons.md
Last active February 12, 2023 03:34
Compute the distribution of unique (equi-probable) coupons given a fixed number of draws

Suppose that you have a pool of n different types of coupons (one of each) and want to sample k coupons with replacement. What is the distribution of the random variable X, which counts the number of distinct coupons observed with each k-sized sample? I was unable to come up with a closed-form solution on my own, instead resorting to simulation and brute force. This captures a solution I was able to find by searching online and putting the pieces together. I've written the equations below in approximate Wolfram language syntax, since math typesetting is not available.

Related problems

@bsidhom
bsidhom / fftimestamp.sh
Created February 21, 2023 07:01
Set the creation timestamp of an MP4 file using `ffmpeg`
#!/usr/bin/env bash
set -euo pipefail
function main() {
local input="$1"
local output="$2"
local timestamp="$3"
if [[ "$input" == "$output" ]] ; then
@bsidhom
bsidhom / fix-video-timestamps.py
Created March 14, 2023 04:21
Update video timestamps to match timestamp data in associated JSON files if they don't already match
#!/usr/bin/env python3
# Update video timestamps to match timestamp metadata in associated JSON files.
import asyncio
import datetime
import json
import os
import os.path
import subprocess
@bsidhom
bsidhom / ff_show_timestamp.sh
Created March 14, 2023 04:22
Print video creation time of MP4 files
#!/usr/bin/env bash
set -euo pipefail
readonly TIME_ZONE="${TIME_ZONE:-America/Los_Angeles}"
function main() {
local file="$1"
local timestamp
timestamp="$(extract_timestamp "$file")"
@bsidhom
bsidhom / client.py
Created April 23, 2023 20:05
Benchmark a single-threaded aiohttp server serving simple responses
#!/usr/bin/env python3
import argparse
import asyncio
import concurrent.futures
import functools
import time
import typing
import aiohttp
@bsidhom
bsidhom / monitor-parent.py
Created April 27, 2023 02:20
Execute/fork a child process and have the child self-monitor. When the parent dies, the child kills itself.
#!/usr/bin/env python3
import argparse
import asyncio
import os
import sys
async def main():
parser = argparse.ArgumentParser("Createa a child process")
@bsidhom
bsidhom / shiller_regression.ipynb
Last active May 25, 2023 05:49
Simulate long-term stock returns using MLP regression (to capture nonlinear dependencies) and assuming a conditional generalized t distribution on monthly returns
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bsidhom
bsidhom / shiller_loss_dist_modeling.ipynb
Last active May 28, 2023 05:13
Notebook showing how I arrived at a t-distribution for regression residuals (of log-returns) with the Shiller dataset.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bsidhom
bsidhom / vilepechora.py
Last active June 12, 2023 03:23
Anagram finder inspired by the Ink Black Heart Novel (Cormoran Strike)
#!/usr/bin/env python3
# Exact anagram finder. We start with a target name ("vilepechora") and consider
# all two-name exact anagrams of this target. Specifically, we do not consider
# anagrams of subsets of the original character set. We consider first and last
# names as different types to narrow the search space (there are 1712 matches if
# you consider first and last names to be interchangeable). There are "only" 582
# matches by considering first and last names separately (based on which dataset
# they're found in).
@bsidhom
bsidhom / overdoses.csv
Last active June 24, 2023 22:15
Dispelling a misunderstanding/pessimistic view of the applicability of population-level rates given potentially-high variance (sampling error)
county od_deaths population
okanogan 16 42634
yakima 96 256035
grays_harbor 43 76841
clallam 38 78209
mason 30 67615
king_county 649 2.252e6