This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def int_to_roman(integer_argument): | |
"""Convert an integer to Roman numerals. | |
>>> int_to_roman(0) | |
Traceback (most recent call last): | |
ValueError: Argument must be between 1 and 3999 | |
>>> int_to_roman(-1) | |
Traceback (most recent call last): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import sys | |
import logging as log | |
from copy import copy | |
if not sys.platform.startswith("win") and sys.stderr.isatty(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progressbar = lambda i: sys.stdout.write("[{}] {}%\r".format( | |
'#' * (70 * i // 100) + '.' * (70 - 70 * i // 100), 100 * i // 100)[:80]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def seconds_time_to_human_string(self, time_on_seconds=0): | |
"""Calculate time, with precision from seconds to days.""" | |
minutes, seconds = divmod(int(time_on_seconds), 60) | |
hours, minutes = divmod(minutes, 60) | |
days, hours = divmod(hours, 24) | |
human_time_string = "" | |
if days: | |
human_time_string += "%02d Days " % days | |
if hours: | |
human_time_string += "%02d Hours " % hours |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# resource is Linux/OsX only | |
import sys | |
import resource | |
# Gives result on Integer, MegaBytes on Linux/OsX, or 0 on Windows since info is not available. | |
int(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * resource.getpagesize() / 1024 / 1024 | |
if not sys.platform.startswith("win") else 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import __future__, sys | |
[name for name in __future__.all_feature_names if getattr(__future__, name).optional <= sys.version_info < getattr(__future__, name).mandatory] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)): |
OlderNewer