Skip to content

Instantly share code, notes, and snippets.

View ryanpitts's full-sized avatar

Ryan Pitts ryanpitts

View GitHub Profile
@ryanpitts
ryanpitts / gist:1304725
Created October 21, 2011 19:34
GROUP BY and Select MAX from each group in Django, 2 queries
'''
given a Model with:
category = models.CharField(max_length=32, choices=CATEGORY_CHOICES)
pubdate = models.DateTimeField(default=datetime.now)
<other fields>
Fetch the item from each category with the latest pubdate.
'''
@ryanpitts
ryanpitts / postrock_song_titles.txt
Last active April 14, 2023 08:51
1,115 postrock song titles
War On Christmas
Glow
Cambian
Somnambulance
Long March
Seperate But Equal
Peterson
Thompson
Twelve Days Awake
Everyone Gets Shot
@ryanpitts
ryanpitts / The Five Cognitive Distortions of People Who Get Stuff Done
Created September 12, 2013 17:32
Notes from Michael Dearing's "The Five Cognitive Distortions of People Who Get Stuff Done," so I don't need to look through slides every time. Source: http://quarry.stanford.edu/xapm1111126lse/docs/02_LSE_Cognitive.pdf
Five recurring, automatic patterns of thought (aka cognitive distortions) among people who get extraordinary stuff done in Silicon Valley.
1. Personal Exceptionalism: "I am special."
Definition: a macro sense that you are in the top of your cohort, your work is snowflake special, or that you are destined to have experiences well outside the bounds of "normal;" not to be confused with arrogance or high self-esteem
Benefit: resilience, stamina, charisma
Deadly risk: assuming macro exceptionalism means micro exceptionalism, brittleness
@ryanpitts
ryanpitts / loremipsum.js
Created September 20, 2011 20:08
Lorem Ipsum from Beowulf in Old English
/*
* Modified Lorem Ipsum Generator by Fredrik Bridell (http://bridell.com/loremipsum/)"
*
* To use: download the .js file, and in your html include the markup:
* <script type="text/javascript" src="loremipsum.js"></script>
*
* Where you want the Lorem Ipsum, include something like:
* <script type="text/javascript">loremIpsumParagraph(100)</script>
*/
@ryanpitts
ryanpitts / .bash_prompt
Last active October 13, 2021 12:24
This is a SUPER handy bash_prompt update. Source this at the end of your .bash_profile, and your command line while in git repo directories adds some awesome information. Example: http://cl.ly/image/1A0c1D3R2H1R Adapted from https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt
#!/bin/bash
# bash_prompt
# Example:
# nicolas@host: ~/.dotfiles on master[+!?$]
# $
# Screenshot: http://i.imgur.com/DSJ1G.png
# iTerm2 prefs: import Solarized theme (disable bright colors for bold text)
@ryanpitts
ryanpitts / summary_level_dict
Last active April 6, 2021 15:24
Summary level codes for Census and ACS
# Sources:
# http://mcdc2.missouri.edu/pub/data/sf32000/Techdoc/ch4_summary_level_seq_chart.pdf
# http://www2.census.gov/acs2011_1yr/summaryfile/ACS_2011_SF_Tech_Doc.pdf
SUMMARY_LEVEL_DICT = {
"010","United States",
"020","Region",
"030","Division",
"040","State",
"050","State-County",
"060","State-County-County Subdivision",
@ryanpitts
ryanpitts / scraper.py
Created March 4, 2020 01:12
example scraper code for NICAR 2020
import requests
import bs4
import csv
URL = 'http://www.dllr.state.md.us/employment/warn.shtml'
warn_page = requests.get(URL)
soup = bs4.BeautifulSoup(warn_page.text, 'html.parser')
table = soup.find('table')
rows = table.find_all('tr')
import csv
from collections import OrderedDict
CLEANED_DICT = OrderedDict()
METADATA_FIELDS = ['districtID','district','schoolID','school']
VALUE_FIELDS = []
with open('schools.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
@ryanpitts
ryanpitts / bible_objects.py
Created February 29, 2016 23:20
Python list of every object mentioned in the Bible, in order. Source: http://www.cabinetmagazine.org/issues/16/kay.php
bible_objects = ['seed', 'gold', 'resin', 'onyx', 'fruit', 'fig leaves', 'fruit', 'vegetables', 'portion of meat', 'ark', 'olive leaf', 'burnt offerings', 'wine', 'bricks', 'silver', 'gold', 'tents', 'bread', 'wine', 'heifer carcass', 'goat carcass', 'ram carcass', 'brazier', 'torch', 'flour', 'curds', 'milk', 'veal', 'bread', 'one thousand silver shekels', 'food', 'skin of water', 'wood', 'knife', 'burnt offering', 'four hundred silver shekels', 'jar', 'gold nose ring', 'gold bracelets', 'straw', 'fodder', 'gold and silver jewellery', 'clothing', 'bread', 'lentil stew', 'quiver', 'bow', 'clothes', 'goatskins', 'bread', 'food', 'wine', 'stone', 'oil', 'mandrake plants', 'poplar branches', 'almond branches', 'watering troughs', 'tent', 'gods', 'saddle', 'stone', 'stones', 'food', 'one hundred pieces of silver', 'tent', 'altar', 'idols', 'earring', 'stone', 'oil', 'ornamented robe', 'food', 'spices', 'balm', 'myrrh', 'twenty shekels', 'clothes', 'goat carcass', 'sackcloth', 'clothes', 'veil', 'seal', 'cord', 's
@ryanpitts
ryanpitts / new.js
Created January 16, 2014 20:04
yay underscore
// hit the /parents API endpoint
$.getJSON(parentGeoAPI)
.done(function(results) {
var parents = results['parents'];
// list of unique parent sumlev types, maintaining order
var parentRelations = _.uniq(_.pluck(parents, 'sumlevel'));
// collect parents into individual sumlev groups
var parentGroups = _.groupBy(parents, function(d) {
return d.sumlevel;
});