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 django.contrib.postgres.indexes import BrinIndex | |
| from django.db import models | |
| class SampleData(models.Model): | |
| created_at = models.DateTimeField() | |
| class Meta: | |
| """ | |
| You must need to use PostgreSQL DB unless you can't use BrinIndex | |
| """ |
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
| """ | |
| ## ==== Never create O(n), if you can O(1) ===== # | |
| “A dispatch table is a table of pointers to functions or methods.” | |
| Link: https://en.wikipedia.org/wiki/Dispatch_table?fbclid=IwAR392A7zZELtQxij7w5iHurjdKJxuYbdyOc6_iVBh7pqvr4oeEUr0xLUNpk | |
| """ | |
| import datetime | |
| def monday_task(): |
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
| yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel | |
| curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash | |
| echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> .zshrc | |
| echo 'eval "$(pyenv init -)"' >> .zshrc | |
| echo 'eval "$(pyenv virtualenv-init -)"' >> .zshrc | |
| exec $SHELL - l | |
| pyenv install 3.6.0 | |
| pyenv global 3.6.0 |
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
| BACKUP_DIR=<back up location> | |
| DAYS_TO_KEEP=14 | |
| FILE_SUFFIX=_db_suffix.sql | |
| DATABASE=<Databae Name> | |
| USER=<Database username > | |
| FILE=`date +"%Y%m%d%H%M%S"`${FILE_SUFFIX} | |
| OUTPUT_FILE=${BACKUP_DIR}/${FILE} |
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 Account: | |
| """ A basic class that store bank account information """ | |
| def __init__(self, bank_account: str, balance: float): | |
| self.bank_account = bank_account | |
| self.balance = balance | |
| self.account_information = dict(bank_account=self.bank_account, balance=self.balance) | |
| def __str__(self): | |
| return f"Bank Account: {self.bank_account} - balance: {self.balance}" |
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
| # Fund transfer process | |
| account.balance = account.balance - 500.25 | |
| # Now call the account_information attribute | |
| print("Calling the account_information attribute") | |
| print(f"Account information: {account.account_information}") | |
| # calling the balance attribute | |
| print(f"Current balance: {account.balance}") | |
| # Output |
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 Account: | |
| """ A basic account information store class """ | |
| def __init__(self, bank_account: str, balance: float): | |
| self.bank_account = bank_account | |
| self.balance = balance | |
| # self.account_information = dict(bank_account=self.bank_account, balance=self.balance) | |
| def account_information(self) -> dict: | |
| """ |
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
| # ....... | |
| # Just declare the @property decorator and solve those problems. | |
| @property | |
| def account_information(self) -> dict: | |
| """ | |
| Get account information | |
| :return: {'bank_account': '0004-0067894712', 'balance': 1000.5} | |
| :rtype: dict | |
| """ | |
| return dict(bank_account=self.bank_account, balance=self.balance) |
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 Account: | |
| """ A basic account information store class """ | |
| def __init__(self, bank_account: str, balance: float): | |
| self.bank_account = bank_account | |
| self.balance = balance | |
| self._account_information = dict(bank_account=self.bank_account, balance=self.balance) | |
| # Just declare the @property decorator and solve those problems. | |
| @property |
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 functools import partial | |
| from django.db.models import signals | |
| class WhoDidMiddleware(object): | |
| """ | |
| his class represent as catch request user and mark the user into that model. | |
| Usage: | |
| MIDDLEWARE = [ | |
| .... |