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_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 / 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 / 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)
@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 / 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 / negate_multiple_words.regex
Created November 4, 2019 17:13
Negate multiple words using PCRE
^(?!development|master).*$
@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 / 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)