Skip to content

Instantly share code, notes, and snippets.

Avatar

Cefn Hoile cefn

View GitHub Profile
@cefn
cefn / gist:7bb3dc5fbc61e03c9457
Created May 18, 2015
Example of trying to use Twisted's trial as an asynchronous unit test framework with paho-mqtt in python
View gist:7bb3dc5fbc61e03c9457
#!/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
View simpletrial.py
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 Jun 22, 2015
Mocha Test of .zip laziness
View zip-mocha-test
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 Jun 22, 2015
Mocha test which successfully tests zipped stream (using onValues to force side effects).
View test.js
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 Jun 23, 2015
RxJS zip to test networked event sequences
View test.js
/** 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 Aug 29, 2015
RxJS zip to test networked event sequences
View test.js
/** 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 Jul 29, 2015
Gist is intended to emulate a networked eventing framework, illustrating a Kefir stream issue
View remoteStream.js
"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.
View sampledByProperty.js
"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();
View testMosca.js
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(){
View mosca.js
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(){
You can’t perform that action at this time.