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
from collections.abc import Iterable, Iterator | |
from typing import TypeVar | |
T = TypeVar('T') | |
def _scan(items: Iterable[T]) -> Iterator[tuple[T, T]]: | |
"""iterator to traverse previous and current items from iterable""" | |
prev, curr, stream = None, None, iter(items) |
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
from collections.abc import Iterator | |
from dataclasses import dataclass, field | |
from typing import Generic, Optional, TypeVar | |
T = TypeVar('T') | |
V = TypeVar('V') | |
@dataclass | |
class CapturedIteration(Generic[T, V]): |
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 | |
import os | |
import re | |
import subprocess | |
from argparse import ArgumentParser, Namespace | |
from dataclasses import dataclass, field | |
def build_parser() -> ArgumentParser: |
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
function pipe(data, fn) { | |
if (typeof data === 'object' && data != null) { | |
return Object.fromEntries( | |
Object.keys(data).map(key => [key, fn(key, data[key])]) | |
); | |
} | |
} | |
const example = { | |
hello: 1, |
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 functools | |
import time | |
class timeit: | |
"""decorator for benchmarking""" | |
def __init__(self, fmt='completed {:s} in {:.3f} seconds'): | |
# there is no need to make a class for a decorator if there are no parameters | |
self.fmt = fmt | |
def __call__(self, fn): |
NewerOlder