Skip to content

Instantly share code, notes, and snippets.

@A
A / app.js
Last active August 29, 2015 13:56
'use strict';
var http = require('http');
var app = http.createServer(function (req, res) {
if ('/foo' === req.url) {
setTimeout(function() {
res.writeHead(200);
res.write('foo');
res.end();
@A
A / r.js
Created February 11, 2014 19:58
.send({
session_key: session_key,
name: 'sup', // не работает еще
page: 1, // default value
per_page: 40, // default value
sort: {
create_at: -1,
users: 1 // не проверял
// Можно указывать и другие поля. Они передаются напрямую драйверу в .sort()
},
.post('/room/silence')
.send({
session_key: session_key,
room_id: room._id, // комната
user_id: otherTestUser._id, // кого заткнуть
finished: (+new Date() + 1000) // timestamp до какого времени активно
})
// socket
'service-message': {
@A
A / mongodb-request.js
Created February 23, 2014 12:01
Get the only one embed document by id from array of subdocuments.
Room.findOne({'chat._id': messageID, 'users': req.user._id}, {'chat.$': 1}, function (err, room) {
console.log(room); // {chat: MessageInstance};
});
Logger.prototype.getDate = function () {
var date = new Date();
return [
[
date.getFullYear(),
date.getMonth() + 1,
date.getDate()
].join('.'),
[
date.getHours(),
'use strict';
/**
* Module dependencies.
*/
var log = require('microlog')(module);
var config = require('nconf');
var express = require('express');
// End of dependencies.
exports.getDialogs = function () {
return function (req, res) {
var dialogs = [];
_getUsersInDialogs(req.user._id, function (err, users) {
users.forEach(function (user, key, all) {
_getCountAndLastMessageInDialog(req.user._id, user, function (err, lastMessage, unread) {
dialogs.push({user: user, last_message: lastMessage, unread:unread});
if (key === all.length - 1) {
res.json(200, {
data: {
module.exports = function () {
return function (req, res) {
var pageNum = req.params.pageNum |0;
var querySet = {};
querySet['pages.'+pageNum] = false;
Project
.update({_id: req.params.projectID, owner: req.user._id}, {$set: querySet})
.exec(function (err, updated) {
err
? res.json(500, {error: err.message})
module.exports = function () {
var ObjectId = mongoose.Schema.ObjectId;
return function (req, res) {
mongoose
.model('Project')
.aggregate({
'$match': {
'pages.texts._id': ObjectId(req.params.componentID)
}
})
@A
A / gist:9706432
Last active August 29, 2015 13:57
module.exports = function () {
var ObjectId = mongoose.Types.ObjectId;
return function (req, res) {
var type = capitalize(req.params.componentType);
var id = new ObjectId(req.params.componentID);
var matchQuery = {};
matchQuery['pages.' + map[type] + '._id'] = id;
Project.aggregate([
// Match documents
{ '$match': matchQuery },