Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Borror nathanborror

View GitHub Profile
View gist:77160
/*
* Widget Maker
*
* <script type="text/javascript">
* var widget = {
* "id": "readernaut_widget",
* "width": 300,
* "height": 300
* };
* </script>
@nathanborror
nathanborror / gist:83774
Created Mar 23, 2009
Django template comparison filters
View gist:83774
from django.template import Library
from django.template.defaultfilters import lower
register = Library()
@register.filter
def gt(value, arg):
"Returns a boolean of whether the value is greater than the argument"
return value > int(arg)
@nathanborror
nathanborror / gist:88735
Created Apr 1, 2009
oEmbed list additions
View gist:88735

2.3.4.5 The books type

This type is used for representing books. The following parameters are defined:

title (required)
The title of the book
url (required)
The source URL of the book.

description (optional)

@nathanborror
nathanborror / gist:88850
Created Apr 1, 2009
Build your own JSON
View gist:88850
object_list = []
for note in object_list:
obj = {
'id': note.pk,
'note': note.note,
'note.reader_book': {
'id': note.reader_book.id,
'title': note.reader_book.title,
'subtitle': note.reader_book.subtitle,
'authors': ", ".join(["%s" % a.get_full_name for a in note.reader_book.authors.all()]),
View gist:88959
def comment_saved_handler(sender, instance, created, **kwargs):
"""
Signal handler to populated comment count fields.
Bound to 'comment_count' field, should probably be checking for a field annotation in the model.
"""
if 'comment_count' in [f.name for f in instance.content_object._meta.fields]:
instance.content_object.count = instance.content_object.comments.count()
instance.content_object.save()
from django.contrib.comments.models import Comment
View snippet.sc
#!/usr/bin/env python
#
# some bits stolen from Travis Cline's http://github.com/traviscline/git-branchdescriptions
#
import os
import re
import sys
from subprocess import Popen, PIPE
View gist:96627
@register.filter
def gt(value, arg):
"Returns a boolean of whether the value is greater than the argument"
return value > int(arg)
@register.filter
def lt(value, arg):
"Returns a boolean of whether the value is less than the argument"
return value < int(arg)
@nathanborror
nathanborror / flopsy.py
Created May 10, 2009
A very simple way to interact with python amqplib
View flopsy.py
"""
Copyright (c) 2008-2009, Nathan Borror
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
View gist:130765
diff --git a/django/contrib/admindocs/templates/admin_doc/model_index.html b/django/contrib/admindocs/templates/admin_doc/model_index.html
index 4dd7caa..47c94c0 100644
--- a/django/contrib/admindocs/templates/admin_doc/model_index.html
+++ b/django/contrib/admindocs/templates/admin_doc/model_index.html
@@ -36,7 +36,7 @@
<ul>
{% regroup models by app_label as grouped_models %}
{% for group in grouped_models %}
- <li><a href="#{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
+ <li><a href="#app-{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
View gist:179792
from dateutil.relativedelta import *
from datetime import *
TODAY = datetime.now()
TODAY+relativedelta(weekday=FR(+2))
You can’t perform that action at this time.