Posts

Creating a Minimal WebSocket Connection in Python, Inspired by the Simplicity of Socket.IO

 Simple Websocket  Connection. LIke socket io. main.py import asyncio import websockets import uuid connections = [] # when new socket connection comes this' function will executeed async def handle_websocket ( websocket , path ): #<-- path of socket recived     # creating uniq id     connection_id = str ( uuid . uuid4 ())       # This function will be append new connection     connections. append ( connection_id )             print (" Connected:- ", connection_id )     # < -- when user connected send him a message -- >     await websocket. send ( f "Your Id: { connection_id } " )         # < -- it\'s a user connection i'ts run antil user connected when user diconnected it will be ditoryed -- >     try :         while True :             try :           ...

Python Video Streaming Server

    Python Video Streaming Server import http.server     import socketserver     import os     PORT = 8000     VIDEO_PATH = ' test.mp4 '     CHUNK_SIZE = 10 ** 6   # Adjust the chunk size as needed (1000000 Bytes)->(1 MB)       class CustomRequestHandler ( http . server . SimpleHTTPRequestHandler ):         def do_GET ( self ):             if self .path == ' / ':                 self . send_response ( 200 )                 self . send_header (' Content-type ', ' text/html ')                 self . end_headers ()                 # Embed video with correct source                 self .wfile. write ( b ' <video width=250 src="/video" controls>...

Find Memory Consumption Of Your Python Program.

  import psutil def get_memory_usage ():     process = psutil. Process ( os . getpid ())     memory_info = process. memory_info ()         print ( f "Memory Usage: { memory_info . rss / ( 1024 ** 2 ) :.2f } MB" ) # Call this function in your code to print the memory usage get_memory_usage ()

Crop Screenshot Save Path (WinLogo+Shift+S)

 C:\Users\avinash\AppData\Local\Packages\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\TempState\ScreenClip

Tkinter Dragable Screen

     # Tkinter Dragable Screen     import tkinter as tk     def start_drag ( event ):         root.x = event.x         root.y = event.y     def stop_drag ( event ):         del root.x         del root.y     def drag ( event ):         try :             deltax = event.x - root.x             deltay = event.y - root.y             x = root. winfo_x () + deltax             y = root. winfo_y () + deltay             root. geometry ( f "+ { x } + { y } " )         except AttributeError :             pass     root = tk. Tk ()     root. geometry (" 400x300 ")     # Create a button to close the window...

how to create a executable (exe) file for GUI like tkinter command in python

how to create a executable (exe) file for GUI like tkinter command in python pyinstaller - w main.py

code copy paste

  <! DOCTYPE html > < html lang =" en "> < head >     < meta charset =" UTF-8 ">     < meta name =" viewport " content =" width=device-width, initial-scale=1.0 ">     < title >Document</ title >     <!-- Replace agate with your theme - find themes at https://highlightjs.org/demo -->     < link rel =" stylesheet "         href =" https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/tomorrow-night-bright.min.css ">     <!-- For icons -->     < script type =" module " src =" https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js "></ script >     < script nomodule src =" https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js "></ script >     < style >         . code-block {             position: relative ...