Skip to content

Instantly share code, notes, and snippets.

View tejas-kr's full-sized avatar
🐢
Learning slowly but thoroughly now !

Tejas Kumar Jaiswal tejas-kr

🐢
Learning slowly but thoroughly now !
  • /home/tejas
View GitHub Profile
@tejas-kr
tejas-kr / flat_list_rec.py
Created September 16, 2024 10:15
Flatten a nested list using recursion
li = ["Ram", 12, [23, 56, "vinod"], [[12, "you"], 1], [["mnb"],
["kjhdsf", 123, 0.8876], [[98, 12, 34], [2345, 8987643]]]]
lo = []
def flatten_list(li):
for i in li:
if isinstance(i, list):
flatten_list(i)
else:
@tejas-kr
tejas-kr / fastapi_sqlalchemy_pydantic_alembic.py
Created September 8, 2024 11:44
A FastAPI CRUD app boilerplate which uses Pydantic, SQLAlchemy and Alembic
# main.py
from fastapi import Depends, FastAPI, HTTPException
from sqlalchemy.orm import Session
from database import SessionLocal, engine
import crud, models, schemas
models.Base.metadata.create_all(bind=engine)
app = FastAPI()
@tejas-kr
tejas-kr / fastapi_vercel.json
Created July 1, 2024 15:13
Vercel.json file for deploying FastAPI app to vercel. (Change the builds[0].src and routes[0].dest)
{
"version": 2,
"builds": [
{
"src": "main.py",
"use": "@vercel/python"
}
],
"routes": [
{
@tejas-kr
tejas-kr / basic_logging.py
Created May 2, 2024 13:05
basic_logging gist
import logging
logging.basicConfig(format='%(asctime)s::%(name)s::%(levelname)s::%(message)s', level='INFO')
logger = logging.getLogger(__name__)
@tejas-kr
tejas-kr / hashing_passwords.py
Created March 12, 2024 14:35
Snippet to hash passwords
import hashlib
hashed_str1 = hashlib.sha256('text123hello'.encode('utf-8')).hexdigest()
print(hashed_str1)
hashed_str2 = hashlib.sha256('text123hello'.encode('utf-8')).hexdigest()
print(hashed_str2)
assert hashed_str1 == hashed_str2
@tejas-kr
tejas-kr / gen_random_str.py
Created March 12, 2024 06:48
Generate Random String (of random characters) Python
import random
import string
letters = []
letters.extend(string.ascii_lowercase)
letters.extend(string.ascii_uppercase)
letters.extend((str(i) for i in range(0, 10)))
print(letters)
print(''.join([random.choice(letters) for i in range(50)]))
@tejas-kr
tejas-kr / flask_db_conn_manager.py
Created March 6, 2024 17:14
Flask DB Connection Manager Script
from flask import g, current_app
from db import DB
def get_db():
if 'db' not in g:
g.db = DB()
return g.db
@tejas-kr
tejas-kr / text_processing.py
Created April 23, 2021 05:05
text processing for nlp tasks (using nltk) [for spacy i will create soon]
from nltk.corpus import stopwords
import string
def text_process(text):
nopunc = [char for char in text if char not in string.punctuation]
nopunc = ''.join(nopunc)
return [word for word in nopunc.split() if word.lower() not in stopwords.words('english')]
@tejas-kr
tejas-kr / check_jquery_load.js
Last active April 23, 2021 04:40
Javascript code to check if jquery is loaded in the page
/**
* This code is very helpful for people who forget things easily
*/
window.onload = function() {
if (window.jQuery) {
alert('jQuery loaded!');
} else {
alert('jQuery not loaded!');
}
{
'jquery file upload' : 'https://blueimp.github.io/jQuery-File-Upload/index.html'
}