Skip to content

Instantly share code, notes, and snippets.

View manfre's full-sized avatar

Michael Manfre manfre

View GitHub Profile
@manfre
manfre / log_settings.py
Created October 5, 2011 13:32
Django logging filter to throttle repeated messages
# Example logging configuration that will restrict console logging to
# at most 2 repeated messages per 30 seconds.
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'simple': {
'format': '%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s'
},
},
@manfre
manfre / check_for_updates.py
Created November 14, 2011 16:21 — forked from zyegfryed/check_for_updates.py
Check locally installed packages against one or more package indexes for updates and list them. Using subprocess instead of stdout (wasn't working on my MacPython 2.6.1). Removed curses dependency to allow it to work on windows.
#!/usr/bin/env python
"""
Use pip to get a list of local packages to check against one or more package
indexes for updated versions.
"""
import sys
import xmlrpclib
import subprocess
from distutils.version import StrictVersion, LooseVersion
@manfre
manfre / gist:1443360
Created December 7, 2011 16:07
Waffle flag view decorator
from django.http import HttpResponse
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils.decorators import available_attrs
import waffle
def waffled_view(function=None, flag=None, template='503-waffled.html', **kwargs):
"""
Check the decorated view to see if the flag is enabled for the current
request. Any kwargs will be made available to the template.
@manfre
manfre / manfre-pycarolinas-django-on-windows.rst
Created July 31, 2012 14:38
PyCarolinas Proposal - Django on Windows

PyCarolinas Talk Proposal: Django on Windows

Presented by Michael Manfre

Overview

www.src.org, a case study of running Django in a Windows environment. This talk will describe the Semiconductor Research Corporation's (SRC) website,

@manfre
manfre / gist:4502333
Last active December 10, 2015 22:28 — forked from Pharylon/gist:4502183
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
@manfre
manfre / contentmiddleware.py
Created March 28, 2013 12:34
Django middleware to handle arbitrary Models that share common URL space. Found URLs matches will be cached and short circuited on subsequent requests.
import logging, os, os.path, re
from hashlib import md5
from django.http import Http404, HttpResponse, HttpResponseForbidden, HttpResponseNotFound, HttpResponseRedirect, HttpResponseNotModified
from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from django.core.urlresolvers import reverse, NoReverseMatch
from django.utils.encoding import smart_str
from django.utils.http import http_date
from django.core.cache import cache
class SQLCompiler(compiler.SQLCompiler):
def resolve_columns(self, row, fields=()):
# If the results are sliced, the resultset will have an initial
# "row number" column. Remove this column before the ORM sees it.
if getattr(self, '_using_row_number', False):
row = row[1:]
values = []
index_extra_select = len(self.query.extra_select.keys())
for value, field in map(None, row[index_extra_select:], fields):
@manfre
manfre / gist:6691126
Created September 24, 2013 20:57
Django test suite run with sqlite on Python 2.7.5
======================================================================
FAIL: test_templates (template_tests.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\projects\django\django\tests\template_tests\tests.py", line 621, in test_templates
('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
AssertionError: Tests failed:
----------------------------------------------------------------------
Template test (Cached='False', TEMPLATE_STRING_IF_INVALID='', TEMPLATE_DEBUG=False): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
----------------------------------------------------------------------
@manfre
manfre / subquerytests.py
Created September 25, 2013 21:12
Improved SubqueryTests to cover some potential problem areas for database backends that must do some trickery for slicing
class SubqueryTests(TestCase):
def setUp(self):
DumbCategory.objects.create(id=1)
DumbCategory.objects.create(id=2)
DumbCategory.objects.create(id=3)
DumbCategory.objects.create(id=4)
def test_ordered_subselect(self):
"Subselects honor any manual ordering"
try: