回歸本文,我選擇了 GCP Cloud Run,這是一種雲端的 Server Less 的解決方案。 產品的規模沒有大到需要 K8s,團隊成員的具備足夠的能力, 類似的方案還有 Cloud Function, 作為一個 Web API Base 的輕量專案,我評估 Cloud Run 更適合 Cloud Function 較適合 Event Driven 的片段行為 Cloud Run 較適合有點複雜度,但是可以容器化的應用。
# Install zsh-syntax-highlighting if it's not installed if [ ! -d ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting ]; then git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting fi # Load zsh-syntax-highlighting plugin plugins+=(zsh-syntax-highlighting) # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes ZSH_THEME="powerlevel10k/powerlevel10k"
TypeScript 在 5.2 引入了一個新關鍵字 using - 可用於在離開作用域時使用 Symbol.dispose 函數處理任何內容。
看一下官方的說明
TypeScript 5.2 introduces support for the forthcoming Explicit Resource Management feature in ECMAScript, which aims to address the need for “cleaning up” after creating an object. This feature allows developers to perform necessary actions such as closing network connections, deleting temporary files, or releasing memory.
using 與 await 的目的在於釋放資源上會非常有用。
在舉例子之前先看一下新的全域 Symbol:Symbol.dispose 與 Symbol.asyncDispose, 任何將函數分配給 Symbol.dispose 的物件都將被視為「資源」(“具有特定存留期的物件”),並且可以與 using 關鍵字一起使用。
#Create a service account gcloud iam service-accounts create gitlab-runner-sa --project=$GCP_PROJECT_ID #Add sample permissions to the Service account gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \ --member=serviceAccount:gitlab-wif-demo@${GCP_PROJECT_ID}.iam.gserviceaccount.com \ --role=roles/storage.admin
手動執行就可以處理的問題,我不會特別想要付款買一個軟體, 而雲端服務會擔心資訊安全,特別是要加密的資料代表有一定程度的重要性。 Terminal 大概是網路文章的主流解。 當我需要經常這樣做時,就太麻煩了,還要記得操作指令,額外增加心智負擔。 理想上,我希望只要選擇文件或資料夾,右鍵點擊”Zip with Password”,就能創建加密的 zip 文件。
實作
打開 Automator app。
創建一個新 Automator 文件:File > New (或按 ⌘N),選擇 “Quick Action” 類型。
repeat set zip_password to text returned of (display dialog prompt_text default answer "" with hidden answer) set verify_password to text returned of (display dialog "再次輸入壓縮密碼" buttons {"OK"} default button 1 default answer "" with hidden answer) considering case and diacriticals if (zip_password = verify_password) then exit repeat else set prompt_text to "密碼不一致,請重新設定" end if end considering end repeat
tell application "Finder" set the_items to selection if ((class of the_items is list) and (count of the_items) > 0) then set items_to_zip to "" repeat with each_item in the_items set each_item_alias to each_item as alias set item_name to name of each_item_alias set item_name to quoted form of (item_name & "") set items_to_zip to items_to_zip & item_name & " " end repeat
set first_item to (item 1 of the_items) as alias set containing_folder to POSIX path of (container of first_item as alias) set zip_name to text returned of (display dialog "輸入壓檔名" default answer "") set zip_file_name to quoted form of (zip_name & ".zip")
if zip_password is not equal to "" then -- 如果存在密碼,執行加密壓縮 do shell script "cd '" & containing_folder & "'; zip -x .DS_Store -r0 -P '" & zip_password & "' " & zip_file_name & " " & items_to_zip else -- 否則執行單純壓縮 do shell script "cd '" & containing_folder & "'; zip -x .DS_Store -r0 " & zip_file_name & " " & items_to_zip end if else display dialog "你未選擇任何檔案。" buttons {"OK"} default button 1 end if end tell
儲存工作流程:File > Save (或按 ⌘S),給它一個名字,如 “Zip with Password”
現在,選擇文件或文件夾,右擊,選擇 “Quick Actions” 中的 “Zip with Password”, 按照提示輸入密碼、驗證密碼和設置 zip 文件的名字。測試新創建的 zip 文件,確保一切運作正常。