Skip to content

Instantly share code, notes, and snippets.

View ptone's full-sized avatar

Preston Holmes ptone

View GitHub Profile
@ptone
ptone / test_lookup.rst
Created October 23, 2011 03:33
which tests in Django hit which source files

django/__init__.py

  • admin_scripts
  • views

django/conf/__init__.py

  • admin_changelist
  • admin_inlines
  • admin_views
  • admin_widgets
@ptone
ptone / html5_simple_boilerplate.html
Created January 17, 2012 03:00 — forked from lukeholder/html5_simple_boilerplate.html
ultra simple html5 boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.min.js" type="text/javascript"></script>
</head>
<body>
<h1>Document</h1>
@ptone
ptone / time-data-convert.py
Created March 1, 2012 17:42
Convert from Paychex Preview time0002 format to CSV delimited
from collections import defaultdict
data_file = '/Users/preston/Dropbox/data/A8306701_ta.txt'
emp_data = defaultdict(lambda: defaultdict(float))
for line in open(data_file, 'r'):
data = line.split()
if len(data) != 3:
# print line
@ptone
ptone / authuser.md
Created March 30, 2012 03:00 — forked from jacobian/authuser.md
Upgrading auth.User - the profile approach

Upgrading auth.User - the profile approach

This proposal presents a "middle ground" approach to improving and refactoring auth.User, based around a new concept of "profiles". These profiles provide the main customization hook for the user model, but the user model itself stays concrete and cannot be replaced.

I call it a middle ground because it doesn't go as far as refactoring the whole auth app -- a laudable goal, but one that I believe will ultimately take far too long -- but goes a bit further than just fixing the most egregious errors (username length, for example).

The User model

This proposal vastly pare down the User model to the absolute bare minimum and defers all "user field additions" to a new profile system.

@ptone
ptone / gist:2662223
Created May 11, 2012 20:31
injects non-printing chars into long strings so that they will wrap properly in a fixed width div
def softwrap(desc):
noprint = '&#8203;'
return ' '.join(
[noprint.join(list(x)) if (len(x) > 20) else x for x in desc.split()])
@ptone
ptone / gist:2662550
Created May 11, 2012 21:39
softwrap long strings
function softwrap(desc){
var words = desc.split(" ");
var newText = "";
for (var i = 0; i < words.length; i++) {
var aWord = words[i];
console.log(aWord);
if (aWord.length > 20) {
aWord = aWord.replace(/(\S{2})/g,"$1&#8203;");
}
@ptone
ptone / cbv_members.py
Created June 8, 2012 16:15
generates an MRO oriented index of Django CBVs
#!/usr/bin/env python
import sys
import os
import re
sys.path[0] = os.path.normpath(os.path.join(sys.path[0], '.'))
os.environ['DJANGO_SETTINGS_MODULE'] = "dummyproj.settings"
import inspect
from pprint import pprint
# https://github.com/django/django/commit/4f306a4c27c8537ca9cd966cea1c0de84aafda9e#django/db/__init__.py
# from django.conf import settings; settings.configure()
class X(object):
if not self.foo
self.foo = self.some_func
property(self.foo)
myfirstproject/
django -> ./django-dist/django (symlink)
django-dist (full clone/dist)
manage.py
myfirstproject/
settings.py etc
from __future__ import print_function
from lxml.html.soupparser import fromstring
import requests
from datetime import datetime, timedelta
start_date = datetime(2012, 8, 6)
end_date = start_date + timedelta(days=45)
url = 'http://www.reserveamerica.com/campsiteCalendar.do?page=calendar&contractCode=CA&parkId=120030&calarvdate={caldate}&sitepage=true&startIdx={page_index}&sitefilter=STANDARD'