Skip to content

Instantly share code, notes, and snippets.

View SethVandebrooke's full-sized avatar

Seth Vandebrooke SethVandebrooke

View GitHub Profile
@SethVandebrooke
SethVandebrooke / CaesarSolver.js
Created November 15, 2023 03:20
Solve Caesar Cyphers
function CaesarSolver(str) {
let alphabet = 'abcdefghijklmnopqrstuvwxyz';
str = str.toLowerCase();
let words = str.split(/\s+/);
let permutations = [];
for (let j = 0; j < alphabet.length; j++) {
let list = [];
for (let i = 0; i < words.length; i++) {
let word = "";
let letters = words[i].split('');
@SethVandebrooke
SethVandebrooke / createDebtKillingPlan.js
Created November 28, 2021 01:14
create a plan for prioritizing and paying off debt
function findBestPayoffSequence(loans) {
return loans.reduce(function (a, b) {
b.effeciencyScore = (b.monthlyPayment / b.amountLeft) * 100
a.push(b)
return a
}, []).sort(function (a, b) { return a.effeciencyScore >= b.effeciencyScore })
}
function createDebtKillingPlan(loans) {
@SethVandebrooke
SethVandebrooke / mda.js
Last active July 21, 2021 03:15
MultiDimensionalArray generation
/**
* Create multi-dimensional array
* @name multiDimensionalArray
* @function
* @param {number[]} d the depth of each dimension
* @example
* // create 3 dimensional array, 10 cells deep in every direction (10 by 10 by 10)
* multiDimensionalArray([10,10,10]);
*/
const multiDimensionalArray = (()=>{
@SethVandebrooke
SethVandebrooke / similarity.js
Created July 9, 2021 20:08
Get the percentage of similar words between two texts. This function returns a score from 0 to 100 and an array of words in common between the two.
function similarity(text1, text2) {
text1 = text1.split(/\s+/);
text2 = text2.split(/\s+/);
let wordsInCommon = [];
let similarWordCount = 0;
for (var i = 0; i < text1.length; i++) {
let word = text1[i];
if (text2.includes(word)) {
similarWordCount++;
if (!wordsInCommon.includes(word)) {
@SethVandebrooke
SethVandebrooke / getSyllables.js
Last active May 14, 2021 21:00
Get the number of syllables in a word or sentence
function getSyllables(word) {
return word.replace(/e$/,'').match(/tion|sion|[aeiou]{3,}|[aeou]+|[aeiou]/g).length;
}
@SethVandebrooke
SethVandebrooke / PromptGenerator.js
Created December 23, 2020 18:31
Generate a writing prompt
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) {
@SethVandebrooke
SethVandebrooke / buildMapWithPath.js
Created November 4, 2020 23:56
Generate a grid with a random path
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;
@SethVandebrooke
SethVandebrooke / mLearn.js
Created October 15, 2020 21:06
Machine learning algorithm that learns underlying patterns in sequences and replicates them using frequency analysis
/**
* 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);
@SethVandebrooke
SethVandebrooke / MindModel.js
Last active January 19, 2021 07:52
Mind Models
// generate character mind model
function MindModel() {
this.id = personality.id + ':' + intelligence.id;
this.personality = generatePersonality();
this.intelligence = generateIntelligence();
}
// 32 fundimental personality types with a total of 1,048,576 (16^5) variations.
// that's 32,768 variations per personality type
function generatePersonality() {
// variable declarations
@SethVandebrooke
SethVandebrooke / JWT.php
Last active April 17, 2020 18:20
PHP implementation of JWT
<?php
/*
// EXAMPLE USE
// construct web token manager
$jwt = new JWT("SecretKey");
// ^ init JWT with a server side secret key ^