Skip to content

Instantly share code, notes, and snippets.

@drwelby
drwelby / statcheck.py
Last active September 25, 2015 01:58
'''
Requires a free InfoChimps account to get census data
You'll need to enter your InfoChimps API key in the perc_black function
'''
from BeautifulSoup import BeautifulSoup
import urllib2
from geopy import geocoders
import simplejson

Curd Is The Word

[Cozy Cow Dairy] (http://www.cozycows.com) is the only source for [fresh cheese curds] (http://www.cozycows.com/products/cheese/) in the Colorado Front Range. If you're not from Wisconsin, the importance of freshness to cheese curds might not seem obvious. After all, cheese seems to stay perfectly fresh when kept cool, and some cheeses get better with age.

First, an explanation of what cheese curds are - consider them the caterpillar to a cheese butterfly. They're small chunks of coagulated milk that have been salted and cooked. Usually they are pressed together in molds and after some aging turn

@drwelby
drwelby / mb2s3.py
Last active December 15, 2015 01:39 — forked from emacsen/mb2s3.py
#!/usr/bin/env python
"""Script to upload contents of an mbtile to an s3 storage bucket"""
from boto.s3.connection import S3Connection
from boto.exception import S3ResponseError
import sqlite3
import sys
import os
import time
@drwelby
drwelby / EZri.py
Created March 31, 2013 16:32
Deal with funky ESRI Python Result objects that don't return sane types, namely getCount which returns not an integer, but a Result object that contains a string.
# Deal with funky python Result objects that don't return sane types
def EZri(result):
value = result.getOutput(0)
#is it numeric?
try:
numval = float(value)
except ValueError:
return value
# maybe it's an int?
import subprocess
import sys
'''usage: pgimport [path/to/fgdb] [database] [schema.tablename] [host] [user] [pass]
This lets you import fgdbs into postgis tables that have views on them '''
fgdb, db, target, host, user, password = sys.argv[1:]
# truncate the target table
sqlcmd = "psql"
import subprocess
import sys
import os
'''usage: pgimport path/to/fgdb layername database schema.tablename host user pass
This lets you import fgdbs into postgis tables that have views on them.
Uses an intermediate table to minimize downtime'''
fgdb, layer, db, target, host, user, password = sys.argv[1:]
@drwelby
drwelby / bitbinsort.md
Last active October 8, 2019 15:21
Bitwise binary range tree sorting, a la SBN

The SBN spatial index is some sort of binary range tree. I've been pretty close in reproducing the indexing by using a tree method, where the input bounding box is sorted through a tree structure by alternately comparing min/max coordinate pair against each division.

However, it's always seemed like there would be some faster way to sort features based on looking at individual bits in the binary representation of the coordinate value.

For example, let's say we have a 4 bit index space ( a 16 x 16 grid). We're trying to bin a bounding box with a max coordinate of (11,9) and min of (8,7).

Using the tree method, we would first look at the first split which occurs at an x of 8. Since xmin is equal to or greater than 8 that would sort the bounding box into the right bin. Next we would look at a y value of 8 for the second division. In this case the y value splits the bounding box, so the box cannot be sorted further and remains in the third bin.

We can also do this bitwise. What we first do is reverse the bin

@drwelby
drwelby / gist:8137625
Created December 26, 2013 19:24
downloadelkodocs.js
javascript:var%20params={};function%20SaveToDisk(fileURL,fileName){var%20save=document.createElement('a');save.href=fileURL;save.target='_blank';save.download=fileName||'unknown';var%20event=document.createEvent('Event');event.initEvent('click',true,true);save.dispatchEvent(event);(window.URL||window.webkitURL).revokeObjectURL(save.href);}if(location.search){var%20parts=location.search.substring(1).split('&');for(var%20i=0;i<parts.length;i++){var%20nv=parts[i].split('=');if(!nv[0])continue;params[nv[0]]=nv[1]||true;}}var%20baseUrl="http://records.elkocountynv.net:5442/docs/";var%20docNum=params.DocNo;var%20pad="0000000";padDocNum=(pad+docNum).slice(-pad.length);var%20imgUrl=baseUrl+padDocNum+".TIF";SaveToDisk(imgUrl,""+docNum+".tif");
var rs = {"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [-105.0763865, 40.540992500000002]}, "type": "Feature", "properties": {"url": "http://www.feastingfortcollins.com/?cat=635", "reviews": [{"date": "2011-04-25", "rating": 3, "url": "http://www.feastingfortcollins.com/1109/3-margaritas/", "title": "3 Margaritas"}], "name": "3 Margaritas", "rating": 3}}, {"geometry": {"type": "Point", "coordinates": [-105.075092, 40.395771000000003]}, "type": "Feature", "properties": {"url": "http://www.feastingfortcollins.com/?cat=490", "reviews": [{"date": "2010-09-03", "rating": 4, "url": "http://www.feastingfortcollins.com/349/th-street-chophouse/", "title": "4th Street Chophouse"}], "name": "4th Street Chophouse", "rating": 4}}, {"geometry": {"type": "Point", "coordinates": [-105.07713099999999, 40.5849209]}, "type": "Feature", "properties": {"url": "http://www.feastingfortcollins.com/?cat=462", "reviews": [{"date": "2013-11-03", "rating": 0, "url": "http://www.feastingfortcoll
var rs = {
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "Point",
"coordinates": [
-105.0763865,
40.540992500000002
]