Skip to content

Instantly share code, notes, and snippets.

View wtfil's full-sized avatar

Evgen Filatov wtfil

  • London, UK
View GitHub Profile
{
get: {..},
routeMatches: [..],
res: instanceOfResponce
}
{
get: {..},
routeMatches: [..],
res: instanceOfResponce
}
@wtfil
wtfil / gist:6523011
Last active December 22, 2015 19:59
ES6 generator usage with co library
var co = require('co'),
fs = require('fs'),
read = co.wrap(fs.readdir);
co(function *(){
var users = yield read('/Users');
console.log(users);
});
@wtfil
wtfil / gist:6523125
Last active December 22, 2015 19:59
ES6 generators with "suspend" module
var suspend = require('suspend'),
fs = require('fs');
suspend(function *(resume){
var users = yield fs.readdir('/Users', resume);
console.log(users);
})();
@wtfil
wtfil / gist:6935834
Created October 11, 2013 14:40
Unique elements of array
function uniq(array) {
return array.filter(function (val, index) {
return array.indexOf(val) === index;
});
}
@wtfil
wtfil / gist:7626765
Created November 24, 2013 12:31
check generator support in javascript
var supported = true;
try {
eval('(function *() {})');
} catch (e) {
supported = false;
}
console.log(supported);
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo npm install -g npm
sudo apt-get install n
@wtfil
wtfil / gist:9619652
Last active August 29, 2015 13:57
Right way to extend Error
var CustomError = function(message, anotherField) {
this.message = message;
this.anotherField = anotherField;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, CustomError);
} else {
var e = new Error;
this.fileName = e.fileName;
this.lineNumber = e.lineNumber;
@wtfil
wtfil / gist:f9121c3b3171132bf960
Last active August 29, 2015 14:01
DelayStream
var Transform = require('stream').Transform,
http = require('http');
function DelayStream () {
Transform.apply(this, arguments);
}
DelayStream.prototype = Object.create(Transform.prototype);
DelayStream.prototype._transform = Transform.prototype.push;
@wtfil
wtfil / script.js
Created June 17, 2014 12:20
generators for async flow
var Promise = require('davy');
//get user as promise
function getUser() {
return new Promise(function (resolve) {
setTimeout(function () {
resolve('user name');
}, 1000);
});
}