Skip to content

Instantly share code, notes, and snippets.

View jdunck's full-sized avatar

Jeremy Dunck jdunck

View GitHub Profile
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@dgouldin
dgouldin / noparse.py
Created October 19, 2010 16:43
Django template block tag {% noparse %} renders template syntax characters within the block as normal text.
from django import template
register = template.Library()
token_formats = {
template.TOKEN_TEXT: '%s',
template.TOKEN_VAR: '%s%%s%s' % (template.VARIABLE_TAG_START, template.VARIABLE_TAG_END),
template.TOKEN_BLOCK: '%s%%s%s' % (template.BLOCK_TAG_START, template.BLOCK_TAG_END),
template.TOKEN_COMMENT: '%s%%s%s' % (template.COMMENT_TAG_START, template.COMMENT_TAG_END),
}
"""
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
@onyxfish
onyxfish / test_cache.py
Created June 28, 2011 21:30
Python unittest-based cache testing rig for Varnish + Wordperss
#!/usr/bin/env python
import cookielib
import json
import re
import random
import unittest
import requests
from wordpress_xmlrpc import Client, WordPressComment, WordPressPost
@dehora
dehora / build-scribe-2.2.tar.gz.rst
Created July 7, 2011 20:17
build-scribe-2.2.tar.gz

Did this to build scribe-2.2.tar.gz

Get thrift 0.5.0 instead of 0.6.1/0:

sudo apt-get install php5-dev
sudo apt-get install php-config # *-php=no didn't quite work out for me
sudo ./configure --with-haskell=no  # with-haskell=for-great-good did NOT work

and then configure/make/install thrift and fb303

@bretthoerner
bretthoerner / client
Created July 27, 2011 19:25
Scribe configuration
port=1464
<store>
category=default
type=buffer
max_write_interval=1 # process messages at least once per second
<primary>
type=network
@dgouldin
dgouldin / gist:1207636
Created September 9, 2011 23:49
Django templatetag to output the current page's querystring updated with the specified values.
from django import template
register = template.Library()
class UpdateQuerystringNode(template.Node):
def __init__(self, **kwargs):
self.kwargs = kwargs
def render(self, context):
query_dict = context['request'].GET.copy()
@dcarley
dcarley / README.md
Created February 1, 2012 10:49
VirtualBox NAT interface stops responding under load

VirtualBox NAT bug

Pushing a certain quantity/mixture of data through a VB guest's NAT interface causes all TCP/UDP connections to fail for a period of time thereafter.

The only way I've been able to reliably reproduce this is to use pip(1) to download a large list of Python packages. After a number of packages have been downloaded (14~20) pip will exit with an HTTP or DNS timeout. Inbound port-forwarded SSH connections will drop with:

Connection to 127.0.0.1 closed by remote host.

This appears most likely to occur with the Intel PRO/1000 MT Desktop (82540EM) NIC. It is harder to reproduce with PCnet-FAST III (Am79C973) NICs. It is not reproducible with host-only or bridged adapters.

# This module intentionally minimizes dependencies to mitigate breakage risk.
# Subset of Syslog's numerical severity codes (RFC 3164, Table 2)
SEVERITY =
ERROR: 3
WARN: 4
INFO: 6
DEBUG: 7
# Configuration
@idan
idan / oauthlib_twitter_example.py
Created May 2, 2012 22:50
Requests + OAuth, sample usage
import requests
from requests.auth import OAuth1
url = u'https://api.twitter.com/1/account/settings.json'
client_key = u'...'
client_secret = u'...'
resource_owner_key = u'...'
resource_owner_secret = u'...'