Skip to content

Instantly share code, notes, and snippets.

View hikaru-y's full-sized avatar

Hikaru Y. hikaru-y

View GitHub Profile
@hikaru-y
hikaru-y / __init__.py
Last active February 15, 2025 23:47
A small Anki add-on that enables indentation with the Tab key and outdentation with Shift+Tab in the editor.
from aqt import gui_hooks, mw
from aqt.editor import Editor
from aqt.webview import WebContent
def on_webview_will_set_content(web_content: WebContent, context: object) -> None:
if isinstance(context, Editor):
web_content.js.append(f"/_addons/{__name__.split('.')[0]}/indent_with_tab.js")
User
pythonで有限状態マシーンを実装しようと思っています。コルーチン(Generator)を使って実装することは可能でしょうか?
ChatGPT
はい、Pythonで有限状態マシンを実装するためにコルーチン(Generator)を使用することは可能です。コルーチンは、状態と状態遷移を効果的に表現し、シンプルな構造で状態遷移を制御するのに役立ちます。以下に、コルーチンを使用して有限状態マシンを実装する基本的な例を示します。
python
Copy code
def state_machine():
state = "start"