Skip to content

Instantly share code, notes, and snippets.

View benjamind's full-sized avatar

Ben Delarre benjamind

View GitHub Profile
@benjamind
benjamind / app.js
Last active December 15, 2015 10:48
Test case for bug involving large strings in couchnode
var couchbase = require('couchbase'),
async = require('async'),
couchbaseConfig = {
debug: process.env.COUCHBASE_DEBUG || false,
user: process.env.COUCHBASE_USER || '',
password: process.env.COUCHBASE_PASSWORD || '',
bucket: process.env.COUCHBASE_BUCKET || 'default'
},
bucket = null;
@benjamind
benjamind / couchbase.js
Created April 11, 2013 19:12
A simple shim around the couchnode library. If you use this in place of the normal couchbase require then you can use REST protocol to workaround this issue http://www.couchbase.com/issues/browse/JSCBC-22 This shim keeps the interface the same, but allows you to just pass 'true' as an additional argument after the callback argument to force usag…
var couchbase = require('couchbase'),
async = require('async'),
request = require('request'),
url = require('url'),
path = require('path'),
_ = require('underscore'),
apiUrl = null,
_config = null;
var Bucket = function(apiUrl, config) {
@benjamind
benjamind / test.js
Last active December 17, 2015 05:18
Test case for Seg Fault in asynchronous calls to endure from couchnode library
var couchbase = require('couchbase'),
async = require('async'),
couchbaseConfig = {
debug: process.env.COUCHBASE_DEBUG || true,
user: process.env.COUCHBASE_USER || '',
password: process.env.COUCHBASE_PASSWORD || '',
bucket: process.env.COUCHBASE_BUCKET || 'default'
},
async = require('async'),
defaultHost = 'localhost:8091',
@benjamind
benjamind / stats-massage.js
Created July 24, 2013 18:03
This is a simple nodejs script that massages our stats data into separate files which we can use in OpenSCAD to produce 3d models.
var filename = 'response-times-15min',
fs = require('fs'),
out = [],
i = 0,
array = fs.readFileSync(filename + '.tsv').toString().split('\n');
for (i=0; i < array.length; i++) {
out.push(array[i]);
out.push(array[i]);
fs.writeFileSync(filename + '-' + i + '.txt', array[i].toString() + "\n");
@benjamind
benjamind / physical-analytics.scad
Created July 24, 2013 18:07
An OpenSCAD script to produce a physical representation of our statistics.
entries = 30;
dataLength = 96;
prefix = "response-times-15min-";
yScale = 0.4;
xScale = 0.2;
zScale = 0.0008;
union() {
translate([0,-entries*yScale/2,0])
@benjamind
benjamind / gist:6199413
Created August 10, 2013 07:02
Neo pixel led test
// include the neo pixel library
#include <Adafruit_NeoPixel.h>
// how many leds in our string?
static const int NUM_LEDS = 6;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
@benjamind
benjamind / gist:6199599
Created August 10, 2013 08:31
More LED testing...
// include the neo pixel library
#include <Adafruit_NeoPixel.h>
// how many leds in our string?
static const int NUM_LEDS =21*6;
static const int TOTAL_BYTES = NUM_LEDS*3;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
@benjamind
benjamind / led-sender.js
Last active July 30, 2016 19:14
Sending LED data over Serial with NodeJS
var serialport = require("serialport"),
SerialPort = serialport.SerialPort;
// first list the serial ports available so we can figure out which is the arduino
serialport.list(function (err, ports) {
var port = null;
ports.forEach(function(p) {
// this should work on windows and maybe osx
if (p.manufacturer.indexOf('Arduino')!==-1) {
port = p.comName;
// include the neo pixel library
#include <Adafruit_NeoPixel.h>
// how many leds in our string?
static const int NUM_LEDS = 5;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
@benjamind
benjamind / gist:e62f5177a975086051b19f35475e8713
Created January 8, 2017 21:10
FastLED power management per controller pseudocode
// this is all pseudocode and will probably not compile but it should give you an idea
// init...
// create your controllers
CLEDController controllerA = FastLED.addLEDs(LED_TYPE, DATA_PIN, COLOR_ORDER(ledsA, 0, NUM_LEDS_A);
CLEDController controllerB = FastLED.addLEDs(LED_TYPE, DATA_PIN, COLOR_ORDER(ledsB, 0, NUM_LEDS_B);
// loop....
// calculate power per controller
uint8_t scaleA = calculate_max_brightness_for_power_mW(controllerA.leds(), controllerA.size(), targetBrightness, MAX_POWER_MW_A);