Skip to content

Instantly share code, notes, and snippets.

View zbentley's full-sized avatar
💭
🌮

Zac Bentley zbentley

💭
🌮
View GitHub Profile
@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'))
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 / 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
@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 / 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"