Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

David Cramer dcramer

💭
I may be slow to respond.
View GitHub Profile
View sc2patch.py
# usage: python <thisfile.py> help -- downloads the files to the current directory
# requires libmpq
# Attempts to brute force and download specific patches
# e.g. python sc2patch.py --current=0.10.0.14803 --next=0.11.0.15097
# This would find and download any patches relevant, the next argument is optional,
# but allows you to provide a starting point. This stops at the first patch it finds,
# so you would need to continue with a new starting point if you wanted a different patch.
# e.g. if you didnt specify next in this example, it would stop at the initial 0.11 build,
# which wasnt publicly released
View comments-count-sample.html
<html>
<head>
<title>Comments count code example</title>
</head>
<body>
<!-- For this link, we will try to fetch comments count by URL: http://example.com/article.html -->
<a href="http://example.com/article.html#disqus_thread">First article</a>
<!-- For this link, we will try to fetch comments count by identifier: article2identifier -->
View gist:550435
def queryset_to_dict(qs, key='pk'):
"""
Given a queryset will transform it into a dictionary based on ``key``.
"""
return dict((getattr(u, key), u) for u in qs)
def distinct(l):
"""
Given an iterable will return a list of all distinct values.
"""
View gist:550436
diff --git a/django_root/django/db/models/base.py b/django_root/django/db/models/base.py
index 37331b3..4da2802 100644
--- a/django_root/django/db/models/base.py
+++ b/django_root/django/db/models/base.py
@@ -5,6 +5,7 @@ from itertools import izip
import django.db.models.manager # Imported to register signal handler.
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS
from django.core import validators
+from django.db.models.expressions import ExpressionNode
from django.db.models.fields import AutoField, FieldDoesNotExist
View monkey.py
from threading import local
_blah = local()
class StopThatShit(Exception):
pass
def patch():
from django.db.backends import util
from django import template
@dcramer
dcramer / debug.py
Created Mar 24, 2011
Django Debug Toolbar On-Demand
View debug.py
from django.conf import settings
from django.conf.urls.defaults import include, patterns
from django.http import HttpResponse
from django.utils.encoding import smart_unicode
if 'debug_toolbar' not in settings.INSTALLED_APPS:
class DebugMiddleware(object):
pass
else:
import debug_toolbar.urls
View gist:942761
"""
Patches the database wrapper and template engine to throw an exception if a query is executed inside of a template.
In your urls.py, enable it like so:
>>> import monkey
>>> monkey.patch_templates()
"""
import logging
@dcramer
dcramer / Questions
Created Jun 21, 2011
Kiwi Pycon Give-away
View Questions
GitHub username: dcramer
Day job: DISQUS
Favorite open source project: Django
Open Source contributions (if any): Sentry, Gargoyle, Debug Toolbar, <100 more>
Stranded on an island, what 3 items do you take: Laptop, Mobile Phone, and as much alcohol as I can manage :)
Tie-breaker, pick a number between 1 and 20,000: 20,000
@dcramer
dcramer / gist:1163531
Created Aug 22, 2011 — forked from voodootikigod/gist:1155790
PyCodeConf Ticket Give-away
View gist:1163531
Day job:
I build cool Python things at Disqus
Favorite Python project:
Does it count if I pick my own? :)
github.com/dcramer/django-sentry
View gist:1268426
"data": {
"__sentry__": {
"frames": [
{
"filename": filename,
"module": module,
"function": function,
"lineno": ...,
"vars": {
"key": "value"
You can’t perform that action at this time.