<commit_before>const mongo = require('mongodb')
const http = require('http')

/** (mongo.db -> Promise) -> () */
exports.mongo = function (actions) {
    if (!Array.isArray(actions)) { actions = [actions] }
    return mongo.MongoClient
         .connect("mongodb://localhost:27017/hexode")
         .then(db => actions
            .reduce((p, action) => p.then(() => action(db)), Promise.resolve())
            .then(() => db.close())
            .catch(e => {
                db.close()
                return Promise.reject(e)
            }))
        .catch(Promise.reject)
}

/** Object -> Option(Object) -> Promise({ code, result }, error) */
exports.request = function (options, data) {
    const headers = Object.assign({
        'X-Requested-With': 'hexodeclient',
        'Content-Type': 'application/json'
    }, options && options.headers || {})

    options = Object.assign({
        hostname: 'localhost',
        port: 8080,
        method: 'GET'
    }, options, { headers })

    return new Promise((resolve, reject) => {
        const req = http.request(options, res => {
            var buf = ""
            res.setEncoding('utf8')
            res.on('data', b => { buf += b })
            res.on('end', () => {
                resolve({
                    code: res.statusCode,
                    result: JSON.parse(buf)
                })
            })
        })
        req.on('error', reject)
        ;['GET', 'DELETE'].indexOf(options.method) === -1 && data && req.write(JSON.stringify(data))
        req.end()
    })
}

exports.after = function (n, f) {
    return () => --n === 0 && f()
}<commit_msg>[patch] Hotfix ugly line in test utils<commit_after>const mongo = require('mongodb')
const http = require('http')

/** (mongo.db -> Promise) -> () */
exports.mongo = function (actions) {
    if (!Array.isArray(actions)) { actions = [actions] }
    return mongo.MongoClient
         .connect("mongodb://localhost:27017/hexode")
         .then(db => actions
            .reduce((p, action) => p.then(() => action(db)), Promise.resolve())
            .then(() => db.close())
            .catch(e => {
                db.close()
                return Promise.reject(e)
            }))
        .catch(Promise.reject)
}

/** Object -> Option(Object) -> Promise({ code, result }, error) */
exports.request = function (options, data) {
    const headers = Object.assign({
        'X-Requested-With': 'hexodeclient',
        'Content-Type': 'application/json'
    }, options && options.headers || {})

    options = Object.assign({
        hostname: 'localhost',
        port: 8080,
        method: 'GET'
    }, options, { headers })

    return new Promise((resolve, reject) => {
        const req = http.request(options, res => {
            var buf = ""
            res.setEncoding('utf8')
            res.on('data', b => { buf += b })
            res.on('end', () => {
                resolve({
                    code: res.statusCode,
                    result: JSON.parse(buf)
                })
            })
        })
        req.on('error', reject)
        if (['GET', 'DELETE'].indexOf(options.method) === -1 && data != null) {
            req.write(JSON.stringify(data))
        }
        req.end()
    })
}

exports.after = function (n, f) {
    return () => --n === 0 && f()
}
{'fraction_non_alphanumeric': 0.1802536231884058, 'fraction_numerical': 0.007246376811594203, 'mean_word_length': 1.8195744680851065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '2842400', 'n_tokens_mistral': 983, 'n_tokens_neox': 949, 'n_words': 204}