This file contains 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 bd(binaryString) { | |
return parseInt(binaryString, 2); | |
} | |
function db(num) { | |
return num.toString(2); | |
} | |
function rl(binaryString,l) { | |
var zeros = ""; | |
for (var i = 0; i < l - binaryString.length; i++) { | |
zeros += "0"; |
This file contains 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 RollingCypher() { | |
var chars = " qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+-=[]\\{}|;':\",./<>?`~\t\r\n"; | |
chars = chars.concat(chars.concat(chars)); | |
function encrypt(s, p) { | |
var o = ""; | |
s = s.split(''); | |
p = p.split(''); | |
for (var i = 0; i < s.length; i++) { | |
o += chars[chars.indexOf(s[i]) + chars.indexOf(p[i % p.length])]; |
This file contains 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 random(a, b) { | |
if(Array.isArray(a)){ | |
return a[random(a.length)]; | |
} | |
if (typeof a === "object") { | |
var key = random(Object.keys(a)); | |
return b === "key" ? key : b === "both" ? {key:key,value:a[key]} : a[key]; | |
} | |
if (typeof a === "string" && !!a) { | |
return (a.toLowerCase() === "bool") ? (Math.floor(Math.random()*2) == 1) : random(a.split('')); |
This file contains 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
/** | |
* Machine learning algorithm that learns underlying patterns in sequences and replicates them using frequency analysis. | |
* AKA a markov chain XD | |
* @function | |
* @param {Array|Number} a A sequence or the length of a sequence to return | |
* @example | |
* // feed it a sequence to learn from | |
* m([1,1,2,3,3,2,1]); | |
* // have it generate a sequence 7 items long | |
* m(7); |
This file contains 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 buildMapWithPath(H, W, L) { | |
let A = [], p = [0,0]; | |
for (let Y = 0; Y < H; Y++) { | |
A[Y] = []; | |
for (let X = 0; X < W; X++) { | |
A[Y].push(0); | |
} | |
} | |
function mark(p) { | |
A[p[0]][p[1]] = 1; |
This file contains 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 PromptGenerator() { | |
var self = this; | |
function pos(a) { | |
if (Array.isArray(a)) { | |
if (!('d' in pos)) pos.d = {}; | |
for (var i = 0, p = null; i < a.length; i++) { | |
(pos.d[p] ? pos.d[p] : pos.d[p] = []).push(p = a[i]); | |
} | |
} else if ("number" == typeof a) { |
This file contains 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 Model(name, OBJ) { | |
function model(obj) { | |
var PUBLIC = this; | |
var PRIVATE = {}; | |
PUBLIC.MODEL_TYPE = name; | |
for (let key in obj) { | |
let value = obj[key]; | |
// Ensure property is set correctly |
This file contains 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 uploadAndConvertToBase64DataURL(callback) { | |
if (!document.getElementById("B64DURL_UL")) { | |
var input = document.createElement("input"); | |
input.id = "B64DURL_UL"; | |
input.style.display = "none"; | |
input.type = "file"; | |
document.body.appendChild(input); | |
} | |
var input = document.getElementById("B64DURL_UL"); | |
input.addEventListener("change", function (e){ |
This file contains 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
var generateRandomRythem = (weight) => { | |
let hit = "x", rythem = "--------".split(""); | |
for (let i = 0; i < ( weight || 4 ); i++) { | |
rythem[Math.floor(Math.random()*rythem.length-1)] = "x"; | |
} | |
return rythem.concat(rythem).join(""); | |
} | |
console.log(generateRandomRythem(6)); |
This file contains 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
var WebSocketServer = require('ws').Server; | |
var wss = new WebSocketServer({port: 8080}); | |
var jwt = require('jsonwebtoken'); | |
/** | |
The way I like to work with 'ws' is to convert everything to an event if possible. | |
**/ | |
function toEvent (message) { | |
try { |