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
| # pip install fastapi, python-extracontext | |
| from fastapi import FastAPI, Request | |
| from extracontext import ContextLocal | |
| app = FastAPI() | |
| ctx = ContextLocal() | |
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 tkinter, fastapi | |
| import requests | |
| port = 8003 | |
| localurl = f"http://localhost:{port}/" | |
| def uimain(): | |
| def doit(): | |
| endpoint = "transform/" |
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 makes use of sys.monitoring, described in PEP 669 and implemented in Python 3.12 | |
| import time | |
| import sys | |
| def aha(*args): | |
| print(args) | |
| def worker(): | |
| while True: |
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 enum import StrEnum | |
| class OrableStrEnum(StrEnum): | |
| """neat hack: Members can be combined with the `|` operator | |
| That will result in a set - and then the `in` operator | |
| is made to work with a single member as wll, so that | |
| `if CAN_REVIEW in permissions:` will work whether permissions content is | |
| permissions = CAN_REVIEW |
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 asynchronous version is really naive: | |
| it will block the asyncio loop while walkign the file tree - TWICE - | |
| and then, the defautl call will print the progress to the terminal | |
| pass a callback as "progress" parameter which takes a dictionary | |
| describing the current progress as its sole parameter: | |
| the callback will be called for each file copied during execution. |
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
| # Usually an exception can be raised with the `raise` statement | |
| # | |
| # however, occasionally it can be useful to be able to do so as part | |
| # of an expression (even if the occasion is code golphing). | |
| # A workaround for that is achievable through a generator's | |
| # `.throw` method: | |
| (_ for _ in ()).throw(Exception()) |
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
| # here, the function that can work "either way" is the nested "payload". | |
| # The external ^morphix_in_thread" can be a decorator, and "payload" the decorated function | |
| def morphix_in_thread(): | |
| try: | |
| loop = asyncio.get_running_loop() | |
| except RuntimeError: | |
| loop = None | |
| def payload(): |
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
| [build-system] | |
| requires = ["setuptools", "wheel"] | |
| build-backend = "setuptools.build_meta" | |
| [project] | |
| name = "mypackage" | |
| version = "1.0" | |
| [tool.setuptools] | |
| packages = ["mypackage"] |
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 not a script - more like a curated command sequence from my history | |
| # after succesfully installing mypaint. | |
| export $PREFIX=/home/<user>/mypaint-git | |
| sudo dnf install swig # fedora/redhat specific. One also will need Python3-dev and other Linux packages | |
| git clone https://github.com/mypaint/mypaint.git | |
| cd mypaint | |
| ~/.pyenv/versions/3.11.4/bin/python -m venv env311 # or use other cPython interpreter of preference |
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
| #original code written as an answer to https://stackoverflow.com/questions/75915644/call-decorator-only-once-in-a-nested-class-function/75915738#75915738 | |
| from functools import wraps | |
| from threading import RLock | |
| import contextvars | |
| RUNONCE = contextvars.ContextVar("RUNONCE", default=None) | |
| class RunOnceDecorator: |
NewerOlder