Skip to content

Instantly share code, notes, and snippets.

View acdha's full-sized avatar

Chris Adams acdha

View GitHub Profile
# encoding: utf-8
# Derived from Piotr Maliński's example with a few modifications to use logging and :
# http://www.rkblog.rk.edu.pl/w/p/profiling-django-object-size-and-memory-usage-pympler/
from pympler.muppy import muppy
from pympler.muppy import summary
from pympler.asizeof import asizeof
from django.conf import settings
import logging
# -*- encoding: utf-8
import functools
import inspect
def memoize(*args, **kwargs):
"""
Generic memoization decorator
Basic usage::
# Monkeypatch this since Django 1.1 provides no way for you to
# provide instance-specific filenames:
media_file.file.field.generate_filename = lambda i, j: os.path.join(
media_file.created.strftime(settings.FEINCMS_MEDIALIBRARY_UPLOAD_TO), # Default behaviour
"%s_resources" % os.path.dirname(new_page_path).split("/")[-1], # Plus the containing page's slug
os.path.basename(fs_path) # Plus the actual filename
)
@acdha
acdha / appcontent.py
Created November 10, 2009 22:55
Example of the new richer ApplicationContent type for FeinCMS - see http://github.com/acdha/feincms/tree/rich_appcontent
"""
Support for embedding blogs as FeinCMS ApplicationContent
"""
from django import forms
from .models import Blog
from .views import blog_detail
def get_admin_fields(form, *args, **kwargs):
@acdha
acdha / webfaction modern python app install notes.rst
Created November 23, 2009 00:24
Installation notes after installing a Django web app on WebFaction

Python 2.6 + Virtualenv + Django 1.1 + Postgres on WebFaction

  1. mkdir -p ~/bin ~/lib/python2.6/site-packages
  2. Configure the environment by putting something like this in your .bashrc and sourcing it:

    export CFLAGS=-I/usr/local/pgsql/include 
    export LDFLAGS=-L/usr/local/pgsql/lib
@acdha
acdha / helium-bookmarklet.js
Created January 15, 2010 15:06
Bookmarklet to load Helium without modifying the page
/*
Loads http://github.com/geuis/helium-css for testing without modifying the source pages
Crunched by http://ted.mielczarek.org/code/mozilla/bookmarklet.html to:
javascript:(function(){(function(msg,target){var loader=function(){if(arguments.callee._executed)return;arguments.callee._executed=true;if(typeof target==="function"){target();}else{jQuery.getScript(target);}var el=document.createElement('div');el.style.position='absolute';el.style.height='30px';el.style.width='200px';el.style.margin='0 auto 0 auto';el.style.top='0';el.style.left='40%';el.style.padding='5px 10px';el.style.backgroundColor='#F00';el.style.fontWeight="bold";el.style.textAlign="center";el.innerHTML=msg;document.body.appendChild(el);window.setTimeout(function(){jQuery(el).fadeOut('slow',function(){jQuery(this).remove();});},2500);};if(typeof jQuery!=='undefined'){loader();}else{var s=document.createElement('script');s.type="text/javascript";s.setAttribute('src',document.location.protocol+'//ajax.googleapis.com/ajax/libs
try:
from south.modelsinspector import add_introspection_rules
from django.db.models.fields import NOT_PROVIDED
from django.conf import settings
JSONField_introspection_rule = (
(JSONField,),
[],
{
"null": ["null", {"default": False}],
def south_field_triple(self):
"""Help South introspect this field for migrations"""
# Since we're just a TextField with some marshalling logic we'll introspect TextField
from south.modelsinspector import introspector
field_class = "django.db.models.fields.TextField"
args, kwargs = introspector(self)
return (field_class, args, kwargs)
diff --git a/tornado/httpclient.py b/tornado/httpclient.py
index 23496d7..c6e61ee 100644
--- a/tornado/httpclient.py
+++ b/tornado/httpclient.py
@@ -343,6 +343,9 @@ def _curl_setup_request(curl, request, buffer, headers):
functools.partial(_curl_header_callback, headers))
except:
# Old version of curl; response will not include headers
+ if not hasattr(_curl_setup_request, "__broken_curl_warning_shown"):
+ logging.warning("CAUTION: the version of curl installed is too old; HTTP headers will be unavailable!")