Skip to content

Instantly share code, notes, and snippets.


Zac Bentley zbentley

  • Klaviyo
  • Boston, MA
View GitHub Profile
zbentley / wrap_example.bash
Created Mar 30, 2018
Bash function wrapping with minimal eval
View wrap_example.bash
#!/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 / anagram.js
Created Mar 26, 2018
Anagram Identifier
View anagram.js
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
View sadcomputer.gif.bash
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"
echo -e "$testname ($url): failed\nexpected to match: $regex\nInstead, got output:$curlout"