Skip to content

Instantly share code, notes, and snippets.

@naholyr
naholyr / dafuq.md
Last active August 29, 2015 13:56
That one was nice

The bug

/*
  The model is something like:
  Person: { name: String }
  Car: { name: String, driver: {type: Schema.Types.ObjectId, ref: 'Person'} }
*/

// Somewhere we do this…
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)
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)
}]))
})
}
}
@naholyr
naholyr / editors.md
Last active August 29, 2015 14:05
Mon ressenti sur les éditeurs

Contexte

Pour du web (HTML/JS/CSS) + Node sous Ubuntu.

Actuellement : SublimeText, mais pas de visibilité sur le futur du projet (d'où recherche d'alternative).

Challengers

@naholyr
naholyr / index.js
Created September 8, 2014 15:20
My usual nconf wrapper
"use strict";
/**
Save as config/index.js
Config files =
- config/config.json
- config/config.$NODE_ENV.json
- config/config.$NODE_ENV.$USER.json
**/
@naholyr
naholyr / fixtures.js
Created September 8, 2014 15:26
My usual fixtures loader
// TODO comments (lol)
"use strict";
/**
Usage:
- Put your data in data.json
- Require from your test files `var fixtures = require('./path/to/fixtures')
- Load and clear with `before(fixtures.clear)`, `before(fixtures.load)`, `after(fixtures.clear)`
function defer () {
var _resolve, _reject;
var promise = new Promise(function (resolve, reject) {
_resolve = resolve;
_reject = reject;
});
return {
"promise": promise,
console.log(JSON.stringify(pathsToTree([
"a/b",
"a/c/d",
"e"
]), null, " "));
/*
{
"e": null,
"a": {
@naholyr
naholyr / README.md
Last active August 29, 2015 14:10
React trivial keys

See the discussion

Before (not good):

return <ul>{ paragraphs.map(p => <li>{ p }</li>) }</ul>;
// Each child in an array should have a unique "key" prop. Check the render method of RoomSpace. See http://fb.me/react-warning-keys for more information.

Uglier (not sure better):

@naholyr
naholyr / jeu.sh
Last active August 29, 2015 14:11
gnome-terminal --zoom=5 -e ~/bin/tts.sh