<commit_before>var express		= require('express');
var fs			= require('fs');
var io			= require('socket.io');
var crypto		= require('crypto');
var app			= express.createServer();
var staticDir	= express.static;
var io			= io.listen(app);
var path    = require('path');
var request = require('request');
var sanitizeHtml = require('sanitize-html');
var mkdirp  = require('mkdirp');
var sanitize = function(slideshow_content){
  return sanitizeHtml(slideshow_content, {
    allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img','section','h1','h2','aside','span']),
    allowedAttributes: {
      'h1': ['class','style'],
      'h2': ['class','style'],
      'h3': ['class','style'],
      'h4': ['class','style'],
      'h5': ['class','style'],
      'h6': ['class','style'],
      'p': ['class','style'],
      'div': ['class','style'],
      'ol': ['class','style'],
      'ul': ['class','style'],
      'li': ['class','style'],
      'pre': ['class','style'],
      'dl': ['class','style'],
      'dt': ['class','style'],
      'dd': ['class','style'],
      'table': ['class','style'],
      'tr': ['class','style'],
      'td': ['class','style'],
      'span': ['class','style'],
      'aside': ['class'],
      'code': ['class','style','contenteditable'],
      'a': ['href', 'name', 'target', 'style','class'],
      'img': ['src','class','style'],
      'section': ['data-markdown', 'id', 'data-state', 'data-transition', 'data-background-transition', 'data-background']
    }
})}

var opts = {
	port: process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080,
  ipAddr : process.env.IP_ADDR || process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0',
  web_host: process.env.REVEAL_WEB_HOST || process.env.OPENSHIFT_APP_DNS || 'localhost:8080',
  socket_host: process.env.REVEAL_SOCKET_HOST || process.env.REVEAL_WEB_HOST || process.env.OPENSHIFT_APP_DNS || 'localhost',
  socket_secret : process.env.REVEAL_SOCKET_SECRET,
  default_gist_id : process.env.DEFAULT_GIST || 'af84d40e58c5c2a908dd',
  theme : process.env.REVEAL_THEME || '60e54843de11a545897e',
  install_gist_themes : process.env.GIST_THEMES || "true",
  template_logo_text : process.env.TEMPLATE_LOGO_TEXT || "Launch on OpenShift",
  template_logo_img : process.env.TEMPLATE_LOGO_IMG || "img/launchbutton.svg",
  template_logo_url : process.env.TEMPLATE_LOGO_URL || "https://openshift.redhat.com/app/console/application_types/custom?name=slides&initial_git_url=https%3A%2F%2Fgithub.com/ryanj/gist-reveal.it.git&cartridges[]=nodejs-0.10",
  ga_tracker_key : process.env.GA_TRACKER,
  gh_client_secret : process.env.GH_CLIENT_SECRET,
  gh_client_id : process.env.GH_CLIENT_ID,
	baseDir : __dirname + '/../../'
};
var rate_limit_slides = require('./rate_limit_response.json');
var default_slides = require('./default_response.json');
var error_slides = require('./error_response.json');
var slideshow_template = fs.readFileSync(opts.baseDir + '/index.html');

var createHash = function(secret) {
	var cipher = crypto.createCipher('blowfish', secret);
	return(cipher.final('hex'));
};

app.configure(function() {
	[ 'css', 'js', 'plugin', 'lib', 'img' ].forEach(function(dir) {
		app.use('/' + dir, staticDir(opts.baseDir + dir));
	});
});

var ga_tracker_html = function(tracker_id, hostname){
  if(typeof(tracker_id) !== 'undefined'){
    return "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n" + 
    "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o)\n" + 
    "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,\n" + 
    "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n" + 
    "ga('create', '"+tracker_id+"', '"+hostname+"');\n" + 
    "ga('send', 'pageview');</script>";
  }else{
    return "";
  }
};

var render_slideshow = function(gist, theme, cb) {
  for(var i in gist.files){
    if( gist.files[i].type == "text/html" || gist.files[i].type.indexOf('image' < 0 ) ){
      var title = sanitize(i);
      var slides = sanitize(gist.files[i].content);
      var description = sanitize(gist.description);
      var user = gist.owner.login;
      break;
    }
  }
  get_theme(theme, function(themename){
    cb(slideshow_template.toString()
                           .replace(/\{\{slides}}/, slides)
                           .replace(/hosted: {}/, getClientConfig())
                           .replace(/\{\{title}}/, title)
                           .replace(/\/\/\{\{ga-tracker}}/, ga_tracker_html(opts.ga_tracker_key, opts.web_host))
                           .replace(/\{\{hostname}}/, opts.web_host)
                           .replace(/\{\{theme}}/, themename)
                           .replace(/\{\{template_logo_url}}/, opts.template_logo_url)
                           .replace(/\{\{template_logo_text}}/, opts.template_logo_text)
                           .replace(/\{\{template_logo_img}}/, opts.template_logo_img)
                           .replace(/\{\{user}}/, user)
                           .replace(/\{\{description}}/, description)<commit_msg>fixing GA tracker template<commit_after>var express		= require('express');
var fs			= require('fs');
var io			= require('socket.io');
var crypto		= require('crypto');
var app			= express.createServer();
var staticDir	= express.static;
var io			= io.listen(app);
var path    = require('path');
var request = require('request');
var sanitizeHtml = require('sanitize-html');
var mkdirp  = require('mkdirp');
var sanitize = function(slideshow_content){
  return sanitizeHtml(slideshow_content, {
    allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img','section','h1','h2','aside','span']),
    allowedAttributes: {
      'h1': ['class','style'],
      'h2': ['class','style'],
      'h3': ['class','style'],
      'h4': ['class','style'],
      'h5': ['class','style'],
      'h6': ['class','style'],
      'p': ['class','style'],
      'div': ['class','style'],
      'ol': ['class','style'],
      'ul': ['class','style'],
      'li': ['class','style'],
      'pre': ['class','style'],
      'dl': ['class','style'],
      'dt': ['class','style'],
      'dd': ['class','style'],
      'table': ['class','style'],
      'tr': ['class','style'],
      'td': ['class','style'],
      'span': ['class','style'],
      'aside': ['class'],
      'code': ['class','style','contenteditable'],
      'a': ['href', 'name', 'target', 'style','class'],
      'img': ['src','class','style'],
      'section': ['data-markdown', 'id', 'data-state', 'data-transition', 'data-background-transition', 'data-background']
    }
})}

var opts = {
	port: process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080,
  ipAddr : process.env.IP_ADDR || process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0',
  web_host: process.env.REVEAL_WEB_HOST || process.env.OPENSHIFT_APP_DNS || 'localhost:8080',
  socket_host: process.env.REVEAL_SOCKET_HOST || process.env.REVEAL_WEB_HOST || process.env.OPENSHIFT_APP_DNS || 'localhost',
  socket_secret : process.env.REVEAL_SOCKET_SECRET,
  default_gist_id : process.env.DEFAULT_GIST || 'af84d40e58c5c2a908dd',
  theme : process.env.REVEAL_THEME || '60e54843de11a545897e',
  install_gist_themes : process.env.GIST_THEMES || "true",
  template_logo_text : process.env.TEMPLATE_LOGO_TEXT || "Launch on OpenShift",
  template_logo_img : process.env.TEMPLATE_LOGO_IMG || "img/launchbutton.svg",
  template_logo_url : process.env.TEMPLATE_LOGO_URL || "https://openshift.redhat.com/app/console/application_types/custom?name=slides&initial_git_url=https%3A%2F%2Fgithub.com/ryanj/gist-reveal.it.git&cartridges[]=nodejs-0.10",
  ga_tracker_key : process.env.GA_TRACKER,
  gh_client_secret : process.env.GH_CLIENT_SECRET,
  gh_client_id : process.env.GH_CLIENT_ID,
	baseDir : __dirname + '/../../'
};
var rate_limit_slides = require('./rate_limit_response.json');
var default_slides = require('./default_response.json');
var error_slides = require('./error_response.json');
var slideshow_template = fs.readFileSync(opts.baseDir + '/index.html');

var createHash = function(secret) {
	var cipher = crypto.createCipher('blowfish', secret);
	return(cipher.final('hex'));
};

app.configure(function() {
	[ 'css', 'js', 'plugin', 'lib', 'img' ].forEach(function(dir) {
		app.use('/' + dir, staticDir(opts.baseDir + dir));
	});
});

var ga_tracker_html = function(tracker_id, hostname){
  if(typeof(tracker_id) !== 'undefined'){
    return "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n" + 
    "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n" + 
    "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n" + 
    "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n" + 
    "ga('create', '"+tracker_id+"', '"+hostname+"');\n" + 
    "ga('send', 'pageview');</script>";
  }else{
    return "";
  }
};

var render_slideshow = function(gist, theme, cb) {
  for(var i in gist.files){
    if( gist.files[i].type == "text/html" || gist.files[i].type.indexOf('image' < 0 ) ){
      var title = sanitize(i);
      var slides = sanitize(gist.files[i].content);
      var description = sanitize(gist.description);
      var user = gist.owner.login;
      break;
    }
  }
  get_theme(theme, function(themename){
    cb(slideshow_template.toString()
                           .replace(/\{\{slides}}/, slides)
                           .replace(/hosted: {}/, getClientConfig())
                           .replace(/\{\{title}}/, title)
                           .replace(/\/\/\{\{ga-tracker}}/, ga_tracker_html(opts.ga_tracker_key, opts.web_host))
                           .replace(/\{\{hostname}}/, opts.web_host)
                           .replace(/\{\{theme}}/, themename)
                           .replace(/\{\{template_logo_url}}/, opts.template_logo_url)
                           .replace(/\{\{template_logo_text}}/, opts.template_logo_text)
                           .replace(/\{\{template_logo_img}}/, opts.template_logo_img)
                           .replace(/\{\{user}}/, user)
                           .replace(/\{\{description}}/, description)
{'fraction_non_alphanumeric': 0.2070458571147412, 'fraction_numerical': 0.011021452469986223, 'mean_word_length': 3.4810405643738975, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '1035342', 'n_tokens_mistral': 3586, 'n_tokens_neox': 3499, 'n_words': 502}