Skip to content

Instantly share code, notes, and snippets.

View ORESoftware's full-sized avatar
🏐
Focusing

Alexander Mills ORESoftware

🏐
Focusing
View GitHub Profile
@ORESoftware
ORESoftware / suman.conf.js
Created December 16, 2016 23:15
suman.conf.js in detail
// => The Suman config file; should always remain at the root of your project
// => If transpile is true, Suman will put your babel deps in ~/.suman/node_modules
// => When you first install Suman, Suman will write a directory called "suman" to your project root,
// it is best practice to simply move the "suman" directory inside your "test" directory,
// when you move the "suman" directory, you must update the "sumanHelpersDir" property below to reflect the path
// from the project root to the "sumanHelpersDir"
// suman.conf.js uses some core utilities, you can change this logic at will
@ORESoftware
ORESoftware / observable-array.js
Created December 18, 2016 21:58
Trying to make an observable array "stay open" so that future values in the array will be seen
const Rx = require('rx-lite');
const values = [1, 2, 3];
const obs = Rx.Observable.from(values);
obs.subscribe(
function onNext(result) {
console.log('item =>', result);
@ORESoftware
ORESoftware / enqueue.js
Last active January 14, 2017 03:10
the enqueue / enq method of an OPQ queue
// enqueues 1 or more items, accepting a string or an array of strings
enq(lines: string | Array<string>, opts: IEnqueueOpts): Observable<any> {
opts = opts || {};
if (opts.controlled) {
return this._enqControlled(lines, opts);
}
@ORESoftware
ORESoftware / new-obs.js
Last active January 16, 2017 04:12
simple observable creation
//import RxJS5
const Rx = require('rxjs');
// create an observable
// An observable is: "just a function that takes a subscriber and returns a function"
const obs = Rx.Observable.create(sub => {
@ORESoftware
ORESoftware / async-constructor.js
Last active January 14, 2017 03:53
An asynchronous constructor pattern
// asynchronous constructor example,
// like always do not explictly return anything from the constructor
function Queue(){
this.ready = false;
let callable = true;
let ee = new EE(); // new event emitter
// import opq
const Queue = require('opq');
// below we create a new client to the queue,
// and create the queue on the filesystem if it does
// not exist. the port is used by Live-Mutex;
// fp is our queue filepath
const q = new Queue({
const Rx = require('rxjs');
console.log(1);
new Promise(function(resolve,reject){
console.log(2);
resolve();
});
@ORESoftware
ORESoftware / obs-vs-promises-resolution.js
Last active January 14, 2017 04:21
Async or sync resolution?
console.log(1);
new Promise(function(resolve,reject){
console.log(2);
resolve();
}).then(function(val){
console.log(3);
});
@ORESoftware
ORESoftware / obs-vs-promise.js
Created January 14, 2017 04:38
Basic Promise vs. Observable
const {Observable} = require('rxjs');
function makeObs(){
const obs = Observable.create(sub => {
setTimeout(() => {
sub.next(3);
},500);
});
@ORESoftware
ORESoftware / obs-vs-streams.js
Last active January 16, 2017 03:45
Comparing Observables with Streams
const stream = require('stream');
function getReadableStream(fn) {
return new stream.Readable({
objectMode: true,