Skip to content

Instantly share code, notes, and snippets.

View deepanshumehtaa's full-sized avatar
💭
If Good things are not coming to you, Snatch them™

Deepanshu mehta deepanshumehtaa

💭
If Good things are not coming to you, Snatch them™
View GitHub Profile
@deepanshumehtaa
deepanshumehtaa / OpenAI chat & Embeddings.py
Last active December 22, 2025 13:46
OpenAI chat & Embeddings
import httpx
from pprint import pprint
from dotenv import load_dotenv
from openai.types import CreateEmbeddingResponse
_ = load_dotenv("../.env")
from openai import (
OpenAI, APIError, RateLimitError, APITimeoutError, APIConnectionError, ChatCompletion,
)
@deepanshumehtaa
deepanshumehtaa / SPARKSQLAllFunctionsPyspark.ipynb
Created November 20, 2025 15:33
SPARKSQLAllFunctionsPyspark.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@deepanshumehtaa
deepanshumehtaa / vdb.py
Created November 12, 2025 22:00
vdb.py
import os
import numpy as np
from databricks.vector_search.client import VectorSearchClient
from dotenv import load_dotenv
load_dotenv()
DATABRICKS_WORKSPACE_URL = os.getenv("DATABRICKS_WORKSPACE_URL")
access_token_dbx = os.getenv("access_token_dbx")
VECTOR_SEARCH_ENDPOINT = os.getenv("VECTOR_SEARCH_ENDPOINT")
@deepanshumehtaa
deepanshumehtaa / postgres on corporate windows
Created October 31, 2025 08:50
postgres on corporate windows
## set postgres data folder:
1. set env PGDATA = "C:/Development/psql_data"
2. RUN
go inside bin folder of postgres and RUN
initdb -D %PGDATA%
## create user
> createuser.exe -U <ROLE> --superuser --pwprompt <USERNAME>
@deepanshumehtaa
deepanshumehtaa / FastAPI with dequeue and custom threadpool executor.py
Created July 11, 2025 14:47
FastAPI with dequeue and custom threadpool executor.py
import concurrent.futures
import collections
import threading
import time
import random
from fastapi import FastAPI, BackgroundTasks
from fastapi.responses import JSONResponse
t_pool = concurrent.futures.ThreadPoolExecutor(max_workers=3)
@deepanshumehtaa
deepanshumehtaa / python socket server - post api.py
Created May 13, 2025 13:15
python socket server - post api.py
import json
import socket
def parse_http_request(request):
headers, _, body = request.partition("\r\n\r\n")
request_line = headers.splitlines()[0]
method, path, _ = request_line.split()
return method, path, headers, body
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@deepanshumehtaa
deepanshumehtaa / docker-compose-kafka.yaml
Created April 27, 2025 11:43
docker-compose-kafka.yaml
version: '3'
services:
zookeeper:
# image: confluentinc/cp-zookeeper:latest
image: bitnami/zookeeper:3.9
container_name: zookeeper
ports:
- "2181:2181"
environment:
ALLOW_ANONYMOUS_LOGIN: 1
@deepanshumehtaa
deepanshumehtaa / Backgrond tasks in FastAPI.py
Last active April 26, 2025 11:16
Backgrond tasks in FastAPI
# gunicorn -w 2 -k uvicorn.workers.UvicornWorker main:app --max-requests 100 --max-requests-jitter 10 --threads 5
# ..........................................................................................
import asyncio
import os
import logging
# from asyncio.log import logger
from time import sleep
@deepanshumehtaa
deepanshumehtaa / Docker Commands.txt
Last active July 1, 2025 19:44
Docker Commands
permission issues:
> ls -l /var/run/docker.sock
> sudo chmod 666 /var/run/docker.sock
# for DockerFIle
Create a Docker Image: (assuming you already have Dockerfile in ur folder)
> docker build -t <my-any-image-name> .
@deepanshumehtaa
deepanshumehtaa / SSE - Server-Sent Events
Last active March 5, 2025 05:18
SSE - Server-Sent Events
what is the time duration of SSE for keep-alive connection ?
The time duration of an SSE (Server-Sent Events) keep-alive connection can vary depending on several factors, including:
Server configuration: The server can specify a keep-alive timeout using the Keep-Alive header or other configuration settings.
Client configuration: The client can also specify a keep-alive timeout using the Keep-Alive header or other configuration settings.
Network conditions: Network conditions, such as latency and packet loss, can affect the keep-alive timeout.
Typically, the keep-alive timeout for SSE connections ranges from a few seconds to several minutes. Here are some common values:
Default timeout: 30 seconds to 1 minute
Typical timeout: 1-5 minutes
Maximum timeout: 30 minutes to 1 hour