Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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'
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 / 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'))
@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 / workflows.py
Last active October 23, 2023 18:46
Delete GitHub workflows using API
import os
from typing import List
import requests
SESSION = requests.Session()
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': f"Bearer {os.getenv('GIT_TOKEN')}",
@thevickypedia
thevickypedia / sound.py
Created November 29, 2023 15:04
Record and play audio using pyaudio module
import logging
import math
import pyaudio
_logger = logging.getLogger(__name__)
_logger.addHandler(logging.StreamHandler())
_logger.setLevel(logging.DEBUG)
@thevickypedia
thevickypedia / requirements.py
Created December 2, 2023 18:29
Update requirements.txt to what's currently available in pip freeze
import os
import shutil
import subprocess
import time
with open('requirements.txt') as file:
requirements = file.readlines()
tmp_name = f'requirements_{int(time.time())}.txt'
os.rename('requirements.txt', tmp_name)