<commit_before>requirejs(['fake_lag', 'server', 'client'], function (fakeLag, server, client) {
  "use strict";

  var withLag = fakeLag.withLag;

  server.start();

  var serverInterface = {
    connect: function (client) {
      var laggyClient = {
        ping: function () {
          withLag(function () {client.ping();});
        },
        state: function (s, p) {
          withLag(function () {client.state(s, p);});
        }
      };

      withLag(function () {server.connect(laggyClient);});
    },
    sendInput: function (input) {
      withLag(function () {server.receiveInput(input);});
    },
    pingBack: function () {
      withLag(function () {server.pingBack();});
    }
  };

  var client = new client.Client(
    30, // fps
    serverInterface);

  client.start();

  {
    var v = 1;
    serverInterface.connect({
      ping: function () {
        serverInterface.pingBack();
      },
      state: function (s, p) {
        // console.log(s);

        if (s.p[0] <= 0)
          v = 1;
        else if (s.p[0] >= 50)
          v = -1;
        serverInterface.sendInput({left: v < 0 ? 1 : 0, right: v > 0 ? 1 : 0});
      }
    });
  }

  document.getElementsByClassName('kill-server')[0].addEventListener('click', function () {
    server.stop();
  });
  document.getElementsByClassName('kill-client')[0].addEventListener('click', function () {
    client.stop();
  });
});<commit_msg>Extract laggy server interface<commit_after>requirejs(['fake_lag', 'server', 'client'], function (fakeLag, server, client) {
  "use strict";

  var withLag = fakeLag.withLag;

  server.start();

  var directServerInterface = {
    connect: function (client) {
      server.connect(client);
    },
    sendInput: function (input) {
      server.receiveInput(input);
    },
    pingBack: function () {
      server.pingBack();
    }
  };

  var laggify = function (delegate) {
    return {
      connect: function (client) {
        var laggyClient = {
          ping: function () {
            withLag(function () {client.ping();});
          },
          state: function (s, p) {
            withLag(function () {client.state(s, p);});
          }
        };

        withLag(function () {delegate.connect(laggyClient);});
      },
      sendInput: function (input) {
        withLag(function () {delegate.sendInput(input);});
      },
      pingBack: function () {
        withLag(function () {delegate.pingBack();});
      }
    };
  };
  var laggyServerInterface = laggify(directServerInterface);

  var client = new client.Client(
    30, // fps
    laggyServerInterface);

  client.start();

  {
    var v = 1;
    laggyServerInterface.connect({
      ping: function () {
        laggyServerInterface.pingBack();
      },
      state: function (s, p) {
        // console.log(s);

        if (s.p[0] <= 0)
          v = 1;
        else if (s.p[0] >= 50)
          v = -1;
        laggyServerInterface.sendInput({left: v < 0 ? 1 : 0, right: v > 0 ? 1 : 0});
      }
    });
  }

  document.getElementsByClassName('kill-server')[0].addEventListener('click', function () {
    server.stop();
  });
  document.getElementsByClassName('kill-client')[0].addEventListener('click', function () {
    client.stop();
  });
});
{'fraction_non_alphanumeric': 0.16774992262457444, 'fraction_numerical': 0.011142061281337047, 'mean_word_length': 2.3114754098360657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5585094', 'n_tokens_mistral': 1060, 'n_tokens_neox': 990, 'n_words': 200}