Skip to content

Instantly share code, notes, and snippets.

// a list of useful queries for profiler analysis. Starting with the most basic.
// 2.4 compatible
//
// output explained:
//
{
"ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred
"op" : "query", // the operation type
"ns" : "game.players", // the db and collection
@vkprasadch
vkprasadch / stream.js
Created July 28, 2016 03:54 — forked from padenot/stream.js
How to serve media on node.js
var http = require('http');
var path = require('path');
var fs = require('fs');
var AUDIOFILE = "./audio.ogg";
function serveWithRanges(request, response, content) {
var range = request.headers.range;
var total = content.length;
var parts = range.replace(/bytes=/, "").split("-");
@vkprasadch
vkprasadch / 0_reuse_code.js
Created June 28, 2016 04:29
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@vkprasadch
vkprasadch / LoginController.js
Created May 25, 2016 09:51 — forked from psi-4ward/LoginController.js
Sails.JS JWT Auth
// controllers/LoginController.js
module.exports = {
index: function(req, res) {
var email = req.param('email');
var password = req.param('password');
// delay everthing to prevent bruteforce, dos and timing attacks
setTimeout(function() {
@vkprasadch
vkprasadch / useDeepPopulate.js
Created May 24, 2016 17:26 — forked from dinana/useDeepPopulate.js
Util Sails Service with PopulateDeep function
User.find(id).populate('preferences').exec(function (err, user) {
if(err) {
sails.log.error("ERR:", err);
}
sails.services['util'].populateDeep('user', user[0], 'preferences.nestedPreferences', function (err, newUser) {
if (err) {
sails.log.error("ERR:", err);
}
console.log(newUser);
});
@vkprasadch
vkprasadch / sails git stage porduction
Created May 23, 2016 13:57 — forked from funyx/sails git stage porduction
sails app production stage (Ubuntu 14+)
Follow the instructions