<commit_before>(function (window) {

var gamepadConfig = {
  axisThreshold: 0,
  indices: {
    'standard': {
      cursorX: 2,
      cursorY: 3,
      scrollX: 0,
      scrollY: 1,
      back: 9,
      forward: 8,
      vendor: 10,
      zoomIn: 5,
      zoomOut: 1
    },
    '46d-c216-Logitech Dual Action': {
      cursorX: 3,
      cursorY: 4,
      scrollX: 1,
      scrollY: 2,
      back: 8,
      forward: 9,
      vendor: null,
      zoomIn: 7,
      zoomOut: 6
    },
    '79-6-Generic   USB  Joystick': {
      cursorX: null,
      cursorY: null,
      scrollX: 3,
      scrollY: 2,
      back: 6,
      forward: 7,
      vendor: null,
      zoomIn: 9,
      zoomOut: 8
    },
    keyEvents: {
      vendor: {
        detail: {
          charCode: 0,
          key: 'Escape',
          keyCode: 27
        }
      }
    }
  }
};

var gamepads = new Gamepads(gamepadConfig);

gamepads.polling = false;

if (gamepads.gamepadsSupported) {
  gamepads.updateStatus = function () {
    gamepads.polling = true;
    gamepads.update();
    window.requestAnimationFrame(gamepads.updateStatus);
  };

  gamepads.cancelLoop = function () {
    gamepads.polling = false;

    if (gamepads.pollingInterval) {
      window.clearInterval(gamepads.pollingInterval);
    }

    window.cancelAnimationFrame(gamepads.updateStatus);
  };

  window.addEventListener('gamepadconnected', function (e) {
    console.log('Gamepad connected at index %d: %s. %d buttons, %d axes.',
      e.gamepad.index, e.gamepad.id, e.gamepad.buttons.length, e.gamepad.axes.length);

    gamepads.updateStatus();
  });

  window.addEventListener('gamepaddisconnected', function (e) {
    console.log('Gamepad removed at index %d: %s.', e.gamepad.index, e.gamepad.id);
  });

  if (gamepads.nonstandardEventsEnabled) {
    window.addEventListener('gamepadaxismove', function (e) {
      console.log('Gamepad axis move at index %d: %s. Axis: %d. Value: %f.',
        e.gamepad.index, e.gamepad.id, e.axis, e.value);
    });

    window.addEventListener('gamepadbuttondown', function (e) {
      console.log('Gamepad button down at index %d: %s. Button: %d.',
        e.gamepad.index, e.gamepad.id, e.button);
    });

    window.addEventListener('gamepadbuttonup', function (e) {
      console.log('Gamepad button up at index %d: %s. Button: %d.',
        e.gamepad.index, e.gamepad.id, e.button);
    });
  }

  if (gamepads.keyEventsEnabled) {
    window.addEventListener('keydown', function (e) {
      if (!e.gamepad) {
        return;
      }
      console.log('Keydown event from gamepad button down at index %d: %s. Button: %d. Key: %s. Key code: %d.',
        e.gamepad.index, e.gamepad.id, e.button, e.key || '?', e.keyCode);
    });

    window.addEventListener('keypress', function (e) {
      if (!e.gamepad) {
        return;
      }
      console.log('Keypress event from gamepad button down at index %d: %s. Button: %d. Key: %s. Key code: %d.',
        e.gamepad.index, e.gamepad.id, e.button, e.key || '?', e.keyCode);
    });

    window.addEventListener('keyup', function (e) {
      if (!e.gamepad) {
        return;
      }
      console.log('Keyup event from gamepad button down at index %d: %s. Button: %d. Key: %s. Key code: %d.',
        e.gamepad.index, e.gamepad.id, e.button, e.key || '?', e.keyCode);
    });
  }

  // At the time of this writing, Firefox and Chrome fire the `gamepadconnected` event.
  // If you wish to manually poll for the gamepads, you can do something like this:
  // 
  // ```js
  // var pollingInterval = window.setInterval(function () {
  //   if (gamepads.poll().length) {
  //     gamepads.updateStatus();
  //     window.clearInterval(pollingInterval);
  //   }
  // }, 100);
  // ```
}

window.gamepads = gamepads;

})(window);
<commit_msg>update demo code for `pollingInterval`<commit_after>(function (window) {

var gamepadConfig = {
  axisThreshold: 0,
  indices: {
    'standard': {
      cursorX: 2,
      cursorY: 3,
      scrollX: 0,
      scrollY: 1,
      back: 9,
      forward: 8,
      vendor: 10,
      zoomIn: 5,
      zoomOut: 1
    },
    '46d-c216-Logitech Dual Action': {
      cursorX: 3,
      cursorY: 4,
      scrollX: 1,
      scrollY: 2,
      back: 8,
      forward: 9,
      vendor: null,
      zoomIn: 7,
      zoomOut: 6
    },
    '79-6-Generic   USB  Joystick': {
      cursorX: null,
      cursorY: null,
      scrollX: 3,
      scrollY: 2,
      back: 6,
      forward: 7,
      vendor: null,
      zoomIn: 9,
      zoomOut: 8
    },
    keyEvents: {
      vendor: {
        detail: {
          charCode: 0,
          key: 'Escape',
          keyCode: 27
        }
      }
    }
  }
};

var gamepads = new Gamepads(gamepadConfig);

gamepads.polling = false;

if (gamepads.gamepadsSupported) {
  gamepads.updateStatus = function () {
    gamepads.polling = true;
    gamepads.update();
    window.requestAnimationFrame(gamepads.updateStatus);
  };

  gamepads.cancelLoop = function () {
    gamepads.polling = false;

    if (gamepads.pollingInterval) {
      window.clearInterval(gamepads.pollingInterval);
    }

    window.cancelAnimationFrame(gamepads.updateStatus);
  };

  window.addEventListener('gamepadconnected', function (e) {
    console.log('Gamepad connected at index %d: %s. %d buttons, %d axes.',
      e.gamepad.index, e.gamepad.id, e.gamepad.buttons.length, e.gamepad.axes.length);

    gamepads.updateStatus();
  });

  window.addEventListener('gamepaddisconnected', function (e) {
    console.log('Gamepad removed at index %d: %s.', e.gamepad.index, e.gamepad.id);
  });

  if (gamepads.nonstandardEventsEnabled) {
    window.addEventListener('gamepadaxismove', function (e) {
      console.log('Gamepad axis move at index %d: %s. Axis: %d. Value: %f.',
        e.gamepad.index, e.gamepad.id, e.axis, e.value);
    });

    window.addEventListener('gamepadbuttondown', function (e) {
      console.log('Gamepad button down at index %d: %s. Button: %d.',
        e.gamepad.index, e.gamepad.id, e.button);
    });

    window.addEventListener('gamepadbuttonup', function (e) {
      console.log('Gamepad button up at index %d: %s. Button: %d.',
        e.gamepad.index, e.gamepad.id, e.button);
    });
  }

  if (gamepads.keyEventsEnabled) {
    window.addEventListener('keydown', function (e) {
      if (!e.gamepad) {
        return;
      }
      console.log('Keydown event from gamepad button down at index %d: %s. Button: %d. Key: %s. Key code: %d.',
        e.gamepad.index, e.gamepad.id, e.button, e.key || '?', e.keyCode);
    });

    window.addEventListener('keypress', function (e) {
      if (!e.gamepad) {
        return;
      }
      console.log('Keypress event from gamepad button down at index %d: %s. Button: %d. Key: %s. Key code: %d.',
        e.gamepad.index, e.gamepad.id, e.button, e.key || '?', e.keyCode);
    });

    window.addEventListener('keyup', function (e) {
      if (!e.gamepad) {
        return;
      }
      console.log('Keyup event from gamepad button down at index %d: %s. Button: %d. Key: %s. Key code: %d.',
        e.gamepad.index, e.gamepad.id, e.button, e.key || '?', e.keyCode);
    });
  }

  // At the time of this writing, Firefox and Chrome fire the `gamepadconnected` event.
  // If you wish to manually poll for the gamepads, you can do something like this:
  // 
  // ```js
  // gamepads.pollingInterval = window.setInterval(function () {
  //   if (gamepads.poll().length) {
  //     gamepads.updateStatus();
  //     window.clearInterval(gamepads.pollingInterval);
  //   }
  // }, 100);
  // ```
}

window.gamepads = gamepads;

})(window);

{'fraction_non_alphanumeric': 0.15159117918922488, 'fraction_numerical': 0.010299749108675559, 'mean_word_length': 2.3903312444046554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3640780', 'n_tokens_mistral': 2710, 'n_tokens_neox': 2606, 'n_words': 611}