Skip to content

Instantly share code, notes, and snippets.

View tobiamos's full-sized avatar
💭
🏠 working from home

Amos Adekunle Ezekiel tobiamos

💭
🏠 working from home
View GitHub Profile
@tobiamos
tobiamos / gist:5cb0fa8316ec98e2e5b47b462d2844e5
Last active February 19, 2024 10:36
Calculates the maximum product of the lengths of two words in an array,
/**
* Converts a word into a bitmask.
* @param {string} word - The word to convert.
* @returns {number} The bitmask representing the word.
*/
const wordToBitmask = (word) => {
let bitmask = 0;
for (let char of word) {
bitmask |= 1 << (char.charCodeAt(0) - 'a'.charCodeAt(0));
@tobiamos
tobiamos / script.js
Created February 12, 2024 10:06
a function that produces a generator that produces values in a range.
/**
* Generates a range of values from `from` to `to`.
* @param {number} from - The starting value of the range.
* @param {number} to - The ending value of the range.
* @returns {function} - A generator function that produces values in the range.
*/
const fromTo = (from, to) => {
let array = [];
@tobiamos
tobiamos / bannedDomains.js
Created March 19, 2022 19:08
List of Banned Subdomains when building Multi-Tenancy App
module.exports = {
0: 'about',
1: 'abuse',
2: 'access',
3: 'account',
4: 'accounts',
5: 'acme',
6: 'activate',
7: 'activities',
8: 'activity',
@tobiamos
tobiamos / hashid.js
Last active January 15, 2019 21:57
generate unique strings
const HashID = {};
HashID.generate = () => {
const alphabet = '23456789abdegjkmnpqrvwxyz';
const idLength = 9;
let result = '';
for (let index = 0; index < idLength; index += 1) {
result += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
}
return result;
@tobiamos
tobiamos / array-flatten.js
Last active October 20, 2018 15:43
Flatten a nested array in javascript
/* This function will flatten an array of arbitrarily nested
arrays of integers into a flat array of integers
it returns an array of flattened items
SETUP INSTRUCTIONS
make sure you have nodejs >= V6.0 installed
in your terminal make a new folder with mkdir flatten
navigate to the newly created folder with cd flatten
make a new file with touch index.js
install mocha and chai using npm install mocha chai