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
| # https://gist.github.com/hest/8798884 | |
| 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 ...) ... |
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
| #### FLASK PROD wsgi python code | |
| location /url_sub_path { | |
| #forward application requests to the wsgi server | |
| proxy_pass http://unix:/var/www/python/flask/flask.sock; | |
| proxy_redirect off; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| } |
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
| """ | |
| SINGLETON CLASS ENCAPSULATING A PYROGRAM TELEGRAM CLIENT | |
| Credit: https://gist.github.com/skeeved/79dfe5652b20182586bb55c3cbc94250 | |
| """ | |
| """ Config """ | |
| from os import environ | |
| BOT_TOKEN = environ.get('BOT_TOKEN') | |
| API_ID = environ.get('API_ID') | |
| API_HASH = environ.get('API_HASH') |
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
| """ | |
| SINGLETON CLASS ENCAPSULATING A REDIS CLIENT | |
| Credit: https://gist.github.com/skeeved/79dfe5652b20182586bb55c3cbc94250 | |
| """ | |
| """ Config """ | |
| from os import environ | |
| REDIS_URL = environ.get('REDIS_URL') | |
| """ Import """ |
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 datetime import datetime | |
| from datetime import timedelta | |
| from pytz import timezone | |
| import time | |
| # My Default Timezone | |
| def default_timezone(): | |
| _tz = timezone('Europe/Rome') | |
| return(_tz) | |
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
| """ | |
| SINGLETON CLASS ENCAPSULATING A SQLALCHEMY ENGINE and SESSION. | |
| Credit: https://gist.github.com/skeeved/79dfe5652b20182586bb55c3cbc94250 | |
| """ | |
| """ Config """ | |
| from os import environ | |
| DB_TYPE = environ.get('DB_TYPE') # Example: mysql | |
| DB_CONNECTOR = environ.get('DB_CONNECTOR') # Example: pymysql | |
| DB_HOST = environ.get('DB_HOST') |