Skip to content

Instantly share code, notes, and snippets.

View ming900518's full-sized avatar

Ming Chang ming900518

View GitHub Profile
@ming900518
ming900518 / static-file-axum-vs-express.md
Last active February 27, 2023 07:21
Rust Axum 與 TypeScript Express 靜態檔案性能比較

Rust Axum 與 TypeScript Express 靜態檔案性能比較

使用 67.2 MB 的 APK 檔案作為測試目標

程式均運行在 M1 MacBook Air 上,Node 和 Rust 編譯出來的成品均為 ARM64 Binary

存取 API 時讀取文件

Axum (Rust)

Code

let apple_jwks = match reqwest::get("https://appleid.apple.com/auth/keys").await {
    Ok(response) => match response.text().await {
        Ok(text) => text,
        Err(_) => {
            return Err(err_json_gen(
                StatusCode::INTERNAL_SERVER_ERROR,
                Some("Could not parse response from Apple.".to_owned()),
            ))
        }
const fileExisted = await Result.safe(fsPromises.stat(targetDir));
if (fileExisted.isOk()) {
    fs.rmSync(targetDir, { recursive: true });
}

const mkdir = await Result.safe(
    fsPromises.mkdir(targetDir, { recursive: true }),
);
if (mkdir.isErr()) {
@ming900518
ming900518 / sign-in-with-apple-let-else.md
Last active March 8, 2023 12:37
Sign in with Apple JWT Validation and Decode, with different pattern matching method.
#[derive(Deserialize)]
pub struct SignInWithAppleJwtClaims {
    sub: String,
    email: String,
}

impl SignInWithAppleJwtClaims {
    pub async fn validate_and_decode(jwt: String) -> Result<Self, (StatusCode, Json<Value>)> {
        let Ok(response) = reqwest::get("https://appleid.apple.com/auth/keys").await else {
@ming900518
ming900518 / rust-static-file-serving-perf-test.md
Last active March 15, 2023 07:39
Rust Static File Serving Performance Test

Rust Static File Serving Performance Test

測試參數

項目 設定
CPU 12th Gen Intel(R) Core(TM) i7-12700
Rust rustc 1.68.0 (2c8cc3432 2023-03-06) stable-x86_64-unknown-linux-gnu
檔案大小 100 MiB
測試指令 hey -z 30s -c 100 http://localhost:1370/sendfile/testfile
@ming900518
ming900518 / perf-result-express.md
Last active March 24, 2023 07:10
API performance benchmark with express proxied result
ezcon@ez500:~/ezmonitor$ hey -z 30s -c 100 http://localhost:1234/api/get

Summary:
  Total:	30.1203 secs
  Slowest:	0.2984 secs
  Fastest:	0.0801 secs
  Average:	0.1514 secs
  Requests/sec:	659.1560
  
@ming900518
ming900518 / node-sqlite3.md
Created May 8, 2023 02:18
node-sqlite3 v.s. rusty-sqlite3
Summary:                                                                                                                                                                              
  Total:        30.0199 secs                                                                                                                                                          
  Slowest:      0.0995 secs                                                                                                                                                           
  Fastest:      0.0212 secs                                                                                                                                                           
  Average:      0.0551 secs                                                                                                                                                           
  Requests/sec: 1813.5947                                                                                
@ming900518
ming900518 / commands.md
Last active May 17, 2023 01:38
解決 Arch Linux ARM 執行 yay -Syu 後 Fcitx5 Rime 無法使用的問題

解決 Arch Linux ARM 執行 yay -Syu 後 Fcitx5 Rime 無法使用的問題

yay -S capnproto
cd /usr/lib
sudo ln -s libcapnpc.so.0.10.4 libcapnpc.so.0.10.3
@ming900518
ming900518 / rust_arm_cross_compile_to_x86.md
Created May 19, 2023 05:48
在 Asahi Linux(Arch Linux ARM) 中編譯 target 為 x86_64-unknown-linux-gnu 的 Rust 程式

在 Asahi Linux(Arch Linux ARM) 中編譯 target 為 x86_64-unknown-linux-gnu 的 Rust 程式

Arch Linux ARM 似乎沒有可用的 x86_64-linux-gnu-gcc

所以我額外用 Docker 模擬出 Debian 環境,並透過 Debian 的 gcc-x86-64-linux-gnu 套件進行編譯

環境準備

  1. 用 Docker 開啓執行 Debian 的 Container
@ming900518
ming900518 / LeetCode 86 - Partition List.md
Last active June 28, 2023 02:47
LeetCode 86 - Partition List

LeetCode 86 - Partition List

Rust Implementation

ListNode struct and the main function for the Rust Playground

#[derive(Debug)]
pub struct ListNode {
    pub val: i32,
    pub next: Option<Box<ListNode>>,
}