Skip to content

Instantly share code, notes, and snippets.

@15joeybloom
15joeybloom / siteswap_validator.go
Created March 17, 2023 16:38
Validate a siteswap pattern
package main
import (
"errors"
"fmt"
)
func isValidSiteswap(pattern []int) error {
total := 0
numBeats := 0
@15joeybloom
15joeybloom / finiteDepth.ts
Created December 8, 2020 03:01
A typescript function to truncate a potentially circular structure to a finite depth
// Takes a structure with possible circular references, e.g.
// functions.https.CallableContext, and truncates it to finite depth.
function finiteDepth(x: any, depth: bigint): any {
if (depth <= 0) {
return "Truncated by finiteDepth"
} else if (x instanceof Array) {
return x.map(e => finiteDepth(e, depth - 1n))
} else if (typeof x === 'object' && x !== null) {
return Object.fromEntries(
Object.entries(x).map(
@15joeybloom
15joeybloom / transducers.clj
Created May 16, 2020 03:43
clojure transducers
;; https://github.com/green-coder/transducer-exercises
(ns transducers)
;; We use this function instead of `into` for debugging.
;; The reason is that this avoids using transient
;; structures which do not `print` nicely.
(defn slow-into [to xf from]
(transduce xf conj to from))
(def identity-transducer
@15joeybloom
15joeybloom / aws_profile_prompt.sh
Last active February 17, 2020 20:51
A dynamic bash prompt displaying the value (if any) of the AWS_PROFILE environment variable.
# https://gist.github.com/15joeybloom/3a24c60b191836deed144c760a0799e0
aws_profile_prompt() {
if [ -z "${AWS_PROFILE+foo}" ] ; then # Check if AWS_PROFILE set
printf ""
elif [ -z "$AWS_PROFILE" ] ; then # Check if AWS_PROFILE empty
# italic, red bg, black fg
printf "\001\033[3;48;5;1;38;5;16m\002AWS Profile empty!\001\033[0m\002 "
else
# bold, yellow bg, black fg
printf "\001\033[1;48;5;220;38;5;16m\002AWS Profile: $AWS_PROFILE\001\033[0m\002 "

Keybase proof

I hereby claim:

  • I am 15joeybloom on github.
  • I am jbloom (https://keybase.io/jbloom) on keybase.
  • I have a public key ASBFgaU0CvyTKzGpAI3BcJ7CSa4l5-Q7K3yA_VOAoTldRAo

To claim this, I am signing this object: