Skip to content

Instantly share code, notes, and snippets.

@jsexauer
jsexauer / template_string.py
Created February 14, 2015 18:31
Quick and dirty function to template strings
import re
def resolve(template, context):
"""Quick and dirty template resolver, replacing {{ }} with context's values
For example, {{foo.bar}} is replaced with foo.bar's value, provided "foo"
is variable passed in context.
Args:
template (str)
Templated string for which will we substitue in templated values
@jsexauer
jsexauer / DataFrameGUI.py
Last active March 28, 2023 21:07
A sophisticated GUI to interact with DataFrame objects
"""
DataFrameTable
==============
Quick and Dirty Qt app to view pandas DataFrames. Includes sorting and
filterting.
Based on qtpandas in pandas sandbox module, by Jev Kuznetsov
Usage:
@jsexauer
jsexauer / grin_blame.py
Last active August 29, 2015 13:57
Interface with git to figure out commit and hint at PR that caused a line from grin to appear.
"""
Take a girn output and find the commits and PRs that caused that code
to be added.
"""
# Find all PRs that brought in future warnings
# for https://github.com/pydata/pandas/issues/6641
# Make sure you have a copy of all the PRs in your upstream
# See:
@jsexauer
jsexauer / data_model2kivy.py
Last active April 18, 2022 16:18
Kivy Data Model Bridge -- A set of classes to allow the effortless bridging of of a data model written in standard python and a UI which is meant to automatically update to display the results of the data model
"""
Allow the simple creation of kivy UIs for arbitrary python object. The UI
will automatically update as the underlying python model changes, provided any
function on the UI side that changes the underlying data model use the
"update" decorator.
"""
import kivy
kivy.require('1.7.0')
@jsexauer
jsexauer / raisePsspyError.py
Last active October 26, 2020 22:44
Decorator for PSSE's psspy module functions
def raisePsspyError(psspyFunc):
"""This decorator raises a python exception whenever a psspy
function returns an ierr that is not 0. """
def callPsspyFunc(*args, **kwargs):
ans = psspyFunc(*args, **kwargs)
if type(ans) is tuple:
ierr = ans[0] # ierr is always first element of tuple
elif type(ans) is int:
ierr = ans # function only returns ierr
else: