Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bsmithgall on github.
  • I am bsmithgall (https://keybase.io/bsmithgall) on keybase.
  • I have a public key whose fingerprint is 94C0 A744 D5FF 2BCF BF5D 982F 8A33 E82F AF50 CA96

To claim this, I am signing this object:

@bsmithgall
bsmithgall / parse.py
Created August 25, 2015 21:31
QScend json -> csv
# -*- coding: utf-8 -*-
import json
import csv
import urllib2
def load_from_url(url):
raw_data = urllib2.urlopen(url).read().decode('utf-8').rstrip()
# standardize file endings
@bsmithgall
bsmithgall / titlecase.py
Created August 3, 2015 18:19
python titlecase filter for jinja
# modified from https://gist.github.com/bsmithgall/372de43205804a2279c9
SMALL_WORDS = re.compile(r'^(a|an|and|as|at|but|by|en|etc|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$', re.I)
SPACE_SPLIT = re.compile(r'[\t ]')
# taken from http://stackoverflow.com/a/267405
CAP_WORDS = re.compile(r'^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$')
PUNC_REGEX = re.compile(r'[{}]'.format(re.escape(string.punctuation)))
# taken from python-titlecase: https://github.com/ppannuto/python-titlecase/blob/master/titlecase/__init__.py#L27
UC_INITIALS = re.compile(r'^(?:[A-Z]{1}\.{1}|[A-Z]{1}\.{1}[A-Z]{1})+$', re.I)
def better_title(string):
UM List
ACRE
ACRE FEET OF WATER
ASSEMBLY
BAGS
BALE
BALL
BAR
BARREL
BASKET
@bsmithgall
bsmithgall / Dockerfile
Last active August 29, 2015 14:21
Docker compose example
FROM python:2.7
COPY . /app/
WORKDIR /app
RUN pip install -r requirements.txt
@bsmithgall
bsmithgall / base_test.py
Created April 27, 2015 22:42
Testing w/Mocks, Persona
from unittest import TestCase
from mock import Mock, patch
class BaseTestCase(TestCase)
@patch('urllib2.urlopen')
def login_user(self, user, urlopen):
_email = user.email if user else 'foo@foo.com'
mock_open = Mock()
mock_open.read.side_effect = ['{"status": "okay", "email": "' + _email + '"}']
urlopen.return_value = mock_open
@bsmithgall
bsmithgall / open-vis.md
Last active August 29, 2015 14:19
Open Vis Notes
@bsmithgall
bsmithgall / cruise.js
Last active August 29, 2015 14:18
fun with p5
var x = 0, backwards = false, s = 800, y = 0, up=true,
r=0, g=0, b=0, circleWidth = 100, mavericks=[],
maxR = false, maxG = false, maxB = false, fft, song, img;
function preload() {
song = loadSound('danger-zone.mp3');
img = loadImage('maverick.png');
}
function setup() {
@bsmithgall
bsmithgall / dogs.json
Last active August 29, 2015 14:18
Sublime Keyboard Shortcuts
// COMMAND + CONTROL + G --> select all matches on a page
// COMMAND + CLICK --> add a new cursor
// COMMAND + D --> select the next match
// COMMAND + CONTROL + UP ARROW --> move the highlighted line up
// COMMAND + CONTROL + DOWN ARROW --> move the highlighted line down
// COMMAND + SHIFT + L (over highlighted lines) --> CURSOR AT THE END OF EACH LINE
// COMMAND + SHIFT + P --> Opens command window for sublime
// CONTROL + N --> Down one line
// CONTROL + P --> Up one line
// CONTROL + F --> Forward one character
@bsmithgall
bsmithgall / parse_blotter.py
Last active August 29, 2015 14:15
Parse Police Blotter with wextractor
import requests
import datetime
import time
import tempfile
from wextractor.extractors import CsvExtractor
upload_url = 'http://opendata.ucsur.pitt.edu/data/api/action/datastore_upsert?resource_id=eaa91ff8-6d63-4750-810a-53957a344346'
resource_id = 'eaa91ff8-6d63-4750-810a-53957a344346'