Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
// Q sample by Jeff Cogswell | |
/*=========== | |
We want to call these three functions in sequence, one after the other: | |
First we want to call one, which initiates an ajax call. Once that | |
ajax call is complete, we want to call two. Once two's ajax call is | |
complete, we want to call three. | |
BUT, we don't want to just call our three functions in sequence, as this quick |
var a = "one"; | |
var obj = { | |
a:"two", | |
b: { | |
a:"three", | |
fn: function(){ | |
return this.a; | |
} | |
} | |
} |
'use strict'; | |
var arr = ['nat', 'gat', 'bat']; | |
var arr2 = ['dd','bb', ...arr]; // spread | |
var [a, ...b] = arr; // rest | |
console.log(arr2); // ["dd", "bb", "nat", "gat", "bat"] | |
console.log(a); // nat | |
console.log(b); // ["gat", "bat"] |
function syncfunc(a, callbackfn){ | |
callbackfn("this is sync"); | |
} | |
syncfunc('temp', function(r){ console.log(r) }); | |
console.log("done sync func"); | |
function asyncfunc(a, callbackfn){ | |
process.nextTick( () => callbackfn("this is async") ); | |
} | |
asyncfunc('temp', function(r){ console.log(r) }); |
const arr = [1,2,3,4,5,6,7,8]; | |
Array.prototype.even = function(){ | |
let r = []; | |
r = this.filter( v => v % 2 == 0 ); | |
return r; | |
} | |
Array.prototype.odd = function(){ | |
let r = []; |
function fun1(){ | |
console.log('fun1 without cllback'); | |
} | |
function fun2(callback){ | |
console.log(callback('fun2 with callback')); | |
} | |
function fun3(callback){ | |
process.nextTick(() => console.log(callback('fun3 with callback + next tick'))); | |
} | |
console.log('1 '); |
var http = require('http'); | |
http.createServer(function(req, res) { | |
var externalReq = http.request({ | |
hostname: "www.google.com", | |
path: "/images/srpr/logo11w.png" | |
}, function(externalRes) { | |
res.setHeader("content-disposition", "attachment; filename=logo.png"); | |
externalRes.pipe(res); | |
}); |
var express = require('express') | |
, mongoskin = require('mongoskin') | |
var app = express() | |
app.use(express.bodyParser()) | |
var db = mongoskin.db('localhost:27017/test', {safe:true}); | |
app.param('collectionName', function(req, res, next, collectionName){ | |
req.collection = db.collection(collectionName) |
var express = require('express'); | |
var path = require('path'); | |
var favicon = require('serve-favicon'); | |
var logger = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); | |
var session = require('express-session'); | |
var validator = require('express-validator'); | |
var csrf = require('csurf'); |
Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/