Skip to content

Instantly share code, notes, and snippets.

View saintsGrad15's full-sized avatar

John Carrell saintsGrad15

View GitHub Profile
@saintsGrad15
saintsGrad15 / getDurationString.js
Created February 17, 2024 21:17
Generate an "H:MM:SS" string from a duration of seconds
const hours = Math.floor(duration / 3600);
const minutes = String(Math.floor(duration % 3600 / 60)).padStart(2, "0");
const seconds = String(duration % 60).padStart(2, "0");
return `${hours}:${minutes}:${seconds}`;
@saintsGrad15
saintsGrad15 / areArraysEqualShallow.js
Created March 6, 2024 19:44
Shallowly compare the value equality of an Array.
function areArraysEqual(a, b) {
if (!Array.isArray(a) || !Array.isArray(b)) { throw new Error("At least one argument is not an Array."); }
if (a === b) { return true; }
if (a.length !== b.length) { return false; }
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
@saintsGrad15
saintsGrad15 / fizz_buzz_1.py
Created December 19, 2024 18:50
First re-pass at FizzBuzz after an interview
cache = {}
def fizz_buzz(n: int, factor_1: int = 3, factor_2: int = 5) -> None:
"""
Given an integer n, for a list of integers 1-n, the task is to print,
"FizzBuzz" if i is divisible by `factor_1` and `factor_2`,
"Fizz" if i is divisible by `factor_1`,
@saintsGrad15
saintsGrad15 / get_digit.py
Last active April 5, 2025 19:41
Return the digit in `number` at the zero-indexed, left-to-right place `ltr_place` without coercing to a string.
def get_digit(number: int, ltr_place: int) -> int:
if ltr_place < 0:
raise ValueError("ltr_place must be >= 0")
length = math.floor(math.log10(number)) + 1
if ltr_place > length - 1:
raise ValueError(f"ltr_place is zero-indexed. {ltr_place} exceeds the length of {number}")
return number % pow(10, length - ltr_place) // pow(10, length - ltr_place - 1)
@saintsGrad15
saintsGrad15 / typescriptDecorator.js
Created June 13, 2025 18:06
A basic TS decorator implementation
function practiceDecorator(target, propertyKey, descriptor) {
return {
...descriptor,
value(...args) {
// Do something here when the decorated function is called
return descriptor.value.apply(this, args);
}
};
}