Skip to content

Instantly share code, notes, and snippets.

View ptone's full-sized avatar

Preston Holmes ptone

View GitHub Profile
class X(object):
if not self.foo
self.foo = self.some_func
property(self.foo)
@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()
@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 / 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 / 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 / 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 / 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 / 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 / patch_coverage.py
Created October 21, 2011 00:17
Annotate coverage report with lines modified by patch
#!/usr/bin/env python
import os
from collections import defaultdict
import patch
import re
import coverage
import django
from optparse import OptionParser
import webbrowser
@ptone
ptone / webdiff.py
Created October 12, 2011 17:24
display diff output in webpage
#!/usr/bin/env python
# encoding: utf-8
"""
Usage: git diff | webdiff
Created by Preston Holmes on 2009-11-20.
Copyright (c) 2009 __MyCompanyName__. All rights reserved.
"""