Skip to content

Instantly share code, notes, and snippets.

View rahimnathwani's full-sized avatar

Rahim Nathwani rahimnathwani

View GitHub Profile
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
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "python-dotenv",
# "openai",
# ]
# ///
import os
@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",
# ]
# ///
@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 / 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 / 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",
# 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 / 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
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):
# wget https://github.com/xtaci/kcptun/releases/download/v20170525/kcptun-linux-amd64-20170525.tar.gz
# tar xvf kcptun-linux-amd64-20170525.tar.gz
mv server_linux_amd64 /usr/local/bin/kcptun_server
mv /usr/local/bin/server_linux_amd64 /usr/local/bin/kcptun_server
sudo mkdir -p /etc/kcptun
sudo bash -c "cat <<EOT > /etc/kcptun/server_conf.json
{
\"listen\": \":21\",
\"target\": \"127.0.0.1:20001\",