<commit_before>//I just spotted some minor things that could be cleaned up code-wise
//I don't have the time to write tests for this today, so code may be non-functional

var express = require('express'),
    twilio  = require('twilio'),
    router  = express.Router(),
    request = require('request'),
    cheerio = require('cheerio'),
    zlib    = require('zlib');

function padLeftTo(string, padChar, numChars) {
    'use strict';
    var padded = (new Array(numChars-string.length+1)).join(padChar) + string;
    return padded
}

function unicodeToBinary(char) {
    'use strict';
    var UTF_BITS = 8,
        binary = char.split('').map(function(codepoint) {
                return padLeftTo(codepoint.charCodeAt(0).toString(2), 0, UTF_BITS);
            }).join('');
    return binary;
    //         ^^^^( ignore this part if you just want a string )^^^^
}

function binaryToUnicode(binaryList) {
    'use strict';
    var codepointsAsNumbers = [],
        codepointBits,
        UTF_BITS = 8,
        unicode;
    while( binaryList.length>0 ){
        codepointBits = binaryList.slice(0,UTF_BITS);
        binaryList = binaryList.slice(UTF_BITS);
        codepointsAsNumbers.push( parseInt(codepointBits.join(''),2) );
    }
    
    unicode = String.fromCharCode.apply(this,codepointsAsNumbers);
    
    return unicode;
}

/* GET users listing. */
router.get('/', function(req, res) {
    'use strict';
  res.send('lolzard');
});

router.post('/sms', function(req, res) {
  'use strict';
  var resp = new twilio.TwimlResponse(),
      tURL = req.body.Body,
      msg = '';
      //msg was previously defined as a global. Not a good idea to have functions depend on
      //globals, so I put it in here. As far as I can see, this is the only function that needs
      //access to it. Strict mode also enforces that a function may never access a global
      //so if it gets put as a global, this script will throw an error because of security.
    
    function sendIt(temp, resp, sendItRes){
      var messages = new Array, slices = Math.ceil(temp.length/1594);
      
      for(var i=0;i<slices;i++){
        messages.push(i+' '+temp.substring(i*1594,(i*1594+1594)));
      }
    
      for(var j=0;j<messages.length;j++){
        resp.message(messages[j]);
      }
    
      res.sendItRes(resp.toString());
    }

  request(tURL, function (error, response, body) {
    var $ = cheerio.load(body);
    $('img').remove();
    $('head').remove();
    $('script').remove();
    $('link').remove();
    $('body').children().removeAttr('style');
    $('body').children().removeAttr('class');
    $('body').children().removeAttr('id');
    $('body').children().removeAttr('name');
    $('body').children().removeAttr('src');
    $('body').children().removeAttr('href');
    $('*').each(function() {      // iterate over all elements
        this[0].attribs = {};     // remove all attributes
    });
    msg = $('body').html()+'';

    zlib.gzip(msg, function(err, result) {
      var messageToSend = new Buffer(msg).toString('base64');
      
      if(err) {
        throw err;
      }
      sendIt(messageToSend, resp, res);
     }
    });
  });
});


module.exports = router;<commit_msg>fixing compile error<commit_after>//I just spotted some minor things that could be cleaned up code-wise
//I don't have the time to write tests for this today, so code may be non-functional

var express = require('express'),
    twilio  = require('twilio'),
    router  = express.Router(),
    request = require('request'),
    cheerio = require('cheerio'),
    zlib    = require('zlib');

function padLeftTo(string, padChar, numChars) {
    'use strict';
    var padded = (new Array(numChars-string.length+1)).join(padChar) + string;
    return padded
}

function unicodeToBinary(char) {
    'use strict';
    var UTF_BITS = 8,
        binary = char.split('').map(function(codepoint) {
                return padLeftTo(codepoint.charCodeAt(0).toString(2), 0, UTF_BITS);
            }).join('');
    return binary;
    //         ^^^^( ignore this part if you just want a string )^^^^
}

function binaryToUnicode(binaryList) {
    'use strict';
    var codepointsAsNumbers = [],
        codepointBits,
        UTF_BITS = 8,
        unicode;
    while( binaryList.length>0 ){
        codepointBits = binaryList.slice(0,UTF_BITS);
        binaryList = binaryList.slice(UTF_BITS);
        codepointsAsNumbers.push( parseInt(codepointBits.join(''),2) );
    }
    
    unicode = String.fromCharCode.apply(this,codepointsAsNumbers);
    
    return unicode;
}

/* GET users listing. */
router.get('/', function(req, res) {
    'use strict';
  res.send('lolzard');
});

router.post('/sms', function(req, res) {
  'use strict';
  var resp = new twilio.TwimlResponse(),
      tURL = req.body.Body,
      msg = '';
      //msg was previously defined as a global. Not a good idea to have functions depend on
      //globals, so I put it in here. As far as I can see, this is the only function that needs
      //access to it. Strict mode also enforces that a function may never access a global
      //so if it gets put as a global, this script will throw an error because of security.
    
    function sendIt(temp, resp, sendItRes){
      var messages = new Array, slices = Math.ceil(temp.length/1594);
      
      for(var i=0;i<slices;i++){
        messages.push(i+' '+temp.substring(i*1594,(i*1594+1594)));
      }
    
      for(var j=0;j<messages.length;j++){
        resp.message(messages[j]);
      }
    
      res.sendItRes(resp.toString());
    }

  request(tURL, function (error, response, body) {
    var $ = cheerio.load(body);
    $('img').remove();
    $('head').remove();
    $('script').remove();
    $('link').remove();
    $('body').children().removeAttr('style');
    $('body').children().removeAttr('class');
    $('body').children().removeAttr('id');
    $('body').children().removeAttr('name');
    $('body').children().removeAttr('src');
    $('body').children().removeAttr('href');
    $('*').each(function() {      // iterate over all elements
        this[0].attribs = {};     // remove all attributes
    });
    msg = $('body').html()+'';

    zlib.gzip(msg, function(err, result) {
      var messageToSend = new Buffer(msg).toString('base64');
      
      if(err) {
        throw err;
      }
      sendIt(messageToSend, resp, res);
    });
  });
});


module.exports = router;
{'fraction_non_alphanumeric': 0.16114410753360425, 'fraction_numerical': 0.009377930603313536, 'mean_word_length': 2.8111971411554495, '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': '3570171', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1995, 'n_words': 503}