Skip to content

Instantly share code, notes, and snippets.

View jainal09's full-sized avatar
🎯
Focusing

Jainal Gosaliya jainal09

🎯
Focusing
  • Doble Engineering
  • Boston
  • 11:22 (UTC -12:00)
View GitHub Profile
apiVersion: apps/v1
kind: Deployment
metadata:
name: graceful-shutdown-fast-api
labels:
app: graceful-shutdown-fast-api
spec:
replicas: 1
selector:
matchLabels:
async def connect(self, websocket: WebSocket, client_id: str) -> None:
"""
Connect the WebSocket
Args:
websocket: WebSocket
id: Client ID
Returns:
None
"""
print(f"Read Flag: {read_flag()}")
@router.post("/create-task/")
async def create_task(background_tasks: BackgroundTasks) -> dict:
"""
Create a task and add it to the queue
Args:
background_tasks: BackgroundTasks
Returns:
dict: Response message
"""
if not read_flag():
class SignalHandler:
async def handle_exit(self):
"""
Handle the exit of the server
Args:
None
Returns:
None
apiVersion: apps/v1
kind: Deployment
metadata:
name: async-app
labels:
app: async-app
spec:
replicas: 1
selector:
matchLabels:
@jainal09
jainal09 / Dockerfile
Created March 14, 2024 01:20
Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY async.py .
ENTRYPOINT ["python", "async.py"]
@jainal09
jainal09 / async.py
Created March 14, 2024 01:16
Grace Full Shutdown Async Python code
import asyncio
import signal
import random
import os
# Shared queue
queue = asyncio.Queue()
# Event to signal the producer to stop
stop_event = asyncio.Event()
@jainal09
jainal09 / pyproject.toml
Created June 8, 2023 23:29
pyproject.toml
[tool.poetry]
name = "xxxxxxx"
version = "0.1.0"
description = "xxxxxxxx"
authors = ["xxxxx <xxxxxx@xxxxx.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
pydantic = "^1.10.8"
@jainal09
jainal09 / OrderAgnosticSearch.py
Created April 1, 2023 23:56
Order Agnostic Binary Search in Python
import random
def search_array(array, target):
start_index = 0
end_index = len(array) - 1
is_ascending = array[start_index] < array[end_index]
while start_index <= end_index:
mid_index = start_index + (end_index - start_index) // 2
@jainal09
jainal09 / OrderAgnosticSearch.java
Created April 1, 2023 23:51
Order Agnostic Binary Search in java
package myPackage.myAlgorithms;
public class MyOrderAgnosticBinarySearch {
public static void main(String[] args) {
int[] nums1 = {-1, 2, 4, 6, 7, 8, 12, 15, 19, 32, 45, 67, 99};
int[] nums2 = {99, 67, 45, 32, 19, 15, 12, 8, 7, 6, 4, 2, -1};
int target = -1;
System.out.println(mySearch(nums1, target));
System.out.println(mySearch(nums2, target));
}