Skip to content

Instantly share code, notes, and snippets.

View kyriesent's full-sized avatar

David Jsa kyriesent

View GitHub Profile
@kyriesent
kyriesent / What.md
Created November 20, 2014 16:52
Using Proxy Module instead of Globals

By using a common module (we can name it whatever we want), we make dependencies explicit, reduce unnecessary documentation, and avoid polluting the global namespace.

var acl = require('../routes/middleware/acl');
var mongoose = require('mongoose');
// var config = require('../libs/configurator'); don't need this
var config = require('../libs/configurator');
var async = require('async');
require('../models')(mongoose);
// mongoose.models.Works.find({}).exec(function (err, works) { <-- Work should be singular, as in below
mongoose.models.Work.find({}).exec(function (err, works) {
async.each(works, function (work, cb) {
map = function() {
return this.tagsL.forEach(function(tagL, i) {
return emit(tagL, 1);
});
};
reduce = function(k, vals) {
print (k)
print (vals)
return vals.length;
diffArray = (a, b, done) ->
u = {};
diff =
a: []
b: []
async.forEach b, (x, cb) ->
u[x] = true
cb()
, (err) ->
async.forEach a, (x, cb) ->
trendingTagsDayTags: [
itemId: 1234
tag: 'javascript'
d: 2/12/2013 # indexed
,
itemId: 1264
tag: 'javascript'
d: 2/11/2013
]
trendingTagsDay [
trendingTags: ['javascript', 'design', 'architecture']
date: 2/12/2013 1:00 pm
]
trendingTagsDayCounts [
tag: 'javascript'
c: 15
,
tag: 'design'
tagSchema:
tagL: String
c: Number
tagSchema.statics.recount, (done) ->
#use mongoose MapReduce to recount the tags and compile the numbers
Tag:
_id: ObjectId
tag: String #formal name of tag, i.e 'Javascript'
tagL:
type: String #lower case name of tag, i.e 'javascript'
index: true #important for performance when searching for tag data from tag name
Item:
_id: ObjectId
tags: [String] #array of informal names of tag, i.e 'jaVAsCripT'