<commit_before>function Storm(options) {

    if (!options || !options.object || !$(options.object).length) {
        throw new Error('required an object.');
    }
    this.storms = [];
    this.options = $.extend(this.defaultOptions, options);

}

Storm.prototype.defaultOptions = {
    spawners: 20,
    minDelay: 600,
    maxDelay: 800,
    minDuration: 200,
    maxDuration: 600
};

Storm.prototype.options = function(options, option) {
    if (typeof options === 'undefined') {
        return this.options;
    }
    var newOptions = this.options;
    if (typeof option === 'undefined' && typeof options === 'object') {
        $.extend(newOptions, options);
    } else if (typeof option !== 'undefined') {
        var v = {};
        v[options] = option;
        $.extend(newOptions, v);
    } else {
        throw TypeError('unexpected configuration');
    }
    if (this.validateOptions(newOptions)) {
        this.options = newOptions;
    } else {
        throw Error('invalid parameter');
    }
    return this;
};

Storm.prototype.validateOptions = function(options) {
    return (
        options &&
        (options.spawners === 'number' && options.spawners > 0 ) &&
        (options.minDelay === 'number' && options.minDelay >= 0 ) &&
        (options.maxDelay === 'number' && options.maxDelay >= 0 ) &&
        (options.minDelay <= options.maxDelay) &&
        (options.minDuration === 'number' && options.minDuration >= 0 ) &&
        (options.maxDuration === 'number' && options.maxDuration >= 0 ) &&
        (options.minDuration <= options.maxDuration) &&
        (options.object instanceof jQuery && options.object.length === 1)
    );
};

Storm.prototype.start = function() {
    if (this.storms.length || this.options.spawners < 0) {
        return this;
    }
    for (var i = 0; i < this.options.spawners; i++) {
        this.storms.push(this.generateSpawner());
    }
    return this;
};

Storm.prototype.generateSpawner = function(i) {

    if (typeof i === 'undefined') {
        i = this.storms.length;
    }

    var o = this.options;
    var element = $(o.object).first().clone()
        .appendTo($('body'));
    element
        .css({
            position: 'fixed',
            left: -1 * element.width(),
            top: this.rand(0, window.innerHeight)
        })
        .animate(
            { left: window.innerWidth },
            this.rand(o.minDuration, o.maxDuration),
            'linear',
            function() { element.remove(); }
        );
    var self = this;
    return window.setTimeout(function() {
        self.storms[i] = self.generateSpawner(i);
    }, this.rand(o.minDelay, o.maxDelay));

};

Storm.prototype.stop = function() {
    var storms = this.storms;
    this.storms = [];
    for (var i = 0; i < storms.length; i++) {
        window.clearInterval(storms[i]);
    }
    return this;
};

Storm.prototype.rand = function(min, max) {
    if (typeof min === 'undefined') min = 0;
    if (typeof max === 'undefined') max = 1;
    if (min > max) {
        throw new RangeError('requested invalid range');
    }
    return Math.floor(Math.random() * (max - min)) + min;
};<commit_msg>bug: clearInterval on a timeout<commit_after>function Storm(options) {

    if (!options || !options.object || !$(options.object).length) {
        throw new Error('required an object.');
    }
    this.storms = [];
    this.options = $.extend(this.defaultOptions, options);

}

Storm.prototype.defaultOptions = {
    spawners: 20,
    minDelay: 600,
    maxDelay: 800,
    minDuration: 200,
    maxDuration: 600
};

Storm.prototype.options = function(options, option) {
    if (typeof options === 'undefined') {
        return this.options;
    }
    var newOptions = this.options;
    if (typeof option === 'undefined' && typeof options === 'object') {
        $.extend(newOptions, options);
    } else if (typeof option !== 'undefined') {
        var v = {};
        v[options] = option;
        $.extend(newOptions, v);
    } else {
        throw TypeError('unexpected configuration');
    }
    if (this.validateOptions(newOptions)) {
        this.options = newOptions;
    } else {
        throw Error('invalid parameter');
    }
    return this;
};

Storm.prototype.validateOptions = function(options) {
    return (
        options &&
        (options.spawners === 'number' && options.spawners > 0 ) &&
        (options.minDelay === 'number' && options.minDelay >= 0 ) &&
        (options.maxDelay === 'number' && options.maxDelay >= 0 ) &&
        (options.minDelay <= options.maxDelay) &&
        (options.minDuration === 'number' && options.minDuration >= 0 ) &&
        (options.maxDuration === 'number' && options.maxDuration >= 0 ) &&
        (options.minDuration <= options.maxDuration) &&
        (options.object instanceof jQuery && options.object.length === 1)
    );
};

Storm.prototype.start = function() {
    if (this.storms.length || this.options.spawners < 0) {
        return this;
    }
    for (var i = 0; i < this.options.spawners; i++) {
        this.storms.push(this.generateSpawner());
    }
    return this;
};

Storm.prototype.generateSpawner = function(i) {

    if (typeof i === 'undefined') {
        i = this.storms.length;
    }

    var o = this.options;
    var element = $(o.object).first().clone()
        .appendTo($('body'));
    element
        .css({
            position: 'fixed',
            left: -1 * element.width(),
            top: this.rand(0, window.innerHeight)
        })
        .animate(
            { left: window.innerWidth },
            this.rand(o.minDuration, o.maxDuration),
            'linear',
            function() { element.remove(); }
        );
    var self = this;
    return window.setTimeout(function() {
        self.storms[i] = self.generateSpawner(i);
    }, this.rand(o.minDelay, o.maxDelay));

};

Storm.prototype.stop = function() {
    var storms = this.storms;
    this.storms = [];
    for (var i = 0; i < storms.length; i++) {
        window.clearTimeout(storms[i]);
    }
    return this;
};

Storm.prototype.rand = function(min, max) {
    if (typeof min === 'undefined') min = 0;
    if (typeof max === 'undefined') max = 1;
    if (min > max) {
        throw new RangeError('requested invalid range');
    }
    return Math.floor(Math.random() * (max - min)) + min;
};
{'fraction_non_alphanumeric': 0.1610855419774639, 'fraction_numerical': 0.00857006824313601, 'mean_word_length': 2.382716049382716, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '1915149', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1908, 'n_words': 422}