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 usim import Pipe, instant | |
from usim._primitives.notification import Notification | |
class MonitoredPipe(Pipe): | |
def __init__(self, throughput: float): | |
super().__init__(throughput) | |
self._monitor = Notification() | |
async def load(self): |
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 accumulate | |
a = ['a', '30', '-', 'foot', 'und', 'ete', 'cted'] | |
b = ['a', '30-foot', 'undetected'] | |
def alignment(a: "Iterable[str]", b: "Iterable[str]") -> "List[List[int]]": | |
if ''.join(a) != ''.join(b): | |
raise ValueError("a and b must be fragments of the same string") | |
target_subs = accumulate(b) |
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 threading, random | |
class StackContext: | |
def __init__(self): | |
self._state = threading.local() | |
self._state.stack = [] | |
def __enter__(self): | |
this_context = random.random() |
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 |
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
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
""" | |
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 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
#!/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
import os | |
import sys | |
import time | |
import multiprocessing | |
def print_pid(*args, **kwargs): | |
print('[%s]' % os.getpid(), *args, **kwargs) | |