This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Function that can run a function supplied in a web worker | |
| // MIT License Copyright TheGreatRambler | |
| // Free to use | |
| function runInWebWorker(func, argsarray, callback) { | |
| // func: function to use | |
| // argsarray: the arguments to pass | |
| // callback: the callback function | |
| var blobdata = 'var returnstatement=(' + func.toString() + ')(' + argsarray.join(",") + ');self.postMessage(returnstatement);self.close();'; | |
| console.log(blobdata); | |
| var blobURL = URL.createObjectURL(new Blob([blobdata], { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function returnheaders(ajaxrequest) { | |
| var headers = ajaxrequest.getAllResponseHeaders(); | |
| var arrofheaders = headers.trim().split(/[\r\n]+/); | |
| var mapofheaders = {}; | |
| arrofheaders.forEach(function (line) { | |
| var parts = line.split(': '); | |
| var header = parts.shift(); | |
| var value = parts.join(': '); | |
| mapofheaders[header] = value; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function randomlySplitArray(inputarray, chunksize, numofloops) { | |
| function randomint(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } | |
| var temparray = inputarray; | |
| for (var q = 0; q < numofloops; q++) { | |
| var start = randomint(0, inputarray.length - chunksize); | |
| var othertemp = temparray.splice(start, chunksize); | |
| var index = randomint(0, temparray.length - chunksize - 1); | |
| // https://stackoverflow.com/questions/7032550/javascript-insert-an-array-inside-another-array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src https://codepen.io/sachmata/post/elegant-pairing | |
| szudzik.getindex = function(x, y) { | |
| var xx = x >= 0 ? x * 2 : x * -2 - 1; | |
| var yy = y >= 0 ? y * 2 : y * -2 - 1; | |
| return (xx >= yy) ? (xx * xx + xx + yy) : (yy * yy + xx); | |
| }; | |
| szudzik.unpair = function(z) { | |
| var sqrtz = Math.floor(Math.sqrt(z)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function distancebetweentwopoints(x1, y1, x2, y2) { | |
| if (x1 > x2) { | |
| x1 = x1 - x2; | |
| x2 = 0; | |
| } else { | |
| x2 = x2 - x1; | |
| x1 = 0; | |
| } | |
| if (y1 > y2) { | |
| y1 = y1 - y2; |
NewerOlder