This file contains hidden or 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 ast | |
def dbg_astdump(node, annotate_fields=True, include_attributes=False, indent=' '): | |
""" | |
AST Pretty Printer | |
Code copied and slightly modified from: | |
http://alexleone.blogspot.com/2010/01/python-ast-pretty-printer.html | |
""" | |
def _format(node, level=0): | |
if isinstance(node, ast.AST): |
This file contains hidden or 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 | |
# | |
# pydump | |
# A Python3 pretty-printer that also does introspection to detect the original | |
# name of the passed variables | |
# | |
# Jean-Charles Lefebvre <[email protected]> | |
# Latest version at: http://gist.github.com/polyvertex (pydump) | |
import sys |
This file contains hidden or 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
class Unbuffered: | |
""" | |
Unbuffered stream emulation | |
Usage: sys.stdout = Unbuffered(sys.stdout) | |
""" | |
def __init__(self, stream): | |
self.stream = stream | |
def write(self, data): | |
self.stream.write(data) | |
self.stream.flush() |
This file contains hidden or 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
class ReMatch(): | |
""" | |
Small class to re.match() and to hold its result. | |
Convenient if you want to "if re.match(): ... elif re.match(): ..." | |
Usage: | |
rem = ReMatch() | |
if rem.match(...): | |
print(rem.group(1, "default value here")) | |
elif rem.match(...): | |
... |
This file contains hidden or 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
"""" | |
The orignal author: Alexer / #python.fi | |
""" | |
import opcode | |
import dis | |
import sys | |
import multiprocessing |
This file contains hidden or 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 ctypes as ct | |
from ctypes.wintypes import * | |
import uuid | |
def has_func(ctypes_dll, func_name): | |
if hasattr(ctypes_dll, func_name): | |
return func_name | |
if not func_name.endswith("W") and hasattr(ctypes_dll, func_name + "W"): | |
return func_name + "W" | |
return None |
This file contains hidden or 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
template <typename T> | |
struct super_decay | |
{ | |
typedef | |
typename std::remove_cv< | |
typename std::remove_pointer< | |
typename std::remove_reference< | |
typename std::remove_extent< | |
typename std::decay<T>::type>::type>::type>::type>::type type; | |
}; |
This file contains hidden or 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
// char_type_of: deduce the char type of virtually any literal or | |
// container (C++11 SFINAE at its finest) | |
// Original author: Jean-Charles Lefebvre <[email protected]> | |
// util: an almighty version of std::decay<>, with super powers | |
template <typename T> | |
struct super_decay | |
{ | |
typedef | |
typename std::remove_cv< |
This file contains hidden or 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 datetime | |
import string | |
def name_file(dt): | |
""" | |
Return a name according to the given `datetime.datetime` object. | |
This is how Garmin devices seem to name their activity files, as explained | |
`here <https://forums.garmin.com/forum/into-sports/running/forerunner-220-aa/53766->`_. |
OlderNewer