Skip to content

Instantly share code, notes, and snippets.

View saintsGrad15's full-sized avatar

John Carrell saintsGrad15

View GitHub Profile
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 / 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
@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 / 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 / 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 / Reporter.py
Last active October 6, 2017 16:59
A Heartbeater offspring that reports periodically.
class Reporter(Heartbeater):
"""
Behaves like a Heartbeater but specifically designed to print statements periodically.
"""
def __init__(self, report_string, period=1, reporting_function=None):
"""
Every 'period' seconds 'report_string' will be passed to 'reporting_function.'
If 'reporting_function' is None it will print 'report_string' instead.
@saintsGrad15
saintsGrad15 / Compose.py
Created June 30, 2017 16:54
A composition class for Python
class Compose(object):
"""
Return a function that, when called, will execute each function in 'functions'
in order, passing the return value of each to the next one
and returning the result of the last one.
NOTE: Generator functions cannot be used.
:param functions: A list of functions.
NOTE: Ensure that the output of one function makes sense
as an input to the next function. A list of values can be
@saintsGrad15
saintsGrad15 / compose.js
Created June 15, 2017 14:04
A composition function that takes N functions, runs them in order, passing arguments to each other and returning the final result.
function compose(...funcs)
{
function _compose(...args)
{
let result = args;
for (func of funcs)
{
if ( !Array.isArray(result) )
result = [result];
@saintsGrad15
saintsGrad15 / getObjectValueFromDottedNotation.js
Created April 14, 2017 20:03
A function to retrieve the value inside an object at a dot-delimited path.
function getObjectValueFromDottedNotation(object, dottedString)
{
/*
* Given an object 'object' and a string 'dottedString' that contains a dot-delimited path
* down the object's members, return the value at that path or false if the entire path does not exist.
*
* For example:
* obj = {
* "person": {
* "name": "john",
@saintsGrad15
saintsGrad15 / context_manager_heartbeater.py
Last active October 3, 2017 21:16
A heartbeater class that implements the context manager interface.
from threading import Thread
from time import sleep
class Heartbeater(Thread):
"""
A class that adheres to the Thread and Context Manager interfaces.
"""
def __init__(self, work=None, work_args=None, work_kwargs=None, period=1, daemon=False):
"""