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 sys, hashlib; from pathlib import Path; print(f'{sys.argv[1]}: {hashlib.md5(Path(sys.argv[1]).read_bytes()).hexdigest()}') |
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
| async def async_partial(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Callable[..., Any]: | |
| """ | |
| Partially apply the given `args` and `kwargs` to the given asynchronous function `func`. | |
| Parameters | |
| ---------- | |
| func : callable | |
| The asynchronous function to partially apply the arguments to | |
| args : Any | |
| The positional arguments to apply |
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 __future__ import annotations | |
| from functools import wraps | |
| from typing import overload | |
| def func_decorator(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| print(f"func_decorator: Calling {func.__name__} with args: {args}, kwargs: {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
| from __future__ import annotations | |
| from typing import Dict, TypeVar, Callable | |
| _K = TypeVar("_K") | |
| _V = TypeVar("_V") | |
| _KV = TypeVar("_KV") | |
| def invert_dict(d: Dict[_K, _V], *, value_to_key: Callable[[_V], _KV] = lambda v: v) -> Dict[_V, _KV]: |
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
| #include <algorithm> | |
| #include <functional> | |
| /** | |
| * @brief Filters the given container @a cont using the given predicate @a pred | |
| * such that only elements that satisfy the predicate remain in the container. The | |
| * container is modified in place. | |
| * | |
| * @tparam Cont The container type | |
| * @param cont The container to filter |
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 sys | |
| if sys.version_info.minor == 7: | |
| import importlib_metadata as metadata | |
| else: | |
| from importlib import metadata | |
| __version__ = metadata.version(__name__) |
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
| #!/bin/bash | |
| # | |
| # My bash script template | |
| # | |
| # inspired by the best practises found at | |
| # https://sharats.me/posts/shell-script-best-practices/ and | |
| # https://bertvv.github.io/cheat-sheets/Bash.html | |
| here="${0%/*}" | |
| self="${0##*/}" |
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 __future__ import annotations | |
| import asyncio | |
| from typing import Coroutine, Set | |
| class AsyncioRunner: | |
| """ | |
| This class can be used to run coroutines in an asyncio event loop without having to `await` them. |
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
| function(from_hex HEX DEC) | |
| string(SUBSTRING "${HEX}" 2 -1 HEX) | |
| string(TOUPPER "${HEX}" HEX) | |
| set(_res 0) | |
| string(LENGTH "${HEX}" _strlen) | |
| while(_strlen GREATER 0) | |
| math(EXPR _res "${_res} * 16") | |
| string(SUBSTRING "${HEX}" 0 1 NIBBLE) | |
| string(SUBSTRING "${HEX}" 1 -1 HEX) |
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> | |
| class QObjectWrapper : public T, public QObject | |
| { | |
| Q_OBJECT | |
| public: | |
| explicit QObjectWrapper(QObject* parent = nullptr) : T{}, QObject{parent} {} | |
| }; |
NewerOlder