Skip to content

Instantly share code, notes, and snippets.

View saintsGrad15's full-sized avatar

John Carrell saintsGrad15

View GitHub Profile
@saintsGrad15
saintsGrad15 / decorator_reporter.py
Created October 3, 2017 21:18
A decorator function that will "report."
def decorator_reporter(report_string="Running...", period=1, reporting_function=None):
"""
A decorator function that will "report."
This function returns 'function_wrapper.'
:param report_string: The string to "report."
:param period: The number of seconds between reports.
:param reporting_function: The reporting function to use instead of 'print.'
This could be a logging function like 'logging.debug' for instance.
This must be capable of taking no more than one string argument.
@saintsGrad15
saintsGrad15 / addAlias.bash
Created October 5, 2017 14:30
A function to add an alias declaration to ~/.bash_profile
function addAlias()
{
echo "alias $1='$2'" >> ~/.bash_profile
. ~/.bash_profile #reload .bash_profile
}
@saintsGrad15
saintsGrad15 / newBranch.bash
Created October 5, 2017 14:31
A function to create a new git branch and set its upstream repo
function newBranch()
{
git checkout -b "$1"
if [ $? -eq 0 ]; then
git push -u
fi
}
@saintsGrad15
saintsGrad15 / deleteBranch.bash
Created October 5, 2017 14:31
A function to delete a branch from git both locally and on the remote
function deleteBranch()
{
git branch -d "$1"
if [ $? -ne 0 ]; then
echo "Trying with -D"
git branch -D "$1"
fi
if [ $? -ne 0 ]; then
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
@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.
"""
@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 / 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 / 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 / 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%);