Consider this blog post model:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.exceptions import MiddlewareNotUsed | |
from django.conf import settings | |
import cProfile | |
import pstats | |
import marshal | |
from cStringIO import StringIO | |
class ProfileMiddleware(object): | |
def __init__(self): | |
if not settings.DEBUG: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Snippet for getting the default gateway on Linux | |
#No dependencies beyond Python stdlib | |
import socket, struct | |
def get_default_gateway_linux(): | |
"""Read the default gateway directly from /proc.""" | |
with open("/proc/net/route") as fh: | |
for line in fh: | |
fields = line.strip().split() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_inline_form(prefix) { | |
var count = parseInt($('#id_' + prefix + '-TOTAL_FORMS').val(), 10); | |
var last_form = $('.' + prefix + ':last'); | |
var new_form = last_form.clone(false).html(last_form.html().replace( | |
new RegExp(prefix + '-\\\\d-', 'g'), prefix + '-' + count + '-')); | |
new_form.find('input[type="text"], textarea').each(function () { | |
$(this).val(''); | |
}); | |
new_form.hide().insertAfter(last_form).slideDown(300); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ======================================== | |
# Testing n-gram analysis in ElasticSearch | |
# ======================================== | |
curl -X DELETE localhost:9200/ngram_test | |
curl -X PUT localhost:9200/ngram_test -d ' | |
{ | |
"settings" : { | |
"index" : { | |
"analysis" : { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
NewerOlder