Skip to content

Instantly share code, notes, and snippets.

var _ = require('underscore');
var util = require('util');
var colors = require('colors');
var moment = require('moment');
var logentries = require('node-logentries');
var sinon = require('sinon');
var log = logentries.logger({
token:process.env.LOGENTRIES_TOKEN
});
var async = require('async');
var ids = [];
var requestInfoTasks = ids.map(function (id) {
return function (callback) {
db.query(id, function (err, data) {
if (err) {
return callback(err);
}
@alexbeletsky
alexbeletsky / logger.js
Created January 22, 2014 10:51
Likeastore logger.
require('colors');
var util = require('util');
var moment = require('moment');
var logentries = require('node-logentries');
var config = require('../../config');
var stub = require('./stub');
var log = logentries.logger({
token: config.logentries.token,
@alexbeletsky
alexbeletsky / proc.js
Created March 22, 2014 13:23
Callbacks + Async
async.waterfall([
download,
process,
upload
], function (err, results) {
if (err) {
return console.error('processing failed, error: ', err);
}
console.log('processing completed, results: ', results);
});
@alexbeletsky
alexbeletsky / aggregate.js
Last active August 29, 2015 13:57
aggregate.js
function aggregate(callback) {
mongo.items.aggregate([
{
$match: {created: {$gte: timespan.from, $lt: timespan.to}}
},
{
$group: {
_id: {
url: '$source',
item: '$itemId'
@alexbeletsky
alexbeletsky / 1.js
Last active August 29, 2015 13:57
Which is better
// which is better?
function f() {
// returns object.. takes some cpu to complete
}
// this one?
return f().one || f().two;
// that one?
@alexbeletsky
alexbeletsky / collections.json
Created April 2, 2014 10:09
collections.json
/* 0 */
{
"_id" : ObjectId("533be1949421f7c070000007"),
"followers" : [
{
"_id" : ObjectId("533be1949421f7c070000005"),
"email" : "1396433300606@tests.com"
}
],
"public" : false,
@alexbeletsky
alexbeletsky / patch.js
Created May 1, 2014 09:29
Using streams for patching db
var _ = require('underscore');
var through = require('through');
var moment = require('moment');
var logger = require('../source/utils/logger');
var log = require('single-line-log');
function run(db, callback) {
var started = moment();
var patched = 0;
var request = require('request');
var testUtils = require('../utils');
var moment = require('moment');
var crypto = require('crypto');
describe('auth.spec.js', function () {
var authUrl, url, payload, error, response, body;
beforeEach(function () {
authUrl = testUtils.getRootUrl() + '/api/auth';
var config = require('../config');
var db = require('./db')(config);
function readUsers(callback) {
db.users.find({unsubscribed: {$exists: false}, firstTimeUser: {$exists: false}}).forEach(function (err, user) {
if (err) {
throw callback(err);
}
if (!user) {