Skip to content

Instantly share code, notes, and snippets.

View saintsGrad15's full-sized avatar

John Carrell saintsGrad15

View GitHub Profile
@saintsGrad15
saintsGrad15 / local_minima_finder_v1.py
Last active August 18, 2020 19:33
Given an array that keeps information about Temperature readings for a city, return an array of equal length that tells you, for a given day how many days have passed since a higher temperature occurred.
# Given an array that keeps information about Temperature readings for a city,
# return an array of equal length that tells you, for a given day
# how many days have passed since a higher temperature occurred
temps = [7, 3, 4, 6, 9, 1, 5, 6, 3, 7, 4, 8, 2, 10]
expected_output = [1, 1, 2, 3, 5, 1, 2, 3, 1, 5, 1, 7, 1, 14]
def local_minima_finder_v1(temps):
complexity_counter = 0
output = [1]
@saintsGrad15
saintsGrad15 / local_minima_finder_v2.py
Created August 18, 2020 19:34
Given an array that keeps information about Temperature readings for a city, return an array of equal length that tells you, for a given day how many days have passed since a higher temperature occurred.
# Given an array that keeps information about Temperature readings for a city,
# return an array of equal length that tells you, for a given day
# how many days have passed since a higher temperature occurred
temps = [7, 3, 4, 6, 9, 1, 5, 6, 3, 7, 4, 8, 2, 10]
expected_output = [1, 1, 2, 3, 5, 1, 2, 3, 1, 5, 1, 7, 1, 14]
def local_minima_finder_v2(temps):
complexity_counter = 0
output = [1]
@saintsGrad15
saintsGrad15 / range_header_regex.py
Created January 21, 2021 16:45
A regex that validates and extracts groups from a valid HTTP "range" header
# Spec source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
import re
range_header_regex = re.compile(r"^((?P<unit>[a-zA-Z]+)=)?(?P<start>\d+)?-(?P<end>\d+)?$")
@saintsGrad15
saintsGrad15 / find_hex_namespace_boundaries.py
Last active October 28, 2021 20:44
Return a list of tuples representing the inclusive lower and upper boundaries of each range of hexadecimal values from a namespace with 'number_of_bytes' bytes divided into 'number_of_sets' "equal" sets.
def find_hex_namespace_boundaries(number_of_bytes:int, number_of_sets:int = 2) -> Tuple[str]:
"""
Return a list of tuples representing the inclusive lower and upper boundaries
of each range of hexadecimal values from a namespace with 'number_of_bytes' bytes
divided into 'number_of_sets' "equal" sets.
:param number_of_bytes: The length of the hexadecimal namespace in bytes.
:param number_of_sets: The number of sets to divide the namespace into.
NOTE: The sets will be of as close to equal length as possible
@saintsGrad15
saintsGrad15 / sample_list_evenly.py
Created January 12, 2022 17:46
Return the contents of 'list_' sampled evenly accross its current order.
def sample_list_evenly(list_: List[Any], samples: int) -> List[Any]:
"""
Return the contents of 'list_' sampled evenly accross its current order.
NOTE: Doesn't work perfectly yet...
:param list_: A list of anything.
:param samples: The number of samples to return.
@saintsGrad15
saintsGrad15 / example.html
Created September 19, 2022 16:16
Cause body to fill the viewport, establish a CSS Grid with a header, left-nav and main body. The nav and body will scroll independently, the body will not scroll.
<template>
<div id="mainLayout">
<div id="header"></div>
<div id="leftNav"></div>
<div id="mainView"></div>
</div>
</template>
<style>
html, body { /* nothing necessary */ }
@saintsGrad15
saintsGrad15 / ruler.css
Created September 19, 2022 16:20
Verify you are seeing the full height of an element
background-color: white;
background-image: url("ruler-vertical.png"); /* Use any image for which being able to see the top and bottom would be easy. */
background-size: contain;
background-repeat: no-repeat;
background-position-x: center;
background-attachment: local; */ Ensures the image will fill the height and scroll with content. */
@saintsGrad15
saintsGrad15 / EnvironmentConfig.py
Last active November 14, 2023 17:24
EnvironmentConfig and EnvironmentVariable classes
class EnvironmentConfig:
def __init__(self, environment_variables_specs: Dict[str, EnvironmentVariable]):
self._environment_variables_specs = environment_variables_specs
self.PORT = None # The naming convention is different because this value is automatically injected by Code Engine
self.SDG_DB_USERNAME = None
self.SDG_DB_PASSWORD = None
self.SDG_DB_HOSTNAME = None
self.SDG_DB_SCHEMA_NAME = None
self.SDG_DB_TABLE_NAME = None
@saintsGrad15
saintsGrad15 / slice_generator.py
Created August 19, 2023 14:19
Iterate over `iterable` yielding only indices between `start_index` and `end_index` inclusive and exclusive, respectively.
import math
from typing import Iterable
def slice_generator(iterable: Iterable, *, start_index: int = 0, end_index: int = math.inf):
"""
Iterate over `iterable` yielding only indices
between `start_index` and `end_index` inclusive and exclusive, respectively.
:param iterable: Any iterable
@saintsGrad15
saintsGrad15 / example.js
Last active January 13, 2024 03:24
Returns a flat proxied object wherein function values serve as computed properties and are called with the object as the value of this upon access.
const object = getDependentObject({
name: "john",
age: 39,
yearsTil40() { return 40 - this.age; }
});
console.log(object.yearsTil40); // 40 - 39 = 1
object.age = 30