Skip to content

Instantly share code, notes, and snippets.

View mgranberry's full-sized avatar

Matthias Granberry mgranberry

View GitHub Profile
function iobCalc(treatment, time) {
var dia=profile.dia;
var scalefactor = 1;
var peak;
if (dia == 3) {
peak=75;
} else {
// console.warn('DIA of ' + dia + ' not supported');
peak = 75;
@mgranberry
mgranberry / dexcom_uploader.py
Last active August 29, 2015 14:17
Upload data from a DexCom G4 CGM into nightscout using dexcom_reader and pymongo
#!/usr/bin/env python
# replace MONGO_URI with your own nightscout mongo URI
MONGO_URI = 'mongodb://nightscout.example.com:1234/'
import dexcom_reader.readdata
import time
from serial.serialutil import SerialException
from datetime import datetime, date
from pymongo import MongoClient
mongo_client = MongoClient(MONGO_URI)
@mgranberry
mgranberry / Treatment.proto
Last active August 29, 2015 14:20
Proposed protocol buffer spec for NightScout treatment data
option java_package = "com.nightscout.core.model";
option java_outer_classname = "Treatment";
// This is a naive conversion of NightScout's current treatments to protocol buffers
message Treatment {
optional EventType event_type = 1;
optional string entered_by = 2;
required string created_at = 3;
@mgranberry
mgranberry / agp.py
Last active August 29, 2015 14:20
quick hack at an AGP report built on OpenAPS
import dateutil.parser
from scipy import stats
from scipy.stats import norm
from numpy import percentile
import math
values = []
hour_buckets = {}
for hour in range(0,24):
hour_buckets[hour] = []
@mgranberry
mgranberry / DesignSupport.kt
Created June 2, 2015 21:26
A set of Anko-compatible extensions for Google's Material Design Support Library
fun ViewManager.appBarLayout(init: AppBarLayout.() -> Unit = {}) =
__dslAddView({ AppBarLayout(it) }, init, this)
fun ViewManager.collapsingToolbarLayout(init: CollapsingToolbarLayout.() -> Unit = {}) =
__dslAddView({ CollapsingToolbarLayout(it) }, init, this)
fun ViewManager.coordinatorLayout(init: CoordinatorLayout.() -> Unit = {}) =
__dslAddView({ CoordinatorLayout(it) }, init, this)
fun ViewManager.floatingActionButton(init: FloatingActionButton.() -> Unit = {}) =
@mgranberry
mgranberry / gist:f3fdf235e6c3480cd29a
Created June 26, 2015 22:26
dex share doesn't love me
06-26 17:23:44.592 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ <--- HTTP 200 https://share1.dexcom.com/ShareWebServices/Services/General/LoginPublisherAccountByName (446ms)
06-26 17:23:44.592 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ Cache-Control: private
06-26 17:23:44.592 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ Content-Length: 38
06-26 17:23:44.592 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ Content-Type: application/json; charset=utf-8
06-26 17:23:44.592 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ Server: Microsoft-IIS/8.5
06-26 17:23:44.593 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ X-AspNet-Version: 4.0.30319
06-26 17:23:44.593 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ Date: Fri, 26 Jun 2015 22:23:44 GMT
06-26 17:23:44.593 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ OkHttp-Selected-Protocol: http/1.1
06-26 17:23:44.593 12955-32136/com.eveningoutpost.dexdrip D/SHAREREST﹕ OkHttp-Sent-Millis: 1435357424491
06-26 17:23:44.593
@mgranberry
mgranberry / precious-status-emails.py
Last active February 17, 2016 21:18
This gist downloads, converts, and tags the time in the images contained emails sent from my daughter's daycare. (Precious Status)
import imaplib
import re
import datetime
from os import system, environ
def process(client):
rv, data = client.search(None, 'ALL')
# print rv, data
emails = data[0].split()
@mgranberry
mgranberry / bounding_ellipse.py
Last active September 6, 2016 21:21
Take the input image (a button on a white background), calculate an ellipse bounding the button, crop the bounded ellipse, and write out the image.
import numpy as np
import cv2
im = cv2.imread('button1.jpg')
hsv_img = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
kernel = np.ones((5,5),np.uint8)
edges = cv2.morphologyEx(hsv_img, cv2.MORPH_GRADIENT, kernel)
ret, thresh = cv2.threshold(edges,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
cv2.imshow("Show", thresh)
cv2.waitKey()
@mgranberry
mgranberry / siobg.py
Last active April 24, 2017 20:36
socketio blood glucose fetch for openaps
#!/usr/bin/env python
from __future__ import print_function
import json
import signal
import subprocess
import sys
from datetime import datetime
from os import environ, utime