A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| def get_count(q): | |
| count_q = q.statement.with_only_columns([func.count()]).order_by(None) | |
| count = q.session.execute(count_q).scalar() | |
| return count | |
| q = session.query(TestModel).filter(...).order_by(...) | |
| # Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ... | |
| print q.count() |
| #!/bin/sh | |
| # UFW blocks for China, Korea, Malaysia, Phillipines, Singapore, Thailand and Vietnam netblocks | |
| # Based on http://www.wizcrafts.net/chinese-iptables-blocklist.html | |
| # Cambodia (KH) | |
| ufw deny from 114.134.184.0/21 to any port 22 | |
| # Chinese (CN) IP addresses follow: | |
| ufw deny from 1.192.0.0/13 to any port 22 | |
| ufw deny from 1.202.0.0/15 to any port 22 |
| from myapp.utils import set_current_user | |
| class CurrentUserMiddleware: | |
| def process_request(self, request): | |
| set_current_user(getattr(request, 'user', None)) | |