Skip to content

Instantly share code, notes, and snippets.

var arr = new Array(100000);
for (var x = 0; x < arr.length; x++) {
arr[x] = 1;
}
console.time("for");
for (var x = 0; x < arr.length; x++) {
console.error(arr[x]);
}
console.timeEnd("for");
var express = require("express"),
nonAuthRouter = express.Router(),
authRouter = express.Router(),
app = express();
authRouter.use(function (req, res, next) {
console.log("This is a routers");
next();
});
reader.pipe(through(function (line) {
console.log(line.toString());
this.push(line);
})).pipe(outputFile);
outputFile.on("close", function (err) {
done(err, tmpFile);
});
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
var lorem = require('lorem-ipsum'),
exercise = require('workshopper-exercise')(),
filecheck = require('workshopper-exercise/filecheck'),
execute = require('workshopper-exercise/execute'),
comparestdout = require('workshopper-exercise/comparestdout'),
path = require("path"),
os = require("os"),
fs = require("fs"),
assert = require("assert"),
tmpFile = path.join(os.tmpDir(), "_generators-adventure_" + process.pid + ".txt");
async.parallel(userId.map(function (individualUserId) {
return createMindMessageQuery(individualUserId);
}, finalizeQueries);
function createMindMessageQuery(userId) {
return function (cb) {
MindMessage.find({userId: userId, "body.type": "pill_reminder"}, function (err, doc) {
if (err) {
cb(err)
}
// Functional serialized asynchronous recursion
(function serialRandomTimeout(x) {
if (x.value) {
setTimeout(function () {
console.log(x.value);
serialRandomTimeout(x.next)
}, Math.random() * 1000);
}
})([1,2,3].reduceRight(function (prev, next) {
prev.next = JSON.parse(JSON.stringify(prev));
// Pipe Couch query for consumption by client
db.get(document)
.pipe(JSONStream(["rows", true, "value"], function (row) {
row.special_property = createSpecialProperty(row);
return row;
})
.pipe(JSONStream.stringify())
.pipe(response);
@ajcrites
ajcrites / gist:754f40a853065fafe1b4
Last active August 29, 2015 14:06
JavaScript function overloading
function overloaded_function() {
if (1 === arguments.length) {
if (Array.isArray(arguments[0])) {
multi_function.apply(undefined, [].slice.call(arguments[0]));
}
else {
single_function(arguments[0]);
}
}
else {

The highly tentative Mobiquity JavaScript style guide

  1. 4 space soft tab
  2. Always use braces for conditionals/loops
  3. Opening brace follows conditional/loop closing paren, else is on same line
  4. No leading comma
  5. Always trailing comma (for array and object literals)
  6. gulp
  7. var declarations must be made before anything else within a given scope
  8. var varFunction = function () {} <- space between paren and brace