Skip to main content

· 3 min read

研究了一下文件, 沒看到能剛好 fit 手邊需求的用法@@...

以官方文件的示範為例,建立一個 Enum:

class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3


print(Color._member_map_)
# {'RED': <Color.RED: 1>, 'GREEN': <Color.GREEN: 2>, 'BLUE': <Color.BLUE: 3>}

如果想要增加一個 ClassVar _favorite 紀錄某些 member, 例如:

class Color2(Enum):
RED = 1
GREEN = 2
BLUE = 3
_favorite = {RED, BLUE}


print(Color2._member_map_)
# {'RED': <Color2.RED: 1>, 'GREEN': <Color2.GREEN: 2>, 'BLUE': <Color2.BLUE: 3>, '_favorite': <Color2._favorite: {1, 3}>}

但是 _favorite 會被當做 enum member ...

· 2 min read

image

git worktree

worktree 指令可以將內容複製一份出來至指定位置,當需要同時處理多個 branch 的時候很方便,可以避免頻繁 switch branch 。

Documentation: https://git-scm.com/docs/git-worktree

Example

gwt alias 參考: ohmyzsh git alias

使用 worktree

# 列出 worktree
gwtls
# {REPO} 3dd0c75 [master]

# 建立 worktree
gwta -b my_wtb ./my_wt # or `-B` to reset
# Preparing worktree (new branch 'my_wtb')
# HEAD is now at 3dd0c75 {MSG}

gwtls
# {REPO} 3dd0c75 [master]
# {REPO}/my_wt 3dd0c75 [my_wtb]
ls
# my_wt
ls .git/worktrees
# my_wt

切換目錄後就會發現 branch 會自動變換

gb --show-current
# master

cd ./my_wt
gb --show-current
# my_wtb

清除 worktree

# 移除 worktree
gwtrm ./my_wt
gwtls
# {REPO} 3dd0c75 [master]

# branch 還在
gb -v | \cat
# * master 3dd0c75 {MSG}
# my_wtb 3dd0c75 {MSG}

gb -d my_wtb # or `-D` if not merged
# Deleted branch my_wtb (was 3dd0c75).

Note

git worktree prune -v

· One min read
fc -l

列出使用過的歷史指令,接近 history,沒有 timestamp,數量少。

· 15 min read

Chapter 15. Parallel Query

  1. 為了更快回應查詢 PostgreSQL 設計的 query plan 可利用多個 CPU
  2. 很多查詢沒辦法受益於 parallel query 因為現在實作的限制,或是沒能找到比 serial 更快的 query plan
  3. 通常受益最多的查詢回傳少數 row ,但觸及大量資料

· 2 min read

signals

ctrl+c: 2(SIGINT)
ctrl+\: 3(SIGQUIT)
ctrl+z: 19(SIGCONT) / 18(SIGTSTP)
ctrl+t: 29(SIGINFO)

man signal

      Name             Default Action       Description
1 SIGHUP terminate process terminal line hangup
2 SIGINT terminate process interrupt program
3 SIGQUIT create core image quit program
4 SIGILL create core image illegal instruction
5 SIGTRAP create core image trace trap
6 SIGABRT create core image abort program (formerly SIGIOT)
7 SIGEMT create core image emulate instruction executed
8 SIGFPE create core image floating-point exception
9 SIGKILL terminate process kill program
10 SIGBUS create core image bus error
11 SIGSEGV create core image segmentation violation
12 SIGSYS create core image non-existent system call invoked
13 SIGPIPE terminate process write on a pipe with no reader
14 SIGALRM terminate process real-time timer expired
15 SIGTERM terminate process software termination signal
16 SIGURG discard signal urgent condition present on socket
17 SIGSTOP stop process stop (cannot be caught or ignored)
18 SIGTSTP stop process stop signal generated from keyboard
19 SIGCONT discard signal continue after stop
20 SIGCHLD discard signal child status has changed
21 SIGTTIN stop process background read attempted from control terminal
22 SIGTTOU stop process background write attempted to control terminal
23 SIGIO discard signal I/O is possible on a descriptor (see fcntl(2))
24 SIGXCPU terminate process cpu time limit exceeded (see setrlimit(2))
25 SIGXFSZ terminate process file size limit exceeded (see setrlimit(2))
26 SIGVTALRM terminate process virtual time alarm (see setitimer(2))
27 SIGPROF terminate process profiling timer alarm (see setitimer(2))
28 SIGWINCH discard signal Window size change
29 SIGINFO discard signal status request from keyboard
30 SIGUSR1 terminate process User defined signal 1
31 SIGUSR2 terminate process User defined signal 2

https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html

· 5 min read
m9H8

SHA-1 是一種 SHA (Secure Hash Algorithm),SHA 是被美國聯邦政府所訂製的標準認證過的 Hash function,目前常被使用的有 SHA-1,像是 git 產生 commit 編號就是,檢查檔案是否完整或被竄改除了使用 md5 也常用 SHA-1,但目前有發現破解方式已經不夠安全。因此傳送機密資料已漸漸不使用 SHA-1 ,通常會選擇 SHA-2 系列,常見的像是比特幣也使用的 SHA-256 (SHA-2 的一種,輸出長度為 256),另外還有與 SHA-1、SHA-2 運算方式不同的 SHA-3 系列。

SHA-1 演算法

以下為 SHA1 演算法的過程,使用位元的角度簡介

· One min read
m9H8

HMAC 的 H 是指 Hash-based,MAC 是指 message authentication code。

計算的輸入

計算 HMAC 需要以下輸入:

  1. key 金鑰
  2. message 訊息
  3. hash algorithm 雜湊函式 及其 blocksize

流程