Skip to content

Instantly share code, notes, and snippets.

View cefn's full-sized avatar

Cefn Hoile cefn

View GitHub Profile
@cefn
cefn / gist:7bb3dc5fbc61e03c9457
Created May 18, 2015 16:29
Example of trying to use Twisted's trial as an asynchronous unit test framework with paho-mqtt in python
#!/usr/bin/python
from __future__ import print_function
from threading import Thread
from twisted.internet.defer import Deferred
from twisted.trial.unittest import TestCase
from paho.mqtt.client import Client
from threading import Thread
from time import sleep
from twisted.trial.unittest import TestCase
from twisted.internet.defer import Deferred
from twisted.internet import reactor
class ThreadTestCase(TestCase):
def setUp(self):
@cefn
cefn / zip-mocha-test
Created June 22, 2015 08:56
Mocha Test of .zip laziness
var Bacon = require("baconjs"),
assert = require("assert");
require('promise.prototype.finally');
describe("Testing stream equality logic", function(){
it( "can match Bacon streams backed by the same array.", function(){
var targetSequence = [
["oldmacdonald/farm", "['sheep','pig','cow','duck']" ] , //n.b. JSON.stringify of array
@cefn
cefn / test.js
Created June 22, 2015 09:19
Mocha test which successfully tests zipped stream (using onValues to force side effects).
var Bacon = require("baconjs"),
assert = require("assert");
require('promise.prototype.finally');
describe("Testing stream equality logic", function(){
it( "can match Bacon streams backed by the same array.", function(){
var targetSequence = [
["oldmacdonald/farm", "['sheep','pig','cow','duck']" ] , //n.b. JSON.stringify of array
@cefn
cefn / test.js
Created June 23, 2015 13:45
RxJS zip to test networked event sequences
/** Verifies that the over-the-wire MQTT messages arising from IdeaTree operations are as expected. */
describe("Tree Protocol", function(){
it("Sends branch keys then leaf values", function(){
var sniffer = mqtt.connect(conf.mqttWsAddr);
var subscribeAndSendPromise = util.createSubscriptionPromise(sniffer, '#')
.then(function(){
writer.setItem('oldmacdonald/farm', {
sheep:"Baa",
@cefn
cefn / test.js
Last active August 29, 2015 14:23
RxJS zip to test networked event sequences
/** Verifies that the over-the-wire MQTT messages arising from IdeaTree operations are as expected. */
describe("Tree Protocol", function(){
it("Sends branch keys then leaf values", function(){
var sniffer = mqtt.connect(conf.mqttWsAddr);
var subscribeAndSendPromise = util.createSubscriptionPromise(sniffer, '#')
.then(function(){
writer.setItem('oldmacdonald/farm', {
sheep:"Baa",
@cefn
cefn / remoteStream.js
Created July 29, 2015 09:06
Gist is intended to emulate a networked eventing framework, illustrating a Kefir stream issue
"use strict";
var _ = require("lodash"),
Kefir = require("kefir"),
events = require("events");
/** This Gist is intended to emulate an eventing framework in which Javascript objects
* containing topic:value pairs are kept in synchrony across a network.
*
* There is a mysterious problem, in which a flatMap actually triggered by a Property event
* creates a stream which is also based on the same Property, but which doesn't seem to generate events.
"use strict";
var Kefir = require("kefir"),
events = require('events');
var empty = void(0);
var localEmitter = new events.EventEmitter(); //used to notify local updates to values against new or old topics
var remoteEmitter = new events.EventEmitter(); //used to notify local updates to values against new or old topics
var localProperty = Kefir.fromEvents(localEmitter, "Hello").toProperty();
var Q = require("q");
var persistence = require("persistence");
var mosca = require("mosca");
var mqtt = require("mqtt");
var chai = require("chai");
var should = chai.should();
var Promise = Q.Promise;
function promiseServer(){
var Q = require("q");
var persistence = require("persistence");
var mosca = require("mosca");
var mqtt = require("mqtt");
var chai = require("chai");
var should = chai.should();
var Promise = Q.Promise;
function promiseServer(){