<commit_before>var connect  = require('connect');
var mu       = require('mu');
var fs       = require('fs');

mu.root = __dirname + '/templates';
['single', 'multi', '404'].forEach(function(template) {
  mu.compile(template + '.html.mu', function(err, data) {
    if (err) { throw err; }
  });
});

var rawTests = {};

fs.readdir(__dirname + '/public/tests/', function(err, list) {
  list.sort().reverse().forEach(function(file) {
    rawTests[file.replace(/\.js/, '')] = fs.readFileSync(__dirname + '/public/tests/' + file, 'utf8');
  });
});

connect.createServer(
  connect.logger('dev'),
  connect.router(function(app) {
    app.get('/sounds/:sound.:format/redirect', function(req, res, next) {
      res.statusCode = 303;
      res.setHeader('Location', '/sounds/' + req.params.sound + '.' + req.params.format);
      res.end();
    });

    app.get('/sounds/:sound.:format/stall', function(req, res, next) {
      var audioStream = fs.createReadStream(__dirname + '/public/sounds/' + req.params.sound + '.' + req.params.format);
      res.statusCode = 200;
      audioStream.pipe(res);
      audioStream.pause();
      setTimeout(function() {
        audioStream.resume();
      }, 3500);
    });

    app.get('/:name', function(req, res, name) {
      var extension = (req.params.name.match(/\.(\w+)$/) || [,])[1];
      var testName  = req.params.name.replace(/\.\w+$/, '');

      if (!rawTests[testName]) {
        res.statusCode = 404;
        mu.render('404.html.mu').pipe(res);
      } else if (!extension) {
        var test = eval(rawTests[testName]);
        test.code = test.assert.toString().split('\n').slice(1).slice(0, -1).join('\n');
        test.js = rawTests[testName];

        res.statusCode = 200;
        mu.render('single.html.mu', test).pipe(res);
      } else if (extension === 'js') {<commit_msg>Fix server code for event-stall<commit_after>var connect  = require('connect');
var mu       = require('mu');
var fs       = require('fs');

mu.root = __dirname + '/templates';
['single', 'multi', '404'].forEach(function(template) {
  mu.compile(template + '.html.mu', function(err, data) {
    if (err) { throw err; }
  });
});

var rawTests = {};

fs.readdir(__dirname + '/public/tests/', function(err, list) {
  list.sort().reverse().forEach(function(file) {
    rawTests[file.replace(/\.js/, '')] = fs.readFileSync(__dirname + '/public/tests/' + file, 'utf8');
  });
});

connect.createServer(
  connect.logger('dev'),
  connect.router(function(app) {
    app.get('/sounds/:sound.:format/redirect', function(req, res, next) {
      res.statusCode = 303;
      res.setHeader('Location', '/sounds/' + req.params.sound + '.' + req.params.format);
      res.end();
    });

    app.get('/sounds/:sound.:format/stall', function(req, res, next) {
      var stream = fs.createReadStream(__dirname + '/public/sounds/' + req.params.sound + '.' + req.params.format);
      var stall = false;

      res.statusCode = 200;

      stream.on('data', function(chunk) {
        if (!stall) {
          res.write(chunk);
        }
      });

      stream.on('end', res.end);

      stall = true;
      setTimeout(function() {
        stall = false;
      }, 3100);
    });

    app.get('/:name', function(req, res, name) {
      var extension = (req.params.name.match(/\.(\w+)$/) || [,])[1];
      var testName  = req.params.name.replace(/\.\w+$/, '');

      if (!rawTests[testName]) {
        res.statusCode = 404;
        mu.render('404.html.mu').pipe(res);
      } else if (!extension) {
        var test = eval(rawTests[testName]);
        test.code = test.assert.toString().split('\n').slice(1).slice(0, -1).join('\n');
        test.js = rawTests[testName];

        res.statusCode = 200;
        mu.render('single.html.mu', test).pipe(res);
      } else if (extension === 'js') {
{'fraction_non_alphanumeric': 0.21173066806943713, 'fraction_numerical': 0.014203051025775907, 'mean_word_length': 2.7916251246261217, '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': '5271340', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1258, 'n_words': 217}