/*
The model is something like:
Person: { name: String }
Car: { name: String, driver: {type: Schema.Types.ObjectId, ref: 'Person'} }
*/
// Somewhere we do this…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrap (fn, args, thisArg) { | |
return function () { | |
return Promise(function (resolve, reject) { | |
fn.apply(thisArg, (args || []).concat([function (err, res) { | |
if (err) reject(err) | |
else resolve(res) | |
}])) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash') | |
var utils = require('./mongo-utils') | |
var docs = require('./random-fixtures')(50000) | |
var db = utils.connect('mongodb://localhost/test') | |
db | |
.then(utils.collection('articles')) | |
.then(utils.clear) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find -name '*.js'|grep -v '^./node_modules'|while read f;do if (head -n3 "$f"|grep -Fv 'use strict'>/dev/null);then echo "$f";sed -i -e '1i "use strict"\n' "$f";fi;done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 1 document in this collection | |
"Collection": [ | |
{"fieldName": "value", "dbRefField": {"$ref": "OtherCollection", "$idx": 0}} | |
// dbRefField == OtherCollection[0] once made available | |
], | |
// 2 documents in this collection | |
"OtherCollection": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I care about context | |
foo = obj.bar.bind(obj).partial(1, 2) | |
foo = obj.bar.bind(obj, 1, 2) | |
// I don't care about context | |
foo = bar.partial(1, 2) | |
foo = bar.bind(null, 1, 2) | |
// In one case, bind() wins obviously | |
// In the other case, partial() wins hardly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DEBUG = false; | |
var DEFAULT_NB_WORKERS = require('os').cpus().length; | |
var fork = require('child_process').fork; | |
var fs = require('fs'); | |
var path = require('path'); | |
if (process.argv.length == 2) console.error('Arguments: <file> [<nb-workers>]'), process.exit(1); | |
var file = path.resolve(process.argv[2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
// Here is a simple function that reads a file and makes something with its content | |
function readLog1 (cb) { | |
// Notice how I even gave a name to my callback, this is useful for stack traces, everyone says… | |
fs.readFile('file-not-found.log', function onRead1 (err, content) { | |
// Usual error handling | |
if (err) return cb(err); |
This may be a dumb solution, you'd better use $rootScope.$on(event, handler)
and $rootScope.$emit(event, args…)
and not use a third-party service.
My solution will bring you:
- support for
off()
if you really want to clean up your event handlers - maybe a conceptually better solution than using scopes, as with a service you make yourself independant from your view