Skip to content

Instantly share code, notes, and snippets.

View dhhagan's full-sized avatar
🙀
Building @quant-aq

David H Hagan dhhagan

🙀
Building @quant-aq
View GitHub Profile
/* PrismJS 1.25.0
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+csv+docker+git+http+json+julia+python+r&plugins=highlight-keywords+toolbar+copy-to-clipboard+match-braces */
var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(u){var c=/\blang(?:uage)?-([\w-]+)\b/i,n=0,e={},M={manual:u.Prism&&u.Prism.manual,disableWorkerMessageHandler:u.Prism&&u.Prism.disableWorkerMessageHandler,util:{encode:function e(n){return n instanceof W?new W(n.type,e(n.content),n.alias):Array.isArray(n)?n.map(e):n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/\u00a0/g," ")},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,"__id",{value:++n}),e.__id},clone:function t(e,r){var a,n;switch(r=r||{},M.util.type(e)){case"Object":if(n=M.util.objId(e),r[n])return r[n];for(var i in a={},r[n]=a,e)e.hasOwnProperty(i)&&(a[i]=t(e[i
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dhhagan
dhhagan / datetime_axis_magic.py
Created April 19, 2017 22:22
autofmt_datetime_axis
"""
This function accepts a matplotlib axis object with a datetime x-axis
and performs magical things to it to make it look not like total shit.
"""
import matplotlib.dates as dates
import matplotlib.ticker as mtick
import datetime
def label_july_only(x, pos=None):
@dhhagan
dhhagan / run_opcn2_usbiss.py
Created December 2, 2016 15:57
run_opcn2_usbiss
"""
This script runs the Alphasense OPC-N2 via the USB-ISS adapter and logs
every X seconds
Written by David H Hagan | Dec. 2016
Contact: [email protected]
"""
import usbiss
import opc
@dhhagan
dhhagan / alphasense-example.py
Created March 24, 2016 15:30
Run the Alphasense OPC-N2 for 10 seconds in a loop.
"""
Simple script to run the Alphasense OPC-N2 using the py-opc library.
Written by David H Hagan | March 24, 2016
"""
import spidev
import opc
from time import sleep
@dhhagan
dhhagan / opc.py
Created March 16, 2016 19:58
opc.py
import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
import seaborn as sns
import warnings
class DataError(TypeError):
pass
import requests
import json
class API(object):
def __init__(self, **kwargs):
self._key = kwargs.pop('key', '')
self._pswd = kwargs.pop('pswd', '')
self._version = kwargs.pop('version', None)
self._baseurl = kwargs.pop('baseurl', None)
self._headers = {'content-type': 'application/json'}
@dhhagan
dhhagan / gist:c36ce965a679e8889513
Last active September 12, 2015 12:51 — forked from maximebf/gist:3986659
Jinja2 macro to render WTForms fields with Twitter Bootstrap
{% macro form_field(field) -%}
{% set with_label = kwargs.pop('with_label', False) %}
{% set placeholder = '' %}
{% if not with_label %}
{% set placeholder = field.label.text %}
{% endif %}
<div class="control-group {% if field.errors %}error{% endif %}">
{% if with_label %}
<label for="{{ field.id }}" class="control-label">
{{ field.label.text }}{% if field.flags.required %} *{% endif %}:
@dhhagan
dhhagan / timeplot.py
Created August 15, 2015 04:34
Make pretty x-axis labels for Time series data
fig, ax = plt.subplots(1, 1)
with sns.axes_style('white'):
ax.plot(final.index, final['AFE1_X2-01_degC'], label = 'T RTD-X2-01')
ax.plot(final.index, final['AFE2_X2-01_degC'], label = 'T RTD-X2-01b')
ax.plot(final.index, final['AFE1_X2-02_degC'], label = 'T RTD-X2-02')
ax.plot(final.index, final['AFE2_X2-02_degC'], label = 'T RTD-X2-02b')
ax.set_title("X2-Series RTD Intercomparison")
ax.set_xlabel("Local Time (EST)")
ax.set_ylabel("T degC")