This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"), | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}]); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}]); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = require('lodash'); | |
exports._camelCaseObj = function (obj) { | |
return _.zipObject(_.map(_.keys(obj), _.camelCase), _.values(obj)); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "create-app", | |
"version": "0.0.0", | |
"main": "server.js", | |
"dependencies": { | |
"express": "^4.12.3", | |
}, | |
"devDependencies": { | |
"supertest": "^0.15.0" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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"}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results = {}; | |
queryRows.forEach(function (row) { | |
if (!results.hasOwnProperty(row.identifier)) { | |
results[row.identifier] = { | |
items: [], | |
}; | |
} | |
results[row.identifier].items.push(row.itemName); |