Skip to content

Instantly share code, notes, and snippets.

View Willy-JL's full-sized avatar
🗿

WillyJL Willy-JL

🗿
View GitHub Profile
@Willy-JL
Willy-JL / basic_async_qt.py
Last active July 28, 2021 00:22
Basic PyQt GUI impementing asyncio behavior
from PyQt5.QtWidgets import QProgressBar
from qasync import QApplication
import functools
import asyncio
import qasync
import sys
async def main():
def close_future(future, loop):
loop.call_later(10, future.cancel)
@Willy-JL
Willy-JL / error.py
Last active November 19, 2022 04:02
Get full exception traceback and short exception description text
import traceback as _traceback
import sys
def traceback(exc: Exception = None):
# Full error traceback with line numbers and previews
if exc:
exc_info = type(exc), exc, exc.__traceback__
else:
exc_info = sys.exc_info()
@Willy-JL
Willy-JL / word_join.py
Last active March 26, 2021 07:52
Join words in a speech-like manner
example = ["abc", "def", "ghi"]
def join_words(words):
return (", ".join(words[:-1]) + (" and " if len(words) > 1 else "") + words[-1]) if len(words) > 0 else ""
result = join_words(example)
print(result)
# abc, def and ghi
@Willy-JL
Willy-JL / singleton.py
Last active November 19, 2022 04:16
Python3 Singleton (Single Instancing)
import os
class Singleton:
def __init__(self, app_id: str):
if os.name == 'nt':
# Requirement: pip install pywin32
import win32api, win32event, winerror
self.mutexname = app_id
self.lock = win32event.CreateMutex(None, False, self.mutexname)
@Willy-JL
Willy-JL / logger.py
Last active May 16, 2022 18:41
Log console output and input to file without custom color codes (supports colorama)
from contextlib import contextmanager
import sys
import re
import os
# Fix missing streams
for stream in ("stdout", "stderr", "stdin"):
if getattr(sys, stream) is None:
setattr(sys, stream, open(os.devnull, "w+"))
@Willy-JL
Willy-JL / colored_console.py
Last active July 2, 2021 21:56
Colored console output with primer for windows' cmd
# Color escape code using rgb values (0-255)
def rgb(r, g, b):
return f'\x1b[38;2;{r};{g};{b}m'
# Primer for windows' cmd to enable color escape codes
import sys
if sys.platform == 'win32':
from ctypes import windll, c_int, byref, c_void_p
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
INVALID_HANDLE_VALUE = c_void_p(-1).value
@Willy-JL
Willy-JL / events.py
Created July 17, 2021 16:12
Event-Callback system using decorators
from collections import defaultdict
import functools
events_callbacks = defaultdict(list)
def callback(event_id: str):
def decorator_callback(func):
functools.wraps(func)
events_callbacks[event_id].append(func)
🌞 Morning 84 commits █▉░░░░░░░░░░░░░░░░░░░ 9.1%
🌆 Daytime 180 commits ████░░░░░░░░░░░░░░░░░ 19.5%
🌃 Evening 374 commits ████████▍░░░░░░░░░░░░ 40.4%
🌙 Night 287 commits ██████▌░░░░░░░░░░░░░░ 31.0%
⭐ Total Stars 288
✅ Total Commits 46.1k
🔀 Total PRs 130
🚩 Total Issues 47
📦 Contributed to 29
C +3.9k -2.1k ████████████████▍░░░░ 78.5%
CSV +272 -274 █▌░░░░░░░░░░░░░░░░░░░ 7.5%
Markdown +249 -78 █▎░░░░░░░░░░░░░░░░░░░ 6.5%
YAML +164 -23 ▉░░░░░░░░░░░░░░░░░░░░ 4.3%
Python +86 -30 ▍░░░░░░░░░░░░░░░░░░░░ 2.1%
Shell +53 -0 ░░░░░░░░░░░░░░░░░░░░░ 0.5%
Diff +16 -18 ░░░░░░░░░░░░░░░░░░░░░ 0.5%
CMake +8 -8 ░░░░░░░░░░░░░░░░░░░░░ 0.2%
TOML +4 -0 ░░░░░░░░░░░░░░░░░░░░░ 0.1%
JSON +1 -1 ░░░░░░░░░░░░░░░░░░░░░ 0.0%