Skip to content

Instantly share code, notes, and snippets.

View mdobson's full-sized avatar
😺
Petting a cat

Matthew Dobson mdobson

😺
Petting a cat
View GitHub Profile
@mdobson
mdobson / gist:9254231
Last active August 29, 2015 13:56
Argo sample.
argo()
.post('/loc', function(handle){
handle('request', function(env, next){
env.request.getBody(function(err, body) {
if(err) {
//blah
} else {
//Get usergrid object
//This would be something from the SDK.
var usergridObject = getUgObj();
@mdobson
mdobson / gist:9250741
Created February 27, 2014 14:08
MQTT with the Arduino Yun
/*
Using an MQTT client with the arduino yun.
*/
#include <SPI.h>
#include <Bridge.h>
#include <YunClient.h>
#include <PubSubClient.h>
byte mac[] = {0x90, 0xA2, 0xDA, 0xF0, 0x0E, 0x0A};
@mdobson
mdobson / gist:9239634
Last active August 29, 2015 13:56
Tunneling HTTP over WebSockets
var http = require('http');
var WebSocketServer = require('ws').Server;
var webSocket = null;
var server = http.createServer(function(req, res) {
var requestLine = [req.method.toUpperCase(), req.url, 'HTTP/' + req.httpVersion + '\r\n'].join(' ');
Object.keys(req.headers).forEach(function(header) {
requestLine += header + ': ' + req.headers[header] + '\r\n';
});
@mdobson
mdobson / gist:9229852
Created February 26, 2014 13:57
Wrapping streams with other streams
var Readable = require('stream').Readable;
var util = require('util');
var Incoming = module.exports = function (opt) {
this.stream = opt.stream;
Readable.call(this, opt);
};
util.inherits(Incoming, Readable);
Incoming.prototype._read = function(n) {
@mdobson
mdobson / gist:9113296
Last active August 29, 2015 13:56
Alternatives to async provision
var HelloApp = module.exports = function() {
this.name = 'hello';
};
HelloApp.prototype.init = function(fog) {
fog.provision('photosensor', function(photosensor){
photosensor.on('change', function(value) {
if (value < 100) {
led.call('turn-on');
} else {
@mdobson
mdobson / gist:9076492
Last active August 29, 2015 13:56
Arduino Yun + Bonjour Service Discovery
/*********************
Elroy Service. Basic.
We'll be discovering where this is on the network with bonjour/mdns.
Then we'll interact with it.
Posting to the /on endpoint will turn pin 13 on.
Posting to the /off endpoint or any other endpoint will turn pin 13 off.
*********************/
@mdobson
mdobson / test.js
Created February 12, 2014 20:37
State Machines. All. The. Way. Down.
var HueDriver = module.exports = function() {
this.states [
{
state: 'on',
transitions: [
{ 'turn-off': this.turnOff },
{
'set-color': this.setColor,
'inputs': [
{ 'name':'RGB', 'type':'text'}
@mdobson
mdobson / gist:8762756
Created February 2, 2014 03:45
xcode 5 gitignore
# Xcode
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
@mdobson
mdobson / gist:8639105
Created January 26, 2014 20:30
Wiichuck Arduino Integration
/*
* WiiChuckDemo --
*
* 2008 Tod E. Kurt, http://thingm.com/
*
*/
#include <Wire.h>
#include "nunchuck_funcs.h"
/***************************************************
****************************************************/
#include <Adafruit_CC3000_UDP_Server.h>
#include <Adafruit_CC3000_ClientRef.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include "protocol.h"