Skip to content

Instantly share code, notes, and snippets.

View zbentley's full-sized avatar
💭
🌮

Zac Bentley zbentley

💭
🌮
View GitHub Profile
@zbentley
zbentley / cold_peanut_sauce.md
Created July 18, 2023 16:32
Cold Peanut Sauce Recipe

Cold Peanut Sauce

While hot-cooked peanut sauce is better, more flavorful, and generally just unctuous to the max, sometimes you want: a) to not cook anything. b) to have a smoother, sweeter sauce for dipping e.g. salad rolls in.

This fits that bill.

Ingredients

@zbentley
zbentley / gist:e0112b5f1d9c0d1a78e6fae557252089
Created December 24, 2023 17:26
Python resource-based coarse memory growth observer
import contextlib
import resource
import typing
memory_profiler_data = dict()
@contextlib.contextmanager
def record_memory(name: str) -> typing.ContextManager:
initial_rusage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
assert name not in memory_profiler_data, f"{name}'s memory usage has already been recorded, can't record again"
@zbentley
zbentley / example.py
Created December 24, 2023 18:28
Static hash model lookup example
@st.cache_resource
def load_model(modelnum: int):
return keras.models.load_model(f"root/C{modelnum}free')
...
modelnum = int(re.findall(r'\d+', option)[0])
cNfree = pred(load_model(modelnum), list50) # model{n} for c{n}free
@zbentley
zbentley / async_memory_reuse.rs
Last active March 4, 2024 16:32
Async Rust memory reuse
use tokio::select;
use tokio::time::{sleep, Duration};
struct CanDrop {
a: Vec<i32>,
}
impl Drop for CanDrop {
fn drop(&mut self) {
println!("Dropping!")
@zbentley
zbentley / heterogenous_wait.rs
Created February 5, 2024 02:14
Rust Heterogenous Select
use tokio::io::AsyncReadExt;
use tokio::net::TcpStream;
use tokio::select;
use tokio::task::spawn_blocking;
use tokio::time::{sleep, Duration};
async fn main() {
let mut stream = TcpStream::connect("...").await?;
let thread_handle = spawn_blocking(|| {