Skip to content

Instantly share code, notes, and snippets.

View jaydeepkarale's full-sized avatar

Jaydeep Karale jaydeepkarale

View GitHub Profile
@jaydeepkarale
jaydeepkarale / six_python_clean_code.md
Created August 10, 2025 12:48
6 Python Clean Code Tips

Quick Summary

Tip # Clean Code Practice Why It Matters Example
1 Avoid pass & ... in placeholder code Prevents silent no-ops; makes unfinished code obvious raise NotImplementedError("Explain purpose")
2 Use *args for variable arguments Makes your function flexible without manual parameter handling def log_messages(*args):
3 Avoid if-else pyramids Improves readability and reduces nested complexity Use early returns instead of deep nesting
4 Use type hints Clarifies expected input types for maintainers and tools def greet(name: str):
5 Specify return types Makes the function’s output clear and helps IDEs def add(a: int, b: int) -> int:
6 Use ... in doctests to skip unimportant lines Keeps examples concise while focusing on key parts # doctest: +ELLIPSIS
@jaydeepkarale
jaydeepkarale / scrape_amazon.py
Created January 7, 2023 02:06
Amazon Product Scrapper
import datetime
import dataclasses
import pygsheets
import json
import time
from playwright.sync_api import sync_playwright
import re
import pywhatkit
import pyautogui
import keyboard
@jaydeepkarale
jaydeepkarale / scrape_selenium_playground.py
Last active December 24, 2022 12:28
Python Playwright Script To Scrape LambdaTest Selenium Playground
import json
import logging
import os
import subprocess
import sys
import time
import urllib
from logging import getLogger
from dotenv import load_dotenv
@jaydeepkarale
jaydeepkarale / playwright_python_webscraping.py
Last active February 23, 2023 01:24
webscraping on cloud playwright grid in python
import json
import logging
import os
import subprocess
import sys
import time
import urllib
from logging import getLogger
from dotenv import load_dotenv
from turtle import *
import turtle as tur
t = tur.Turtle()
tur.speed(6)
tur.bgcolor("black")
tur.color("gold")
tur.pensize(5)
@jaydeepkarale
jaydeepkarale / app.py
Created July 26, 2022 13:19
Flask CRUD App In 60 Secodnds
from flask import Flask, request, Response, jsonify
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
class Todo(db.Model):
@jaydeepkarale
jaydeepkarale / urlshortner.py
Last active June 24, 2022 16:26
URL Shortner In Pure Python & Ngrok
from email import header
from aiohttp import web
import sqlite3
import validators
import requests
import requests.exceptions
from http import HTTPStatus
import json
import string
import random
@jaydeepkarale
jaydeepkarale / redirect_to_longurl.py
Created June 23, 2022 13:03
redirect logic for url shortner
@routes.get("/{code}")
async def redirect_to_longurl(request):
"""Function to retrieve long URL based on code
:param request: HTTP request
"""
data = request.match_info["code"]
longurl = cursor.execute("SELECT longurl from URLSHORTNER where code = ?",(data,)).fetchone()
print(longurl[0])
return web.HTTPFound(longurl[0])
@jaydeepkarale
jaydeepkarale / integtratevalidatorwithshorten.py
Last active June 24, 2022 16:26
Integrate Validators With Shorten Method
def validate_url_format(longurl: str):
"""This function returns True if the longurl is in a valid format"""
return validators.url(longurl)
def validate_url(longurl: str):
"""This function returns True if the longurl is a valid web address"""
try:
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0'}
response = requests.get(longurl, headers=headers)
return response.status_code == HTTPStatus.OK
@jaydeepkarale
jaydeepkarale / db.py
Created June 23, 2022 12:50
Initialise a sqlitedb
import sqlite3
from aiohttp import web
# create a sqllite db
connection = sqlite3.connect("urlshortner.db")
cursor = connection.cursor()
routes = web.RouteTableDef()
if __name__ == "__main__":