Skip to content

Instantly share code, notes, and snippets.

from django.db import models
class Author(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
class Book(models.Model):
title = models.CharField(max_length=200)
@palewire
palewire / albums.py
Created December 16, 2014 19:57
Mechanize scrape with Python
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
def extract(html):
soup = BeautifulSoup(html)
table = soup.find("table", border=1)
list_of_rows = []
for row in table.findAll('tr')[1:]:
list_of_cells = []
for cell in row.findAll('td'):
@palewire
palewire / datadesk-server-name-picker.py
Last active August 29, 2015 14:17
Datadesk server name picker
import random
nominee_list = [
"Eric Malnik", # http://articles.latimes.com/print/2010/jul/29/local/la-me-eric-malnic-20100729
"Charles Hillenger", # http://articles.latimes.com/print/2008/apr/30/local/me-hillinger30
"Jim Murray", # http://articles.latimes.com/print/1998/aug/18/news/mn-14252
"George Ramos", # http://articles.latimes.com/print/2011/jul/25/local/la-me-george-ramos-20110725
"Frank del Olmo", # http://www.latimes.com/local/obituaries/la-me-delolmo20feb20-story.html#page=1
"Laurie Becklund", # http://www.latimes.com/opinion/op-ed/la-oe-becklund-breast-cancer-komen-20150222-story.html#page=1
"Bill Billiter", # http://articles.latimes.com/print/1997-04-20/local/me-50644_1_orange-county
@palewire
palewire / 0_reuse_code.js
Last active August 29, 2015 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
httpd 21621 root cwd DIR 0,179 4096 169321800 /
httpd 21621 root rtd DIR 0,179 4096 169321800 /
httpd 21621 root txt REG 0,179 312372 30417878 /usr/sbin/httpd
httpd 21621 root mem REG 0,179 46680 7938536 /lib/libnss_files-2.5.so
httpd 21621 root mem REG 0,179 13420 7938518 /lib/libutil-2.5.so
httpd 21621 root mem REG 0,179 1611095 14621180 /usr/lib/httpd/modules/mod_python.so
httpd 21621 root mem REG 0,179 30300 14625108 /usr/lib/httpd/modules/mod_proxy_ajp.so
httpd 21621 root mem REG 0,179 5500 14625070 /usr/lib/httpd/modules/mod_version.so
httpd 21621 root mem REG 0,179 22136 14625164 /usr/lib/httpd/modules/mod_cgi.so
httpd 21621 root mem REG 0,179 22076 14625080 /usr/lib/httpd/modules/mod_mem_cache.so
@palewire
palewire / GeoDjango model with viewport bias.py
Created June 29, 2010 02:13
Generate a viewport bias from a GeoDjango model. Useful when geocoding.
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
class Multipolygon(models.Model):
"""
Try using it with this: http://github.com/palewire/latimes-mappingla-geopy
"""
name = models.CharField(max_length=200, null=True, blank=True)
multipolygon = models.MultiPolygonField(srid=2229, null=True, blank=True)
objects = models.GeoManager()
@palewire
palewire / pdf.py
Created January 5, 2011 18:47
pdf2txt ripper from EveryBlock code.
"""
Utilities for reading data from PDF files.
Lifted from EveryBlock source code.
These require the pdftotext binary, available in the Xpdf package:
http://www.foolabs.com/xpdf/download.html
"""
import os
{"project":{"id":null,"title":"This is bad test","description":null,"document_ids":[]}}
@palewire
palewire / AP_STATES_NORMALIZATION.py
Created April 21, 2011 22:50
A crosswalk that converts state names and abbreviations to A.P. style.
AP_STATES_NORMALIZATION = {
'ak': 'Alaska',
'al': 'Ala.',
'ala': 'Ala.',
'alabama': 'Ala.',
'alaska': 'Alaska',
'american samao': 'A.S.',
'american samoa': 'A.S.',
'ar': 'Ark.',
'ariz': 'Ariz.',
@palewire
palewire / dorling.py
Created September 20, 2011 08:26
Takes a GeoDjango queryset and creates a cartogram of circles based on the Dorling algorithm.
import math
from django.contrib.gis.geos import Point
class Cartogram(object):
"""
Takes a GeoDjango queryset and creates a cartogram of circles based on
the Dorling algorithm.
User must provide a queryset and strings pointing to the data attribute