Skip to content

Instantly share code, notes, and snippets.

View swimauger's full-sized avatar
📚

Mark Auger swimauger

📚
View GitHub Profile
@swimauger
swimauger / uuid.js
Last active February 2, 2021 17:46
UUID Generator : Using Generators and yield
// Create a UUID Generator
function* UUIDGenerator() {
for (let i = 0; true; i++) {
yield i;
}
}
// Initialize UUID Generator
const uuid = UUIDGenerator();
@swimauger
swimauger / uuid2.js
Last active February 2, 2021 18:22
UUID Generator v2 : Using Generators, yield, and 999,999,999,999 100% unique ids
function* UUIDGenerator() {
for (let i = 100000000000; true; i++) {
yield `${`${i}`.substr(0, 4)}-${`${i}`.substr(4, 4)}-${`${i}`.substr(8, 4)}`;
}
}
const uuid2 = UUIDGenerator();
for (let i = 0; i < 10001; i++) {
console.log(uuid2.next().value) // 1000-0000-0000 -> 1000-0001-0000
@swimauger
swimauger / create_tsl.sh
Created May 19, 2021 16:15
Create Self-Signed TLS Certificate
openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out <key_name>.crt -keyout <key_name>.key
@swimauger
swimauger / collatz.js
Last active August 4, 2021 12:27
Collatz Conjecture Function Implementation in JavaScript
/**
* 3x + 1 or the Collatz Conjecture is a simple mathematical conjecture
* that declares all positive integers will eventually reach a value of 1
*
* Inspiration from https://www.youtube.com/watch?v=094y1Z2wpJg
*
* @author Mark Auger
* @social Follow me on GitHub at https://github.com/swimauger
* @license
* Copyright (c) 2021 Mark Auger
@swimauger
swimauger / fibonacci.js
Last active August 4, 2021 12:58
Fibonacci Function Implementation in JavaScript
/**
* Fibonacci is a popular sequence known amongst both mathematicians and programmers.
* Fibonacci starts with 1,1 in the sequence and upon a specified iteration count
* will continue to add the last two numbers in the sequence.
*
* @author Mark Auger
* @social Follow me on GitHub at https://github.com/swimauger
* @license
* Copyright (c) 2021 Mark Auger
*
/**
* calculateBits function can be used to get a rough measurement of how much
* memory a JavaScript object costs
*
* @author Mark Auger
* @social Follow me on GitHub at https://github.com/swimauger
* @license
* Copyright (c) 2021 Mark Auger
*
* Permission is hereby granted, free of charge, to any person obtaining a copy