<commit_before>var app = require("app");
var net = require("net");

console.log('Args:');
console.log(process.argv);

function arg(name) {
  for (var i = 0; i < process.argv.length; i++) {
    if (process.argv[i] == name) {
      return process.argv[i+1];
    }
  }
}

var server = net.createServer(function(c) { //'connection' listener
  c.on('end', function() {
    app.quit();
  });

  var buffer = [''];
  c.on('data', function(data) {
    str = data.toString();
    lines = str.split('\n');
    buffer[0] += lines[0];
    for (var i = 1; i < lines.length; i++)
      buffer[buffer.length] = lines[i];

    while (buffer.length > 1)
      line(buffer.shift());
  });

  function line(s) {
    data = JSON.parse(s);
    var result;
    if (data.type == "eval") {
      result = eval(data.code);
      if (data.callback) {
        result == undefined && (result = null);
        result = {type: 'callback', callback: data.callback, result: result};
        c.write(JSON.stringify(result));
      }
    } else {
      throw "No such command: " + data.type;
    }
  }
});

var port = parseInt(arg('port'));
server.listen(port, function() { //'listening' listener
  console.log('server bound: ' + port);
});

app.on("ready", function() {
  app.on('window-all-closed', function(e) {
  });
});
<commit_msg>allow custom handlers in atom-shell<commit_after>var app = require("app");
var net = require("net");

console.log('Args:');
console.log(process.argv);

function arg(name) {
  for (var i = 0; i < process.argv.length; i++) {
    if (process.argv[i] == name) {
      return process.argv[i+1];
    }
  }
}

var handlers = {};

handlers.eval = function(data, c) {
  var result = eval(data.code);
  if (data.callback) {
    result == undefined && (result = null);
    result = {type: 'callback', callback: data.callback, result: result};
    c.write(JSON.stringify(result));
  }
}

var server = net.createServer(function(c) { //'connection' listener
  c.on('end', function() {
    app.quit();
  });

  var buffer = [''];
  c.on('data', function(data) {
    str = data.toString();
    lines = str.split('\n');
    buffer[0] += lines[0];
    for (var i = 1; i < lines.length; i++)
      buffer[buffer.length] = lines[i];

    while (buffer.length > 1)
      line(buffer.shift());
  });

  function line(s) {
    data = JSON.parse(s);
    if (handlers.hasOwnProperty(data.type)) {
      handlers[data.type](data, c);
    } else {
      throw "No such command: " + data.type;
    }
  }
});

var port = parseInt(arg('port'));
server.listen(port, function() { //'listening' listener
  console.log('server bound: ' + port);
});

app.on("ready", function() {
  app.on('window-all-closed', function(e) {
  });
});

{'fraction_non_alphanumeric': 0.20244263508512214, 'fraction_numerical': 0.0044411547002220575, 'mean_word_length': 3.0223214285714284, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7422506', 'n_tokens_mistral': 947, 'n_tokens_neox': 937, 'n_words': 205}