Skip to content

Instantly share code, notes, and snippets.

View WillyJL's full-sized avatar
πŸ—Ώ

WillyJL WillyJL

πŸ—Ώ
View GitHub Profile
@WillyJL
WillyJL / 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)
@WillyJL
WillyJL / 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()
@WillyJL
WillyJL / 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
@WillyJL
WillyJL / 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)
@WillyJL
WillyJL / 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+"))
@WillyJL
WillyJL / 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
@WillyJL
WillyJL / 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 287 commits β–ˆβ–ˆβ–ˆβ–ˆβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 19.7%
πŸŒ† Daytime 386 commits β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 26.5%
πŸŒƒ Evening 422 commits β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 29.0%
πŸŒ™ Night 361 commits β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 24.8%
⭐ Total Stars 568
βœ… Total Commits 78.2k
πŸ”€ Total PRs 275
🚩 Total Issues 64
πŸ“¦ Contributed to 48
C +19.2k -3.8k β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œβ–‘ 93.1%
Python +413 -222 β–‹β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 3.1%
TypeScript +305 -20 β–Žβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 1.2%
Markdown +78 -21 ▏░░░░░░░░░░░░░░░░░░░░ 0.8%
JavaScript +117 -18 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0.6%
CSV +58 -19 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0.6%
C++ +115 -47 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0.6%
YAML +3 -3 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0.1%
Linker Sc… +7 -0 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0.0%
JSON +5 -4 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 0.0%