Skip to content

Instantly share code, notes, and snippets.

View bjpirt's full-sized avatar

Ben Pirt bjpirt

View GitHub Profile
### Keybase proof
I hereby claim:
* I am bjpirt on github.
* I am bjpirt (https://keybase.io/bjpirt) on keybase.
* I have a public key whose fingerprint is D8A0 CC19 C743 9E5C 55BA 20E9 938E E78B D67A 7EFA
To claim this, I am signing this object:
#include <stdlib.h>
#include <AFMotor.h>
// COMMAND_COUNT specifies how many commands we are going to be able to hold
// You can reduce this to save memory
#define COMMAND_COUNT 7
#define BUFFER_LENGTH 20
// Define the different types of results
#define INTEGER_TYPE 1
#define FLOAT_TYPE 2
@bjpirt
bjpirt / nnc.rb
Created February 6, 2012 16:46
Naughty Netcat
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
class Client < EventMachine::Connection
def initialize(server)
@server = server
@server.client = self
@start_time = Time.now.to_f
end
@bjpirt
bjpirt / bucket.rb
Created May 2, 2012 16:19
Quick bucketing of PG logs
#!/usr/bin/env ruby
outputs = {}
STDIN.each_line do |line|
data = line.gsub(';', '').split(' ')
outputs[data[1].to_i] = [] unless outputs[data[1].to_i]
outputs[data[1].to_i] << data[0].to_f
end
outputs.keys.sort.each do |k|
@bjpirt
bjpirt / selenium_server.js
Created May 25, 2012 08:59
A module to make sure selenium is already started
var http = require('http'),
spawn = require('child_process').spawn,
selenium;
var selenium_server = {
host: 'localhost',
port: 4444,
path: '/wd/hub/static/resource/hub.html',
method: 'GET'
};
#!/usr/bin/env node
var Backbone = require('backbone-postgresql');
// Configure our connection to PostgreSQL
Backbone.pg_connector.config = {db: 'pg://postgres:m0nday27@localhost/bb_pg_demo'}
// Define some models
var Category = Backbone.Model.extend({
urlRoot: 'category'
@bjpirt
bjpirt / cheerlights-node-red.json
Created December 25, 2015 19:28
An Arduino sketch that takes a colour and cycles through the spectrum to transition to it and an accompanying node-red flow to hook it up to twitter
[{"id":"800baf19.7ff45","type":"serial-port","z":"2d82a309.d27d5c","serialport":"/dev/ttyUSB1","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":true},{"id":"4121fbbc.bede04","type":"twitter in","z":"2d82a309.d27d5c","twitter":"","tags":"cheerlights","user":"false","name":"cheerlights","topic":"tweets","x":150,"y":162.00001525878906,"wires":[["eb35c13.f14ca4"]]},{"id":"eb35c13.f14ca4","type":"function","z":"2d82a309.d27d5c","name":"parse @Cheerlight colours","func":"msg.payload = msg.payload.toLowerCase();\n\nvar result = msg.payload.match(\n/red|green|blue|cyan|white|warmwhite|purple|magenta|yellow|orange|black|pink|oldlace/g);\n\nmsg = [];\nfor (var colour in result) {\n msg.push({payload:result[colour]+\"\\n\"});\n}\n\nconsole.log(msg);\n\nreturn [msg];\n\nif(context.global.enabled){\n return [msg];\n}else{\n return [];\n}","outputs":1,"noerr":0,"x":387.00001525878906,"y":194,"wires":[["b591b09d.4a6e5"]]},{"id":"b591b09d.4a6e5","
@bjpirt
bjpirt / face.py
Last active February 10, 2017 17:43
A quick demo of doing face tracking on the MeArm Pi so that you can make the arm follow you
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
from mearm import MeArm
width = 640
arm = MeArm()
arm.base.moveTo(0)
@bjpirt
bjpirt / mearm.py
Created February 10, 2017 17:49
Controlling the MeArm Pi from Minecraft
import os
import math
import pigpio
#import RPi.GPIO as GPIO
pi = pigpio.pi()
class Servo:
def __init__(self, config):
self.pin = config['pin']
var KS = require('./kickstarter-data/');
var MeArmPi = require('../mearm-js/lib/MeArmPi.js').MeArmPi,
arm = new MeArmPi();
var backers = 0;
arm.moveBaseTo(20);
function drawBack(current, dest, cb){
if(current < dest){