Skip to content

Instantly share code, notes, and snippets.

View saintsGrad15's full-sized avatar

John Carrell saintsGrad15

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / ClassInstanceCacher.py
Created October 29, 2019 20:34
A general form of a class instance cacher
class ClassInstanceCacher(object):
# Rename the outer class at will.
# Implement Klass to suit use case
__cache = {}
def __new__(cls, _id):
if cls.__cache.get(_id) is None:
cls.__cache[_id] = cls.Klass(_id)
return cls.__cache[_id]
@saintsGrad15
saintsGrad15 / negate_multiple_words.regex
Created November 4, 2019 17:13
Negate multiple words using PCRE
^(?!development|master).*$
@saintsGrad15
saintsGrad15 / tox.ini
Created November 22, 2019 15:44
Basic tox.ini setup
[tox]
envlist = py27
[testenv]
install_command=pip install --extra-index-url=http://pypi.ad.cleversafe.com/simple/ --trusted-host=pypi.ad.cleversafe.com {opts} {packages}
# Allows running e.g. `tox -e DCC`
# Otherwise include commands in [testenv]
# NOTE: -s can be run pointed at a directory and it will run all modules inside
[testenv:DCC]
@saintsGrad15
saintsGrad15 / gist:afbcc0c27c2c1db90fe8e8d1b6e129e6
Created January 15, 2020 18:06
Solve MacOS pycurl issue.md
Source: https://github.com/transloadit/python-sdk/issues/4
1. Uninstall pycurl
2. brew install openssl (May already be installed...)
3. export CPPFLAGS=-I/usr/local/opt/openssl/include
4. export LDFLAGS=-L/usr/local/opt/openssl/lib
5. pip install pycurl --global-option="--with-openssl"
6. Rejoice
@saintsGrad15
saintsGrad15 / get_dict_path.py
Created July 23, 2020 19:05
A tail-recursive function to return the value at a path within a dictionary.
def get_dict_path(dict_, path, default=None):
if len(path) < 1:
return dict_
return get_dict_path(dict_.get(path[0], default), path[1:], default)