Skip to content

Instantly share code, notes, and snippets.

View SethVandebrooke's full-sized avatar

Seth Vandebrooke SethVandebrooke

View GitHub Profile
@SethVandebrooke
SethVandebrooke / generateRandomHexCode.js
Created February 1, 2019 22:03
Generate Random Hex Code
function generateRandomHexCode(length) {
var charSet = "0123456789ABCDEF";
var result = "";
for (var i = 0; i < length; i++) {
result += charSet.charAt(Math.floor(Math.random()*charSet.length));
}
return result;
}
@SethVandebrooke
SethVandebrooke / topHatMan.txt
Last active February 1, 2019 21:27
ASCII man in top hat
/*
_________________
| |
| |
| |
| |
| |
___| ____|___
|_________________________|
@SethVandebrooke
SethVandebrooke / binaryDecisions.js
Last active January 18, 2021 21:56
Code for making decisions off of binary values
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";
@SethVandebrooke
SethVandebrooke / worldNameGenerator.js
Last active January 18, 2021 21:59
Generate fantastical names of worlds, cities, or general places.
function generatePlace(type) {
var name = "";
var l = "bcdfghjklmnprstvwxyz";
var v = "aeiou";
var a = ["an","on","al","aph","ah"];
var b = ["or","an","ro","ain","am"];
var c = ["ia","sha","ea","ae","on","ue","a","as","in","na","o","di"];
var d = ["ph","th","sh"];
var sequences = [
@SethVandebrooke
SethVandebrooke / CRUDPermissions.js
Last active February 1, 2019 14:35
Handling CRUD Permissions via bitwise operations
// Crud Permissions
function CRUDPermissions () {
var self = this;
self.CREATE = 8,
self.READ = 4,
self.UPDATE = 2,
self.DELETE = 1,
@SethVandebrooke
SethVandebrooke / crc8.js
Created January 30, 2019 19:17
Base 16 CRC8 Hash
// "Class" for calculating CRC8 checksums...
function CRC8(polynomial) { // constructor takes an optional polynomial type from CRC8.POLY
if (polynomial == null) polynomial = CRC8.POLY.CRC8_CCITT
this.table = CRC8.generateTable(polynomial);
}
// Returns the 8-bit checksum given an array of byte-sized numbers
CRC8.prototype.checksum = function(byte_array) {
var c = 0
@SethVandebrooke
SethVandebrooke / componentsCompiler.php
Created January 16, 2019 20:01
Create html components that can be included like calling a function and compiled into a dist directory of html files
<?php
//TODO: implement recursion
$rootPath = "\\source\\";
$distPath = "\\public\\";
$componentsPath = "\\components\\";
function insertComponents($targetFilePath, $componentsPath) {
$components = array();
$componentFiles = scandir(__DIR__ . $componentsPath);
@SethVandebrooke
SethVandebrooke / regexForFunctions.php
Last active January 16, 2019 17:46
Regex expression for getting string starting with something and ending with something else
<?php
//start with $ end with )
preg_match_all('/\$.+?(?=\))/', '<p>$test(hello)</p> <p>$test(testing)</p>', $matches, PREG_UNMATCHED_AS_NULL);
print_r($matches);
/*
Array
(
[0] => Array
(
[0] => $test(hello
@SethVandebrooke
SethVandebrooke / getNoun.js
Created December 10, 2018 16:31
get the first noun of a sentence using RiTa
function getNoun (str) {
var indexOfNoun = RiTa.getPosTags(str,true).indexOf("n");
if (indexOfNoun != -1) {
return RiTa.tokenize(str)[indexOfNoun];
} else {
return false;
}
}
@SethVandebrooke
SethVandebrooke / setObservable.js
Created December 4, 2018 18:34
An observable entity utilizing the set type.
// Observable
function Observable(val) {
var listeners = new Set();
var value;
function observable(val) {
if (val !== undefined) {
value = val;
observable.update(val);
}