# 建立Image
docker build -t image -f docker/Dockerfile.dev .
# 運行
docker run -it --rm --name containerName -p 8080:8080 -v .:/app image
2025/05/27
用 Docker 建立 Vue.js 開發環境:簡單一步啟動 npm run serve
2025/04/30
用一行指令搞定 Git 歷史中的大檔案:git lfs migrate import
用一行指令搞定 Git 歷史中的大檔案:git lfs migrate import
如果你曾經在推送 Git 專案到 GitHub 時遇到以下錯誤訊息:
那麼你就遇到 GitHub 強制限制:單一檔案不可超過 100MB。而這個限制,不只是針對目前版本的檔案,就算該檔案只曾出現在 Git 歷史中一次,也會導致整個 Push 被拒絕。
常見的錯誤誤解
2025/03/27
Using C# Reflection to Get Public Method Call Count
class Program
{
public static void SampleMethod()
{
Console.WriteLine("Hello World!");
AnotherMethod();
}
public static void AnotherMethod()
{
Console.WriteLine("This is another method.");
}
static void Main(string[] args)
{
// 取得 SampleMethod 的 MethodInfo
MethodInfo sampleMethodInfo = typeof(Program).GetMethod("SampleMethod");
// 分析方法內的呼叫次數
int callCount = MethodUtils.AnalyzeMethodCalls(sampleMethodInfo);
Console.WriteLine($"SampleMethod has {callCount} method calls inside it.");
}
}
2025/03/21
Windows 11 配置 Claude Desktop MCP
簡介
多點 Claude Desktop MCP 是一款高效能且高度可擴展的人工智慧模型運行平台,旨在支援多點操作與併行處理,適用於開發、測試與生產環境。此平台能夠透過多點控制 (Multi-Point Control, MCP) 提供更靈活的資源調度與管理能力,大幅提升效能與穩定性。
Model Context Protocol (MCP)
MCP(Model Context Protocol)是一種用於人工智慧模型運行環境的標準化協議,旨在協調多個模型、模組或應用程式之間的互動與資料交換。MCP 提供了一個統一的協作框架,使各個元件能夠在多點控制環境中高效運行。
在 Claude Desktop MCP 中,MCP 被應用於:
- 調整資源配置:允許動態分配 CPU、記憶體與網路資源,以符合不同模型的需求。
- 資料同步與管理:確保多點操作中的資料一致性與安全性。
- 通訊協議設計:標準化不同元件之間的通訊格式與資料協定。
- 併行處理架構:支持多個模型同時運行並協調結果輸出。
MCP 支援的應用程式 (MCP Clients)
以下是支援 MCP 的一些應用程式與工具:
- Claude 桌面應用程式:提供對 MCP 的全面支援,允許深度整合本地工具和資料來源。
- 5ire:支援 MCP 的工具功能,允許 AI 模型執行特定任務。
- BeeAI 框架:在代理工作流程中支援 MCP 的工具功能。
- Cline:支援 MCP 的工具和資源功能,增強了 AI 的操作能力。
- Continue:全面支援 MCP 的所有功能,提供完整的整合體驗。
特點
- 支援多點操作與併行處理
- 高效能模型運行與資源管理
- 友善的圖形化操作介面
- 高度可擴展的組態檔配置系統
- 支援自訂測試工具與模組開發
2025/03/14
透過CloudFlare GraphQL 取得SubDomain國家來源數據
curl -X POST "https://api.cloudflare.com/client/v4/graphql" ^
-H "Authorization: Bearer YourToken" ^
-H "Content-Type: application/json" ^
--data "{ \"query\": \"query { viewer { zones(filter: { zoneTag: \\\"YourZoneID\\\" }) { httpRequestsAdaptiveGroups( limit: 1000, filter: { clientRequestHTTPHost: \\\"YourSubDomain\\\", datetime_geq: \\\"2025-03-13T00:00:00Z\\\", datetime_lt: \\\"2025-03-14T00:00:00Z\\\" }, orderBy: [count_DESC] ) { dimensions { clientCountryName } count sum { edgeResponseBytes } } } } }\" }"
2025/03/13
如何使用 cURL 刪除與查詢 GitHub Packages 的 NuGet 套件版本
在 GitHub Packages 上,你可以透過 API 來查詢或刪除已發布的 NuGet 套件版本。本篇文章將介紹如何使用 curl 來執行這些操作。
🔍 查詢 NuGet 套件的所有版本
如果你想要取得某個 GitHub Organization 內的 NuGet 套件的所有版本,可以使用以下 curl 指令:
curl -H "Authorization: Bearer ghp_xxxxxx" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/orgs/YourOrgName/packages/nuget/ProjectName/versions"
這段指令會:
- 使用
-H "Authorization: Bearer ghp_xxxxxx"提供你的 GitHub Personal Access Token(PAT)來進行身份驗證。 - 加上
-H "Accept: application/vnd.github+json"以確保回傳的 JSON 資料格式符合最新 API 版本。 - 向 GitHub API 發送請求,列出 Organization
YourOrgName下,NuGet 套件ProjectName的所有版本。
2025/03/10
透過 Git Subtree 無痛整合 GitHub 上的既有專案
Git Subtree 輕鬆合併專案,保留完整 commit 歷史
在軟體開發的過程中,時常會遇到這樣的需求:
- 你有一個現有的 Git 專案,但需要將另一個儲存庫的內容整合進來,並且希望保留完整的 commit 歷史。
這時,Git 提供了幾種不同的方式來達成這個目標,其中 Git Subtree 是一個簡單又強大的解法。
本文將帶你了解 Git Subtree 的用途、與 Submodule 的差異,以及如何實際操作,讓你的開發流程更順暢!
2025/03/03
Ubuntu 24.04 取得當前硬碟總大小及已使用空間
df --block-size=1K | awk '{total+=$2; used+=$3; avail+=$4} END {printf "總大小: %.2fG, 已使用: %.2fG, 可用: %.2fG\n", total/1024/1024, used/1024/1024, avail/1024/1024}'就會得到
2025/03/02
修正 Ubuntu 24.04 systemd-networkd-wait-online 導致開機過慢問題
輸入下方指令
sudo systemctl edit systemctl-networkd-wait-online.service
# 再ExecStart=/usr/lib/systemd/systemd-networkd-wait-online 加入--timeout=15
sudo systemctl daemon-reload
參考資料:
https://www.reddit.com/r/Ubuntu/comments/16xi5h0/how_do_i_fix_systemdnetworkdwaitonlineservice/
使用 GitHub Actions 在 NX Monorepo 中實現單元測試與 Cypress E2E 測試
# 單元測試及E2E測試
test:
name: 單元測試及E2E測試
runs-on: [ self-hosted, Ubuntu, 24.04 ]
steps:
# 單元測試
- name: Unit Test
run: pnpm nx test project
# E2E 測試
- name: E2E Test
run: |
# 安裝依賴套件
sudo apt install -y libgtk2.0-0t64 libgtk-3-0t64 libgbm-dev libnotify-dev libnss3 libxss1 libasound2t64 libxtst6 xauth xvfb
# 安裝 Cypress
pnpm cypress install
# 驗證 Cypress
pnpm cypress verify
# 執行 E2E 測試
pnpm nx e2e project --headless
2025/03/01
透過 Github Actions 自動清除7天前Actions紀錄
name: Cleanup Workflow Runs
on:
# 每週日 UTC 15:59 執行 (台灣時間 23:59)
schedule:
- cron: "59 15 * * 0"
# 允許手動執行
workflow_dispatch:
jobs:
cleanup:
# 改為使用自建代理
runs-on: [self-hosted, Ubuntu, 24.04]
permissions:
# 允許刪除 workflow runs
actions: write
steps:
- name: Install GitHub CLI
run: |
sudo apt update
sudo apt install -y gh jq
- name: Authenticate GitHub CLI
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Get workflow runs from last week
run: |
# 設定刪除 7 天前的 workflow runs
SEVEN_DAYS_AGO=$(TZ=UTC date -d "7 days ago" +%s)
# 取得目前 repository 內所有 workflows
gh api repos/${{ github.repository }}/actions/workflows | jq -r '.workflows[].id' > workflows.txt
# 清空刪除列表
> runs_to_delete.txt
# 迴圈檢查每個 workflow,刪除超過 7 天的 workflow runs
while read WORKFLOW_ID; do
gh api --paginate repos/${{ github.repository }}/actions/workflows/$WORKFLOW_ID/runs | \
jq -r --argjson SEVEN_DAYS_AGO "$SEVEN_DAYS_AGO" '
.workflow_runs[] | select((.created_at | fromdateiso8601) < $SEVEN_DAYS_AGO) | .id' >> runs_to_delete.txt
done < workflows.txt
- name: Display need delete workflow runs
run: cat runs_to_delete.txt
- name: Delete old workflow runs
run: |
if [ -s runs_to_delete.txt ]; then
while read RUN_ID; do
echo "Deleting workflow run ID: $RUN_ID"
gh api --method DELETE repos/${{ github.repository }}/actions/runs/$RUN_ID
done < runs_to_delete.txt
else
echo "No workflow runs to delete."
fi
使用 Go Lang 撰寫一個 SSE(Server-Sent Events) Testing Server
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func sseHandler(w http.ResponseWriter, r *http.Request) {
// 設置 SSE 頭
w.Header().Set("Content-Type", "text/event-stream")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Connection", "keep-alive")
// 強制刷新,以保持連接
flusher, ok := w.(http.Flusher)
if !ok {
log.Fatal("Server does not support HTTP streaming.")
}
// 連接時顯示訊息
log.Printf("新用戶連接:%s", r.RemoteAddr)
// 模擬逐步發送 SSE 資料
for i := 1; i <= 3; i++ {
// 顯示正在發送資料
log.Printf("開始發送第 %d 條資料", i)
// 模擬 SSE 資料
fmt.Fprintf(w, "data: 第一段資料 %d\n\n", i)
flusher.Flush() // 刷新資料
time.Sleep(3 * time.Second) // 模擬延遲
}
// 完成 SSE 流
fmt.Fprintf(w, "data: SSE 流結束\n\n")
flusher.Flush()
// 完成後顯示訊息
log.Printf("完成發送資料給 %s", r.RemoteAddr)
}
func main() {
http.HandleFunc("/sse", sseHandler)
log.Println("伺服器啟動,請訪問 http://localhost:8080/sse")
log.Fatal(http.ListenAndServe(":8080", nil))
}
2025/02/28
2025/02/26
打造自建 GitHub Actions 2.322 環境:在 Windows 11 設置 Self-Hosted Runner 並建置.Net Core專案
在 Windows 上設定 GitHub Actions Runner 需要額外的權限與步驟。請先 以管理員身份 開啟 PowerShell,然後執行以下指令:
下載並安裝 GitHub Actions Runner
# 回到 C:\
cd ..\..\
# 創建一個文件夾
mkdir actions-runner; cd actions-runner
# 下載最新的runner包
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.322.0/actions-runner-win-x64-2.322.0.zip -OutFile actions-runner-win-x64-2.322.0.zip
# 可選:驗證哈希值
if((Get-FileHash -Path actions-runner-win-x64-2.322.0.zip -Algorithm SHA256).Hash.ToUpper() -ne 'ace5de018c88492ca80a2323af53ff3f43d2c82741853efb302928f250516015'.ToUpper()){ throw 'Computed checksum did not match' }
# 解壓安裝程序
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/actions-runner-win-x64-2.322.0.zip", "$PWD")
# 配置 GitHub Actions runner
# 接著填入需要配置的設定即可
./config.cmd --url https://github.com/YourOrganization --token yourToken
MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.Sdk" because directory did not exist
MSBuildSDKsPath=C:\Program Files\dotnet\sdk\8.0.406\SdksWindows 安裝 Git 並使用 ls、cat 等 Linux 指令
安裝 Git 後,如果安裝路徑位於 C 槽,可以將以下路徑加入 環境變數 (Path),重啟 cmd 後即可使用 Git Bash 提供的 Linux 指令:
C:\Program Files\Git\usr\bin