Skip to content

Instantly share code, notes, and snippets.

View zbentley's full-sized avatar
💭
🌮

Zac Bentley zbentley

💭
🌮
View GitHub Profile
@zbentley
zbentley / sadcomputer.gif.bash
Last active February 7, 2018 04:20
Panzerbjörne
function testshit {
local testname="${1:?Test name needs to be first parameter bro}"
local url="${2:?URL needs to be second parameter bro}"
local regex="${3:?Regex needs to be third parameter bro}"
# Can do this multiple times if you want with different CURL args to e.g. test the headers/response code/body:
local curlout=$(curl -whatever "$url")
if echo "$curlout" | grep -P "$regex" >/dev/null; then
echo "$testname ($url): all good"
else
echo -e "$testname ($url): failed\nexpected to match: $regex\nInstead, got output:$curlout"
@zbentley
zbentley / anagram.js
Created March 26, 2018 20:59
Anagram Identifier
/*
Optimized potential-anagram identifier function.
Runs in O(N) time on the supplied string, with several o(N) optimizations as well.
Consumes at worst half of the supplied string's space in memory (additionally), plus overhead.
This algorithm uses two paths: a reusable array of integer values (it could just as well be a bitfield,
but that probably won't save any performance since memory has to be written in whole words anyway)
with a known, fixed size: it will store the first, most common, 512 characters of the alphabet and
@zbentley
zbentley / wrap_example.bash
Created March 30, 2018 15:54
Bash function wrapping with minimal eval
#!/usr/bin/env bash
wrap() {
local old_name="${1:?get fuct}"
local new_name="${2:?get fuct}"
_temp_function() {
echo "wrapping the old one!"
_old_function_call_placeholder param
class Foo(object):
def __init__(s, foo):
s.wrapped = foo
def __getattr__(s, attr):
target = attr
if attr.startswith('__') and not attr.endswith('__'):
target = '_{}{}'.format(s.wrapped.__class__.__name__, attr)
return getattr(s.wrapped, target)
@zbentley
zbentley / wack.py
Created June 7, 2021 04:11
dat zb good shit
#!/usr/bin/env python
import os
import os.path
import sys
from collections import namedtuple, defaultdict
ResultSpec = namedtuple('ResultSpec', ('subdir', 'file_filter', 'join'))
@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.
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"

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
@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 {} \;
@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.