<commit_before>// Copyright (C) 2011 - Texas Instruments, <NAME> 
//
// 
var fs = require('fs');
var child_process = require('child_process');
var http = require('http');
var url = require('url');
var path = require('path');
var winston = require('winston');
var b = require('../bonescript');
var socketio = require('socket.io');
var express = require('express');

myrequire('systemd', function() {
    winston.debug("Startup as socket-activated service under systemd not enabled");
});

var port = (process.env.LISTEN_PID > 0) ? 'systemd' : 80;
listen(port, '/usr/share/beaglebone-getting-started');

function listen(port, directory) {
    var app = express();
    app.use(express.favicon());
    app.use(express.logger('dev'));
    app.use(express.directory(directory));
    app.use(express.static(directory));
    var server = http.createServer(app);
    addSocketListeners(server);
    server.listen(port);
}

function handler(req, res) {
    var parsedUrl = url.parse(req.url);
    var uri = parsedUrl.pathname;
    var host = 'http://' + req.headers['host'];
    if(uri == '/bonescript.js') {
        function sendFile(err, file) {
            if(err) {
                res.writeHead(500, {"Content-Type": "text/plain"});
                res.write(err + "\n");
                res.end();
                return;
            }
            res.writeHead(200, {"Content-Type": "text/javascript"});
            file = file.replace(/___INSERT_HOST___/, host);
            res.write(file);
            res.end();
        }
        fs.readFile('bonescript.js', 'utf8', sendFile);
    }
}

function addSocketListeners(server) {
    var io = socketio.listen(server);
    io.set('log level', 2);
    winston.debug('Listening for new socket.io clients');
    io.sockets.on('connection', onconnect);
    function onconnect(socket) {
        winston.debug('Client connected');

        // on disconnect
        socket.on('disconnect', function() {
            winston.debug('Client disconnected');
        });

        var shell = spawn(socket);

        for(var i in b) {
            var m = {};
            m.module = 'bonescript';
            m.data = {};
            m.data.name = i;<commit_msg>server.js: enable index.html and bonescript.js to be served up<commit_after>// Copyright (C) 2011 - Texas Instruments, <NAME> 
//
// 
var fs = require('fs');
var child_process = require('child_process');
var http = require('http');
var url = require('url');
var path = require('path');
var winston = require('winston');
var b = require('../bonescript');
var socketio = require('socket.io');
var express = require('express');

myrequire('systemd', function() {
    winston.debug("Startup as socket-activated service under systemd not enabled");
});

var port = (process.env.LISTEN_PID > 0) ? 'systemd' : 80;
listen(port, '/usr/share/beaglebone-getting-started/Docs');

function listen(port, directory) {
    var app = express();
    app.use(express.logger('dev'));
    app.use(express.favicon());
    app.get('/bonescript.js', handler);
    app.use(express.static(directory));
    var server = http.createServer(app);
    addSocketListeners(server);
    server.listen(port);
}

function handler(req, res) {
    var parsedUrl = url.parse(req.url);
    var uri = parsedUrl.pathname;
    var host = 'http://' + req.headers['host'];
    if(uri == '/bonescript.js') {
        fs.readFile('bonescript.js', 'utf8', sendFile);
        function sendFile(err, file) {
            if(err) {
                res.writeHead(500, {"Content-Type": "text/plain"});
                res.end(err + '\n');
                return;
            }
            res.setHeader('Content-Type', 'text/javascript');
            file = file.replace(/___INSERT_HOST___/, host);
            res.end(file);
        }
    }
}

function addSocketListeners(server) {
    var io = socketio.listen(server);
    io.set('log level', 2);
    winston.debug('Listening for new socket.io clients');
    io.sockets.on('connection', onconnect);
    function onconnect(socket) {
        winston.debug('Client connected');

        // on disconnect
        socket.on('disconnect', function() {
            winston.debug('Client disconnected');
        });

        var shell = spawn(socket);

        for(var i in b) {
            var m = {};
            m.module = 'bonescript';
            m.data = {};
            m.data.name = i;
{'fraction_non_alphanumeric': 0.16369455875628716, 'fraction_numerical': 0.006172839506172839, 'mean_word_length': 2.603789126853377, 'pattern_counts': {'":': 3, '<': 5, '<?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': '4131316', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1298, 'n_words': 291}