Skip to content

Instantly share code, notes, and snippets.

View brookjordan's full-sized avatar

Brook Jordan brookjordan

View GitHub Profile
class ISO8601 {
#originalString: ParsedISO["originalString"];
#repetitions?: ParsedISO["repetitions"];
#dates:
| Readonly<[Readonly<ISOPart>, Readonly<ISODatePart>]>
| Readonly<[Readonly<ISODatePart>, Readonly<ISOPart>]>
| Readonly<[Readonly<ISOPart>]>;
get originalString() {
return this.#originalString;
const units = [
'zero', 'one', 'two', 'three', 'four',
'five', 'six', 'seven', 'eight', 'nine',
'ten', 'eleven', 'twelve', 'thirteen', 'fourteen',
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen',
];
const tens = [
'', 'ten', 'twenty', 'thirty', 'fourty',
'fifty', 'sixty', 'seventy', 'eighty', 'ninety',
const units = [
'zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
@brookjordan
brookjordan / small-random-colours.js
Last active March 16, 2023 11:51
Functions to get random colours string in hex or RGB
const byteNumber = () => Math.random() * 2 ** 8 >> 0;
export const randomHex = () =>
'#' + (2 ** (2 ** 3 * 3) * Math.random() >> 0).toString(16).padStart(6,'0')
;
export const randomRGB = () =>
`rgb(${[byteNumber(),byteNumber(),byteNumber()]})`
;
@brookjordan
brookjordan / get-payload-types.js
Last active July 22, 2021 03:45
Interpret the types of a list of objects and log out a yaml swagger file
// TODO: output “required:” array correctly
const payloads = [{
a: 'one',
b: 2,
c: {
face: 'me'
},
d: [1,2]
},{
@brookjordan
brookjordan / birthday-paradox.js
Created September 1, 2020 16:10
Test the birthday paradox for yourself
async function getChanceOfMatchingBirthday({
numberOfPeopleInTheRoom = 23,
howManyRoomsToAverageBetween = 1e5,
} = {}) {
let initDate = Date.now();
let testCount = 0;
let matchCount = 0;
while (testCount < howManyRoomsToAverageBetween) {
if (!(testCount % 5e3) && Date.now() >= initDate + 16) {
@brookjordan
brookjordan / getFIles.js
Last active August 26, 2020 14:18
Get all files from within a given directory using Node.js
// To log the results:
//
// getFiles(__dirname, { ignore: ['node_modules'] })
// .then(files => console.log(
// files
// .flat(Infinity)
// .filter(( Oo) => (Oo ))
// ));
// Available options:
@brookjordan
brookjordan / get-yarn-lock-dupes.js
Created August 4, 2020 07:49
Pass in an entire yarn.lock file contents and this will spit out duplicate resolutions
function getYarnLockDupes(yarnLock) {
return yarnLock
.split('\n')
.filter(a => !a.startsWith(' ') && !a.startsWith('#'))
.map(a => a.replace(/[:"]/g, ''))
.flatMap(a => a.split(/, ?/g))
.filter(a => a)
.flatMap(a => {
const versions = a.split(' || ');
if (versions.length === 1) { return a; }
@brookjordan
brookjordan / bem-class-builder.ts
Created July 7, 2020 11:30
BEM-style class name builder
/**
* Used like:
* const cls = buildBEMBuilder("block-name");
*
* let blockClass = cls();
* // => "block-name"
*
* let modifiedBlockClass = cls({
* goodModifier: true,
* badModifier: false,
@brookjordan
brookjordan / bem-class-builder.js
Last active July 7, 2020 10:57
Simple function to aid with building BEM-style class names
/**
* Used like:
* const cls = buildBEMBuilder("block-name");
*
* let blockClass = cls();
* // => "block-name"
*
* let modifiedBlockClass = cls({
* goodModifier: true,
* badModifier: false,