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 / .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"
@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 / 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 / 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 / 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 / admin_network.xml
Last active July 12, 2021 15:33
admin CLI network file for clish parser
<?xml version="1.0" encoding="UTF-8"?>
<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
http://clish.sourceforge.net/XMLSchema/clish.xsd">
<!--=======================================================-->
<PTYPE name="STRING"
pattern="[^\-]+"
help="String"/>
@premchalmeti
premchalmeti / network_schema.json
Created July 12, 2021 15:31
Network schema file for clish parser
{
"version": "2.0.0",
"created_on": "2021-06-28T17:29:37.714428",
"module": {
"name": "network",
"source_file": "network.xml",
"commands": [
{
"cmd": "network show",
"meta": {
@premchalmeti
premchalmeti / user_network.xml
Created July 12, 2021 15:32
user_network.xml file generated by clish parser
<?xml version="1.0" encoding="UTF-8"?>
<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
http://clish.sourceforge.net/XMLSchema/clish.xsd">
<COMMAND name="network show"
help="Show currently added devices">
<ACTION>network show</ACTION>
</COMMAND>
@premchalmeti
premchalmeti / parsing_algorithm.txt
Created July 25, 2021 16:09
The CLISH XML parsing algortihm
0. START
1. Traverse the CmdTree node from the root CALL process_node(CmdTree.root)
2. START process_node:
If the CmdNode is not a leaf node then
2.1. Process all the child nodes of the current node first. CALL process_node(node)
2.2. After processing all child CmdNode. Set current node visibility
If all the childs are removed then
node.visible = False
Else
node.visible = True
@premchalmeti
premchalmeti / terminal_auto_load_.env.sh
Last active August 28, 2021 17:23
Load folder specific `.env` file. Append below the code inside `.bashrc` file
function loadenv() {
if [ -f .env ];
then
source .env
fi
}
loadenv
function cd() {