Skip to content

Instantly share code, notes, and snippets.

View idan's full-sized avatar
💫
Prototypin'

Idan Gazit idan

💫
Prototypin'
View GitHub Profile
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
import re
register = template.Library()
# (?:\A|[\s\.,:;'"])(@(\w{1,20}))(?!\.?\w)
twitterize_pattern = r'''
OH on IRC:
bastih_: thinking about fancy lifestreams
• idangazit is thinking about resolving merge conflicts
• jezdez is thinking about another beer
• bitprophet is thinking about hitting the bathroom, brb
• ubernostrum wodners if bitprophet's bathroom will hit back.
• Alex_Gaynor is thinking about rst
• idangazit guffaws
• andrewgodwin is impressed cPickle is 10x faster than eval+repr
[mmalone]: and there are a lot of things here that are pissing me off :/
[idangazit]: mmalone: can't say I've used it much, but I'm playing with it right now too
[idangazit]: what's bugging you?
[mmalone]: heh
[mmalone]: where should I start... :/
Gulopine joined the chat room.
[mmalone]: lemme dpaste my notes
[idangazit]: I'm still at the wrapping-my-brain-around-it phase, the lack of nontrivial examples is making that harder
[mmalone]: http://dpaste.com/85843/
[mmalone]: yea, and the example that ships with it is broken
# urls.py
object_list_dict = {
'queryset': Post.objects.published(),
'paginate_by': 20,
}
# managers.py
class PublicManager(Manager):
def published(self):
return self.get_query_set().filter(public=True, published__lte=datetime.datetime.now())
import site
from os import environ
from os.path import join
from sys import version_info
if 'VIRTUAL_ENV' in environ:
virtual_env = join(environ.get('VIRTUAL_ENV'),
'lib',
'python%d.%d' % version_info[:2],
'site-packages')
try:
import simplejson as json
except ImportError:
try:
import json
except ImportError:
from django.utils import simplejson
from django.http import HttpResponse, HttpResponseBadRequest
from parsedatetime.parsedatetime import Calendar
from datetime import datetime
from django.utils import simplejson as json
from django.utils.dateformat import format
def dtparse(request):
"""
Attempts to parse a natural-language date/time string and return a
formatted representation of the parsed date/time.
.content form .field_wrap>input.natural_dtinput {
width: 220px;
float: left;
height: 24px;
margin-bottom: 10px;
}
.content form .field_wrap>input.natural_dtinput.annotated {
width: 200px;
from foo import bar
fruit = ['apple', 'orange', 'banana']
bar(fruit)