Skip to content

Instantly share code, notes, and snippets.

@jacobian
jacobian / models.py
Created February 15, 2011 18:11
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):

Test

Just testing reST rendering.

@jacobian
jacobian / deleting_file_field.py
Created March 27, 2011 22:19
DeletingFileField
from django.db import models
from django.db.models import signals
class DeletingFileField(models.FileField):
"""
FileField subclass that deletes the refernced file when the model object
itself is deleted.
WARNING: Be careful using this class - it can cause data loss! This class
makes at attempt to see if the file's referenced elsewhere, but it can get
@jacobian
jacobian / chunked.py
Created April 18, 2011 20:59
See if your WSGI server will chunk for you.
#
# Run this under your WSGI server, and then try
#
# curl -N -i <server>
#
# If you're chunked, you should see the pause between "hello" and "world".
import time
def application(environ, start_response):
CREATE TABLE CdmaCellLocation (MCC INTEGER, SID INTEGER, NID INTEGER, BSID INTEGER, ZONEID INTEGER, BANDCLASS INTEGER, CHANNEL INTEGER, PNOFFSET INTEGER, Timestamp FLOAT, Latitude FLOAT, Longitude FLOAT, HorizontalAccuracy FLOAT, Altitude FLOAT, VerticalAccuracy FLOAT, Speed FLOAT, Course FLOAT, Confidence INTEGER, PRIMARY KEY (MCC, SID, NID, BSID, ZONEID, BANDCLASS, CHANNEL, PNOFFSET));
CREATE VIRTUAL TABLE CdmaCellLocationBoxes USING rtree(ROWID, MinimumLatitude, MaximumLatitude, MinimumLongitude, MaximumLongitude);
CREATE TABLE "CdmaCellLocationBoxes_node"(nodeno INTEGER PRIMARY KEY, data BLOB);
CREATE TABLE "CdmaCellLocationBoxes_parent"(nodeno INTEGER PRIMARY KEY, parentnode INTEGER);
CREATE TABLE "CdmaCellLocationBoxes_rowid"(rowid INTEGER PRIMARY KEY, nodeno INTEGER);
CREATE TABLE CdmaCellLocationCounts (Count INTEGER);
CREATE TABLE CdmaCellLocationHarvest (MCC INTEGER, MNC INTEGER, SID INTEGER, NID INTEGER, BSID INTEGER, BSLatitude FLOAT, BSLongitude FLOAT, ZoneID INTEGER, SectorID TEXT, SectorLatitud
/Users/jacob/Projects/Django/.tox/py27sqlite/log$ ../bin/pip install --download-cache=/Users/jacob/Projects/Django/.tox/_download ../../dist/Django-1.3.zip >1.log
Unpacking /Users/jacob/Projects/Django/.tox/dist/Django-1.3.zip
Running setup.py egg_info for package from file:///Users/jacob/Projects/Django/.tox/dist/Django-1.3.zip
Installing collected packages: Django
Running setup.py install for Django
changing mode of build/scripts-2.6/django-admin.py from 644 to 755
changing mode of /Users/jacob/Projects/Django/.tox/py27sqlite/bin/django-admin.py to 755
Successfully installed Django
Cleaning up...
INI_HEADER = '''[tox]
setupdir = {toxinidir}/upstream
'''
ENV_TEMPLATE = '''[testenv:%(envname)s]
basepython = python%(pyver)s
deps = %(deps)s
commands =
ln -sf {toxinidir}/testsettings {envdir}/lib/python%(pyver)s/site-packages
{toxinidir}/upstream/tests/runtests.py --settings=%(settings)s []
We couldn’t find that file to show.
We couldn’t find that file to show.
max = Math.max.apply.bind(Math.max, {});
min = Math.min.apply.bind(Math.min, {});
// Plot symbols just for the first, last, highest, and lowest values.
// gRaphael wants symbols to be an array of characters to write for
// each point. E.g. ['o', '', '', ..., 'o', ..., '', '', 'o']
var symbols = data.values.map(function() { return '' });
symbols[0] = 'o';
symbols[symbols.length-1] = 'o';
symbols[symbols.lastIndexOf(max(data.values))] = 'o';