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
| """ "Writing SQL is just as fast as using an ORM" proof of concept | |
| Below is a simple Python object model, where we represent a database that | |
| stores the names of employees at a company, some of whom are "engineers", | |
| and a list of the jobs they do and the programming languages they use. | |
| We'd like to persist the state represented by this Python object model | |
| in a relational database, using our Python objects as a start. Then we'd | |
| like to write SQL queries for rows in this database, and we get back instances | |
| of Python objects exactly as they were created. |
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 sqlalchemy import * | |
| from sqlalchemy.orm import * | |
| from sqlalchemy.ext.declarative import declarative_base | |
| e = create_engine("sqlite://", echo=True) | |
| # first, we're in the old version of the app | |
| OldBase = declarative_base() | |
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 sqlalchemy import Column | |
| from sqlalchemy import create_engine | |
| from sqlalchemy import inspect | |
| from sqlalchemy import Integer | |
| from sqlalchemy import MetaData | |
| from sqlalchemy import select | |
| from sqlalchemy import String | |
| from sqlalchemy import Table | |
| from sqlalchemy.orm import aliased | |
| from sqlalchemy.orm import declarative_base |
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
| #!/usr/bin/env bash | |
| # | |
| # Fetch diff stats for the current repo from the last year | |
| # Get a commit SHA from a year ago | |
| OLD_SHA=$(git log --since="365 days ago" --until="364 days ago" -1 --pretty=format:"%H") | |
| NEW_SHA=$(git rev-parse HEAD) | |
| # Number of lines then and now | |
| OLD_LINES=$(git diff --stat `git hash-object -t tree /dev/null`..$OLD_SHA | awk '/files changed/ {print $4}') |
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 celery import chain | |
| from django.core.management.base import BaseCommand | |
| from . import tasks | |
| class Command(BaseCommand): | |
| def handle(self, *args, **kwargs): |
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 TransactionAwareTask(Task): | |
| ''' | |
| Task class which is aware of django db transactions and only executes tasks | |
| after transaction has been committed | |
| ''' | |
| abstract = True | |
| def apply_async(self, *args, **kwargs): | |
| ''' | |
| Unlike the default task in celery, this task does not return an async |
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
| django-celery-beat==2.0.0 # https://github.com/celery/django-celery-beat | |
| flower==0.9.5 # https://github.com/mher/flower | |
| pydantic==1.6.1 # https://github.com/samuelcolvin/pydantic | |
| measurement==3.2.0 # https://github.com/coddingtonbear/python-measurement | |
| whitenoise==5.2.0 # https://github.com/evansd/whitenoise | |
| django-environ==0.4.5 # https://github.com/joke2k/django-environ | |
| django-model-utils==4.0.0 # https://github.com/jazzband/django-model-utils | |
| django-allauth==0.42.0 # https://github.com/pennersr/django-allauth | |
| django-crispy-forms==1.9.2 # https://github.com/django-crispy-forms/django-crispy-forms | |
| django-redis==4.12.1 # https://github.com/jazzband/django-redis |
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
| ############################################################################ | |
| # # | |
| # ------- Useful Docker Aliases -------- # | |
| # # | |
| # # Installation : # | |
| # copy/paste these lines into your .bashrc or .zshrc file or just # | |
| # type the following in your current shell to try it out: # | |
| # wget -O - https://gist.github.com/jgrodziski/9ed4a17709baad10dbcd4530b60dfcbb/raw/d84ef1741c59e7ab07fb055a70df1830584c6c18/docker-aliases.sh | bash | |
| # # | |
| # # Usage: # |
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 BaseErrorHandlerMixin: | |
| """A mixin to use to handle errors occuring when running tasks. | |
| Usage: | |
| >>> from celery import Task | |
| >>> from .mixins import BaseErrorHandlerMixin | |
| >>> | |
| >>> # Be careful with ordering the MRO | |
| >>> class ThirdPartyBaseTask(BaseErrorHandlerMixin, Task): | |
| >>> pass |