快轉到主要內容

各式各樣的小抄

-
目錄

magick

轉換資料夾到 WebP 加上 crop,crop 參數為 "長x寬+起始寬度+起始高度"

magick mogrify -format webp -quality 80 -crop 2000x800+300+420 *.png

使用範例 [1] [2]

Exiftool

我的檔案整理流程,用於將錯誤的 Exif(通常來自於網路下載)轉換成粗略的時間,並且依照時間重新命名。請根據個人需求自行選擇需要的步驟,例如時間是對的就不需要改,檔名使用自己的規範,或者不用 datetimeoriginal 改用別的標籤。

  • 時間格式: "YYYY:MM:DD HH:MM:SS",如 2025:01:01 12:30:00
  • 路徑可以是整個資料夾
  • 在網路磁碟進行此操作可能會有奇怪問題,例如 FileModifyDate 無法修改
P=/Path/to/file/dir

# 先把整個資料夾的時間設定成一樣
exiftool -overwrite_original -datetimeoriginal='時間' -filemodifydate='時間' $P

# 根據檔案名稱依序把時間延後 10 秒(時間完全相同會造成圖片順序隨機,而下載下來的檔案通常包含 suffix 標記順序)
exiftool -overwrite_original '-FileModifyDate+<0:0:${FileSequence; $_*=10}' '-datetimeoriginal+<0:0:${FileSequence; $_*=10}' -FileOrder Filename $P

# 再根據元資料設定檔案名稱
exiftool -d %Y%m%d_%H%M%S%%-c'-DEVICE_MODEL'.%%e "-filename<DateTimeOriginal" -fileorder DateTimeOriginal $P

# 如果元資料沒有攝影裝置名稱,可以手動設定
exiftool -d %Y%m%d_%H%M%S%--iPhone16.%%e "-filename<filemodifydate" -fileorder filemodifydate $P

語言模型

翻譯 Prompt

I want you to act as an English translator, spelling corrector and improver. I will speak to you in English, translate it to Traditional Chinese 繁體中文. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same. I want you to only reply the correction, the improvements and nothing else, do not write explanations.

Understand?

Python

pip 刪除所有套件和快取

支援 win/mac

pip freeze > unins && pip uninstall -y -r unins && rm unins
pip cache purge

從原始碼構建程式

gallery-dl 為例

git clone --depth=1 https://github.com/mikf/gallery-dl.git
cd gallery-dl
python3 -m venv .venv
source .venv/bin/activate

# 使用 setup.py 安裝
pip3 install setuptools
python3 setup.py install

# 或者,使用 pyproject.toml 安裝
pip install .

pip install . 其實兩種安裝方式都接受,但是 pyproject.toml 優先。可以加上 -e 選項使用開發模式安裝,和正式安裝的差別在於所有改動都會立刻生效,因為正式安裝的程式碼在 python 路經(虛擬環境)中的 site-packages 內。

Google Style Docstring

養成寫註解的好習慣。Sphinx 風格難以閱讀並且 VSC 常常偵測錯誤直接剔除,Numpy 風格適合更長且深入的說明文件1,反之使用 Google 風格

def update_config(self, options: dict[str, Any]) -> None:
    """
    Updates the configuration with the provided options.

    This method updates the `self.config` dictionary based on the given `options` dictionary.

    Example:
        ### Python usage example:
        >>> args.options = {
                "local": "path/to/local",
                "remote": "path/to/remote",
                "categories": "category1, category2, category3",
                "custom_setting": {
                    "Others": {
                        "tags": {
                            "nice_job": "好欸!",
                            "114514": "id_ed25519",
                        }
                    }
                }
            }
        >>> config_loader.load_config()
        >>> config_loader.update_config(args.options)

        ### Command line input examples:

        Overwrite local_path:
        $ python -m p5d -o local=/Users/leo/Pictures/downloads

        Only process specified categories:
        $ python -m p5d -o category="Marin, IdolMaster, Others"

        Overwrite rsync parameters:
        $ python -m p5d -o rsync="--remove-source-files -avzd"

        Specify multiple configs at once:
        $ python3 -m p5d -o local=/Users/leo/Pictures/downloads remote=/Users/leo/Downloads/TestInput category="Marin, IdolMaster, Others" rsync="--remove-source-files -a"

    Args:
        options (dict[str, Any]): A dictionary of configuration options to update.

    Raises:
        ValueError: If the input is not a dictionary, if an invalid key is provided,
            or if a value for `tag_delimiter` or `file_type` is not a string.
        KeyError: If a key in `options` is not valid or is missing from the configuration.
    """

Misc

H.264 and H.265 硬體解碼支援列表

DDR4 vs. DDR5 on Intel Core i9-12900K Alder Lake Review DDR5 isn't worth the money.

Github Alerts highlight

VSC 遠端連線1 2

清理書籤

MacOS 注音輸入法

  • Yahoo! 輸入法:使用時間約一週,停止更新已久,很難用也很醜。
  • 小麥注音:使用時間約三個月,中規中舉,選字位置在字的前一格所以每次選字都要多按一次左鍵,完全不記憶選字偏好,錯的字永遠錯,單詞量非常少,浪費很多時間在字字修正。
  • 鼠鬚管:使用時間約一天,選字框很醜,醜到我忘記他還有什麼特點。
  • 威注音:使用時間至今約兩個月,幾乎沒有記憶選字偏好,單詞量較小麥注音多,出現過一次記憶體異常佔用高達 300MB。

KVM 虛擬機

翻新硬碟

ServerPartDeals 硬碟:官方翻新硬碟,沒什麼問題,但加上運費後不如去南京梵多買。
https://www.reddit.com/r/DataHoarder/comments/13p1y5d/anyone_have_experiences_with_renewed_seagate/
https://www.reddit.com/r/DataHoarder/comments/1352drh/whats_the_general_consensus_on_serverpartdeals/

Cloudflare Tunnel CLI 設定

使用 CLI 設定,我原本也是用 CLI 但是在後續更新後 GUI 已經可以正常使用 影片教學
文字教學
官方文檔1
官方文檔2 官方文檔3

Cloudflare 重導向設定(適用 WAF)

https://www.sakamoto.blog/cloudflare-non-www-to-www/

NOIP 設定

https://lins2000.gitbooks.io/raspberry-pi-installation-guide/content/di-yi-ci-qi-dong/noip-an-zhuang-she-ding.html
注意 NOIP 無法將 DNS 伺服器改為 Cloudflare,所以使用 Github Pages 等服務無法使用他的網域名稱。

在Linux上使用Let’s Encrypt

https://klab.tw/2022/05/get-free-ssl-credentials-with-nginx-with-lets-encrypt-on-linux/
使用 Cloudflare Tunnel 或者 Tailscale 可更輕鬆簡單的達成公眾訪問 / 私人訪問伺服器。缺點是 Cloudflare Tunnel 單檔案大小限制為 100MB,在使用 stirling pdf 可能會無法上傳。

TrueNAS TailScale 設定

等 2024/10 的 TrueNAS 24.10 版本更新後 k3s 將替換成 Docker,到時候再看設定是否改變。 https://www.youtube.com/watch?v=K_0vGr_rvds

SAMBA 安全設定

修正漏洞防止中間人攻擊
https://blog.csdn.net/qq_46106285/article/details/130273351

Linux OPNsense 防禦入侵偵測

https://www.sakamoto.blog/opnsense-ids-suricata/

GPG 超詳細設定

https://gist.github.com/troyfontaine/18c9146295168ee9ca2b30c00bd1b41e

ZSL
作者
ZSL
正事不做。

相關文章

tmux 使用教學
使用 tmux 管理多視窗,讓程序在 SSH 斷線後繼續運行。介紹 tmux 的安裝、基本使用方法以及整理常用的指令。
常用Linux指令
-
常用的 Linux 指令小抄
常用Docker指令
常用的 docker 指令小抄