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
@mattwigway
mattwigway / corplot.R
Created February 22, 2014 19:47
Draw visual correlation plots
# Draw visual correlation plots, http://www.indicatrix.org/2014/02/22/visual-correlation-matrices/
# Copyright (C) 2014 Matthew Wigginton Conway.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
@mattwigway
mattwigway / README.md
Last active August 29, 2015 14:02
Shelby County, TN property values

This map shows the change in median property value per square foot for parcels in Shelby County, TN.

<html>
<head>
<title>Test CartoDB</title>
</head>
<body>
<iframe src="https://mattwigway.cartodb.com/viz/6f540a5e-1998-11e4-add7-0edbca4b5057/embed_map" width="800" height="600" />
</body>
</html>
@mattwigway
mattwigway / MapDBEmptyPumpSource.java
Created February 24, 2015 18:54
Cannot use empty pump source with MapDB
import java.util.Iterator;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.Fun.Tuple2;
public class MapDBEmptyPumpSource {
public static void main(String... args) {
Iterator<Tuple2<String, String>> data = new Iterator () {
@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));
<!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 / 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'
@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 / twisted-xmlrpc.py
Created October 13, 2011 05:20
Quick twisted XMLRPC test
from twisted.web import xmlrpc, server
from twisted.internet import reactor, defer
class rpctest(xmlrpc.XMLRPC):
def xmlrpc_test(self):
return "Hello, world!"
if __name__ = '__main__':
r = rpctest()
@mattwigway
mattwigway / selectline.sql
Created November 9, 2011 23:23
Selecting a line from NextBus data
SELECT loc_a.oid, loc_a.vehicle, loc_a.route, loc_a.direction, transform(ST_MakeLine(loc_a.the_geom, loc_b.the_geom), 26945) AS the_geom,
(ST_Length(transform(ST_MakeLine(loc_a.the_geom, loc_b.the_geom), 26945))/
(EXTRACT(EPOCH FROM loc_b.time) - EXTRACT(EPOCH FROM loc_a.time))) *
2.23693629 AS mph, loc_a.time AS starttime, loc_b.time AS endtime
INTO acrt.lametrolines
FROM
(SELECT *, ROW_NUMBER() OVER (ORDER BY vehicle, time) AS num FROM acrt.nextbus) AS loc_a
JOIN
(SELECT *, ROW_NUMBER() OVER (ORDER BY vehicle, time) AS num FROM acrt.nextbus) AS loc_b
ON (loc_a.vehicle = loc_b.vehicle AND