<commit_before>/**
 * Singleton stuff adapted from http://afshinm.name/mongodb-singleton-connection-in-nodejs
 * 2014-5-28
 *
 * EventEmitter stuff adapted from qubyte at 
 * http://stackoverflow.com/questions/14058990/inheriting-node-js-eventemitter-fails
 * 2014-6-6
 */
var Db = require('mongodb').Db,
    Connection = require('mongodb').Connection,
    Server = require('mongodb').Server,
    util = require('util'),
    utils = require('gebo-utils'),
    EventEmitter = require('events').EventEmitter;

// Configuration
var nconf = require('nconf');
nconf.file({ file: 'gebo.json' });

// Logging
var winston = require('winston'),
    logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ colorize: true }) ] });

// The MongoDB connection
var connectionInstance;

// This module emits the native-connect event when
// successfully connected to mongo with the 
// native driver
exports = module.exports = new EventEmitter();

exports.get = function(testing, callback) {

    if (typeof testing === 'function') {
      callback = testing;
      testing = false;
    }

    // If we already have a connection, don't connect to the database again
    if (connectionInstance) {
      callback(connectionInstance);
      return;
    }

    var dbName = utils.getMongoDbName(nconf.get('email'));
    if (testing) {
      dbName = utils.getMongoDbName(nconf.get('testEmail'));
    }

    var db = new Db(dbName, new Server('localhost', Connection.DEFAULT_PORT, { auto_reconnect: true }), { safe: true });
    db.open(function(error, databaseConnection) {
        if (error) {
          logger.error('Native Mongo connection', error);
          throw new Error(error);
        }
        exports.emit('native-connect');
        connectionInstance = databaseConnection;
        logger.info('Successfully established native Mongo connection to:', 'mongodb://localhost/' + dbName);
        callback(databaseConnection);
    });
  };
<commit_msg>Emit connect signal after assigning instance variable<commit_after>/**
 * Singleton stuff adapted from http://afshinm.name/mongodb-singleton-connection-in-nodejs
 * 2014-5-28
 *
 * EventEmitter stuff adapted from qubyte at 
 * http://stackoverflow.com/questions/14058990/inheriting-node-js-eventemitter-fails
 * 2014-6-6
 */
var Db = require('mongodb').Db,
    Connection = require('mongodb').Connection,
    Server = require('mongodb').Server,
    util = require('util'),
    utils = require('gebo-utils'),
    EventEmitter = require('events').EventEmitter;

// Configuration
var nconf = require('nconf');
nconf.file({ file: 'gebo.json' });

// Logging
var winston = require('winston'),
    logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ colorize: true }) ] });

// The MongoDB connection
var connectionInstance;

// This module emits the native-connect event when
// successfully connected to mongo with the 
// native driver
exports = module.exports = new EventEmitter();

exports.get = function(testing, callback) {

    if (typeof testing === 'function') {
      callback = testing;
      testing = false;
    }

    // If we already have a connection, don't connect to the database again
    if (connectionInstance) {
      callback(connectionInstance);
      return;
    }

    var dbName = utils.getMongoDbName(nconf.get('email'));
    if (testing) {
      dbName = utils.getMongoDbName(nconf.get('testEmail'));
    }

    var db = new Db(dbName, new Server('localhost', Connection.DEFAULT_PORT, { auto_reconnect: true }), { safe: true });
    db.open(function(error, databaseConnection) {
        if (error) {
          logger.error('Native Mongo connection', error);
          throw new Error(error);
        }
        connectionInstance = databaseConnection;
        logger.info('Successfully established native Mongo connection to:', 'mongodb://localhost/' + dbName);
        exports.emit('native-connect');
        callback(databaseConnection);
    });
  };

{'fraction_non_alphanumeric': 0.1350125944584383, 'fraction_numerical': 0.01057934508816121, 'mean_word_length': 3.4368715083798884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2244027', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1121, 'n_words': 284}