Skip to content

Instantly share code, notes, and snippets.

View fogonthedowns's full-sized avatar
👋

JZ fogonthedowns

👋
View GitHub Profile
@fogonthedowns
fogonthedowns / api_post_example.json
Last active October 21, 2016 21:36
hitpicker api
{
"screening": 8,
"date": 1476908234241,
"uid": "UID-16-0003",
"linkage_matrix": [[2, 3, 0.06571365, 2],
[0, 10, 0.07951425, 2],
[5, 6, 0.09405724, 2],
[11, 13, 0.10182075, 3],
[1, 12, 0.12900146, 3],
[14, 15, 0.13498948, 5],
@fogonthedowns
fogonthedowns / clusternode_parse.py
Created October 17, 2016 17:07
proper tree parse scipy ClusterNode object
def parse(tree, p):
path = p[:]
path.append(str(tree.get_id()))
if tree.is_leaf():
print('.'.join(path))
else:
#Here I assume get_left() returns some falsey value for no left child
left = tree.get_left()
if left:
parse(left, path)
@fogonthedowns
fogonthedowns / tree_node_paths.py
Last active October 17, 2016 16:31
return the leaf paths from scipy.cluster ClusterNode
linkage_matrix =
[[2, 3, 0.06571365, 2], [0, 10, 0.07951425, 2], [5, 6, 0.09405724, 2], [11, 13, 0.10182075, 3], [1, 12, 0.12900146, 3], [14, 15, 0.13498948, 5], [8, 9, 0.16806049, 2], [7, 16, 0.1887918, 4], [17, 19, 0.2236683, 9], [18, 20, 0.29471335, 11], [4, 21, 0.45878, 12]]
from scipy.cluster import hierarchy
a = hierarchy.to_tree(linkage_matrix)
def parse_tree(tree, path):
path = path
if path ==[]:
path.append(str(tree.get_id()))
@fogonthedowns
fogonthedowns / parse tree
Created October 14, 2016 21:56
parse tree
def parse_tree(tree, path):
path = path
if path ==[]:
path.append(str(tree.get_id()))
if tree.is_leaf() is False:
left = tree.get_left()
left_id = str(left.get_id())
if left.is_leaf() is False:
path.append(left_id)
parse_tree(left, path)
@fogonthedowns
fogonthedowns / parse tree
Created October 14, 2016 20:33
parse tree
def parse_tree(tree, path):
path = path
path.append(str(tree.get_id()))
if tree.is_leaf() is False:
right = tree.get_right()
parse_tree(right, path)
left = tree.get_left()
parse_tree(left, path)
else:
print(('.').join(path))
@fogonthedowns
fogonthedowns / psql Trigger
Created August 12, 2016 16:30
psql Trigger
CREATE OR REPLACE FUNCTION process_inv_audit() RETURNS TRIGGER AS $inv_audit$
BEGIN
IF (TG_OP = 'DELETE') THEN
INSERT INTO inventory_audit (id, old_column, op, location, notes, amount, original_amount, units, original_units, lot, batch, date_opened, date_expired, plant_material_id, uid, is_active, received_date, order_date, secondary_location, price, country_code, vendor_code, legacy_id, brand, status) VALUES (nextval('inventory_audit_id_seq'), OLD.id, 'D', OLD.location, OLD.notes, OLD.amount, OLD.original_amount, OLD.units, OLD.original_units, OLD.lot, OLD.batch, OLD.date_opened, OLD.date_expired, OLD.plant_material_id, OLD.uid, OLD.is_active, OLD.received_date, OLD.order_date, OLD.secondary_location, OLD.price, OLD.country_code, OLD.vendor_code, OLD.legacy_id, OLD.brand, OLD.status);
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
INSERT INTO inventory_audit (id, old_column, op, location , notes, amount, original_amount, units, original_units, lot, batch, da
from bs4 import BeautifulSoup
import logging
try:
from Queue import Queue # PY2
except ImportError:
from queue import Queue # PY3
import requests
from requests.exceptions import RequestException
from six import iteritems
from threading import Thread
@fogonthedowns
fogonthedowns / April 29th
Created April 29, 2016 22:48
April 29th
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<link href="slider.css" rel="stylesheet">
<!-- Example based on http://bl.ocks.org/mbostock/3887118 -->
<!-- Tooltip example from http://www.d3noob.org/2013/01/adding-tooltips-to-d3js-graph.html -->
@fogonthedowns
fogonthedowns / gist:431d1144acbcfe3a3c9d72343b6d43c2
Last active April 27, 2016 20:31
bokeh plotting with column data source
import pandas as pd
from bokeh.plotting import ColumnDataSource, figure, output_file, show
from bokeh.models import HoverTool
output_file("scatter.html")
df = pd.read_csv('/Users/jzollars/07_isolate_selection.csv')
hash = {}
c = ('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black',
'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse',
@fogonthedowns
fogonthedowns / bokeh
Last active April 27, 2016 20:30
bokeh
import pandas as pd
from bokeh.charts import Scatter, output_file, show
output_file("scatter.html")
df = pd.read_csv('/Users/jzollars/07_isolate_selection.csv')
hash = {}
# List colors:
c = ('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen