Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Dewar mikedewar

View GitHub Profile
@mikedewar
mikedewar / df2json.py
Created Dec 16, 2011
A little script to convert a pandas data frame to a JSON object. Is there a better way?
View df2json.py
"""
tiny script to convert a pandas data frame into a JSON object
"""
import ujson as json
import pandas
import numpy as np
df = pandas.DataFrame({
"time" : [1,2,3,4,5],
@mikedewar
mikedewar / vimrc
Created Feb 11, 2016
my vimrc as of Feb 11 2016
View vimrc
execute pathogen#infect()
syntax on
filetype plugin indent on
syntax enable
colorscheme monokai
" indents
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
" backspace
@mikedewar
mikedewar / instapaper_xauth
Created Feb 17, 2013
This is an example script to get the list of articles on your instapaper account. You need to ask Instapaper for xauth access and you (or your user) need to be an instapaper subscriber ($3 a month) to be able to see the API.
View instapaper_xauth
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth1
key = "key"
secret ="secret"
oauth = OAuth1(key, secret)
View pubsub.json
{"label":"pubsub","blocks":[{"label":"","type":"endpoint","id":8,"inputs":[{"name":"name","value":{"data":"bob"},"type":"string"}],"outputs":[{"name":"request","type":"object"},{"name":"writer","type":"writer"},{"name":"body","type":"string"}],"source":"server","position":{"x":543,"y":83}},{"label":"","type":"kvSet","id":9,"inputs":[{"name":"key","value":null,"type":"string"},{"name":"value","value":null,"type":"any"}],"outputs":[{"name":"new","type":"boolean"}],"source":"key_value","position":{"x":748,"y":153}},{"label":"","type":"kvDump","id":2,"inputs":[{"name":"dump","value":null,"type":"any"}],"outputs":[{"name":"object","type":"object"}],"source":"key_value","position":{"x":516,"y":465}},{"label":"","type":"sink","id":11,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[],"source":null,"position":{"x":916,"y":89}},{"label":"","type":"keys","id":3,"inputs":[{"name":"in","value":null,"type":"object"}],"outputs":[{"name":"keys","type":"array"}],"source":null,"position":{"x":654,"y":589}},{"labe
View splitting.json
{"label":"splitting","blocks":[{"label":"","type":"get","id":2,"inputs":[{"name":"in","value":null,"type":"object"},{"name":"key","value":{"data":"a"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":901,"y":393}},{"label":"","type":"delay","id":1,"inputs":[{"name":"in","value":{"data":{"a":1,"b":2}},"type":"any"},{"name":"duration","value":{"data":"1s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":692,"y":470}},{"label":"","type":"+","id":11,"inputs":[{"name":"x","value":null,"type":"number"},{"name":"y","value":{"data":1},"type":"number"}],"outputs":[{"name":"x+y","type":"number"}],"source":null,"position":{"x":1031,"y":392}},{"label":"","type":"get","id":3,"inputs":[{"name":"in","value":null,"type":"object"},{"name":"key","value":{"data":"b"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":1193,"y":578}},{"label":"","type":"merge","id":6,"inputs":[{"name":"in","value":null,"type":"objec
@mikedewar
mikedewar / blockingExample.json
Last active Nov 14, 2015
a simple blocking example
View blockingExample.json
{"label":"root","blocks":[{"label":"","type":"delay","id":13,"inputs":[{"name":"in","value":{"data":2},"type":"any"},{"name":"duration","value":{"data":"2s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":226,"y":272}},{"label":"","type":"log","id":16,"inputs":[{"name":"log","value":null,"type":"any"}],"outputs":[],"source":null,"position":{"x":777,"y":190}},{"label":"","type":"delay","id":3,"inputs":[{"name":"in","value":{"data":1},"type":"any"},{"name":"duration","value":{"data":"1s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":221,"y":159}},{"label":"","type":"set","id":22,"inputs":[{"name":"key","value":{"data":"top"},"type":"string"},{"name":"value","value":null,"type":"any"}],"outputs":[{"name":"object","type":"object"}],"source":null,"position":{"x":474,"y":146}},{"label":"","type":"set","id":23,"inputs":[{"name":"key","value":{"data":"bottom"},"type":"string"},{"name":"value","value":null,"type":"any"}],"outputs":[{"n
@mikedewar
mikedewar / control.json
Created Nov 13, 2015
control flow example
View control.json
{"label":"root","blocks":[{"label":"","type":"latch","id":2,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"boolean"}],"outputs":[{"name":"true","type":"any"},{"name":"false","type":"any"}],"source":null,"position":{"x":794,"y":227}},{"label":"","type":"gate","id":4,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":426,"y":228}},{"label":"ticker","type":"delay","id":1,"inputs":[{"name":"in","value":{"data":"boo"},"type":"any"},{"name":"duration","value":{"data":"1s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":490,"y":371}},{"label":"","type":"+","id":14,"inputs":[{"name":"x","value":null,"type":"number"},{"name":"y","value":{"data":1},"type":"number"}],"outputs":[{"name":"x+y","type":"number"}],"source":null,"position":{"x":433,"y":106}},{"label":"","type":"identity","id":10,"inputs":[{"name":"in","value":{"data":0},
@mikedewar
mikedewar / PoissonProcess.json
Created Nov 11, 2015
a streamtools pattern describing a poisson process
View PoissonProcess.json
{"label":"root","blocks":[{"label":"","type":"exponential","id":1,"inputs":[{"name":"rate","value":{"data":1},"type":"number"}],"outputs":[{"name":"draw","type":"number"}],"source":null,"position":{"x":263,"y":345}},{"label":"","type":"delay","id":2,"inputs":[{"name":"in","value":{"data":1},"type":"any"},{"name":"duration","value":null,"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":578,"y":330}},{"label":"","type":"toString","id":4,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[{"name":"out","type":"string"}],"source":null,"position":{"x":387,"y":345}},{"label":"","type":"concat","id":5,"inputs":[{"name":"a","value":null,"type":"string"},{"name":"b","value":{"data":"s"},"type":"string"}],"outputs":[{"name":"a+b","type":"string"}],"source":null,"position":{"x":486,"y":345}},{"label":"","type":"log","id":9,"inputs":[{"name":"log","value":null,"type":"any"}],"outputs":[],"source":null,"position":{"x":713,"y":330}}],"connections":[{"from":{"id":2,"route":0},
@mikedewar
mikedewar / counter.json
Created Nov 10, 2015
streamtools counter
View counter.json
{"label":"root","blocks":[{"label":"","type":"latch","id":1,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"boolean"}],"outputs":[{"name":"true","type":"any"},{"name":"false","type":"any"}],"source":null,"position":{"x":358,"y":348}},{"label":"","type":"first","id":2,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[{"name":"first","type":"boolean"}],"source":null,"position":{"x":249,"y":417}},{"label":"","type":"identity","id":4,"inputs":[{"name":"in","value":{"data":0},"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":147,"y":320}},{"label":"","type":"delay","id":10,"inputs":[{"name":"in","value":{"data":true},"type":"any"},{"name":"duration","value":{"data":"1s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":367,"y":544}},{"label":"","type":"gate","id":11,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"any"}],"outputs":[{"name":"out","type":"an
@mikedewar
mikedewar / initialCondition.json
Created Nov 10, 2015
a streamtools pattern that emits an initial condition
View initialCondition.json
{"label":"root","blocks":[{"label":"","type":"latch","id":1,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"boolean"}],"outputs":[{"name":"true","type":"any"},{"name":"false","type":"any"}],"source":null,"position":{"x":366,"y":322}},{"label":"","type":"first","id":2,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[{"name":"first","type":"boolean"}],"source":null,"position":{"x":253,"y":383}},{"label":"","type":"identity","id":4,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":180,"y":296}},{"label":"","type":"identity","id":7,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":509,"y":314}}],"connections":[{"from":{"id":2,"route":0},"to":{"id":1,"route":1},"id":3},{"from":{"id":4,"route":0},"to":{"id":1,"route":0},"id":5},{"from":{"id":4,"route":0},"to":{"id":2,"route":0},"id":6},{"from":{"id":1,"route":0},"to":{"id":7,
You can’t perform that action at this time.