Skip to content

Instantly share code, notes, and snippets.

View pradishb's full-sized avatar

Pradish Bijukchhe pradishb

View GitHub Profile
@pradishb
pradishb / pyqt6_fix_taskbar_icon.py
Last active April 1, 2024 14:46
Fix pyqt6 taskbar icon in windows 11
import ctypes
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("company.app.1")
@pradishb
pradishb / handlers.py
Created December 27, 2023 07:19
PyQt6 logging handler
import logging
from logging import Handler
from logging import LogRecord
from PyQt6.QtCore import QObject
from PyQt6.QtCore import pyqtSignal
COLORS = {
logging.DEBUG: "#0071A6",
logging.INFO: "#0071A6",
@pradishb
pradishb / convert_xlsx_to_pdf.py
Last active October 2, 2023 11:10
Convert all xlsx files in folder to pdf using libre office in threads
import os
import concurrent.futures
from tqdm import tqdm
from glob import glob
def process_file(file_path):
os.system(f'"C:\Program Files\LibreOffice\program\swriter.exe" --headless --convert-to pdf {file_path}')
def process_files_with_threads():
files = list(glob('*.xlsx'))
@pradishb
pradishb / disk_usage_bot.py
Created September 24, 2023 11:13
A script that sends discord notification when the disk size is below a threshold, can be used in servers to monitor disk usage periodically by pairing with cron
import json
import subprocess
threshold = 10 # GB
webhook_url = "https://discord.com/api/webhooks/xxx/xxx"
environment = "my-server-name"
free_space = (
int(
@pradishb
pradishb / expo_backoff_with_jitter.py
Last active January 30, 2024 01:59
Exponential backoff with jitter in python
from random import randint
def get_expo_backoff(
base: int, attempts: int = 1, cap: int = 100_000_000, jitter: bool = True
):
"""
Returns a backoff value https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
:param base: The time to sleep in the first attempt.
:param attempts: The number of attempts that have already been made.
@pradishb
pradishb / index.css
Created August 15, 2023 17:08
Remove input autofill background
input:-webkit-autofill,
input:-webkit-autofill:focus {
transition: background-color 600000s 0s, color 600000s 0s;
}
input[data-autocompleted] {
background-color: transparent !important;
}
@pradishb
pradishb / proxy_params
Last active July 26, 2023 16:53
nginx proxy params
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Referrer $http_referer;
proxy_set_header Referer $http_referer;
@pradishb
pradishb / gist:8639ac6d8ed02c07b9702830e13d5f75
Created June 16, 2023 13:14
Set commit name, email and date to author name, email and date
git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_COMMITTER_NAME="%aN" GIT_COMMITTER_EMAIL="%aE" git commit --amend --no-edit' rebase -i --root
@pradishb
pradishb / sentry.py
Last active March 17, 2023 08:41
Python sentry config with LoggingIntegration CRITICAL
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
sentry_logging = LoggingIntegration(event_level=logging.CRITICAL)
sentry_sdk.init(
dsn=SENTRY_DSN,
traces_sample_rate=1.0, integrations=[sentry_logging],
ignore_errors=[KeyboardInterrupt],
)
@pradishb
pradishb / logger.py
Last active November 1, 2023 16:23
Logger conifuration with StreamHandler and RotatingFileHandler
import logging
import os
import sys
from logging import Formatter
from logging import LogRecord
from logging import StreamHandler
from logging.handlers import RotatingFileHandler
class ColorFormatter(logging.Formatter):