<commit_before>var timer = (function() {
  'use strict';

  var intervalIndex = 0;
  var timerInterval = config.workInterval;

  var intervals = [];
  var timer;

  var timerTick = function () {
    timerInterval--;

    if (config.debug) {
      console.log(intervals);
      console.log(intervalIndex + ' - ' + intervals[intervalIndex]);
      console.log(timerInterval);
    }

    if (timerInterval <= 0) {
      nextInterval();
    }

    views.timer.setTime(secondsToTime(timerInterval));
  };

  var nextInterval = function() {
    intervalIndex++;
    if (intervalIndex > intervals.length - 1) {
      intervalIndex = 0;
    }
    
    timerInterval = intervals[intervalIndex];
  };

  var addLeadingZero = function(number) {
    if (number < 10) {
      number = '0' + number;
    }

    return number;
  };

  var secondsToTime = function(seconds) {
    var minutes = Math.floor(seconds / 60);
    seconds = seconds % 60;

    return addLeadingZero(minutes) + ':' + addLeadingZero(seconds);
  };

  var startTimer = function() {
    timer = setInterval(timerTick, 1000);
  };

  var pauseTimer = function() {
    clearInterval(timer);
  };

  var resetTimer = function() {
    pauseTimer();

    intervalIndex = 0;
    timerInterval = config.workInterval;
    views.timer.setTime(secondsToTime(timerInterval));
  };

  var init = function () {
    views.timer.setTime(secondsToTime(timerInterval));

    for (var i = 0; i < config.repeat; i++) {
      intervals.push(config.workInterval);
      if (i < config.repeat - 1) {
        intervals.push(config.breakInterval);
      }
    }
    intervals.push(config.bigBreakInterval);

    startTimer();
<commit_msg>timer: only one instance of timer can run<commit_after>var timer = (function() {
  'use strict';

  var intervalIndex = 0;
  var timerInterval = config.workInterval;

  var intervals = [];
  var timer;

  var timerTick = function () {
    timerInterval--;

    if (config.debug) {
      console.log(intervals);
      console.log(intervalIndex + ' - ' + intervals[intervalIndex]);
      console.log(timerInterval);
    }

    if (timerInterval <= 0) {
      nextInterval();
    }

    views.timer.setTime(secondsToTime(timerInterval));
  };

  var nextInterval = function() {
    intervalIndex++;
    if (intervalIndex > intervals.length - 1) {
      intervalIndex = 0;
    }

    timerInterval = intervals[intervalIndex];
  };

  var addLeadingZero = function(number) {
    if (number < 10) {
      number = '0' + number;
    }

    return number;
  };

  var secondsToTime = function(seconds) {
    var minutes = Math.floor(seconds / 60);
    seconds = seconds % 60;

    return addLeadingZero(minutes) + ':' + addLeadingZero(seconds);
  };

  var startTimer = function() {
    if (!timer) {
      timer = setInterval(timerTick, 1000);
    }
  };

  var pauseTimer = function() {
    clearInterval(timer);
  };

  var resetTimer = function() {
    pauseTimer();

    intervalIndex = 0;
    timerInterval = config.workInterval;
    views.timer.setTime(secondsToTime(timerInterval));
  };

  var init = function () {
    views.timer.setTime(secondsToTime(timerInterval));

    for (var i = 0; i < config.repeat; i++) {
      intervals.push(config.workInterval);
      if (i < config.repeat - 1) {
        intervals.push(config.breakInterval);
      }
    }
    intervals.push(config.bigBreakInterval);

    startTimer();

{'fraction_non_alphanumeric': 0.13274336283185842, 'fraction_numerical': 0.010619469026548672, 'mean_word_length': 2.8186936936936937, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '1302794', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1016, 'n_words': 217}