Skip to content

Instantly share code, notes, and snippets.

View mattwigway's full-sized avatar

Matthew Wigginton Bhagat-Conway mattwigway

  • Department of City and Regional Planning, University of North Carolina at Chapel Hill
  • Durham, NC, USA
View GitHub Profile
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.
# similar to Python's built in zip function, but yielding named tuples instead of tuples.
# i.e. list(namedzip(a=[1, 2], b=[3, 4])) => [namedzipitem(a=1, b=3), namedzipitem(a=2, b=4)]
# Author: Matthew Wigginton Conway <[email protected]>
# feel free to use and share
from collections import namedtuple
def namedzip (**kwargs):
keys = list(kwargs.keys())
typ = namedtuple('namedzipitem', keys)
length = len(kwargs[keys[0]])
@mattwigway
mattwigway / boxplot.py
Last active January 4, 2018 23:23
Matplotlib boxplot with custom summary stats
# To the extent possible under law, Matthew Wigginton Conway has waived all copyright and
# related or neighboring rights to this work. This work is published from: United States.
def customBoxPlot (whiskerLo, boxLo, med, boxHi, whiskerHi, **kwargs):
fakeData = [np.array([42, 42]) for i in whiskerLo]
bp = plt.boxplot(fakeData, **kwargs)
for i in range(len(whiskerLo)):
# https://stackoverflow.com/questions/27214537
# This can't possibly be the best way to do this...
# lower whisker
@mattwigway
mattwigway / ocrpdf.sh
Last active August 21, 2017 20:35
Command-line tool to OCR PDFs
#!/bin/bash
# OCR a PDF using Tesseract and Ghostscript
# (brew install tesseract, brew install ghostscript using Homebrew on a Mac)
# Usage: ocrpdf input.pdf output.pdf
# Copyright (c) 2017 Matthew Wigginton Conway
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
This file has been truncated, but you can view the full file.
"{"places":[{"place_id":"from","place_name":"Origin","place_lat":38.914544497799476,"place_lon":-77.0196533203125},{"place_id":"to","place_name":"Destination","place_lat":38.77335772026906,"place_lon":-77.0196533203125}],"journeys":[{"journey_id":0,"journey_name":0,"segments":[{"type":"WALK","from":{"type":"PLACE","place_id":"from"},"to":{"type":"STOP","stop_id":"1095"}},{"type":"TRANSIT","pattern_id":"66","from_stop_index":8,"to_stop_index":17},{"type":"WALK","from":{"type":"STOP","stop_id":"3581"},"to":{"type":"STOP","stop_id":"9613"}},{"type":"TRANSIT","pattern_id":"526","from_stop_index":1,"to_stop_index":27},{"type":"WALK","from":{"type":"STOP","stop_id":"1192"},"to":{"type":"STOP","stop_id":"10067"}},{"type":"TRANSIT","pattern_id":"256","from_stop_index":26,"to_stop_index":27},{"type":"WALK","from":{"type":"STOP","stop_id":"10622"},"to":{"type":"PLACE","place_id":"to"}}]},{"journey_id":1,"journey_name":1,"segments":[{"type":"WALK","from":{"type":"PLACE","place_id":"from"},"to":{"type":"STOP","stop_id":"
@mattwigway
mattwigway / StringNPE.java
Last active September 15, 2015 16:11
StringNPE.java
import org.mapdb.*;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* Created by matthewc on 9/15/15.
@mattwigway
mattwigway / addNullValues.py
Created September 9, 2015 12:50
Replace bottom-coded values with null
#!/usr/bin/python
# Remove all the -99999... values in the NL neighborhoods file and replace them with NULL
from sys import argv
import fiona
with fiona.open(argv[1]) as infile:
meta = infile.meta
meta['schema']['geometry'] = 'MultiPolygon'
<!DOCTYPE html>
<html>
<head>
<title>MetricsGraphics Confidence Bound Test</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/metrics-graphics/2.2.1/metricsgraphics.css" />
</head>
<body>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
@mattwigway
mattwigway / InverseKeys.java
Created March 16, 2015 14:16
MapDB inverse secondary keys
/**
* Create a set of Tuple2<key in original map, value> - secondary keys, backwards.
*/
public static <K, V, V2> void inverseSecondaryKeys (MapWithModificationListener<K, V> map,
final NavigableSet<Fun.Tuple2<K, V2>> set, final Function2<V2[], K, V> fun) {
if (set.isEmpty()) {
for (Map.Entry<K, V> e : map.entrySet()) {
for (V2 val : fun.run(e.getKey(), e.getValue())) {
set.add(new Tuple2<K, V2>(e.getKey(), val));