Skip to content

Instantly share code, notes, and snippets.

View saintsGrad15's full-sized avatar

John Carrell saintsGrad15

View GitHub Profile
@saintsGrad15
saintsGrad15 / basic_logging_setup.py
Last active March 8, 2023 23:37
The very most basic logging setup for Python
import logging
import sys
# Use this format for more verbosity
LOGGING_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(stream=sys.stdout)
@saintsGrad15
saintsGrad15 / Centered Upright Text In Table Cell.css
Created September 17, 2019 14:18
Display upright text in a table cell
writing-mode: vertical-rl;
text-orientation: upright;
margin-left: auto;
margin-right: auto;
/* Add vertical-align: middle to <td> */
@saintsGrad15
saintsGrad15 / getObjectPaths.js
Created August 21, 2019 20:22
A function that returns all paths into an arbitrarily nested javascript object.
function getObjectPaths(object, parentalPath="", delimiter=".")
{
let paths = [];
for (const [key, value] of Object.entries(object))
{
const pathComponents = [];
// If 'parentalPath' doesn't indicate the root of the tree...
if (parentalPath.length > 0)
@saintsGrad15
saintsGrad15 / enumerate.js
Created July 18, 2019 21:13
A generator function that returns an Array consisting of [index, element]. Behaves like the Python function.
function* enumerate(array)
{
/**
* Duplicates the functionality of Python's enumerate function.
*
* Return, for each element of 'array' an array the element's index and the element.
*
* e.g.
*
* [i, elem]
@saintsGrad15
saintsGrad15 / requirements.txt
Created June 28, 2019 14:19
How to refer to a git repo in a requirements.txt
git+ssh://git@github.com/user/repo.git@branch
@saintsGrad15
saintsGrad15 / verticalCenter.css
Last active September 10, 2019 16:34
Vertically Center an Element
vertical-align: top;
display: inline-block;
position: relative;
top: 50%;
transform: translateY(-50%);
@saintsGrad15
saintsGrad15 / client_secrets.json
Last active September 26, 2023 16:54
Basic Flask application using IBMid SSO
{
"client_secrets": {
"web": {
"auth_uri": "<Retrieve from IBMid registration>",
"client_id": "<your_client_id>",
"client_secret": "<your_client_secret>",
"token_uri": "<Retrieve from IBMid registration>",
"token_introspection_uri": "<Retrieve from IBMid registration>",
"issuer": "<Retrieve from IBMid registration>"
}
@saintsGrad15
saintsGrad15 / ColorCycler.js
Created April 9, 2019 16:13
A class that will cycle through a range of colors according to an internal map of "items" to "hsl" color values.
class ColorCycler
{
/**
* A class that will return a CSS-valid "hsl()" string, assigned to distinct items.
*
* An internal mapping of "items" (any valid Object key) to "hsl()" strings.
* If a color is requested for an existing item, the existing color is returned.
* If a color is requested for a non-existing item, a new color is generated, stored for future use and returned.
*
* When a new color is generated the "hue" value is rotated (0 - 360).
@saintsGrad15
saintsGrad15 / DefaultList.py
Created February 1, 2019 17:41
A simple list implementation that yields None or a defined default if an out-of-bounds index is referenced.
class DefaultList(list):
def __init__(self, iterable=[], default=None):
super(self.__class__, self).__init__(iterable)
self.default = default
def __getitem__(self, index):
"""
If 'index' is outside of the bounds (including negative indexing) of the list,
return 'self.default.'
@saintsGrad15
saintsGrad15 / temporary_directory.py
Created January 18, 2019 15:03
A Class usabled directly or as a context manager that creates a temporary directory and enables its deletion.
class TemporaryDirectory(object):
"""
Produces a temporary directory on the system using tempfile.mkdtemp() under the hood.
Exposes a path attribute that will represent the path of the directory
until the instance has deleted the temporary directory.
TemporaryDirectory can be used as a context manager.
"""