<commit_before>###

Copyright (c) 2011-2012  Voicious

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU Affero General Public License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this
program. If not, see <http://www.gnu.org/licenses/>.

###

class   Utilities
    constructor         : () ->

    randNb              : () =>
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)

    generateRandomId    : () =>
        return (@randNb() + @randNb() + "-" + @randNb() + "-" + @randNb() +
                "-" + @randNb() + "-" + @randNb() + @randNb() + @randNb())

    splitString         : (str, len) =>
        size    = Math.ceil str.length / len 
        ret     = []
        lc      = 0

        for i in [0...size] by 1
            ret[i] = str.slice lc, lc += len

        return ret

    getMapSize          : (map) =>
        i = 0
        for key, val of map
            i++
        return i

U = Utilities

if window?
    window.Utilities    = new U
if exports?
    exports.Utilities   = new U<commit_msg>[DOC] Add documentation for src/frontend/utilities.coffee<commit_after>###

Copyright (c) 2011-2012  Voicious

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU Affero General Public License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this
program. If not, see <http://www.gnu.org/licenses/>.

###

# Contain useful functions.
class   Utilities
    constructor         : () ->

    # Generate a random number.
    randNb              : () =>
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)

    # Generate a random key.
    generateRandomId    : () =>
        return (@randNb() + @randNb() + "-" + @randNb() + "-" + @randNb() +
                "-" + @randNb() + "-" + @randNb() + @randNb() + @randNb())

    # Split a string by size and return an array of strings.
    splitString         : (str, len) =>
        size    = Math.ceil str.length / len 
        ret     = []
        lc      = 0

        for i in [0...size] by 1
            ret[i] = str.slice lc, lc += len

        return ret

    # Get the size of a map.
    getMapSize          : (map) =>
        i = 0
        for key, val of map
            i++
        return i

U = Utilities

if window?
    window.Utilities    = new U
if exports?
    exports.Utilities   = new U
{'fraction_non_alphanumeric': 0.1039650327817671, 'fraction_numerical': 0.014985950671245708, 'mean_word_length': 2.204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4713418', 'n_tokens_mistral': 963, 'n_tokens_neox': 906, 'n_words': 377}