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
class DotDict(dict): | |
def __getattr__(self, attr): | |
return self.get(attr, None) | |
__setattr__= dict.__setitem__ | |
__delattr__= dict.__delitem__ |
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 google.appengine.ext import db | |
class ReferenceProperty(db.ReferenceProperty): | |
"""A property that represents a many-to-one reference to another model. | |
This class has serveral enhancement on | |
google.appengine.ext.db.ReferenceProperty. | |
1. Its object returns None when referenced entity does not exist, nstead | |
of raising ReferencePropertyResolveError. |
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
#!/bin/sh | |
hg log -b `hg branch` -v | awk '$1 !~ /(changeset|branch|user|date|files|description|tag):/ {print}' |
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
auto: | |
@while :; do make html_silent; sleep 1; done | |
html_silent: .built | |
@echo > /dev/null | |
.built: *.rst img/* | |
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html | |
@touch .built | |
@echo |
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
class CascadingTestCaseMeta(type): | |
"""Metaclass for TestCase class | |
This metaclass make setUp method calls all setUp methods in base classes | |
and then calls defined setUp method. Likewise tearDown but in opposite | |
order. | |
""" | |
def __init__(cls, name, bases, ns): | |
for method_name, reverse in [('setUp',False), ('tearDown', True)]: |
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 unittest | |
from nonvirtualunittest import TestCase | |
class BaseTestCase(TestCase): | |
def setUp(self): | |
self.foo = [1] | |
class MyTestCase(BaseTestCase): | |
def setUp(self): | |
self.foo.append(2) |
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 unittest | |
class TestCaseMeta(type): | |
"""Metaclass for TestCase class | |
This metaclass make setUp method calls all setUp methods in base classes | |
and then calls defined setUp method. Likewise tearDown but in opposite | |
order. | |
""" |
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 google.appengine.ext import db | |
class ReferenceProperty(db.ReferenceProperty): | |
"""A property that represents a many-to-one reference to another model. | |
This acts as identical to google.appengine.ext.db.ReferenceProperty, | |
except objects returns None when referenced entity does not exist | |
instead of raising ReferencePropertyResolveError. | |
""" | |
def __get__(self, *args, **kw): |
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
alias mksandbox='virtualenv --no-site-packages sandbox; source sandbox/bin/activate' | |
alias usesandbox='source sandbox/bin/activate' |
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
""" | |
- /init to initialize service | |
- /update?uid=XXX to tell service XXX is active | |
- /count to get how many clients are active within last TIME_LIMIT sec. | |
""" | |
KEY = 'users' | |
TIME_LIMIT = 10 | |
MAX_RETRIES = 3 |
NewerOlder