Skip to content

Instantly share code, notes, and snippets.

View premchalmeti's full-sized avatar
🎯
Focusing

Premkumar Chalmeti premchalmeti

🎯
Focusing
View GitHub Profile
@premchalmeti
premchalmeti / sequential_testcase_loader.py
Last active August 28, 2021 17:23
The python's unittest library executes the tests in alphabetical order to override this behaviour and execute tests in (defined) order. Use `unittest.main(testLoader=SequentialTestCaseLoader())` to trigger execution.
import unittest
class SequentialTestCaseLoader(unittest.TestLoader):
"""
The python's unittest library executes the tests in alphabetical order
to override this behaviour and execute tests in (defined) order.
Use `unittest.main(testLoader=SequentialTestCaseLoader())` to
the trigger execution.
"""
def getTestCaseNames(self, tcCls):
@premchalmeti
premchalmeti / boto3_s3_list_objects.py
Created August 26, 2020 14:33
This function takes a S3 bucket name and optionally folder name and returns a sorted list of objects inside s3
def list_objects(
bucket_name: str, folder_name: str
) -> None:
""" This function takes a S3 bucket name and optionally folder name
and returns a sorted list of objects inside S3
Args:
bucket_name ([string]): Name of the S3 bucket
folder_name ([string]): Sub folder inside S3 (optional)
"""
@premchalmeti
premchalmeti / sqlalchemy_wipe_data.py
Last active October 17, 2022 23:12
SQLAlchemy delete all tables data
session = Session()
# Explicitly mention the tables having foreign key then concrete classes.
tables = [UserEmail, UserPermission, User, GroupPermission, Permission, Role, GroupMember, Group]
for table in tables:
session.query(table).delete()
session.commit()
print(table, 'data deleted')
@premchalmeti
premchalmeti / sqlalchemy_base_model_mixins.py
Last active August 19, 2020 19:47
Django Style SQLAlchemy Base Models (Auto ID, CreatedDateTime & UpdatedDateTime)
import datetime as dt
from sqlalchemy import Column, Integer, DateTime
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declared_attr, declarative_base
from db.config import SQLA_URL
engine = create_engine(SQLA_URL, echo=True)
@premchalmeti
premchalmeti / .zshrc
Last active May 11, 2022 13:29
My zsh profile
# Path to your oh-my-zsh configuration.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#export ZSH_THEME="robbyrussell"
export ZSH_THEME="gnzh"