Skip to content

Instantly share code, notes, and snippets.

View brianfay's full-sized avatar

Brian Fay brianfay

View GitHub Profile
@brianfay
brianfay / turtle-DOL.js
Created March 17, 2022 04:23
p5.js implementation of a DOL system as described in "The Algorithmic Beauty of Plants"
function derive(axiom, rules) {
let out = '';
for (c of axiom) {
out += rules[c] || c;
}
return out
}
function deriveTimes(axiom, rules, n) {
let out = axiom;
@brianfay
brianfay / bela-simple-looper.cpp
Last active February 19, 2019 03:20
A simple looper for Bela. Press a button attached to P9_12 to start recording. Press again to start playback. Loops until button is pressed again. Additionally plays the input signal, regardless of whether or not the loop is being played. Can control the volume with a nexus ui slider (browser websockets->node server->cpp osc server)
#include <Bela.h>
#include <OSCServer.h>
#include <OSCClient.h>
#include <math.h>
#include <digital_gpio_mapping.h>
//44100 * 60 * 4 (4 minute loop)
#define LOOP_BUFFER_SIZE 10584000
float gLoopBuffer_l[LOOP_BUFFER_SIZE] = {0};
@brianfay
brianfay / bela-btn-test.cpp
Created February 1, 2019 03:55
Modified examples to play three sine waves, with the amplitude controlled by three momentary switches connected as digital inputs. Need to do some switch debouncing to get rid of some crackling
#include <Bela.h>
#include <stdio.h>
#include <cmath>
#include <digital_gpio_mapping.h>
float gPhase1, gPhase2, gPhase3;
float gInverseSampleRate;
bool setup(BelaContext *context, void *userData)
{
@brianfay
brianfay / serve-vinyl
Last active January 10, 2017 08:00
Streaming vinyl over wifi from raspberry pi to laptop
#! /bin/bash
#shove this in /usr/local/bin/ on the Pi and give it execute permissions
#could probably improve very easily by checking if port 5555 is listening before trying to toss data at it
#stole ideas from here: https://hydrogenaud.io/index.php/topic,102996.0.html
{
while true;
do sox -talsa hw:CODEC -r44100 -b16 --buffer 4096 -tflac - \
| pv | nc 192.168.1.4 5555;
sleep 10;
@brianfay
brianfay / nasty-diff.clj
Created January 20, 2016 04:36
Nasty WIP thing that will take two sequences and return a list of actions that will transform the first sequence into the second one.
(defn diff-sorted
[old new]
;;iterate through new list
(let [old-set (set old)]
(loop [actions '()
old-list old
new-list new]
(let [old-val (first old-list)
new-val (first new-list)
rest-old (rest old-list)
@brianfay
brianfay / my-update-in.clj
Created November 22, 2015 01:17
my-update-in
(defn my-update-in
[m [k & ks] v]
(if (empty? ks)
(update m k v)
(assoc m k (my-update-in (k m) ks v))))
@brianfay
brianfay / my-assoc-in.clj
Created November 22, 2015 00:57
my-assoc-in
(defn my-assoc-in
[m [k & ks] v]
(if (empty? ks)
(assoc m k v)
(assoc m k (my-assoc-in (k m) ks v))))
@brianfay
brianfay / my-comp
Last active November 18, 2015 19:45
Simple implementation of comp using reduce
;;The one thing I don't really like about this is that I have to reverse funcs, not sure if there is a more elegant solution
(defn my-comp
[& funcs]
(let [funcs (reverse funcs)]
(fn [& args]
(reduce #(%2 %1) (apply (first funcs) args) (rest funcs)))))
;;this solution from "toolkit" on StackOverflow seems a tad better to me, but I'm not sure how it works...
(fn [& fs]
@brianfay
brianfay / validate.clj
Created November 10, 2015 01:56
Not actually clojure for the brave and true chap 4 ex 3
;;I just spent forever and a half writing a function that takes a list of keys and an input map, and validates
;;that all keys are present within the input map. I wrote it in two different ways, but they're both ugly as sin.
;;Rereading the exercise, I realize that it was actually asking for something different. But whatever, still a useful exercise!
;;could probably clarify by making "all-true?" a function, like
(defn all-true?
[seq]
((complement #(some false? %) seq))
;;Implemented some using reduce, based on a challenge in Daniel Higginbotham's "Clojure for the Brave and True
;;This doesn't really work right; it breaks on lists, and it keeps running through the sequence even after it finds
;;a value that passes the predicate...
(defn my-some
"If the predicate is true for some value, returns that value (implemented with reduce)"
[pred sequence]
(reduce (fn
[x y]
(if (pred x) x y)) (conj sequence nil)))