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
""" | |
The Enum Recipe | |
http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/ | |
""" | |
import re | |
from sqlalchemy.types import SchemaType, TypeDecorator, Enum | |
class EnumSymbol(object): |
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
# http://stackoverflow.com/a/5518073/720077 | |
from django.conf import settings | |
# ... your normal urlpatterns here | |
if settings.DEBUG: | |
# static files (images, css, javascript, etc.) | |
urlpatterns += patterns('', | |
(r'^media/(?P<path>.*)$', 'django.views.static.serve', { |
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
[core] | |
pager = less -F -X | |
[alias] | |
a = add | |
# status short format, only show changed files. | |
s = status -sb | |
ss = status | |
d = diff |
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
# http://stackoverflow.com/a/2186639/720077 | |
import os, fnmatch | |
def recursive_glob(treeroot, pattern): | |
results = [] | |
for base, dirs, files in os.walk(treeroot): | |
goodfiles = fnmatch.filter(files, pattern) | |
results.extend(os.path.join(base, f) for f in goodfiles) | |
return results |
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
# http://stackoverflow.com/a/5032238/720077 | |
import os | |
import errno | |
def make_sure_path_exists(path): | |
try: | |
os.makedirs(path) | |
except OSError as exception: | |
if exception.errno != errno.EEXIST: |
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
# I don't know why a simple self.check_attribute doesn't work. | |
# Nosetests doc says something about this, but not the reason | |
# https://nose.readthedocs.org/en/latest/writing_tests.html#test-generators | |
class BaseTest(object): | |
@staticmethod | |
def check_attribute(self, attr, res): | |
assert getattr(self.hand, attr) == res | |
def test_header(self): |
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 http://stackoverflow.com/a/4131007/720077 | |
def get_next_month(year, month): | |
"""Return the year and month of the next month.""" | |
plus_year, new_month = divmod(month + 1, 12) | |
if new_month == 0: | |
new_month = 12 | |
plus_year -= 1 | |
return year + plus_year, new_month |
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
# http://stackoverflow.com/questions/8702772/django-get-list-of-models-in-application | |
from django.db.models import get_app, get_models | |
app = get_app('my_application_name') | |
for model in get_models(app): | |
new_object = model() # Create an instance of that model | |
model.objects.filter(...) # Query the objects of that model | |
model._meta.db_table # Get the name of the model in the database | |
model._meta.verbose_name # Get a verbose name of the model |
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
# very beautiful, readable code, isn't it? :D | |
shared_app_models = [app_model for app_models in [get_models(app) for app in map(lambda appstr: get_app(appstr.split('.')[-1]), getattr(settings, 'SHARED_APPS'))] for app_model in app_models] |
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
# prevent the creation of .DS_Store files on network drives | |
# http://hints.macworld.com/article.php?story=2005070300463515 | |
defaults write com.apple.desktopservices DSDontWriteNetworkStores true | |
#--------------------------------------------------------------------- | |
# Disable/enable Dashboard: | |
# http://hints.macworld.com/article.php?story=20050723123302403 | |
defaults write com.apple.dashboard mcx-disabled -boolean YES |