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 time | |
import select | |
import socket | |
class AsyncSleep: | |
"""Event and action to sleep ``until`` a point in time""" | |
def __init__(self, until): | |
self.until = until |
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
def switch(on): | |
def switch_decorator(cls): | |
for try_case in cls.__dict__.values(): | |
try: | |
switch_case = try_case.__switch_case__ | |
except AttributeError: | |
pass | |
else: | |
print(switch_case, '?') | |
if on == switch_case: |
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 multiprocessing | |
import time | |
import sys | |
process_identifier = 'main' | |
class Collectible: | |
def __init__(self, identifier): | |
self.identifier = identifier |
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 os | |
import sys | |
import time | |
import multiprocessing | |
def print_pid(*args, **kwargs): | |
print('[%s]' % os.getpid(), *args, **kwargs) | |
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 | |
from __future__ import print_function | |
import random | |
import math | |
import sys | |
import argparse | |
#: alphabet of 2**6 letters | |
ALPHABET_64 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+=" |
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
from itertools import product, islice | |
import argparse | |
import math | |
import string | |
import psutil | |
import keyword | |
CLI = argparse.ArgumentParser('Test memory consumption of instances') | |
CLI.add_argument( |
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
""" | |
This is a toy example for implementing private fields via decorators | |
Provides a base type ``Class`` and decorator ``trusted`` to handle | |
private/public data fields. Classes that derive from ``Class`` can own | |
private data, and methods marked as ``trusted`` can access it. | |
Every ``trusted`` method receives a privileged ``self`` that operates on | |
private data; public data is accessible as ``self.__public__``. Regular | |
methods and all external clients only operate on the public data. |
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
from multiprocessing.queues import Queue | |
from multiprocessing import get_context, Process, cpu_count | |
import os | |
class IterableQueue(Queue): | |
""" | |
``multiprocessing.Queue`` that can be iterated to ``get`` values | |
:param sentinel: signal that no more items will be received |
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
r""" | |
Another class-based implementation of a ``switch`` type | |
Toy example for building types that emulate ``switch``-statements. | |
Supports type-based matching, and can be extended to destructuring/pattern | |
matching and value-based matching. | |
``switch``-types must derive from the ``Switch`` class. Each match case | |
is a method ``def case(self, name: pattern [, name: pattern [, ...]]):``. | |
Cases are seemingly evaluated in-order, without guarantee on side-effects. |
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/python | |
""" | |
Copy a gridmapdir to a new location, preserving its mappings | |
This script clones a gridmapdir, taking into account relative hardlinks. | |
This allows copying a gridmapdir to a different device, without losing mappings | |
from identities to accounts. | |
.. code:: bash |