<commit_before>//======================================================
// File: server.js
// Descr: Nodejs server for Saving Nemo
// 
// Author: <NAME>
// Date: 2014-01-31
//======================================================
//======================================================
// Configuration
//======================================================
var os = require('os');
var version = "0.1";
var port = process.env.PORT || 8082;

//======================================================
// Initialization
//======================================================
var server = require("http");

var mysql = require('mysql');
var connection = undefined;

DBConnect();
connection.query('CREATE TABLE IF NOT EXISTS players (id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), name VARCHAR(13), score INT, clicks INT, date_played TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, host VARCHAR(50))', function(err, rows, fields) {
      if (err) throw err;
});
connection.end();


server = server.createServer(Handler);
//var io = require("socket.io").listen(server);
var webSocketServer = require('websocket').server;
var io = new webSocketServer({
  httpServer: server
});
io = io.on("request", SocketHandler);

var fs = require("fs");
var path = require("path");
var logger = require('util');
var sys = require('sys');
server.listen(port);



console.log("===================================");
console.log("Server for Saving Nemo");
console.log("Author: nergal");
console.log("Version: "+version);
console.log("===================================");
logger.log("Started server on port "+port);

//======================================================
//
// Server only stuff
//
//======================================================

function DBConnect() {
    var connurl = process.env.MYSQL_URI;
    if(connurl == undefined) {
        connection = mysql.createConnection({
            host: 'localhost',
            user: 'root',
            password: '<PASSWORD>',
            database: 'nemo'
        });
    } else {
        connection = mysql.createConnection(connurl);
    }
    connection.connect();
}

// Socket handler
function SocketHandler(request) {
    var socket = request.accept(null, request.origin);
    logger.log("Incoming connection from "+socket.remoteAddresses[0]);

    socket.on("message", OnMessage.bind(this, socket));
}

function OnMessage(sock, msg) {
    data = JSON.parse(msg.utf8Data);
    switch(data.type) {
        case "GetScore":
               GetScore(data, sock);
            break;
        case "SetScore": 
                SetScore(data, sock);<commit_msg>Convert for openshift<commit_after>//======================================================
// File: server.js
// Descr: Nodejs server for Saving Nemo
// 
// Author: <NAME>
// Date: 2014-01-31
//======================================================
//======================================================
// Configuration
//======================================================
var os = require('os');
var version = "0.1";
var port = process.env.PORT || 8082;

//======================================================
// Initialization
//======================================================
var server = require("http");

var mysql = require('mysql');
var connection = undefined;

DBConnect();
connection.query('CREATE TABLE IF NOT EXISTS players (id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), name VARCHAR(13), score INT, clicks INT, date_played TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, host VARCHAR(50))', function(err, rows, fields) {
      if (err) throw err;
});
connection.end();


server = server.createServer(Handler);
//var io = require("socket.io").listen(server);
var webSocketServer = require('websocket').server;
var io = new webSocketServer({
  httpServer: server
});
io = io.on("request", SocketHandler);

var fs = require("fs");
var path = require("path");
var logger = require('util');
var sys = require('sys');
server.listen(port);



console.log("===================================");
console.log("Server for Saving Nemo");
console.log("Author: nergal");
console.log("Version: "+version);
console.log("===================================");
logger.log("Started server on port "+port);

//======================================================
//
// Server only stuff
//
//======================================================

function DBConnect() {
    var connurl = process.env.MYSQL_URI;
    if(connurl == undefined) {
        console.log(process.env);
        connection = mysql.createConnection({
            host: process.env.MYSQL_SERVICE_HOST,
            user: process.env.MYSQL_USER,
            password: <PASSWORD>,
            database: process.env.MYSQL_DATABASE
        });
    } else {
        connection = mysql.createConnection(connurl);
    }
    connection.connect();
}

// Socket handler
function SocketHandler(request) {
    var socket = request.accept(null, request.origin);
    logger.log("Incoming connection from "+socket.remoteAddresses[0]);

    socket.on("message", OnMessage.bind(this, socket));
}

function OnMessage(sock, msg) {
    data = JSON.parse(msg.utf8Data);
    switch(data.type) {
        case "GetScore":
               GetScore(data, sock);
            break;
        case "SetScore": 
                SetScore(data, sock);
{'fraction_non_alphanumeric': 0.31328227162338873, 'fraction_numerical': 0.007472445357743321, 'mean_word_length': 4.3220675944334, 'pattern_counts': {'":': 4, '<': 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': '6756065', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1360, 'n_words': 344}