Skip to content

Instantly share code, notes, and snippets.

View rahimnathwani's full-sized avatar

Rahim Nathwani rahimnathwani

View GitHub Profile
import random
donkey = 0
car = 10 # car is worth more than a donkey
prizes = [car, donkey, donkey] # there's always exactly one car
N = 1000000
def pick_a_door(prizes):
@rahimnathwani
rahimnathwani / setup.sh
Last active November 24, 2020 06:26 — forked from bradp/setup.sh
New Mac Setup Script
echo "Creating an SSH key for you..."
ssh-keygen -t rsa -b 2048
echo "Please add this public key to Github \n"
echo "https://github.com/account/ssh \n"
echo "and to virtual servers\n"
read -p "Press [Enter] key after this..."
echo "Installing xcode-stuff"
xcode-select --install
# From https://xiaoxing.us/2018/09/04/creating_swap_on_lightsail/
# fallocate is instant; no point wasting time writing zeroes
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
# Activate swap on boot
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
@rahimnathwani
rahimnathwani / label-images-csv.py
Created January 30, 2025 04:28
Label facial images using deepface
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12.2"
# dependencies = [
# "deepface",
# "pandas==2.2.3",
# "tqdm==4.67.1",
# "opencv-contrib-python==4.10.0.84",
# "tensorflow==2.18.0",
# "keras==3.7.0",
@rahimnathwani
rahimnathwani / process-pdf.sh
Created February 17, 2025 21:40
Convert an MRC PDF from Internet Archive into pure black and white
#!/bin/bash
# Check if a filename was provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <pdf-file>"
exit 1
fi
# Convert to absolute paths
input_pdf=$(realpath "$1")
@rahimnathwani
rahimnathwani / transcribe-mp3.sh
Created February 21, 2025 03:18
Transcribe mp3 file
#!/bin/bash
# Check if an input file was provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <input.mp3>"
exit 1
fi
input_file="$1"
@rahimnathwani
rahimnathwani / extract-slides.py
Created March 10, 2025 20:28
Extract slides (as images) from a video file of a live presentation
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.8"
# dependencies = [
# "opencv-python>=4.5.0",
# "numpy>=1.20.0",
# "pillow>=8.0.0",
# ]
# ///
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "python-dotenv",
# "openai",
# ]
# ///
import os
import numpy as np
from sklearn.decomposition import FactorAnalysis
from sklearn.preprocessing import StandardScaler
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# --- Parameters ---
# Spearman's early work involved small numbers of tests/variables and modest samples.
n_subjects = 200 # Number of simulated individuals
@rahimnathwani
rahimnathwani / parse_math_topics.py
Created October 14, 2025 01:15
Math Academy 'up next'
#!/usr/bin/env python3
"""
Parse SVG file to find unfamiliar topics that have no unfamiliar or just-started-learning prerequisites.
"""
import re
import xml.etree.ElementTree as ET
from collections import defaultdict
from typing import Dict, List, Set, Tuple