Skip to content

Instantly share code, notes, and snippets.

@JimHaughwout
JimHaughwout / check_dependencies.py
Created September 5, 2015 21:04
Check Install Dependencies
import subprocess
DEPENDENCIES = ['cqlsh', 'ttab', 'kafka']
def check_dependency(program):
"""TODO"""
try:
subprocess.check_output(["which", program])
except:
msg = "%s not installed. Please install" % program
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JimHaughwout
JimHaughwout / gen_cobra_poly.py
Last active August 29, 2015 14:25
Gen Cobra Polyline
#!/usr/bin/python
import sys
import json
import getopt
import webbrowser
html_header = """<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
@JimHaughwout
JimHaughwout / try_dict_extract.py
Created July 11, 2015 15:17
TryExcept Dict Element Extract
def try_dict_extract(dictionary, key_list):
"""
Iterates through a list of nested keys to try to return a dictionary key value.
On exception, returns NoneType
"""
try:
x = dictionary
for key in key_list:
x = x[key]
return x
@JimHaughwout
JimHaughwout / mapping_example.py
Created June 26, 2015 14:50
Dicts for Mapping
#! /usr/bin/env python
"""
Using dictionaries for mapping lookups
See: http://www.tutorialspoint.com/python/python_dictionary.htm
"""
# Use a Python Dictionary for mapping
mapping = {
'CB' : 'Cobra',
'foo' : 'bar',
@JimHaughwout
JimHaughwout / cobra.py
Last active August 29, 2015 14:23
Cobra Tag Exercise
import getopt
import sys
from datetime import datetime
from time import sleep
import pytz
#### CRC-16 MODBUS Stuff. Included so we do all in one script ####
INITIAL_MODBUS = 0xFFFF
@JimHaughwout
JimHaughwout / path_distance.py
Created November 13, 2014 23:55
Compute distance and interpolate speed along path of coordinates and timestamps
from sys import argv
import csv
import dateutil.parser
from geopy.distance import vincenty
'''
Input file is downloaded movements from Savi Tracking
column 1 (a.k.a. row[0]) = lat
column 2 (a.k.a. row[1]) = lng
column 3 (a.k.a. row[2]) = utc time
'''
@JimHaughwout
JimHaughwout / oracle_dt_utils.py
Last active August 29, 2015 14:08
Python Dates, Date-Time to Oracle
from datetime import date, datetime
def oracle_weekday(dt):
'''
Takes a python datetime or date object.
Returns Day of Week in Oracle model
Day python oracle
Mon 0 2
Tue 1 3
Wed 2 4
@JimHaughwout
JimHaughwout / ts_bin.py
Created October 7, 2014 23:11
Binary search: closest ts in list of datetime.datetimes
from sys import argv, exit
import datetime as dt
import dateutil.parser
import random
from bisect import bisect_left
from utils import ts_diff_in_seconds as time_diff
def built_test_ts_list(length=1, min_diff=60, max_diff=60, start_dt=None):
@JimHaughwout
JimHaughwout / kdtree_sample.py
Created October 7, 2014 23:09
playing with KDTrees
from scipy.spatial import KDTree
import numpy as np
from sys import argv, exit
'''
One-dimensional KDTree to lookup ts with nearest value
usage = "Usage: python %s value_to_seek optional_distance" % argv[0]
if len(argv) != 2: