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
import tracemalloc | |
from time import perf_counter | |
def performance(func): | |
def wrapper(*args, **kwargs): | |
tracemalloc.start() | |
start_time = perf_counter() | |
func(*args, **kwargs) | |
current, peak = tracemalloc.get_traced_memory() | |
finish_time = perf_counter() |
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
import os | |
import logging | |
import logging.config | |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
LOGGER = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'formatters': { |
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
-- Get Database Size | |
select pg_size_pretty(pg_database_size('<DB Name>')); | |
-- Get Table Size | |
select pg_size_pretty(pg_table_size('<Table SIze>')); | |
-- Delete a small table | |
delete from table_name; | |
-- Delete a big table | |
TRUNCATE TABLE table_name; | |
-- Count row of a table |
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 = [ | |
.... |
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
# ....... | |
# 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) | |
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
# 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 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
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} |
NewerOlder