Skip to content

Instantly share code, notes, and snippets.

View kevinswiber's full-sized avatar
🍄
lizard person

Kevin Swiber kevinswiber

🍄
lizard person
View GitHub Profile
@kevinswiber
kevinswiber / root.feature
Last active August 29, 2015 13:55
Exploring hypermedia aware acceptance testing.
Feature: Root Resource
As an API client
I want to see the root resource
So that I have a starting point to complete my task.
Scenario: Request the root
Given an anonymous client
When I make a GET request to /
Then I should get a 200 status code
And the content type should be JSON
@kevinswiber
kevinswiber / npm-debug.log
Created February 2, 2014 17:17
Can't publish new packages to NPM.
0 info it worked if it ends with ok
1 verbose cli [ '/Users/kevin/nvm/v0.10.17/bin/node',
1 verbose cli '/Users/kevin/nvm/v0.10.17/bin/npm',
1 verbose cli 'publish' ]
2 info using npm@1.3.8
3 info using node@v0.10.17
4 verbose publish [ '.' ]
5 verbose cache add [ '.', null ]
6 verbose cache add name=undefined spec="." args=[".",null]
7 verbose parsed url { protocol: null,
@kevinswiber
kevinswiber / app.js
Last active August 29, 2015 13:56
Elroy app with promises.
var Scientist = require('../scientist');
var Nightlight = require('./nightlight');
var wrap = require('./elroy_promise');
var HelloApp = module.exports = function() {
this.name = 'hello';
};
HelloApp.prototype.init = function(elroy) {
elroy = wrap(elroy);
@kevinswiber
kevinswiber / fake_socket.js
Last active August 29, 2015 13:56
Fake net.Socket with HTTP
var Duplex = require('stream').Duplex;
var util = require('util');
var FakeSocket = module.exports = function() {
Duplex.call(this);
this.source = new BufferSource();
this.on('finish', function() {
this.source.state = 'ready';
@kevinswiber
kevinswiber / buffer_stream.js
Last active August 29, 2015 13:56
Buffered Duplex Stream
var Duplex = require('stream').Duplex;
var util = require('util');
var BufferStream = module.exports = function() {
Duplex.call(this);
this.source = new BufferSource();
this.on('finish', function() {
this.source.state = 'ready';
@kevinswiber
kevinswiber / packet.js
Last active August 29, 2015 13:56
Simple packet format for tunneling messages over WebSockets.
/*
+----------------------------------+
|S| MessageID (31bits) |
+----------------------------------+
| Reserved (8) | Length (24 bits) |
+----------------------------------+
| Data |
+----------------------------------+
*/
@kevinswiber
kevinswiber / argo_cors.js
Created March 1, 2014 22:33
Using CORS with Argo.
var argo = require('argo');
argo()
.use(function(handle) {
handle('response', function(env, next) {
env.response.setHeader('Access-Control-Allow-Origin', '*');
next(env);
});
})
.use(function(handle) {
@kevinswiber
kevinswiber / 1_Queryable.md
Last active August 29, 2015 13:57
Documentation of elroy findables.

Query methods

elroy.get(name, callback)

Get a device by name.

elroy.get('joes-office-photosensor', function(err, photosensor) {
});
@kevinswiber
kevinswiber / app.js
Created March 15, 2014 21:42
Annotated Elroy app with reactive patterns.
var HelloApp = module.exports = function() {
this.name = 'hello';
};
HelloApp.prototype.init = function(elroy) {
elroy.observe('type="led"') // set up an observer to grab LEDs
.zip(elroy.observe('type="photosensor"')) // combine output with another observable
.first() // only observe until the first pair is discovered
.timeout(3000) // if the pair isn't discovered within 3 seconds, throw a timeout error
.subscribe(function(err, devices) { // fires for each pair discovered. Because we called first(), this only happens once.
@kevinswiber
kevinswiber / observable.js
Created March 18, 2014 20:16
Hand-rolled Elroy Observable
var Logger = require('./logger');
var Observable = module.exports = function(query, runtime) {
this.query = query;
this.runtime = runtime;
this.registry = this.runtime.registry;
this.logger = new Logger();
this.state = 'ready'; // disposed
this.remainder = null;
this.takePredicate = null;