Skip to content

Instantly share code, notes, and snippets.

@jrfk
jrfk / websocket_by_rust---Cargo.toml
Last active November 7, 2023 01:58
websocket_by_rust/main.rs
[dependencies]
tokio = { version = "1", features = ["full"] }
warp = "0.3"
tokio-tungstenite = "0.15"
@jrfk
jrfk / await_single_task_exceptions.py
Last active September 2, 2023 07:25
Trying cancellation on a single task.
"""
Trying cancellation on a single task.
This code snippet was created in response to a question about task cancellation
during the PyConTW 2023 talk.
$ python await_single_task_exceptions.py
"""
import asyncio
@jrfk
jrfk / minimum_webserver_for_micropython.py
Last active July 19, 2023 12:56
minimum_webserver_for_micropython
"""micropython webserver
$ micropython minimum_webserver_for_micropython.py
docker image: micropython/unix:latest
micropython uasyncio document (ja)
https://micropython-docs-ja.readthedocs.io/ja/latest/library/uasyncio.html
"""
import uasyncio as asyncio
@jrfk
jrfk / cpu_stats_by_asyncio.py
Last active May 28, 2023 13:45
cpu_stats_by_async
"""This code is for monitoring CPU usage. It performs 3 minutes of polling and 3 minutes of monitoring.
During the 3 minutes of polling, it acquires CPU usage every second and adds it to a list.
During the 3 minutes of monitoring, it acquires CPU usage every second and adds it to a list.
Finally, it calculates and displays the average value and median value.
$ pip install statistics psutil
$ python cpu_stats_by_asyncio.py
Average CPU usage: 9.531666666666666%
Median CPU usage: 7.75%
"""
@jrfk
jrfk / interactive_exception_handling.py
Created May 25, 2023 04:34
interactive_exception_handling
"""
Description:
This script enhances the Python interactive console (REPL) by introducing
a custom exception handling mechanism. It leverages the built-in InteractiveConsole
and InteractiveInterpreter classes and overrides the 'showtraceback' method
for personalized exception handling. This enables more flexible control over
how exceptions are dealt with in the console, and can be particularly useful for
debugging or for enhancing console output in specific applications.
"""
import sys