Skip to content

Instantly share code, notes, and snippets.

@tejinderss
tejinderss / render_to.py
Created October 29, 2012 10:40
render_to decorator for django views
import os
from django.http import HttpResponse
from django.shortcuts import render
from django.utils.functional import wraps
from django.utils import simplejson
def render_to(view=None, template_name=None):
"""
Warning: /usr/local/share/python is not needed in PATH.
Formerly homebrew put Python scripts you installed via `pip` or `pip3`
(or `easy_install`) into that directory above but now it can be removed
from your PATH variable.
Python scripts will now install into /usr/local/bin.
You can delete anything, except 'Extras', from the /usr/local/share/python
(and /usr/local/share/python3) dir and install affected Python packages
anew with `pip install --upgrade`.
import unittest
from collections import defaultdict
class Anagrams(object):
def __init__(self):
self.words = open('words.txt').readlines()
self._load_anagrams()
import json
import unittest
from functools import partial
from operator import itemgetter
from math import sin, cos, sqrt, asin, radians
from cStringIO import StringIO
def get_records(fl):
for line in fl:
class Config(dict):
def __init__(self, root_path, defaults=None):
dict.__init__(self, defaults or {})
self.root_path = root_path
def from_envvar(self, variable_name, silent=False):
"""Loads a configuration from an environment variable pointing to
a configuration file. This is basically just a shortcut with nicer
error messages for this line of code::