Skip to content

Instantly share code, notes, and snippets.

View zbentley's full-sized avatar
💭
🌮

Zac Bentley zbentley

💭
🌮
View GitHub Profile
@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(|| {
@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 / 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 / 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 / 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 / mexican_pickled_onions.md
Created May 29, 2023 23:34
Mexican Pickled Onion Recipe

Mexican Quick-Pickled Red Onions

I keep a jar of these in the fridge at all times. Great on tacos, burritos, fried rice, burgers, stirfy, or side for steak.

Equipment

  • Knife and cutting board.
  • Zester or fine grater.
  • Mixing bowl.
  • 3 quarts worth of Mason jars or other airtight-sealing tupperware.
@zbentley
zbentley / workstation_cleanup.bash
Created March 3, 2023 17:07
ZB's MacOS Workstation Cleanup
#!/usr/bin/env bash
set -xuo pipefail
brew cleanup
brew cleanup --prune=all
rm -rf "$(brew --cache)"
pip cache purge
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
sudo rm -rf "/Users/$USER/Library/Caches/Sublime Text/Cache/__pycache__"
find ~ -type d -name "__pycache__" -exec rm -rv {} \;

Nduja mac and cheese recipe

Ingredients

Stirfry:

  • Oil (olive, neutral, schmaltz, whatever)
  • 1/2lb, plus or minus 1/2lb Andouije or kielbasa sausage, cubed up into 1cm pieces
  • korean chives: 3 cups diced. Substitute a shitload of scallions.
  • bacon: 1/2 pound diced
  • Couple slices smoked turkey (optional), diced
  • kimchi, 1 cup, diced
class Bkt < Formula
desc "Utility for caching the resilts of shell commands"
homepage "https://www.bkt.rs"
url "https://crates.io/api/v1/crates/bkt"
sha256 "e6acab9ae6a617fe471dceed9f69064e1f0cb3a8eb93d82e2087faeab4d48ee8"
license "MIT"
depends_on "rust" => :build
uses_from_macos "zlib"
@zbentley
zbentley / sad.py
Last active July 28, 2021 05:02
The worst object system in the world
"""
Are you tired of Python being slow? Wish it was faster in irrelevant ways at the cost of being massively slower
and more fragile in every relevant way? Tired of how costly it is to look up attributes on classes? Wish you could
"stop" a class when you're done with it, and cause all future interactions with it to raise baffling exceptions? Do
you hate that attribute assignment is a statement? Then you might like this alternative* object system I wrote!
Don't have any of those problems? Well, that's fine, because nobody asked for this anyway.
It has:
- Access without dots. Dots are so .... Java.