Skip to content

Instantly share code, notes, and snippets.

@Sequoia
Sequoia / Agent.js
Created May 18, 2016 19:05
hasMany relationship
/**
* @return {Promise}
* @fulfill {Array} [{HomeActivityEvent}] array of digest sent events
*/
Agent.sendDigestToClients = function(id){
let recordid;
return Agent.findById(id)
.then(function(agent){
recordid = agent.id;
return agent;
@Sequoia
Sequoia / comment.md
Last active February 1, 2016 17:01
comment on nodejs/node

I'm just a developer not so much a core contributor so forgive me if I'm missing something, but I can't help but wonder:

  1. With the JS ecosystem evolving so rapidly, what happens when some other async flow-control pattern displaces promises in 6, 12, 18 months? Another semver major bump & major BC break?
  2. With respect to "If it ain't broke, don't fix it", what's "broke?" I love promises & use them all the time, Bluebird works great! Are all these BC breaks really just to avoid require('bluebird').promisifyAll(...)? I feel like I must be missing something cuz this seems like a lot of squeeze for very little juice.

From the non-core-dev peanut gallery: please don't make node core chase the latest API. The wild mix of approaches to handling async flow control exist because core doesn't pick a solution. Promises themselves have evolved quite a bit since Futures/Defereds hit the scene. If core had settled on the prevailing API of the the time (jquery/Q.deferred or whatever), a lot of this evolution might no

@Sequoia
Sequoia / change-indent.vim
Created January 22, 2016 19:37
switch between soft/hard 2/4 space tabs in vim
function! SetSoftTab(n)
"for changing tabstops
let &l:shiftwidth=a:n
let &l:softtabstop=a:n
let &l:expandtab=1
endfunction
function! SetHardTab()
let &l:expandtab=0
let &l:shiftwidth=4
@Sequoia
Sequoia / foo.js
Created January 21, 2016 18:13
Why doesn't this hit the callback for a2?
var express = require('express')
var a1 = express();
var a2 = express();
a1.listen(3000, function(err){
if(err){ console.error('a1 ERROR!!'); }
else{ console.log('Server a1 started on port 3000'); }
});
@Sequoia
Sequoia / route-test.js
Created January 21, 2016 17:39
testing express routing
var app = require('express')();
app.use('/admin',function(rq,rs){
rs.send('/admin');
});
app.use('/admin*',function(rq,rs){
rs.send('/admin*');
});
app.use('/admin/*',function(rq,rs){
rs.send('/admin/*');
@Sequoia
Sequoia / example.js
Created January 19, 2016 22:19
Lucky Middleware
var app = require('express')();
var luck = require('./luck-filter');
var prettyLucky = luck(0.6);
var reallyQuiteLucky = luck(0.9);
app.use('/blog', prettyLucky);
//bad luck is contagious; only allow luckiest of all users to contact you
app.use('/contact', prettyLucky);
@Sequoia
Sequoia / README.md
Last active November 7, 2019 04:02
Simulation to visualize event loop

Gif of the script running

Purpose

This is a little in-terminal ⚠️simulation⚠️ of blocking I/O + threads vs. non-blocking I/O + event loop. The purpose is to illustrate the different execution times visually.

Please remember it's a simulation and take it with a grain of salt. 😄

Install

  1. clone this gist: git clone https://gist.github.com/Sequoia/94d192908e05f7674423 eventloop-simulation
  2. cd eventloop-simulation
@Sequoia
Sequoia / common.js
Created December 10, 2015 19:36
some iterations on a compose function for JS
//stuff shared across many vs of compose
//util
const call = method => (...args) => obj => obj[method](...args);
let l = console.log.bind(console);
///
const compose = require(/*one of them*/);
//fs = [x, y, z];
//return a => x(y(z(a)));
@Sequoia
Sequoia / otherfile.js
Last active October 2, 2015 19:56
no idea whether this runs also use babel maybe
PollGh = require('./pollGh');
function handleRes(resBody){
//emit event ??
//write to another process?
//write to disk?
console.log(resBody);
}
function handleErr(err){
console.error(err);
@Sequoia
Sequoia / fib.js
Created August 21, 2015 23:13
different fibs
/* jshint esnext: true */
var input = parseInt(process.argv[2]);
var iterations = Number.isNaN(input) ? 10 : input;
console.log('%d iterations', iterations);
var fib = function(iter){
var state;
state = { curr: 1, last: 0 };
for(var i=0; i<iter-1; i++){
state = {