<commit_before>/* https://github.com/williame/barebones.js project

Contains a basic web-worker wrapper.  You can also instansiate it in the browser page thread too if you choose,
which may simplify debugging or for browsers that do not support web workers.

* You make the game() function do whatever you like e.g. create a UIViewport control
  to draw a 3D scene in

BSD LICENSE:

Copyright (c) 2013, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

function isOnGithubPages() {
	return window.location.hostname.indexOf(".github.") > 0;
}

function isOnFileSystem() {
	return "file:" === window.location.protocol;
}

function isLocalHost() {
	return isOnFileSystem() || window.location.hostname == "localhost";
}

function getServerHost() {
	var server = getParameterByName("server");
	if(!server) {
		if(isLocalHost()) // if running locally, connect locally
			server = window.location.host;
		else if(window.server_host)
			server = window.server_host;
		else
			server = window.location.host; //"192.168.3.11:28283"; // my private server; if you fork, you have to change this
	}
	return server;
}

function getParameterByName(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var	regexS = "[\\?&]" + name + "=([^&#]*)",
		regex = new RegExp(regexS),
		results = regex.exec(window.location.search);
	if(results == null) return "";
	return decodeURIComponent(results[1].replace(/\+/g, " "));
}
 
function arrayToString() {
	var args = [];
	for(var arg in arguments) {
		arg = arguments[arg];
		if(arg instanceof Array)
			arg = "["+arrayToString.apply(null,arg)+"]";
		else if(arg instanceof Object) try {
			arg = JSON.stringify(arg);
		} catch(error) {}
		args.push(String(arg));
	}
	return args.length == 1? args[0]: args.join();
}

var fail = fail || function(error) {
	if(!(error instanceof Error)) try {
		error = new Error(arrayToString.apply(null,arguments));
	} catch(e) {}
	fail.error = error;
	console.log("error",error,"at",error.stack? error.stack: "");
	if(!isInWebWorker) {
		report_error(""+error+"\n"+error.stack);
		if(isOnGithubPages && !isOnGithubPages() && isOnFileSystem && !isOnFileSystem() && isLocalHost && !isLocalHost())
			window.setTimeout(function() { window.location.reload(false); },2500);
		var div = window.document.getElementById("error");
		if(div) {
			div.innerHTML = "<b>AN ERROR OCCURRED</b><br/>"+error+"<br/><pre>"+error.stack;
			div.style.display = "block";
		}
	}
	throw error;
}

function report_error(message) {
	if(isOnFileSystem()) return;
	var doc = new XMLHttpRequest();
	doc.open("POST","http://"+getServerHost()+"/api/report_error",false);
	doc.overrideMimeType("text/plain");
	doc.onerror = function(evt) { console.log("report_error:", evt); };
	doc.onreadystatechange = function () {};
	doc.send(message);
}

function report_info(message) {
	if(isOnFileSystem()) return;
	var doc = new XMLHttpRequest();
	doc.open("POST","http://"+getServerHost()+"/api/report_info",false);
	doc.overrideMimeType("text/plain");
	doc.onerror = function(evt) { console.log("report_info:", evt); };
	doc.onreadystatechange = function () {};
	doc.send(message);
}

var assert = assert || function(condition,msg) {
	if(!condition)
		fail.apply(this,Array.prototype.slice.call(arguments,1));
}

function now() { return (new Date()).getTime(); }

function startsWith(str,prefix) {
	return str.indexOf(prefix) == 0;
}

function endsWith(str,suffix) {
	return str.indexOf(suffix,str.length-suffix.length) !== -1;<commit_msg>trying to tame xmlrequest errors<commit_after>/* https://github.com/williame/barebones.js project

Contains a basic web-worker wrapper.  You can also instansiate it in the browser page thread too if you choose,
which may simplify debugging or for browsers that do not support web workers.

* You make the game() function do whatever you like e.g. create a UIViewport control
  to draw a 3D scene in

BSD LICENSE:

Copyright (c) 2013, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

function isOnGithubPages() {
	return window.location.hostname.indexOf(".github.") > 0;
}

function isOnFileSystem() {
	return "file:" === window.location.protocol;
}

function isLocalHost() {
	return isOnFileSystem() || window.location.hostname == "localhost";
}

function getServerHost() {
	var server = getParameterByName("server");
	if(!server) {
		if(isLocalHost()) // if running locally, connect locally
			server = window.location.host;
		else if(window.server_host)
			server = window.server_host;
		else
			server = window.location.host; //"192.168.3.11:28283"; // my private server; if you fork, you have to change this
	}
	return server;
}

function getParameterByName(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var	regexS = "[\\?&]" + name + "=([^&#]*)",
		regex = new RegExp(regexS),
		results = regex.exec(window.location.search);
	if(results == null) return "";
	return decodeURIComponent(results[1].replace(/\+/g, " "));
}
 
function arrayToString() {
	var args = [];
	for(var arg in arguments) {
		arg = arguments[arg];
		if(arg instanceof Array)
			arg = "["+arrayToString.apply(null,arg)+"]";
		else if(arg instanceof Object) try {
			arg = JSON.stringify(arg);
		} catch(error) {}
		args.push(String(arg));
	}
	return args.length == 1? args[0]: args.join();
}

var fail = fail || function(error) {
	if(!(error instanceof Error)) try {
		error = new Error(arrayToString.apply(null,arguments));
	} catch(e) {}
	fail.error = error;
	console.log("error",error,"at",error.stack? error.stack: "");
	if(!isInWebWorker) {
		report_error(""+error+"\n"+error.stack);
		if(isOnGithubPages && !isOnGithubPages() && isOnFileSystem && !isOnFileSystem() && isLocalHost && !isLocalHost())
			window.setTimeout(function() { window.location.reload(false); },2500);
		var div = window.document.getElementById("error");
		if(div) {
			div.innerHTML = "<b>AN ERROR OCCURRED</b><br/>"+error+"<br/><pre>"+error.stack;
			div.style.display = "block";
		}
	}
	throw error;
}

function _server_post_silent(page, body, mimeType) {
	if(isOnFileSystem()) return;
	try {
		var doc = new XMLHttpRequest();
		doc.open("POST","http://"+getServerHost()+"/api/" + page,false);
		doc.overrideMimeType(mimeType || "text/plain");
		doc.onerror = function(evt) { console.log(page+ ": ", evt, body); };
		doc.onreadystatechange = function () {};
		doc.send(body);
	} catch(e) {
		console.log(page+ ": ", e, body);
	}
}

function report_error(message) { _server_post_silent("report_error", message); }

function report_info(message) { _server_post_silent("report_info", message); }

var assert = assert || function(condition,msg) {
	if(!condition)
		fail.apply(this,Array.prototype.slice.call(arguments,1));
}

function now() { return (new Date()).getTime(); }

function startsWith(str,prefix) {
	return str.indexOf(prefix) == 0;
}

function endsWith(str,suffix) {
	return str.indexOf(suffix,str.length-suffix.length) !== -1;
{'fraction_non_alphanumeric': 0.13234841489689136, 'fraction_numerical': 0.006155740227762389, 'mean_word_length': 4.68065268065268, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '896875', 'n_tokens_mistral': 3103, 'n_tokens_neox': 2885, 'n_words': 934}