Skip to content

Instantly share code, notes, and snippets.

View sachnaror's full-sized avatar
🍺

Sachin sachnaror

🍺
View GitHub Profile
@sachnaror
sachnaror / t25.py
Created September 20, 2025 08:12
An async Ninja endpoint that calls two remote systems concurrently
#An async Ninja endpoint that calls two remote systems concurrently
#(e.g., inventory + billing) and merges results
from ninja import NinjaAPI
import httpx
import asyncio
api = NinjaAPI()
@api.get("/order-summary")
@sachnaror
sachnaror / t24.py
Created September 18, 2025 00:12
# t24.py — PyFlink wordcount with clean shutdown (no noisy gRPC at exit)
# t24.py — PyFlink wordcount with clean shutdown (no noisy gRPC at exit)
# A PyFlink mini streaming job. It takes a small list (["apple", "banana", "apple"]), maps each word to (word, 1), groups by word, and reduces counts. Then it prints the running totals.
# So the flow is:
# "banana" → ('banana', 1)
# "apple" → ('apple', 1)
# second "apple" → updates to ('apple', 2)
import os
@sachnaror
sachnaror / DeepSeek_Test.py
Last active August 10, 2025 08:24
DeepSeek API test script
import os
import logging
from typing import Optional
from tenacity import retry, stop_after_attempt, retry_if_exception_type
from openai import AsyncOpenAI, APIError, APIConnectionError
# --- Configure Logging ---
logging.basicConfig(
level=logging.INFO,
{
"keys": [
{
"kty": "RSA",
"kid": "demo-key-001",
"use": "sig",
"alg": "RS256",
"n": "vg2gksIn5um5GnBx15LpzTtVTHHtGGQLD_F-10PKZyckjhZLJM_vtoOwoxFAg1ysi6jH_OPl9EYudUYLpKzNwbK6Q89zwfT2vJEMf-4mIKabcVz-hOLR9GIlDpy6ouoPBBqx-youANM1wUiTTPJb7RpUKZ4_MC5o0BRlLBP7uAIENdy4PWcFvWeatNkqSlaKS1pws7JNdb2qa3p0Xn_wMzII1scmXFJh6KPOHL3P-X4ps3beY9k3xJBIBSD0D6auArRgC1Wo2a4rlOKKs3243auHsvSrt9_dPOb06GFN6ZSYG-Aiaqc6quQwaxpIJiQ3IpIORQYz1FqTW44TA4WYeQ",
"e": "AQAB"
}
@sachnaror
sachnaror / t14.py
Last active September 18, 2025 00:13
This Python script uses the OpenAI API to send a user query and receive a concise, semi-formal response in under 3 lines using the GPT model gpt-3.5-turbo.
import openai
# ✅ Use your actual API key here (never share it in public code)
openai.api_key = "sk-proj-GyQv44xNGlYPhFSOp6UaOxQ44oH_ZtUH_VpUutCuGiw2Wgc2pB7TQiGEkY6eyOB5uadZzgT3BlbkFJKr6segLT2r0fjqSV9jtQbV23XtxrXxxJIEk-s9kfgauib3EbD-m_ap81NajCOkpsLZsGwvqQA"
# Define a concise system message
system_prompt = (
"You are a helpful assistant. Respond in a semi-formal tone. "
"Keep your answer under 3 lines. Be informative and friendly."
)
@sachnaror
sachnaror / t13.py
Created March 6, 2025 23:20
This Python script listens for “keyword xxx” typed anywhere on macOS, deletes it, and replaces it with a predefined sentence in real-time. It runs for 15 minutes and then stops. 🚀
# Your code goes here
import time
import re
import threading
from pynput import keyboard
# Keyword-to-replacement mappings
keyword_map = {
"marketing": "Focus on customer engagement for better sales.",
"ai": "AI is revolutionizing industries.",
@sachnaror
sachnaror / t10.py
Created February 21, 2025 09:40
The Python script uses Whisper AI to transcribe an audio file into text. It splits audio into 30-sec chunks, processes each part, and combines results. It runs on CPU (fixes MPS issues) and supports PSD3 analysis. 🚀
import librosa
import numpy as np
import whisper
# Load Whisper model and force CPU usage
model = whisper.load_model("medium").to("cpu")
# Load audio file
audio_path = "/Users/homesachin/Downloads/20250221_125939.aac"
audio, sr = librosa.load(audio_path, sr=16000)
@sachnaror
sachnaror / t8.py
Created January 17, 2025 21:21
A shell script to pull specific files or the entire repository from a remote GitHub repository. By default, it pulls README.md unless a different file name or . for the full repository is specified. Ideal for quick file fetches or repo syncs
#!/bin/bash
# Get the repository URL from the current folder
REPO_URL=$(git config --get remote.origin.url)
if [ -z "$REPO_URL" ]; then
echo "Error: No remote GitHub repository detected in this folder."
exit 1
fi
@sachnaror
sachnaror / t7.py
Created January 13, 2025 20:53
This script transcribes sorted audio chunks using Google Speech Recognition. It processes .wav files in order, combines their transcriptions into a single text, and handles errors gracefully, outputting the final combined transcription.
# Full Description: nal transcription.
# Full Description: nal transcription.
import os
import speech_recognition as sr
# Initialize the recognizer
recognizer = sr.Recognizer()
@sachnaror
sachnaror / t7.py
Created January 13, 2025 20:52
This script processes audio chunks in a folder, transcribes them using Google Speech Recognition, and combines the transcriptions into a single text. It sorts audio files numerically to maintain order and handles errors during processing, outputting the fi
# Full Description: nal transcription.
import os
import speech_recognition as sr
# Initialize the recognizer
recognizer = sr.Recognizer()
# Folder containing chunks
chunk_folder = "."