Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# A script to terminate an EC2 instance and remove its local SSH config entry.
# --- Configuration ---
SSH_CONFIG_FILE="$HOME/.ssh/config"
# Exit script if any command fails.
set -e
#!/bin/bash
# A script to launch an EC2 instance and add it to your SSH config.
# --- Configuration ---
# The name of your SSH key pair as it appears in AWS.
KEY_NAME="<KEY_NAME>"
# The path to your private SSH key file.
# This script assumes it is in ~/.ssh/ and has a .pem extension.
KEY_PATH="$HOME/.ssh/${KEY_NAME}.pem"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Decibel Threshold Demonstrator</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.7.77/Tone.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
def torch_determinism_pls(seed: int):
np.random.seed(seed) # if you're using numpy
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.use_deterministic_algorithms(True)
torch.utils.deterministic.fill_uninitialized_memory(True)
@lucapericlp
lucapericlp / async_tpe_bridge.py
Created February 4, 2025 16:18
In an async context, run a sync generator inside a threadpool to utilise the iterative nature of the generator without blocking the event loop
import asyncio
from concurrent.futures import ThreadPoolExecutor
from typing import AsyncIterator, Iterator
import queue
def compute_intensive_generator() -> Iterator[int]:
"""Example compute-bound generator that yields numbers."""
result = 0
for i in range(10):
# Simulate heavy computation
@lucapericlp
lucapericlp / arc.py
Created January 30, 2025 12:14 — forked from pior/arc.py
Adaptive replacement cache implementation in Python
"""
ARC implementation
Based on
http://code.activestate.com/recipes/576532-adaptive-replacement-cache-in-python/
Original Paper
https://www.usenix.org/legacy/events/fast03/tech/full_papers/megiddo/megiddo.pdf
Warning: patented by IBM
@lucapericlp
lucapericlp / finisher.js
Created January 18, 2025 18:25
An Obsidian plugin QuickAdd macro that updates the `finished` frontmatter property with today's date
module.exports = async (params) => {
const activeFile = this.app.workspace.getActiveFile();
if (!activeFile) return;
// Get the current frontmatter
const metadata = this.app.metadataCache.getFileCache(activeFile);
let frontmatter = metadata?.frontmatter || {};
// Update the finished date - store as a Date object
const now = new Date()
@lucapericlp
lucapericlp / readwise_youtube_toggle.js
Created December 26, 2024 10:00
usable as a browser bookmarklet
javascript:(function(){const prefix='_ytPlayerContainer_';let toggleCount=0;document.querySelectorAll('*').forEach(el=>{el.classList.forEach(cls=>{if(cls.startsWith(prefix)){el.style.display=el.style.display==='none'?%27%27:%27none%27;toggleCount++;return;}});});console.log(`Toggled display for ${toggleCount} element(s) with classes starting with "${prefix}".`);})();
"""
Using torchrun to create a process per GPU, we shard the data accordingly and each
torchrun process spins up a Dask LocalCluster to process the data in parallel to
maximise GPU utilisation.
"""
import os
from typing import Any, Iterator, Sequence, TypeVar
import socket
import orjson
@lucapericlp
lucapericlp / calculate_pesq.py
Created May 10, 2024 13:23
Quickly calculate the PESQ between two audio files.
# coding: utf-8
import click
import torchaudio as ta
import torch
import librosa
from pesq import pesq
MAX_WAV_VALUE = 32768.0
@click.command()