Skip to content

Instantly share code, notes, and snippets.

View wtfil's full-sized avatar

Evgen Filatov wtfil

  • London, UK
View GitHub Profile
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);
});
}
@wtfil
wtfil / command_line
Last active August 29, 2015 14:03
open page of current branch in browser
> ./open-remote.sh
@wtfil
wtfil / arduino-motors.ino
Created July 19, 2014 09:49
arduino-motors
#include <Servo.h>
int MOTOR_PIN = 9;
int MIN = 1000;
int MAX = 2000;
@wtfil
wtfil / index.js
Created May 4, 2015 10:38
promises
// nested
callA().then(function () {
return callB().then(function () {
return callC()
});
});
// equivalent
@wtfil
wtfil / index.js
Last active August 29, 2015 14:20
es6 destructuring
function someAction({x, y, z}) {
console.log('x:', x);
console.log('y:', y);
console.log('z:', z);
}
someAction({
y: 1,
z: 2
});
@wtfil
wtfil / gulpfile.js
Last active September 15, 2015 09:49
var browserify = require('browserify');
var watchify = require('watchify');
var gutil = require('gulp-util');
var fs = require('fs')
var files = {
js: {
src: 'path to src',
dst: 'path to dst'
}
{
get: {..},
routeMatches: [..],
res: instanceOfResponce
}