Skip to content

Instantly share code, notes, and snippets.

// Connect to a Mongo replica set using SSL through Mongoose and the power of love
var db = {
dsn: 'mongodb://db1:27017/DB_NAME,mongodb://db2:27017/DB_NAME,mongodb:db3:27017/DB_NAME',
options: {
replset: {
rs_name: 'rs0',
ssl: true,
sslCert: fs.readFileSync("/path/to/file.crt"),
sslKey: fs.readFileSync("/path/to/file.key"),
},
describe('Home', function () {
var HomeCtrl, $httpBackend;
beforeEach(angular.mock.module('app'));
beforeEach(angular.mock.inject(function ($controller, _$httpBackend_) {
$httpBackend = _$httpBackend_;
$httpBackend.when("GET", "/things.json")
.respond([4,5,6]);
var uniqueByProp = require("./unique-by-prop"),
assert = require("assert");
describe('Unique by prop', function () {
it('filter values based on identical property', function () {
var arr = [{x: 1}, {x: 1}, {x: 2}];
assert.deepEqual(uniqueByProp(arr, 'x'), [{x: 1}, {x: 2}]);
});
var uniqueByProp = require("./unique-by-props"),
assert = require("assert");
describe('Unique by props', function () {
it('filter values based on identical properties', function () {
var arr = [{x: 1, y: 1}, {x: 1, y: 1}, {x: 2, y: 2}, {x: 1, y: 2}];
assert.deepEqual(uniqueByProp(arr, ['x', 'y']), [{x: 1, y: 1}, {x: 2, y: 2}, {x: 1, y: 2}]);
});
_ = require('lodash');
exports._camelCaseObj = function (obj) {
return _.zipObject(_.map(_.keys(obj), _.camelCase), _.values(obj));
};
{
"name": "create-app",
"version": "0.0.0",
"main": "server.js",
"dependencies": {
"express": "^4.12.3",
},
"devDependencies": {
"supertest": "^0.15.0"
}
var deepExtend = require("deep-extend");
var config = {
local: {
port: process.env.PORT || 3000,
uri: "http://localhost:" + process.env.PORT || 3000,
apiThings: {
apiKey: process.env.APIKEY || "my test api key"
}
}
/**
* Exercise in consolidating common response handling using promises
* Duplicated code is on lines 34 and 68. How can we consolidate it?
*/
var http = require("http"),
express = require("express"),
errorFactory = require("error-factory"),
app = express(),
/**
* Error Factory does not allow (or do anything about)
* duplicate error definitions
*/
var assert = require("assert");
var errorFactory = require("error-factory");
var one = errorFactory("One", {value: "one"});
var two = errorFactory("Two", {value: "two"});
results = {};
queryRows.forEach(function (row) {
if (!results.hasOwnProperty(row.identifier)) {
results[row.identifier] = {
items: [],
};
}
results[row.identifier].items.push(row.itemName);