Skip to content

Instantly share code, notes, and snippets.

View phated's full-sized avatar
πŸ’°
Sponsor my open source work! https://github.com/sponsors/phated

Blaine Bublitz phated

πŸ’°
Sponsor my open source work! https://github.com/sponsors/phated
View GitHub Profile
@phated
phated / 01-fractal-weird-design.md
Created July 23, 2016 00:01 — forked from spion/01-fractal-weird-design.md
Node streams - a fractal of weird design

Node streams - a fractal of weird design

and a potential refactor that could fix that

This is a list of issues and confusions I've encountered with node streams, and things I wish were designed and implemented differently. If promise-streams is ever going to change to a design that doesn't build on top of node streams, this would be a list of mistakes to avoid

  1. enc parameter - Why is encoding always passed together with the data? It should be a separate concern. It doesn't even make sense in objectMode
  2. eventemitter base - There is no reason to use an uncomposable grab-bag of stringy events as a base
  3. relying on nextTick etc for execution order - This is very unreliable and causes all sorts of unpredictable rules for implementers which are not documented anywhere.
  4. no error propagation
@phated
phated / dont-end.js
Created July 7, 2016 22:13
Streams confusion
// This doesn't work because I use { end: false } but I need the fd
var fs = require('fs');
var outStream = fs.createWriteStream('out-file.txt');
outStream.once('finish', function() {
console.log('finish');
outStream.end();
});
@phated
phated / gulpfile.js
Last active April 19, 2018 06:36
Non-misinformed gulp browserify usage
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
gulp.task('js', function(){
return browserify('./entry.js', { debug: true, transform: ['reactify']})
.bundle().pipe(process.stdout);
});
@phated
phated / index.js
Created September 22, 2015 21:46
pathprefix
var rest = require('rest');
var pathPrefix = require('rest/interceptor/pathPrefix');
var client = rest.wrap(pathPrefix, { prefix: 'http://example.com/' });
// will request from `http://example.com//something`
client({ path: '/something' }).then(console.log.bind(console));
@phated
phated / test.js
Created July 19, 2015 06:05
electron tests
it('does window things', function(done){
window.onhashchange = function(){
console.log('change!');
window.onhashchange = undefined;
done();
};
window.location.href = '#change';
});
@phated
phated / 1.good.js
Last active August 29, 2015 14:16
Idiomatic React - Rule #1: Don't generate children; Always forward them.
/*
List is an abstract React component for building lists.
Think of it like a wrapper around <ul> or <ol>
*/
var List = require('custom-components/list');
/*
ListItem is an abstract React component for adding items to the List component.
Think of this like a <li> that might have styling, classes, etc to work nicer in the List.
*/
var ListItem = require('custom-components/list-item');
@phated
phated / Quimby.md
Last active August 29, 2015 14:11 — forked from jasonpincin/Quimby.md

Quimby

Quimby is Walmart's service layer for mobile clients' configuration, CMS, a-b testing setup, and a few other sundry related services. It stitches together a constellation of data sources into a concise menu of API calls that mobile clients make to intialize and configure themselves.

Quimby is a REST service layer based upon the Gogo micro-service framework that we in turn built with Node.js, Hapi, Zookeeper, and Redis. Gogo is able to expose an array of web servers as a single host, and offers the ability to isolate tasks into smaller focused processes, emphasizing scalability and failure recovery. For example, a failure in any micro-service will not affect the life cycle of a request. Gogo also offers the additional features required to build distributed services with shared state, such as leader election.

Quimby components

  • Penny (part of Gogo) - The micro-service router, responsible for pairing a request with a servicer
@phated
phated / gulpfile.js
Last active August 29, 2015 14:10
gulp4 gulpfile.js
var path = require('path');
var gulp = require('gulp-next');
var gulpif = require('gulp-if');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var es = require('event-stream');
var webpack = require('webpack');
var sweetjs = require('gulp-sweetjs');
var regenerator = require('gulp-regenerator');
var rename = require('gulp-rename');
$ gulp-next -T
[21:22:57] Tasks for ~/test/jlongster-rebuild/gulpfile.js
[21:22:57] β”œβ”€β”¬ webpack
[21:22:57] β”‚ └─┬ series
[21:22:57] β”‚ β”œβ”€β”€ <anonymous>
[21:22:57] β”‚ └── <anonymous>
[21:22:57] β”œβ”€β”€ regenerate
[21:22:57] β”œβ”€β”€ src
[21:22:57] β”œβ”€β”€ bin
[21:22:57] β”œβ”€β”€ watch
@phated
phated / index.js
Last active August 29, 2015 14:05
when.join antipattern?
var promise1 = require('./promise1');
var promise2 = require('./promise2');
var promise3 = require('./promise3');
promise1()
.then(promise2)
.spread(promise3)