<commit_before>
var stderr = require('system').stderr;
var stdin = require('system').stdin;

function write(obj) {
    stderr.write(JSON.stringify(obj) + "\n");
    if (obj.event !== "ack") read();
}

function read() {
    var data = stdin.readLine();
    try { data.split("\v").forEach(_read) } 
    catch (e) { throw new Error(data); }
}

function _read(data) { return _readLine(JSON.parse(data)); }
function _readLine(obj) {
    if (obj.event !== "ack") write({ event: "ack", message: obj });
    // TODO: invoke routes here
    // if (obj.event)
}

setInterval(function() {
    write({ "event" : "heartbeat" });
}, 1e2);

var page = require('webpage').create();
page.open("http://github.com", function(status) {
    if (status == "success") {
        write({ "event": "open" });
        // page.render('github.jpg');
        write({ "event": "render" });
    }
    phantom.exit();
});<commit_msg>completely refactored implementation of EventEmitting sleepyhollow<commit_after>
var EventEmitter = require('./EventEmitter.js');

var stderr = require('system').stderr;
var stdin = require('system').stdin;

(function(window) {
    "use strict";

    function _sleepyhollow() {

        // the modified event-emitter bridge
        var sleepyhollow = new EventEmitter();
        _emit = sleepyhollow.emit;
        sleepyhollow.emit = function(event, message) {
            if (event !== "ack") write({ event: event, message : message });
            _emit.apply(sleepyhollow, Array.prototype.slice.call(arguments, 0));
        }

        // custom write <> read bridge
        function write(obj) {
            stderr.write(JSON.stringify(obj) + "\n");
            if (obj.event !== "ack") read();
        }

        function read() {
            var data = stdin.readLine();
            try { data.split("\v").forEach(_read); }
            catch (e) { throw new Error(data); }
        }

        function _read(data) { return _readLine(JSON.parse(data)); }
        function _readLine(obj) {
            if (obj.event !== "ack") write({ event: "ack", message: obj });
            _emit.apply(sleepyhollow, [obj.event, obj.message]);
        }

        // minimal writing to make sure the Node side doesn't have to buffer
        setInterval(function() { write({ "event" : "syn" }); }, 1e2);

        return sleepyhollow;
    }

    return exports = (module || {}).exports = _sleepyhollow;

})(this);
{'fraction_non_alphanumeric': 0.1709045435598166, 'fraction_numerical': 0.0020842017507294707, 'mean_word_length': 2.6753445635528332, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, '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': '1228785', 'n_tokens_mistral': 743, 'n_tokens_neox': 719, 'n_words': 178}