Skip to content

Instantly share code, notes, and snippets.

Rx.Observable.asStream = function (ev) {
return Rx.Observable.create(function (obs) {
function handler (data) {
obs.onNext(data); // Call as many times with onNext to yield new data
// obs.onCompleted(); // optional to signal the end of the stream
}
ev.on('data', handler);
@creationix
creationix / output.log
Created May 8, 2013 22:02
Working version of generator async code sample. Using node from https://github.com/andywingo/node/tree/v8-3.19
tim@touchsmart:~/Code$ nvm use v0.11.2-generators
Now using node v0.11.2-generators
tim@touchsmart:~/Code$ node --harmony testgen.js
<Buffer 76 61 72 20 66 73 20 3d 20 72 65 71 75 69 72 65 28 27 66 73 27 29 3b 0a 66 75 6e 63 74 69 6f 6e 20 72 65 61 64 46 69 6c 65 28 70 61 74 68 2c 20 65 6e 63 ...>
Sleeping for 2000ms...
Done
@subtleGradient
subtleGradient / index.js
Created June 5, 2013 19:25
MeeMoo.org DataFlow Graph from Quartz Composer QTZ file
var bplistParser = require('bplist-parser')
var bplistCreator = require('node-bplist-creator')
var fs = require('fs')
var DFGraph = {}
DFGraph.edgeFromQCConnection = function(qcConnection, connectionKey){
return {
source:{node: qcConnection.sourceNode, port:qcConnection.sourcePort},
target:{node: qcConnection.destinationNode, port:qcConnection.destinationPort}
o.toObservable = function () {
var o = this;
return Rx.Observable.create(function (obs) {
function handler (e) {
obs.onNext(e);
}
Object.observe(o, handler);
return function () {
@subtleGradient
subtleGradient / Behavior.framer.js
Last active July 28, 2017 17:27
Simple Behavior sheet system for FramerJS. Allows you to apply pre-defined behaviors to your layers by changing the layer name. by Thomas Aylott (http://subtlegradient.com) Copyright 2013 Facebook. All rights reserved. MIT License.
function Behavior(PSD){
var _BehaviorNames = Object.keys(Behavior.behaviors)
.filter(function(BehaviorName){ return !!Behavior.behaviors[BehaviorName].namingPattern });
Object.keys(PSD).forEach(function(layerName){
var layer = PSD[layerName];
_BehaviorNames.forEach(function(BehaviorName){
var match = layerName.match(Behavior.behaviors[BehaviorName].namingPattern);
try {
@mattpodwysocki
mattpodwysocki / allexists.js
Last active December 23, 2015 04:29
Examples of using the Node.js bindings for callback handling
var Rx = require('rx');
var fs = require('fs');
function allExists (files) {
return Rx.Observable.for(files,
function (file) {
return Rx.Node.fromCallback(fs.exists)(file);
}
)
.all();
endScrollMomentum = function(event) {
var animation, constant1, constant2, totalVelocity, touchEvent, velocity;
touchEvent = Events.sanitize(event);
constant1 = 1000;
constant2 = 0;
velocity = dragger.calculateVelocity();
@forresto
forresto / noflo.json
Last active October 23, 2017 17:22
snapped to 30px for the-graph - NoFlo clock example
{
"properties": {
"environment": {
"runtime": "html",
"content": "<div class='area' title='.area'>\n <img id='clock' src='https://i.imgur.com/0S7R8OU.png' style='position:absolute; width:300px; height:300px; top:0; left:0;' />\n <img id='hours' src='https://i.imgur.com/Fw8L3L1.png' style='position:absolute; top:50px; left:130px; height:200px;' />\n <img id='minutes' src='https://i.imgur.com/WtSz99Q.png' style='position:absolute; top:0; left:140px; height:300px;' />\n <img id='seconds' src='https://i.imgur.com/m2PQs6E.png' style='position:absolute; top:0; left:145px; height:300px;' />\n</div>",
"width": 300,
"height": 300,
"src": "./preview/iframe.html"
},
"name": "NoFlo"
fs = require 'fs'
noflo = require 'noflo'
split = require 'split'
class ReadFileStream extends noflo.Component
constructor: ->
@inPorts =
in: new noflo.Port()
@outPorts =
out: new noflo.Port()
(ns react-cljs.core
(:require-macros [reactjs.macros :refer [pure]])
(:require React [reactjs.core :as r]))
(enable-console-print!)
(declare render-ui)
(defn render-counter [id state cb]
(pure state