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 djangobb_forum.models import Post | |
| from django.db.models import Max | |
| # id__max is None if there are no Posts in the database | |
| id_max = Post.objects.all().aggregate(Max('id'))['id__max'] | |
| id_next = id_max + 1 if id_max else 1 |
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://bryan-murdock.blogspot.hu/2013/04/list-foreign-keys-in-your-postgresql.html | |
| select confrelid::regclass, af.attname as fcol, | |
| conrelid::regclass, a.attname as col | |
| from pg_attribute af, pg_attribute a, | |
| (select conrelid,confrelid,conkey[i] as conkey, confkey[i] as confkey | |
| from (select conrelid,confrelid,conkey,confkey, | |
| generate_series(1,array_upper(conkey,1)) as i | |
| from pg_constraint where contype = 'f') ss) ss2 | |
| where af.attnum = confkey and af.attrelid = confrelid and |
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/7819465/720077 | |
| takeover() { | |
| # create a temporary session that displays the "how to go back" message | |
| tmp='takeover temp session' | |
| if ! tmux has-session -t "$tmp"; then | |
| tmux new-session -d -s "$tmp" | |
| tmux set-option -t "$tmp" set-remain-on-exit on | |
| tmux new-window -kt "$tmp":0 \ | |
| 'echo "Use Prefix + L (i.e. ^B L) to return to session."' |
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
| # Blog post: http://www.huyng.com/posts/python-performance-analysis/ | |
| import time | |
| class Timer(object): | |
| def __init__(self, verbose=False): | |
| self.verbose = verbose | |
| def __enter__(self): | |
| self.start = time.time() |
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
| description "Redmine with standalone Passenger" | |
| author "Walkman <kissgyorgy@me.com>" | |
| start on started-postgresql | |
| stop on stopped-postgresql | |
| expect fork | |
| respawn |
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 |
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
| # 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
| # 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
| # 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): |