<commit_before>$(function() {
  "use strict";
  
  var isEdge = /extras\/edge/.test(location.href);
  
  var srcFragment  = "try:";
  var $keyboard = $("#keyboard");
  
  var editor = ace.edit("editor");
  editor.setTheme("ace/theme/github");
  editor.setPrintMarginColumn(-1);
  editor.getSession().setTabSize(2);
  editor.getSession().setMode("ace/mode/coffee");
  editor.setSelectionStyle("text");
  
  var config = {};
  location.search.substr(1).split("&").forEach(function(kv) {
    var items = kv.split("=");
    if (items[0] != "") {
      var key   = items[0];
      var value = items[1];
      if (value == "false") {
        value = false;
      } else if (value == "true" || value == undefined) {
        value = true;
      } else if (!isNaN(+value)) {
        value = +value;
      }
      config[key] = value;
    }
  });
  
  var showKeyboard = function(code) {
    if (/Message\.on\(?\s*"keyboard"/.test(code)) {
      $keyboard.show(500);
    } else {
      $keyboard.hide(500);
    }
  };
  
  var cc = window.cc = new CoffeeCollider(config);
  cc.on("play", function() {
    viewer.start();
    $("#run").addClass("btn-danger");
    changeFavicon("play");
  });
  cc.on("pause", function() {
    viewer.stop();
    $("#run").removeClass("btn-danger");
    changeFavicon("pause");
  });
  
  var viewer = new WaveViewer(cc, document.getElementById("canvas"), {
    width:200, height:100, fillStyle:"#2c3e50", strokeStyle:"#f1c40f", lineWidth:2
  });
  
  var changeFavicon;
  if (isEdge) {
    changeFavicon = function(mode) {
      $("#favicon").attr({href:"../img/" + mode + ".gif"});
    };
  } else {
    changeFavicon = function(mode) {
      $("#favicon").attr({href:"./extras/img/" + mode + ".gif"});
    };
  }
  
  $("#run").on("click", function() {
    var code;
    if (isCoffee) {
      code = editor.getValue().trim();
    } else {
      code = coffeeSource;
    }
    cc.execute(code, function(res) {
      if (res !== undefined) {
        console.log(res);
      }
    }).play();
    showKeyboard(code);
  });
  
  $("#stop").on("click", function() {
    cc.reset().pause();
  });
  
  $("#link").on("click", function() {
    var code;
    if (isCoffee) {
      code = editor.getValue().trim();
    } else {
      code = coffeeSource;
    }
    window.location = "#" + srcFragment + encodeURIComponent(code);
  });
  
  $("a", "#example-list").each(function(i, a) {
    var $a = $(a);
    $a.on("click", function() {
      window.location = "#" + $(this).attr("data-path");
      return false;
    });
  });
  
  $("#version").text(cc.version);

  var isCoffee = true, coffeeSource = "";
  $("#compile").on("click", function() {
    var jsSource = "";
    isCoffee = !isCoffee;
    if (isCoffee) {
      editor.setReadOnly(false);
      editor.setValue(coffeeSource);
      editor.getSession().setMode("ace/mode/coffee");
    } else {
      coffeeSource = editor.getValue().trim();
      jsSource     = cc.compile(coffeeSource);
      editor.setValue(jsSource);
      editor.setReadOnly(true);
      editor.getSession().setMode("ace/mode/javascript");
    }
    editor.clearSelection();
  });
  
  window.onhashchange = function() {
    var hash = decodeURIComponent(location.hash.replace(/^#/, ""));
    var code;
    if (hash.indexOf(srcFragment) === 0) {
      code = hash.substr(srcFragment.length);
      editor.setValue(code);
      editor.clearSelection();
      showKeyboard(code);
    } else if (/.+\.coffee$/.test(hash)) {
      var path = "./examples/";
      if (isEdge) {
        path = "../../examples/";
      }
      $.get(path + hash).then(function(res) {
        code = res;
        editor.setValue(res);
        editor.clearSelection();<commit_msg>Added gistFragment<commit_after>$(function() {
  "use strict";
  
  var isEdge = /extras\/edge/.test(location.href);
  
  var srcFragment  = "try:";
  var gistFragment = "gist:";
  var $keyboard = $("#keyboard");
  
  var editor = ace.edit("editor");
  editor.setTheme("ace/theme/github");
  editor.setPrintMarginColumn(-1);
  editor.getSession().setTabSize(2);
  editor.getSession().setMode("ace/mode/coffee");
  editor.setSelectionStyle("text");
  
  var config = {};
  location.search.substr(1).split("&").forEach(function(kv) {
    var items = kv.split("=");
    if (items[0] != "") {
      var key   = items[0];
      var value = items[1];
      if (value == "false") {
        value = false;
      } else if (value == "true" || value == undefined) {
        value = true;
      } else if (!isNaN(+value)) {
        value = +value;
      }
      config[key] = value;
    }
  });
  
  var showKeyboard = function(code) {
    if (/Message\.on\(?\s*"keyboard"/.test(code)) {
      $keyboard.show(500);
    } else {
      $keyboard.hide(500);
    }
  };
  
  var cc = window.cc = new CoffeeCollider(config);
  cc.on("play", function() {
    viewer.start();
    $("#run").addClass("btn-danger");
    changeFavicon("play");
  });
  cc.on("pause", function() {
    viewer.stop();
    $("#run").removeClass("btn-danger");
    changeFavicon("pause");
  });
  
  var viewer = new WaveViewer(cc, document.getElementById("canvas"), {
    width:200, height:100, fillStyle:"#2c3e50", strokeStyle:"#f1c40f", lineWidth:2
  });
  
  var changeFavicon;
  if (isEdge) {
    changeFavicon = function(mode) {
      $("#favicon").attr({href:"../img/" + mode + ".gif"});
    };
  } else {
    changeFavicon = function(mode) {
      $("#favicon").attr({href:"./extras/img/" + mode + ".gif"});
    };
  }
  
  $("#run").on("click", function() {
    var code;
    if (isCoffee) {
      code = editor.getValue().trim();
    } else {
      code = coffeeSource;
    }
    cc.execute(code, function(res) {
      if (res !== undefined) {
        console.log(res);
      }
    }).play();
    showKeyboard(code);
  });
  
  $("#stop").on("click", function() {
    cc.reset().pause();
  });
  
  $("#link").on("click", function() {
    var code;
    if (isCoffee) {
      code = editor.getValue().trim();
    } else {
      code = coffeeSource;
    }
    window.location = "#" + srcFragment + encodeURIComponent(code);
  });
  
  $("a", "#example-list").each(function(i, a) {
    var $a = $(a);
    $a.on("click", function() {
      window.location = "#" + $(this).attr("data-path");
      return false;
    });
  });
  
  $("#version").text(cc.version);

  var isCoffee = true, coffeeSource = "";
  $("#compile").on("click", function() {
    var jsSource = "";
    isCoffee = !isCoffee;
    if (isCoffee) {
      editor.setReadOnly(false);
      editor.setValue(coffeeSource);
      editor.getSession().setMode("ace/mode/coffee");
    } else {
      coffeeSource = editor.getValue().trim();
      jsSource     = cc.compile(coffeeSource);
      editor.setValue(jsSource);
      editor.setReadOnly(true);
      editor.getSession().setMode("ace/mode/javascript");
    }
    editor.clearSelection();
  });
  
  window.onhashchange = function() {
    var hash = decodeURIComponent(location.hash.replace(/^#/, ""));
    var code, gistid, path;
    if (hash.indexOf(srcFragment) === 0) {
      code = hash.substr(srcFragment.length);
      editor.setValue(code);
      editor.clearSelection();
      showKeyboard(code);
    } else if (hash.indexOf(gistFragment) === 0) {
      gistid = hash.substr(gistFragment.length);
      $.ajax({
        url:"https://api.github.com/gists/" + gistid,
        type:"GET", dataType:"jsonp"
      }).success(function(data) {
        data = data.data.files;
        code = "";
        Object.keys(data).forEach(function(key) {
          if (data[key].language === "CoffeeScript") {
            code += data[key].content;
          }
        });
        editor.setValue(code);
        editor.clearSelection();
        editor.moveCursorTo(0, 0);
        editor.moveCursorToPosition(0);
        showKeyboard(code);
      });
    } else if (/.+\.coffee$/.test(hash)) {
      path = "./examples/";
      if (isEdge) {
        path = "../../examples/";
      }
      $.get(path + hash).then(function(res) {
        code = res;
        editor.setValue(code);
        editor.clearSelection();
{'fraction_non_alphanumeric': 0.20101434933201384, 'fraction_numerical': 0.007174666006927264, 'mean_word_length': 2.5569731632204133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6156068', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2719, 'n_words': 443}