This file contains hidden or 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 collections import Mapping, namedtuple | |
def choices(fields): | |
'''Create a tuple-like instance appropriate for Django's ``Field.choices``. | |
Additionally the returned instance also supports attribute access by field name. | |
Example usage:: | |
>>> t = choices(enumerate(['abc', 'pqr', 'xyz'])) |
This file contains hidden or 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
'''Manager-based polymorphic model inheritance. | |
This module provides a non-intrusive approach for accessing polymorphically | |
instances of a model hierarchy. Non-intrusive means: | |
- It does not require extending a custom ``Model`` base class or metaclass. | |
- It does not require a ``ForeignKey`` to ``ContentType`` or the ``contenttypes`` | |
app in general. Instead the real class of an instance is determined based on | |
the value (**polymorphic identity**) of a user-specified discriminating field | |
(**polymorphic on**). | |
- It does not override the default (or any other) model ``Manager`` (unless |
This file contains hidden or 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
diff --git a/django/views/generic/base.py b/django/views/generic/base.py | |
--- a/django/views/generic/base.py | |
+++ b/django/views/generic/base.py | |
@@ -9,6 +9,39 @@ | |
logger = getLogger('django.request') | |
+class AsViewDescriptor(object): | |
+ def __get__(self, instance, cls): | |
+ if instance is not None: |
This file contains hidden or 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
import os, sys | |
class Winpdb(object): | |
'''Embed a Winpdb server. | |
If you have to tunnel to connect remotely from the Winpdb client, run: | |
ssh -C -N -f -L 51000:localhost:51000 $SERVER_HOST |
This file contains hidden or 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
import sys | |
from itertools import groupby | |
from operator import itemgetter | |
def bincount_histogram(nums, num_bins=sys.maxint, min_bin_count=1): | |
num_bins = max(num_bins, 1) | |
min_bin_count = max(min_bin_count, 1) | |
# initialize the bins of width=1 | |
bin_edges, counts = [], [] |
This file contains hidden or 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
import sys, csv, time | |
from collections import defaultdict | |
from itertools import islice | |
import orig_slopeone, slopeone, numpy_slopeone | |
classes = [ | |
orig_slopeone.SlopeOne, | |
#orig_slopeone.SlopeOneNumpy, # XXX: dog slow | |
slopeone.SlopeOne, |
This file contains hidden or 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
import pkgutil | |
def recursive_import(package): | |
for imp, name, ispkg in pkgutil.walk_packages(package.__path__, package.__name__ + '.'): | |
yield __import__(name, fromlist=[name]) |
This file contains hidden or 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
-2.695 | |
reduced by ROUND_UP, ROUND_FLOOR, ROUND_HALF_UP, ROUND_HALF_EVEN | |
increased by ROUND_DOWN, ROUND_05UP, ROUND_CEILING, ROUND_HALF_DOWN | |
-2.669, -2.699 | |
reduced by ROUND_UP, ROUND_FLOOR, ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN | |
increased by ROUND_DOWN, ROUND_05UP, ROUND_CEILING | |
-2.665 | |
reduced by ROUND_UP, ROUND_FLOOR, ROUND_HALF_UP | |
increased by ROUND_DOWN, ROUND_05UP, ROUND_CEILING, ROUND_HALF_DOWN, ROUND_HALF_EVEN | |
-2.661, -2.691 |
This file contains hidden or 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
import random | |
from sqlalchemy import Column, ForeignKey, Integer, String, create_engine | |
from sqlalchemy.exc import IntegrityError | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
Base = declarative_base() | |
class Author(Base): | |
__tablename__ = 'author' |
OlderNewer