Skip to content

Instantly share code, notes, and snippets.

View rwaldron's full-sized avatar

Rick Waldron rwaldron

  • Boston, MA
View GitHub Profile
@mzgoddard
mzgoddard / tessel-api-mockup.rs
Last active March 6, 2017 21:34
Mockup a Tessel API covering the same basic APIs as Tessel JS
//
// Examples
//
mod examples {
fn main() {
// Different ways to get a single pwm pin.
//
// These earlier ones are a bit wasteful as they also create the leds
@cowboy
cowboy / object-forin-forown.js
Created June 5, 2012 17:34
JavaScript: Object#forIn and Object#forOwn
/*
* Object#forIn, Object#forOwn
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
Object.defineProperties(Object.prototype, {
forIn: {
@dherman
dherman / node.c
Created July 18, 2013 23:48
A lightweight implementation of node.js
#include <stdio.h>
int main() {
int *p = 0;
char line[1024];
printf("> ");
fgets(line, 1024, stdin);
*p = 12;
@parshap
parshap / sphero-with-node.md
Last active December 28, 2015 22:19
Orbotix Sphero with Node.js

Sphero with Node

This document will help you get started with controlling an Orbotix Sphero using Node.js.

Client Libraries

There are several different libraries for controlling the Sphero. Currently, the best one seems to be spheron. This module provides a simple interface to the Sphero API.

There is also CylonJS, but this just uses the spheron module and exposes the same API, so unless you are already using Cylon to control different hardware it probably makes sense to just use spheron directly.

@genericallyloud
genericallyloud / protocols.md
Created October 21, 2013 16:03
A potential solution for doing scoped binding of methods to types using a technique similar to Clojure protocols instead of Ruby refinements.

The following example uses the '::' operator which has a proposal already and a champion on the committee. Other than the bind operator, the example I give uses no new syntax (other than what is new to ES6), and could fairly easily be polyfilled - though I expect it could be optimized if implemented natively. If you haven't seen Clojure protocols, they allow for single dispatch polymorpism based on type, without the methods being defined as part of that type. In clojure, they use the first parameter, but for my proposal, it uses the receiver (this), and uses the bind operator to make the call look similar to a normal method call. While I haven't actually written an implementation of the Protocol class I demonstrate here, I've thought enough about it that I feel it could be done in a few different ways without too much complexity.

/**
  • The following module is a sampling of underscore methods conver
@bmeck
bmeck / Reading a message.md
Created September 30, 2013 05:47
A romp through time, on how we got our problems written down / ready to be read by a computer.
  • 1940s : "In my day we wrote down our problems"
  • 1950s : "In my day we plugged wires in manually"
  • 1970s : "In my day we read punch cards not "key" boards"
  • 1980s : "In my day we deserialized the baud connections manually"
  • 1990s : "In my day we read a shared key state mask"
  • 2000s : "In my day we listened for when buttons are pressed on the BIOS itself"
  • 2010s : "In my day we read our chars from a buffer"
  • 2020s : "In my day we waited for keys to be pressed"
  • 2030s : "In my day we used to have movies about terminators"
var five = require('../lib/johnny-five.js'),
board, button;
board = new five.Board();
board.on("ready", function() {
this.firmata.sendI2CConfig();
var LSM303_CTRL_REG1_A = 0x20
, LSM303_CTRL_REG2_A = 0x21
@creationix
creationix / randomlights.js
Created July 6, 2013 02:57
Talking to tinyduino over firmatta using johnny-five.
var five = require('johnny-five');
var board = new five.Board();
board.on("ready", function () {
var leds = new Array(5);
for (var i = 0; i < 5; i++) {
leds[i] = new five.Led({pin: i + 5});
}
@domenic
domenic / Elements.js
Last active December 18, 2015 23:49
class Elements extends Array
import { absolutizeRelativeSelectorList } from "http://dev.w3.org/csswg/selectors/#absolutizing";
// Assume JSIDL conversions have been applied already,
// i.e. we don't do `selectors = String(selectors)` manually.
class Elements extends Array {
query(selectors) {
return this.queryAll(selectors)[0]; // highly inefficient obviously, but clear semantics
}
queryAll(selectors) {
@Protonk
Protonk / notquitefusion.js
Last active December 18, 2015 10:29
Adjust the smoothing parameter w/ the sensor slider value.
var five = require("./lib/johnny-five.js"),
board, slider;
board = new five.Board();
board.on("ready", function() {
var accel = new five.Accelerometer({
pins: [ "I0", "I1" ],
freq: 100