Skip to content

Instantly share code, notes, and snippets.

View trustmaster's full-sized avatar

Vladimir Sibirov trustmaster

View GitHub Profile
@trustmaster
trustmaster / pipeline.go
Created January 24, 2021 10:43
Go test pipeline
package pipeline
import fmt
// pipeline allows chaining simple calls in tests
type pipeline struct {
err error
}
// ok asserts that a function does not return an error
@trustmaster
trustmaster / HOWTO.md
Last active February 23, 2017 13:09
NPM shrinkwrap with NoFlo 0.8

Using NPM Shrinkwrap to force NoFlo 0.8

Installing noflo-0.8 for all dependencies

  1. npm install latest dependency tree
  2. npm shrinkwrap to generate initial npmshrinkwrap.json file
  3. In npmshrinkwrap.json find all occurances of "noflo" and replace the contents with e.g.
// ...
@trustmaster
trustmaster / DbInsert.coffee
Created December 7, 2016 14:39
Example assembly component
assembly = require '../lib/assembly'
class DbInsert extends assembly.Component
description: 'Inserts a database record'
# Validation of the input message is done automatically
# before relay() method is entered
validates:
'db': 'func' # expect a constructor function
'query.table': 'ok' # expect something truthy
'query.data': 'obj' # expect an object
@trustmaster
trustmaster / SomeComponent.coffee
Last active June 6, 2016 15:57
Ignore brackets in Process API
process: (input, output) ->
# Drop brackets
if input.ip.type isnt 'data'
buf = if input.scope isnt null then input.port.scopedBuffer[input.scope] else input.port.buffer
return buf.pop()
# Then do whatever you want with data packets, e.g.
data = input.getData 'foo'
@trustmaster
trustmaster / ParseYaml.coffee
Created April 5, 2016 20:08
Bracket forwarding the quick way
noflo = require 'noflo'
parser = require 'js-yaml'
exports.getComponent = ->
c = new noflo.Component
c.description = 'Parse YAML to an object'
c.inPorts.add 'in',
datatype: 'string'
description: 'YAML source'
c.outPorts.add 'out',
@trustmaster
trustmaster / streamy.coffee
Created April 1, 2016 10:49
Substreams and scalar example
c = new noflo.Component
inPorts:
streamy:
datatype: 'object'
description: 'Substreams'
inty:
datatype: 'int'
description: 'Scalar'
outPorts:
result:
@trustmaster
trustmaster / AddPost.coffee
Created February 24, 2016 04:38
Example component prototype
c = new noflo.Component
c.desciption = 'A component that posts on behalf of user'
c.inPorts = new noflo.InPorts
db:
datatype: 'object'
control: true
user:
datatype: 'object'
post:
datatype: 'object'
@trustmaster
trustmaster / 0_PortsDefinition.coffee
Last active February 22, 2016 14:43
WirePattern must die
c = new noflo.Component
c.desciption = 'A component that posts on behalf of user'
c.inPorts = new noflo.InPorts
timeout:
datatype: 'int'
control: true
user:
datatype: 'object'
post:
datatype: 'object'
@trustmaster
trustmaster / SomeComponentSpec.coffee
Created December 15, 2015 15:36
Testing a NoFlo component with transaction rollback
noflo = require 'noflo'
chai = require 'chai'
uuid = require 'uuid'
db = require '../lib/db'
Tester = require 'noflo-tester'
describe 'SomeComponent', ->
c = new Tester 'some-project/SomeComponent'
productData =
id: uuid.v4()
@trustmaster
trustmaster / Test.js
Created February 18, 2015 17:43
NoFlo issue #273 example
var noflo = require("noflo");
exports.getComponent = function() {
var component = new noflo.Component;
component.description = "Test";
component.inPorts.add('in', {
datatype: 'all',
addressable: true
});