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 / README.md
Last active May 2, 2024 00:04
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
@liviaerxin
liviaerxin / gstreamer_empty_plugin_test_case.py
Last active February 14, 2024 19:48
Install Gst Python Binding
#!/usr/bin/python3
#-*- coding: utf-8 -*-
import logging
import timeit
import traceback
import time
import gi
gi.require_version('Gst', '1.0')
@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 / build_opencv_in_mac.md
Last active December 11, 2023 14:50
Build OpenCV and Python Bindings in Mac(QT, Gstreamer Support)

Build OpenCV in Mac with QT, Gstreamer Support

Install dependencies

brew install cmake #
brew install qt5 #optional
brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav #optional
pip3 install numpy
@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 / ssh.md
Created March 8, 2023 06:46
SSH Login Setup #ssh

SSH Login Setup

  1. Generate ssh key
# Generate ssh key with files(~/.ssh/id_rsa, ~/.ssh/id_rsa/pub) and username in default
ssh-keygen -t rsa

# Generate ssh key with specified files and username
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
@liviaerxin
liviaerxin / check_is_translated.md
Last active June 16, 2023 11:46
Determine Universal App Is Running as a Native or Translated Binary #apple-silicon

Check Universal App Is Running as Native or Translated Binrary

On Apple silicon, arm app is running as native binary and x86_64 app is translated by Rosseta before executing.

Make Test Demo

❯ clang -o arm_proc_translated proc_translated.c -target arm64-apple-macos11
❯ clang -o x86_64_proc_translated proc_translated.c -target x86_64-apple-macos11
❯ lipo -create -output universal_proc_translated x86_64_proc_translated arm_proc_translated
@liviaerxin
liviaerxin / .zshrc
Last active June 8, 2023 15:08
Development Tools Setup in Apple Silicon #apple-silicon
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH