Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Eat · Sleep · Code · Repeat

Vignesh Rao thevickypedia

🤓
Eat · Sleep · Code · Repeat
View GitHub Profile
@thevickypedia
thevickypedia / timezones.ipynb
Created Nov 1, 2022
Timezones using python
View timezones.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thevickypedia
thevickypedia / camera.py
Created Oct 7, 2022
Get information and list cameras in macOS and Windows
View camera.py
import json
import platform
import subprocess
from typing import Dict, List
from xml.etree import ElementTree
import xmltodict
Win32 = """wmic path CIM_LogicalDevice where "Description like 'USB Video%'" get /value"""
MacOS = "system_profiler -xml SPCameraDataType"
@thevickypedia
thevickypedia / video.py
Last active Jun 24, 2022
Stream videos using FastAPI
View video.py
"""
pip install fastapi uvicorn aiofiles jinja2
uvicorn video:app --reload
"""
import mimetypes
import logging
import os
import pathlib
from fastapi import FastAPI, Request, Response, Header
@thevickypedia
thevickypedia / retry.py
Created Jun 19, 2022
Retry a function for given number of times and handle known exceptions
View retry.py
import functools
import logging
import random
from typing import Callable, Any
logging.root.setLevel(level=logging.DEBUG)
def retry(attempts: int = 3, exclude_exc=None) -> Callable:
"""Calls child func recursively.
@thevickypedia
thevickypedia / playaudio.py
Last active Jun 13, 2022
Play audio using pyaudio module
View playaudio.py
import os
import wave
from threading import Thread
from typing import NoReturn, Union
import pyaudio
from pydantic import FilePath
class PlayAudio:
@thevickypedia
thevickypedia / scan_att_router.py
Last active Sep 26, 2022
Scan devices attached to router - At&t
View scan_att_router.py
# pip install requests pandas lxml
import json
import socket
import pandas
import requests
socket_ = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
socket_.connect(("8.8.8.8", 80))
@thevickypedia
thevickypedia / timeout_handler.py
Created May 26, 2022
Timeout handler using threading and wrapper
View timeout_handler.py
import functools
import time
from threading import Thread
from typing import Union, Callable, NoReturn
def timeout(duration: Union[float, int]) -> Callable:
"""Timeout handler for Windows OS.
Args:
@thevickypedia
thevickypedia / timeout_handler.py
Last active May 26, 2022
Handle timeout using multiprocessing
View timeout_handler.py
import multiprocessing
import time
from typing import Callable, Union
class TimeoutHandler:
"""Initiates TimeoutHandler object to run a function and terminate it after a given time limit.
>>> TimeoutHandler
@thevickypedia
thevickypedia / timeout_handler.py
Last active May 26, 2022
Handle timeout using context manager and singal (Linux and Darwin)
View timeout_handler.py
import signal
import time
from contextlib import contextmanager
from types import FrameType
from typing import Union, NoReturn
@contextmanager
def timeout(duration: Union[int, float]) -> NoReturn:
"""Creates a timeout handler.
View display.py
import inspect
import os
from datetime import datetime
from typing import Any
class Format:
"""Initiates Format object to define variables that print the message in a certain format.
>>> Format