<commit_before>/**
 * Created by Awesome on 1/30/2016.
 */

    // use strict
'use strict';

// require dependencies
var os           = require ('os');
var path         = require ('path');
var http         = require ('http');
var child        = require ('child_process');
var debug        = require ('debug');
var colors       = require ('colors');
var express      = require ('express');
var cookieParser = require ('cookie-parser');
var bodyParser   = require ('body-parser');
var mongorito    = require ('mongorito');
var session      = require ('express-session');
var RedisStore   = require ('connect-redis') (session);
var portastic    = require ('portastic');

// require local dependencies
var config   = require (global.appRoot + '/config');
var view     = require (global.appRoot + '/bin/view');
var compiled = require (global.appRoot + '/cache/config.json');
var daemons  = require (global.appRoot + '/cache/daemons.json');

/**
 * build bootstrap class
 */
class bootstrap {
    /**
     * construct bootstrap class
     */
    constructor () {
        // bind variables
        this.app      = false;
        this.debugger = false;
        this.port     = false;
        this.server   = false;
        this.router   = false;

        // bind private variables
        this._ctrl   = {};
        this._daemon = {};

        // bind methods
        this.onError  = this.onError.bind (this);
        this.onListen = this.onListen.bind (this);

        // bind private methods
        this._getPort = this._getPort.bind (this);

        // bind registration methods
        this._register = [
            '_registerDebugger',
            '_registerDatabase'
        ];

        // bind and run register methods
        for (var i = 0; i < this._register.length; i ++) {
            this[this._register[i]] = this[this._register[i]].bind (this);
            this[this._register[i]] ();
        }

        // bind build methods
        this._build = [
            '_buildApp',
            '_buildLocals',
            '_buildServer',
            '_buildView',
            '_buildRouter',
            '_buildErrorHandler'
        ];

        // build app and server
        this._getPort ().then (() => {
            for (var i = 0; i < this._build.length; i ++) {
                this[this._build[i]] = this[this._build[i]].bind (this);
                this[this._build[i]] ();
            }

            // server events
            this.server.on ('error', this.onError);
            this.server.on ('listening', this.onListen);
        });
    }

    /*
     * REGISTER FUNCTIONS
     */

    /**
     * registers server debugger
     *
     * @private
     */
    _registerDebugger () {
        this.debugger = debug ('EdenFrame:server');
    }

    /**
     * registers mongodb database
     *
     * @private
     */
    _registerDatabase () {
        this.database = mongorito.connect (config.database[config.environment].host + '/' + config.database[config.environment].db);
    }

    /*
     * GET FUNCTIONS
     */

    /**
     * registers port
     *
     * @private
     */
    _getPort () {
        var that   = this;
        var length = config.threads ? config.threads : os.cpus ().length;
        var start  = parseInt ((process.env.PORT || config.port), 10);
        var end    = start + (length - 1);

        return new Promise ((resolve, reject) => {
            // find port
            portastic.find ({
                'min' : start,
                'max' : end
            }).then (ports => {
                // check if available port or exit
                if (!ports.length) {
                    process.exit();
                }

                // set port
                that.port = ports[0];

                // resolve
                resolve (true);

                // log
                that._log ('using port ' + that.port, 'bootstrap');
            });
        });
    }

    /*
     * BUILD FUNCTIONS
     */

    /**
     * builds app
     *
     * @private
     */
    _buildApp () {
        // create express app
        this.app = (this.app ? this.app : express ());
<commit_msg>complete port resolution in bootstrapper<commit_after>/**
 * Created by Awesome on 1/30/2016.
 */

    // use strict
'use strict';

// require dependencies
var os           = require ('os');
var path         = require ('path');
var http         = require ('http');
var child        = require ('child_process');
var debug        = require ('debug');
var colors       = require ('colors');
var express      = require ('express');
var cookieParser = require ('cookie-parser');
var bodyParser   = require ('body-parser');
var mongorito    = require ('mongorito');
var session      = require ('express-session');
var RedisStore   = require ('connect-redis') (session);
var portastic    = require ('portastic');

// require local dependencies
var config   = require (global.appRoot + '/config');
var view     = require (global.appRoot + '/bin/view');
var compiled = require (global.appRoot + '/cache/config.json');
var daemons  = require (global.appRoot + '/cache/daemons.json');

/**
 * build bootstrap class
 */
class bootstrap {
    /**
     * construct bootstrap class
     */
    constructor () {
        // bind variables
        this.app      = false;
        this.debugger = false;
        this.port     = false;
        this.server   = false;
        this.router   = false;

        // bind private variables
        this._ctrl   = {};

        // bind methods
        this.onError  = this.onError.bind (this);
        this.onListen = this.onListen.bind (this);

        // bind private methods
        this._getPort = this._getPort.bind (this);

        // bind registration methods
        this._register = [
            '_registerDebugger',
            '_registerDatabase'
        ];

        // bind and run register methods
        for (var i = 0; i < this._register.length; i ++) {
            this[this._register[i]] = this[this._register[i]].bind (this);
            this[this._register[i]] ();
        }

        // bind build methods
        this._build = [
            '_buildApp',
            '_buildLocals',
            '_buildServer',
            '_buildView',
            '_buildRouter',
            '_buildErrorHandler'
        ];

        // build app and server
        this._getPort ().then (() => {
            for (var i = 0; i < this._build.length; i ++) {
                this[this._build[i]] = this[this._build[i]].bind (this);
                this[this._build[i]] ();
            }

            // server events
            this.server.on ('error', this.onError);
            this.server.on ('listening', this.onListen);
        });
    }

    /*
     * REGISTER FUNCTIONS
     */

    /**
     * registers server debugger
     *
     * @private
     */
    _registerDebugger () {
        this.debugger = debug ('EdenFrame:server');
    }

    /**
     * registers mongodb database
     *
     * @private
     */
    _registerDatabase () {
        this.database = mongorito.connect (config.database[config.environment].host + '/' + config.database[config.environment].db);
    }

    /*
     * GET FUNCTIONS
     */

    /**
     * registers port
     *
     * @private
     */
    _getPort () {
        var that   = this;
        var length = config.threads ? config.threads : os.cpus ().length;
        var start  = parseInt ((process.env.PORT || config.port), 10);
        var end    = start + (length - 1);

        return new Promise ((resolve, reject) => {
            // find port
            portastic.find ({
                'min' : start,
                'max' : end
            }).then (ports => {
                // check if available port or exit
                if (!ports.length) {
                    process.exit();
                }

                // set port
                that.port = ports[0];

                // resolve
                resolve (that.port);

                // log
                that._log ('using port ' + that.port, 'bootstrap');
            });
        });
    }

    /*
     * BUILD FUNCTIONS
     */

    /**
     * builds app
     *
     * @private
     */
    _buildApp () {
        // create express app
        this.app = (this.app ? this.app : express ());

{'fraction_non_alphanumeric': 0.13662193205174708, 'fraction_numerical': 0.0031435134808366584, 'mean_word_length': 1.5296636085626911, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1150912', 'n_tokens_mistral': 2321, 'n_tokens_neox': 2218, 'n_words': 561}