Skip to content

Instantly share code, notes, and snippets.

View brianfay's full-sized avatar

Brian Fay brianfay

View GitHub Profile
@brianfay
brianfay / FilteredButtonInput
Created November 29, 2013 22:30
Using a momentary push-button switch as input to a Raspberry Pi - sometimes extra button "presses" would be recorded when releasing it. This filters the button press so that it only registers if has been in it's current state for a couple of polls.
import RPi.GPIO as gpio
gpio.setmode(gpio.BCM)
gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_UP)
minNum = 3
oneCount = 0
zeroCount = 0
currentMode = gpio.input(17)
while True:
@brianfay
brianfay / DetectMarkers.pde
Created December 16, 2013 00:32
Takes a live video feed and detects 10x10 black and white pattern on a piece of paper (the edges of this pattern should all be black) Borrows very heavily from atduskgreg's Marker Detection example: https://github.com/atduskgreg/opencv-processing/tree/master/examples/MarkerDetection May require some tweaking to use, depending on lighting conditi…
import gab.opencv.*;
import org.opencv.imgproc.Imgproc;
import org.opencv.core.Core;
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.opencv.core.Mat;
@brianfay
brianfay / buttonListener.c
Created February 2, 2014 20:46
A Pure Data external using the Wiring Pi library to listen for button presses on GPIO pin 17
#include "m_pd.h"
#include <wiringPi.h>
t_class *buttonlistener_class;
typedef struct _buttonlistener
{
t_object x_obj;
t_clock *x_clock;
int defaultButtonState; //some buttons close switch when pressed, others open it, might as well make the code neutral.
@brianfay
brianfay / Soroboruo.scd
Last active August 29, 2015 14:01
Drooooooone
(
SynthDef(\sineGrain, {|out, freq=440, sustain=0.02, amp=0.1, pan|
var wavetable = Buffer.alloc(s, 512, 1, { |buf| buf.chebyMsg([1,0,1,1,0,1])});
var env = EnvGen.ar(Env.sine(sustain, amp), doneAction: 2);
var sound = SinOsc.ar(freq) * env;
sound = Shaper.ar(wavetable, sound) * 0.1;
Out.ar(out, Pan2.ar(sound, LFNoise1.kr(40, 2, -1)))
}).add;
SynthDef(\verb, { arg outBus = 0, inBus;
@brianfay
brianfay / 85-arduino.rules
Created August 10, 2014 19:04
Add udev rule - triggered when Arduino Uno is connected
#Rule to run script when Arduino Uno is connected
KERNEL=="ttyACM0",ACTION=="add",RUN+="/path/to/script"
@brianfay
brianfay / .toggleJack.sh
Last active November 25, 2015 00:30
Toggle Jack on and off (I just mapped this to Ctrl-Alt-J, probably still won't handle suspending computer...)
#!/bin/bash
if [ -n "`jack_control status | grep started`" ]
then
echo "jack already started, stopping it..."
jack_control stop
else
echo "let's get this owl hootin'"
jack_control eps realtime true
jack_control ds alsa
@brianfay
brianfay / mapTouchscreen.sh
Created June 6, 2015 22:23
map touch screen
#!/bin/sh
#map laptop's touch screen to appropriate display (the laptop screen)
TOUCH_ID=`xinput list | grep SYNAPTIC | awk -F '\t' '{print $2}' | cut -c 4-`
xinput --map-to-output $TOUCH_ID eDP1
@brianfay
brianfay / leaveWork.js
Created October 27, 2015 21:01
When to leave work
function timer(){
var fivePM = new Date();
fivePM.setHours(17);
fivePM.setMinutes(0);
fivePM.setSeconds(0);
var startTime = Date.now();
var secondsTilEOD = Math.floor((fivePM.getTime() - startTime) / 1000);
var secondsLeft = secondsTilEOD;
var secondsElapsed = 0;
function tick(){
@brianfay
brianfay / map-via-reduce.clj
Created November 8, 2015 03:58
Implement map using reduce (clojure)
;;Excerpt "Clojure for the Brave and True" by Daniel Higginbotham:
;;"If you want an exercise that will really blow your hair back, try implementing map using reduce..."
;;This actually took me a really long time to come up with, have to keep thinking about how reduce expands to (fn (fn (fn...
;;Tried cons first, but couldn't figure it out - needed to think about the order arguments are applied in within the anonymous
;;function AND the order of arguments for reduce. That was more obvious after I tried using conj
(defn my-map-conj
"map implemented in terms of reduce and conj"
[f coll]
(defn my-filter-cons
"Filter a sequence, implemented with reduce and cons"
[pred sequence]
(reduce (fn [seq x]
(if (pred x) (cons x seq) seq)) '() sequence))
(defn my-filter-conj
"Filter a sequence, implemented with reduce and conj"
[pred sequence]
(reduce (fn [seq x]