<commit_before>var  http = require('http')
    ,url = require('url')
    ,fs = require('fs')
    ,sys = require('sys')
    
var webserver = http.createServer(function (req, res) {
  res.writeHead(200, { "Content-Type": "text/plain" })
  res.end("Hello world\n");
});

webserver.listen(8082);
    
send404 = function(res){
  res.writeHead(404);
  res.write('404');
  res.end();
},

server = createChannel();
server.listen(8080);
bindEventHandlers(server);

// server.listen();
    
// socket.io, I choose you
// simplest chat application evar


function createChannel() {
	return http.createServer(function(req, res){
	  var path = url.parse(req.url).pathname;
		try {
			path = '/lib/socket.io-node/example' + path
			res.writeHead(200, {'Content-Type': 'text/html'});
			fs.readFile(__dirname + path, 'utf8', function(err, data){
				if (!err) res.write(data, 'utf8');
				res.end();
			});
		} catch(e){ 
			send404(res); 
		}
	});
}

function bindEventHandlers(server) {
	var socketIO = require('./lib/socket.io-node/lib/socket.io');
	var io = socketIO.listen(server),
	    buffer = [];

	io.on('connection', function(client){
	  client.send({ buffer: buffer });
	  client.broadcast({ announcement: client.sessionId + ' connected' });

	  client.on('message', function(message){
	    var msg = { message: [client.sessionId, message] };
	    buffer.push(msg);
	    if (buffer.length > 15) buffer.shift();
	    client.broadcast(msg);
	  });

	  client.on('disconnect', function(){
	    client.broadcast({ announcement: client.sessionId + ' disconnected' });
	  });
	});
}<commit_msg>more refactorings<commit_after>var  http = require('http')
    ,url = require('url')
    ,fs = require('fs')
    ,sys = require('sys')

// server.listen();
    
// socket.io, I choose you
// simplest chat application evar

Channel = function() {
	
	server = createChannel();
	server.listen(8080);
	bindEventHandlers(server);
	
	
	function createChannel() {
		return http.createServer(function(req, res){
		  var path = url.parse(req.url).pathname;
			try {
				path = '/lib/socket.io-node/example' + path
				res.writeHead(200, {'Content-Type': 'text/html'});
				fs.readFile(__dirname + path, 'utf8', function(err, data){
					if (!err) res.write(data, 'utf8');
					res.end();
				});
			} catch(e){ 
				send404(res); 
			}
		});
	}

	function bindEventHandlers(server) {
		var socketIO = require('./lib/socket.io-node/lib/socket.io');
		var io = socketIO.listen(server),
		    buffer = [];

		io.on('connection', function(client){
		  client.send({ buffer: buffer });
		  client.broadcast({ announcement: client.sessionId + ' connected' });

		  client.on('message', function(message){
		    var msg = { message: [client.sessionId, message] };
		    buffer.push(msg);
		    if (buffer.length > 15) buffer.shift();
		    client.broadcast(msg);
		  });

		  client.on('disconnect', function(){
		    client.broadcast({ announcement: client.sessionId + ' disconnected' });
		  });
		});
	}
	
	send404 = function(res){
	  res.writeHead(404);
	  res.write('404');
	  res.end();
	}
}


new Channel();
{'fraction_non_alphanumeric': 0.18397144711226476, 'fraction_numerical': 0.01719662556781311, 'mean_word_length': 3.4295977011494254, 'pattern_counts': {'":': 1, '<': 3, '<?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': '1827939', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1009, 'n_words': 198}