Skip to content

Instantly share code, notes, and snippets.

View mattdennewitz's full-sized avatar

Matt Dennewitz mattdennewitz

  • Lancaster, OH
View GitHub Profile
# models.py:
# ----------
from django.contrib.gis.db import models as geomodels
class Place(geomodels.Model):
woe_id = geomodels.IntegerField()
place_id = geomodels.CharField(max_length=255)
place_type = geomodels.CharField(max_length=255)
place_type_id = geomodels.IntegerField()
# -*- coding: utf8 -*-
"""
Download and import US census data from
`http://www.census.gov/geo/www/cob/z52000.html`
# shapefile mapping:
zipcode_mapping = {
'area' : 'AREA',
'perimeter' : 'PERIMETER',
from django.contrib.gis.db import models as geomodels
class Place(geomodels.Model):
woe_id = geomodels.IntegerField()
place_id = geomodels.CharField(max_length=255)
place_type = geomodels.CharField(max_length=255)
place_type_id = geomodels.IntegerField()
label = geomodels.CharField(max_length=255)
created = geomodels.DateTimeField()
geometry = geomodels.PolygonField(srid=4326)
import sys
from math import log, sqrt
def pnormaldist(qn):
b = [1.570796288, 0.03706987906, -0.8364353589e-3,
-0.2250947176e-3, 0.6841218299e-5, 0.5824238515e-5,
-0.104527497e-5, 0.8360937017e-7, -0.3231081277e-8,
0.3657763036e-10, 0.6936233982e-12]
if qn < 0.0 or 1.0 < qn:
# quick & dirty example
def get_placemark_point(raw_location):
"""Attempt to resolve ``raw_location`` using Google's geocoder.
Returns a tuple with the canonical address and GEOS point
"""
import cjson
from urllib import urlencode
from urllib2 import urlopen
def test_map_reduce_finalize(self):
"""Ensure finalize is running by simulating "hotness"
ranking with Reddit algorithm.
"""
from time import mktime
class Link(Document):
title = StringField()
up_votes = IntField()
down_votes = IntField()

Runs/Replacement

Use 20 runs per 600 pa as baseline and scale from there, eg, 23.3 runs per 700 pa.

FIP

(13*hr+3*bb-2*k)/ip

curl -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null -s http://www.domain.com/
@mattdennewitz
mattdennewitz / corrupt.py
Created October 15, 2010 02:44
python port of corrupt, for image disruption.
#!/usr/bin/env python
"""
corrupt
usage: ./corrupt.py --source=input.jpg [--output=corrupted.jpg] [--iterations=10]
originally: http://www.recyclism.com/corrupt.php
ported: @mattdennewitz
"""
@mattdennewitz
mattdennewitz / gist:638800
Created October 21, 2010 16:22
s3 can stream a file to the user with a different filename
from boto.s3.connection import S3Connection
file_to_upload = "e434b232c2e4f70aa2819d708dfd30fb4cebcf6c.zip"
s3 = S3Connection(YOUR_AWS_ACCESS_KEY, YOUR_AWS_SECRET_KEY)
bucket = s3.get_bucket(YOUR_BUCKET_NAME)
# user will receive "mixtape.zip" instead of "e434b232c2e4f70aa2819d708dfd30fb4cebcf6c.zip"
s3_headers = {'Content-Disposition': "attachment; filename=mixtape.zip"}