Skip to content

Instantly share code, notes, and snippets.

@thevickypedia
thevickypedia / timeout_handler.py
Created May 26, 2022 14:28
Timeout handler using threading and wrapper
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 / scan_att_router.py
Last active January 26, 2023 20:38
Scan devices attached to router - At&t
# pip install requests pandas lxml
import logging
import socket
from typing import Iterable, Optional, Union, Any
import pandas
import requests
from pandas import DataFrame
SOURCE = "http://{NETWORK_ID}.254/cgi-bin/devices.ha"
@thevickypedia
thevickypedia / playsound.py
Last active November 29, 2023 15:03
Play audio files using pyaudio module
import mimetypes
import os
import wave
from threading import Thread
from typing import NoReturn, Union
import pyaudio
class PlayAudio(Thread):
@thevickypedia
thevickypedia / retry.py
Created June 19, 2022 13:26
Retry a function for given number of times and handle known exceptions
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 / video.py
Last active June 24, 2022 18:56
Stream videos using FastAPI
"""
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 / camera.py
Last active December 29, 2022 04:03
Get information and list cameras for Linux, macOS and Windows
import platform
import subprocess
from typing import Dict, Iterable, List, Union
Windows = """wmic path CIM_LogicalDevice where "Description like 'USB Video%'" get /value"""
Darwin = "system_profiler SPCameraDataType"
Linux = "v4l2-ctl --list-devices"
def list_splitter(original_list: List[str], delimiter: str) -> List[List[str]]:
@thevickypedia
thevickypedia / timezones.ipynb
Last active January 16, 2023 14:27
Timezones using python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thevickypedia
thevickypedia / github.py
Created January 24, 2023 04:24
Check availability of an username and get details of the particular account
"""Check availability of an username and get details of the particular account.
Requirements:
python -m pip install python-dotenv requests
"""
import json
import os
import string
from typing import Union
@thevickypedia
thevickypedia / domain_availability.py
Last active January 27, 2023 14:50
Check domain name availability across all top-level domains in AWS using whois service
import logging
import subprocess
from typing import Iterable, NoReturn
import requests
from bs4 import BeautifulSoup
class CustomFormatter(logging.Formatter):
"""Override logging.Formatter using custom colors."""
@thevickypedia
thevickypedia / timezones.py
Last active March 14, 2023 02:18
Get all timezone names, descriptions and GMT offsets
import os
from collections.abc import Generator
from threading import Thread
from typing import List, Union, NoReturn, Dict
import pandas
import requests
import yaml
from jarvis.modules.exceptions import EgressErrors