Skip to content

Instantly share code, notes, and snippets.

View juancarlospaco's full-sized avatar
👑
https://t.me/NimArgentina

Juan Carlos juancarlospaco

👑
https://t.me/NimArgentina
View GitHub Profile
@juancarlospaco
juancarlospaco / setup.py
Last active June 5, 2024 22:21
setup.py Template, Generic but Complete, with instructions to Release to PyPI, DEB, RPM, PKGBUILD, EXE, EGG, ZIP, PYZ, and more.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#
# To generate DEB package from Python Package:
# sudo pip3 install stdeb
# python3 setup.py --verbose --command-packages=stdeb.command bdist_deb
#
#
# To generate RPM package from Python Package:
@juancarlospaco
juancarlospaco / check_working_folder.py
Last active January 10, 2022 01:07
Check working folder, for all possible things that can go wrong.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, os
import logging as log
try:
from shutil import disk_usage
@juancarlospaco
juancarlospaco / post_exec_message.py
Last active April 6, 2018 19:37
Simple Post-Execution Message for Apps, print used Resources and Running Time (A.K.A. Uptime)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, os
import logging as log
from datetime import datetime
try:
@juancarlospaco
juancarlospaco / logging_logger.py
Last active April 6, 2018 19:26
Logging Logger for Logs, the best in the world!, Colored, SysLog, Log File, CrossPlatform, Optional Arguments, and more...
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, os
import logging as log
from copy import copy
from tempfile import gettempdir
@juancarlospaco
juancarlospaco / encoding_debug_no_root.py
Last active April 6, 2018 19:32
Debug Encoding and Check for root.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, os
import logging as log
from getpass import getuser
from platform import platform, python_version
@juancarlospaco
juancarlospaco / static_typing_python3.py
Last active May 22, 2023 17:19
Python3 Annotations as Static Typing, checks code blocks inputs and outputs enforcing Types via Decorator (change "log.critical" to "log.exception" to Force Fail).
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import functools
import logging as log
def typecheck(f):
"""Decorator for Python3 annotations to type-check inputs and outputs."""
@juancarlospaco
juancarlospaco / sound_play_crossplatform.py
Last active June 28, 2021 20:59
Cross-platform Sound Playing with Standard Libs only, No Sound file is required, No install is required, Python2 / Python3.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os, sys
from tempfile import gettempdir
from subprocess import call
def beep(waveform=(79, 45, 32, 50, 99, 113, 126, 127)):
@juancarlospaco
juancarlospaco / smooth_cpu_process_name.py
Last active April 6, 2018 19:37
Set Smooth CPUs Priority and set Process Name. Linux only.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import logging as log
from ctypes import byref, cdll, create_string_buffer
def set_process_name_and_cpu_priority(name):
@juancarlospaco
juancarlospaco / single_instance_no_root.py
Last active April 6, 2018 19:25
Single Instance App Singleton.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, os, socket
import logging as log
def set_single_instance(name, single_instance=True, port=8888):
"""Set process name and cpu priority, return socket.socket object or None.
@juancarlospaco
juancarlospaco / traceback_human.py
Last active May 22, 2021 23:53
Tracebacks friendly pretty printed with more info, good to copy-paste on bug reports.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, traceback
import logging as log
def log_exception():
"""Log Exceptions but pretty printing with more info, return string."""