Skip to content

Instantly share code, notes, and snippets.

View SethVandebrooke's full-sized avatar

Seth Vandebrooke SethVandebrooke

View GitHub Profile
@SethVandebrooke
SethVandebrooke / AJAX.js
Created May 18, 2017 18:01
Basic AJAX Methods
const AJAX = {
get: function(url,onGet) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
onGet(this.responseText);
}
};
xhttp.open("GET", url, true);
xhttp.send();
@SethVandebrooke
SethVandebrooke / AnExcuseOfAHashFunction.js
Last active November 14, 2017 17:36
An excuse of a hash function: for hashing things you don't actually care about.
// Please note: while the returned hash would be a pain in the butt to decode, it does not ensure uniqueness for smaller strings.
// If you have a string at least 9 varying characters than it might be worth using.
function hash(s,base64){var a="";s.split('').forEach(e=>{a+=e.charCodeAt(0)>>2;});return !!base64?btoa(a):a;}
// Example: hash("mySuperSecretPassword",true); // Base64
// Output: "MjczMDIwMjkyODI1MjgyMDI1MjQyODI1MjkyMDI0MjgyODI5MjcyODI1"
// Example: hash("mySuperSecretPassword");
// Output: "273020292825282025242825292024282829272825"
@SethVandebrooke
SethVandebrooke / parseURL.js
Last active June 20, 2018 17:40
Get URL data easily
const parseURL = function(char) {
var url = window.location.href, data = {};
char = !!char ? char === "?" || char === "#" ? char : "check" : "check";
if (char==="check") {
char = url.includes("?") ? "?" : url.includes("#") ? "#" : false;
if (char === false) { return false; }
}
url = url.substring(url.indexOf(char)+1,url.length);
if (url.includes("=")) {
var kv = url.split("&");
@SethVandebrooke
SethVandebrooke / CCV.js
Last active November 15, 2017 13:52
Compress small Ints based off a character string
function intToCCV(n,c) { // Character compression value
var c = c || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!?";
var r = [0,0,0,0];
while (n - 64 >= 0) {
var pos = 2;
r[r.length-pos] += 1;
while (r[r.length-pos]==c.length) {
r[r.length-pos] = 0;
pos += 1; // Go to next position
if (r.length-pos in r) { // If that position is alread in the data
@SethVandebrooke
SethVandebrooke / random.js
Last active January 22, 2019 15:19
Get a random int, character from a string, item from an array, key or value from an object, or any value between two given ints.
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(''));
@SethVandebrooke
SethVandebrooke / README.md
Created November 27, 2017 16:08
Tiny. Simple. Pubsub (No dependencies)

SUP

Subscribe. Unsubscribe. Publish.

Super simple event handling.

Basic use

var handle = SUP.sub("points", function(data){
  console.log("Oh sweet! I got "+data+" more points!");
});
SUP.pub("points",12);
@SethVandebrooke
SethVandebrooke / Random ID
Created December 12, 2017 19:27
Generate a safe (URL/SQL) ID randomly
var randID = (n)=>{var i,a="";for(i of new Array(n)){a+=("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890").charAt(~~(Math.random()*62));}return a;};
//console.log(randID(6));
@SethVandebrooke
SethVandebrooke / definedParameters.js
Created December 18, 2017 15:26
Get an array of the parameters defined for a given function
function definedParameters(func) {
return func.toString().split("\n")[0].match(/\({1}.*\){1}/)[0].replace("(","").replace(")","").split(" ").join("").split(",");
}
// definedParameters(function (a,b,c){return a*b*c;}) returns ["a","b","c"];
@SethVandebrooke
SethVandebrooke / personList.hta
Last active August 3, 2022 04:54
Self Modifying HTA file ( HTML + VBS + JavaScript)
<head>
<title>HTA Test</title>
<HTA:APPLICATION
APPLICATIONNAME="Application"
SCROLL="no"
SINGLEINSTANCE="yes"
>
</head>
@SethVandebrooke
SethVandebrooke / TDROM.js
Last active March 30, 2018 19:35
3D Relational Object Mapping
function TDROM() {
var THIS = this;
THIS.data = [];
THIS.props = {};
THIS.vals = {};
THIS.map = [];
THIS.add = function(obj) {
var index = THIS.data.push(obj) - 1, p, v, k;
for (k in obj) {