timmy / MySQL 與 phpMyAdmin 容器部署
1 likes
0 forks
1 files
Last active 9 months ago
利用 Docker 快速部署 MySQL 資料庫與 phpMyAdmin 管理介面,方便管理及測試資料庫。
| 1 | services: |
| 2 | mysql: |
| 3 | container_name: database_server |
| 4 | image: mysql:latest |
| 5 | ports: |
| 6 | - "3306:3306" |
| 7 | environment: |
| 8 | MYSQL_ROOT_PASSWORD: StrongRootPass123 # MySQL 的根密碼 |
| 9 | MYSQL_DATABASE: production_db # 要建立的資料庫名稱 |
| 10 | MYSQL_USER: db_user # 新使用者的名稱 |
timmy / Docker Compose 部署 MySQL
1 likes
0 forks
6 files
Last active 9 months ago
| 1 | MYSQL_USER=user |
| 2 | MYSQL_PASSWORD=password |
| 3 | MYSQL_ROOT_PASSWORD=rootpassword |
Last active 9 months ago
此腳本用於快速檢視 Linux 系統的基本資訊,包括作業系統、CPU、記憶體、檔案描述符、網路設定、TCP 參數、連線追蹤與當前開啟的 TCP 連線狀況,方便系統管理與效能調校。
chmod +x system_info.sh
./system_info.sh > system_report.txt
Last active 10 months ago
此程式使用 pretty_errors 改善錯誤輸出,並使用 icecream (ic) 進行簡潔的除錯訊息輸出,方便開發人員快速定位錯誤與分析變數內容,提高程式除錯效率。
| 1 | import pretty_errors |
| 2 | from icecream import ic |
| 3 | |
| 4 | |
| 5 | def configure_pretty_errors() -> None: |
| 6 | """ |
| 7 | 配置 pretty_errors 庫,用於更好的錯誤輸出。 |
| 8 | |
| 9 | 不需要任何參數。 |
| 10 | """ |
timmy / Python Mixin 類別設計
1 likes
0 forks
1 files
Last active 10 months ago
這段程式碼展示了如何使用 Mixin 類別來提供額外功能。GraphicMixin 提供 draw() 方法,而 ColorMixin 提供 set_color() 方法,ColoredGraphic 繼承這兩個 Mixin,使其具備繪圖與設定顏色的功能。這種設計可以在不影響主要類別結構的情況下,為不同類別添加額外行為。
| 1 | class GraphicMixin: |
| 2 | def draw(self): |
| 3 | print("Drawing the graphic") |
| 4 | |
| 5 | class ColorMixin: |
| 6 | def set_color(self, color): |
| 7 | self.color = color |
| 8 | print(f"Setting color to {color}") |
| 9 | |
| 10 | class ColoredGraphic(ColorMixin, GraphicMixin): |
timmy / YAML 檔案讀寫與資料管理
1 likes
0 forks
1 files
Last active 10 months ago
這段程式碼提供了一個 YAMLProcessor 類別,負責讀取和寫入 YAML 檔案(預設為 local_data.yaml),並將其內容轉換為 pandas.DataFrame 進行處理,適用於需要以表格形式操作 YAML 資料的應用場景。
| 1 | import os |
| 2 | import yaml |
| 3 | import pandas as pd |
| 4 | import logging |
| 5 | from typing import Any, Dict, List |
| 6 | |
| 7 | # 設定 logging 基本參數 |
| 8 | logging.basicConfig(level=logging.INFO) |
| 9 | logger = logging.getLogger(__name__) |
timmy / Docker 部署 SQL Server 2019
1 likes
0 forks
2 files
Last active 9 months ago
這是一個 Docker Compose 配置檔,用於設定 Microsoft SQL Server 環境,包括一個 mssql-server 容器(SQL Server Express 版本)和一個 sqlcmd 容器(用於執行 SQL 命令)。兩個容器透過自定義網路連接,並將資料庫數據保存到命名卷 mssql_data。
| 1 | services: |
| 2 | mssql-server: |
| 3 | image: mcr.microsoft.com/mssql/server:2019-latest |
| 4 | container_name: mssql-server |
| 5 | environment: |
| 6 | ACCEPT_EULA: "Y" |
| 7 | SA_PASSWORD: "StrongP@ssw0rd!" |
| 8 | MSSQL_PID: "Express" |
| 9 | ports: |
| 10 | - "1433:1433" |
timmy / Python 虛擬環境自動化設定
1 likes
0 forks
2 files
Last active 10 months ago
這段 Bash 腳本用於建立和管理 Python 虛擬環境,檢查虛擬環境是否存在,若不存在則建立並啟動環境,升級 pip,並自動安裝 requirements.txt 中的依賴(若檔案存在)。
| 1 | #!/bin/bash |
| 2 | |
| 3 | # 設定虛擬環境名稱 |
| 4 | VENV_DIR="myenv" |
| 5 | |
| 6 | # 檢查是否已經存在虛擬環境 |
| 7 | if [ -d "$VENV_DIR" ]; then |
| 8 | echo "虛擬環境 '$VENV_DIR' 已經存在。" |
| 9 | else |
| 10 | echo "正在建立虛擬環境 '$VENV_DIR'..." |