Skip to content

Instantly share code, notes, and snippets.

@thevickypedia
thevickypedia / package.py
Last active October 1, 2023 16:34
Create a package.zip from the files modified within a Github repo
import asyncio
import logging
import os
import shutil
import subprocess
logger = logging.getLogger(__name__)
logger.addHandler(hdlr=logging.StreamHandler())
logger.setLevel(level=logging.DEBUG)
@thevickypedia
thevickypedia / async_telegram_polling.py
Last active September 11, 2023 07:03
Asynchronous calls for long polling Telegram API - A better broken state
import asyncio
from typing import Dict
from urllib.parse import urljoin
import aiohttp
from pydantic import HttpUrl
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
@thevickypedia
thevickypedia / cert.py
Created September 10, 2023 22:22
Generate a self signed certificate
import binascii
import getpass
import json
import os
import time
from urllib.request import urlopen
from OpenSSL import crypto
IP_INFO = json.load(urlopen('http://ipinfo.io/json')) or json.load(urlopen('http://ip.jsontest.com'))
timezone_map = {
'GMT': 'Greenwich Mean Time',
'UTC': 'Universal Coordinated Time',
'ECT': 'European Central Time',
'EET': 'Eastern European Time',
'ART': '(Arabic) Egypt Standard Time',
'EAT': 'Eastern African Time',
'MET': 'Middle East Time',
'NET': 'Near East Time',
'PLT': 'Pakistan Lahore Time',
@thevickypedia
thevickypedia / tokenizer.py
Last active May 4, 2023 15:19
Tokenize a string using python
import base64
import binascii
import string
UNICODE_PREFIX = base64.b64decode(b'XA==').decode(encoding="ascii") + \
string.ascii_letters[20] + string.digits[:1] * 2
input_text = 'hello world'
@thevickypedia
thevickypedia / python_to_curl.py
Created April 27, 2023 12:13
Convert a python request to curl (without actually making a request)
SS_HEADERS = {
"Content-Type": "text/plain"
}
def check(response):
req = response.prepare()
command = "curl -X {method} \\\n -H {headers} \\\n -d '{data}' \\\n '{uri}'"
method = req.method
uri = req.url
@thevickypedia
thevickypedia / stop_process.sh
Last active April 16, 2023 18:30
Stop a process with process name in argument
if [[ $1 == "" ]]
then
echo "Pass process name as argument"
exit
else
echo "Stopping PIDs for $1"
fi
for pid in $(ps -ef | grep $1 | awk '{print $2}'); do echo "Stopping pid $pid" && kill -9 $pid; done
# for pid in $(ps -ef | awk '/$1/ {print $2}'); do echo "Stopping pid $pid" && kill -9 $pid; done
@thevickypedia
thevickypedia / cleanup_release_and_tags.py
Last active April 9, 2023 15:59
Clean up releases and tags in GitHub
import logging
import os
from threading import Thread
from typing import List, Tuple, Union
import requests
LOGGER = logging.getLogger(__name__)
LOGGER.addHandler(logging.StreamHandler())
LOGGER.setLevel(logging.DEBUG)
@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
@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."""