Skip to content

Instantly share code, notes, and snippets.

View schwanksta's full-sized avatar
💭
(┛ಠ_ಠ)┛彡┻━┻

Ken Schwencke schwanksta

💭
(┛ಠ_ಠ)┛彡┻━┻
View GitHub Profile
@schwanksta
schwanksta / apdate_to_datetime.py
Created May 5, 2010 00:10
Converts an AP Style date string to a Python datetime object.
def apdate_to_datetime(date):
"""
Takes an AP-formatted date string and returns a Python datetime
object. This will also work on any date formatted as either
'%b. %d, %Y' or '%B %d, %Y'
Examples:
>>> apdate_to_datetime("Sept. 4, 1986")
datetime.datetime(1986, 9, 4, 0, 0)
>>> apdate_to_datetime("Sep. 4, 1986")

Smoke, mirrors and madlibs: How to break news while you sleep

Around 6:25 a.m. I was awakened by a jolt from slipping tectonic plates. The tremor didn't last very long, and as soon as my window stopped rattling my first thought was to check for an email.

Here it was:

L.A. Now: Ready for copyedit: Earthquake: 4.7 quake strikes near Westwood, California

This is a robopost from your friendly earthquake robot. Please copyedit & publish the

@schwanksta
schwanksta / models.py
Last active August 13, 2019 20:41
Simple Django FOIA CCing code
from django.db import models
from django.db.models import Q
from django.conf import settings
from django.utils.functional import cached_property
from django.contrib.postgres.fields import HStoreField, ArrayField
from datetime import date, datetime, time, timedelta
from foiaminder.schedule import SCHEDULES
from business_calendar import Calendar
import requests

Keybase proof

I hereby claim:

  • I am schwanksta on github.
  • I am schwanksta (https://keybase.io/schwanksta) on keybase.
  • I have a public key ASBcdo7HTW0HfyikZ8M0_Adaaf4V4Yq8wnUqja3WkJEZkwo

To claim this, I am signing this object:

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.
@schwanksta
schwanksta / parallelcopy.py
Created February 25, 2016 20:57
parallelized COPY in postgres
import multiprocessing
import subprocess
from glob import glob
import os
fields = ["field1", "field2", "field3"]
def work(fname):
print "starting %s" % fname
fname = os.path.abspath(fname)
@schwanksta
schwanksta / index.html
Last active December 27, 2015 10:39
high homicide tracts
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script type="text/javascript">
geojson = {"type":"FeatureCollection","features":[{"type":"Feature","id":651,"properties":{"GEOID10":"06037600304","CT10":"600304","LABEL":"6003.04","X_Center":6472482.0,"Y_Center":1798989.0,"Shape_area":4798305.86046,"Shape_len":9662.240288860000874,"PNTCNT":15.0,"SumLev":"140","AreaName":"CensusTract6003.04","State":"06","AreaLand":"445759","AreaWatr":"0","TotPop":"3424","Wht":"50","Blk":"1330","Asn":"7","Hisp":"1986","Oth":"51","NAMELSAD10":"CensusTract6003.04","per_capita":0.0043808411,"PopInt":3424},"geometry":{"type":"Polygon","coordinates":[[[-118.291637000512452,33.939880999892225],[-118.291639000350102,33.939056000142166],
@schwanksta
schwanksta / parse_inspections.py
Last active December 25, 2015 16:08
Parse LA County restaurant inspection data
import mechanize
from BeautifulSoup import BeautifulSoup
def parse_table(html):
"""
Returns a list of lists. Each list is a row in the table.
"""
soup = BeautifulSoup(html)
# The 9th table down the page is the one with all the info.
table = soup.findAll('table')[9]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.