Skip to content

Instantly share code, notes, and snippets.

John Carrell saintsGrad15

Block or report user

Report or block saintsGrad15

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Centered Upright Text In Table Cell.css
writing-mode: vertical-rl;
text-orientation: upright;
margin-left: auto;
margin-right: auto;
/* Add vertical-align: middle to <td> */
@saintsGrad15
saintsGrad15 / getObjectPaths.js
Created Aug 21, 2019
A function that returns all paths into an arbitrarily nested javascript object.
View getObjectPaths.js
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 Jul 18, 2019
A generator function that returns an Array consisting of [index, element]. Behaves like the Python function.
View enumerate.js
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 Jun 28, 2019
How to refer to a git repo in a requirements.txt
View requirements.txt
git+ssh://git@github.com/user/repo.git@branch
@saintsGrad15
saintsGrad15 / verticalCenter.css
Last active Sep 10, 2019
Vertically Center an Element
View verticalCenter.css
vertical-align: top;
display: inline-block;
position: relative;
top: 50%;
transform: translateY(-50%);
@saintsGrad15
saintsGrad15 / client_secrets.json
Last active May 30, 2019
Basic Flask application using IBMid SSO
View client_secrets.json
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 Apr 9, 2019
A class that will cycle through a range of colors according to an internal map of "items" to "hsl" color values.
View ColorCycler.js
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 Feb 1, 2019
A simple list implementation that yields None or a defined default if an out-of-bounds index is referenced.
View DefaultList.py
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 Jan 18, 2019
A Class usabled directly or as a context manager that creates a temporary directory and enables its deletion.
View temporary_directory.py
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.
"""
View DEV Things to Remember
Python
- A directory that contains a __main__.py file can be executed directly by the python interpreter
- If that directory contains a __init__.py file it can be executed as a module.
- If using MatPlotLib you might receive a "Python was not installed as a framework..." error.
- Create a file `~/.matplotlib/matplotlibrc` and populate it with `backend: TkAgg` to solve the problem.
- Why? Who fuckin knows?
Jupyter
- When installing a Javascript Jupyter kernel following the following page:
- https://github.com/n-riesco/ijavascript
You can’t perform that action at this time.