Skip to content

Instantly share code, notes, and snippets.

View liviaerxin's full-sized avatar

Frank liviaerxin

  • ASTRI
  • Hong Kong
View GitHub Profile
@liviaerxin
liviaerxin / server_whoami.py
Last active January 26, 2024 07:01
A simple whoami server to analyze incoming HTTP requests
"""A simple whoami server to analyze incoming HTTP requests
# For simplicity, we don't do:
# 1. Detect End of HTTP Request either by double CRLF(`\r\n\r\n`) or `Content-Length`.
# 2. Parse the HTTP request message.
# Instead, we just do:
# 1. Read max size of `GET` and `POST` requests data is 4096 bytes.
# 2. Close the connection for each request.
"""
@liviaerxin
liviaerxin / python-unicode.md
Last active December 19, 2023 08:31
Dive into Python Unicode Object

authors:

  • frank tags:
  • Python
  • Unicode
  • ctypes description: Python Unicode keywords:
  • Python Unicode
‎‎​
@liviaerxin
liviaerxin / Dicom3dCube.py
Last active May 10, 2023 08:05
DICOM Files Read, 3D Reconstruction and Visualization. #vtk-dicom
"""
DICOM files --> vtk array --> vtk 3D visualization
1. read a series of DICOM files by vtkDICOMImageReader(which will do HU and don't resample)
2. process vtk 3D array with marching cubes algorithm
3. render vtk 3D array
"""
import vtk
from utils import CreateTissue
@liviaerxin
liviaerxin / main.py
Created March 31, 2023 08:44
Serving long-running/heavy-computation task via FastAPI and concurrent.futures.ProcessPoolExecutor #python #fastapi #ml
"""
Serving long-running/heavy-computation task via FastAPI and concurrent.futures.ProcessPoolExecutor
usage:
```sh
uvicorn main:app --reload
```
"""
from fastapi import FastAPI
@liviaerxin
liviaerxin / main.py
Created March 31, 2023 08:21
Serving long-running/heavy-computation task via FastAPI and multiprocessing.Process #python #fastapi #ml
"""
Serving long-running/heavy-computation task via FastAPI and multiprocessing.Process
usage:
```sh
uvicorn main:app --reload
```
"""
from fastapi import FastAPI
@liviaerxin
liviaerxin / ffmpeg_samples.md
Last active November 16, 2023 22:49
FFmpeg samples #ffmpeg

FFmpeg Samples

FFmpeg Wiki

List private options of the codec

# Show available `presets`
ffmpeg -h encoder=h264_nvenc
@liviaerxin
liviaerxin / multiple_process_queue.py
Created March 8, 2023 08:37
Measure Multiple Process/Thread Queue #python
from multiprocessing import Queue
from multiprocessing import Process
import time
import os
import numpy as np
def put_into_queue(q: Queue):
print(f"PID[{os.getpid()}] put_into_queue")
@liviaerxin
liviaerxin / README.md
Last active April 25, 2024 20:50
FastAPI and Uvicorn Logging #python #fastapi #uvicorn #logging

FastAPI and Uvicorn Logging

When running FastAPI app, all the logs in console are from Uvicorn and they do not have timestamp and other useful information. As Uvicorn applies python logging module, we can override Uvicorn logging formatter by applying a new logging configuration.

Meanwhile, it's able to unify the your endpoints logging with the Uvicorn logging by configuring all of them in the config file log_conf.yaml.

Before overriding:

uvicorn main:app --reload