timmy / 使用 functools 進行函式工具操作

0 Kedvelések
0 forkok
3 fájlok
Utoljára aktív 9 months ago
functools 模組提供多種函式工具,如記憶化(lru_cache)、部分應用(partial)和函式包裝(wraps),適用於提升效能、簡化回呼函式與裝飾器開發。
1 import functools
2
3 @functools.lru_cache(maxsize=5)
4 def fibonacci(n):
5 """計算費氏數列(具備快取功能)"""
6 if n < 2:
7 return n
8 return fibonacci(n - 1) + fibonacci(n - 2)
9
10 print(fibonacci(10)) # 快速計算

timmy / 台灣假日 API 查詢與快取

0 Kedvelések
0 forkok
1 fájlok
Utoljára aktív 10 months ago
這段程式碼是一個節假日查詢工具,從指定 API 獲取節假日資料,支援緩存與分頁,並提供按年份篩選節假日、檢查特定日期是否為節假日的功能,同時以 Holiday 類別封裝每個節假日的詳細資訊,便於操作與顯示。
1 import requests
2 import os
3 import json
4
5 class HolidayAPI:
6 def __init__(self, base_url, cache_dir="cache"):
7 """
8 Initialize the HolidayAPI class.
9 :param base_url: The base URL for the API endpoint.
10 :param cache_dir: Directory to store cached data.

timmy / Dnsmasq 設定與網路管理

0 Kedvelések
0 forkok
1 fájlok
Utoljára aktív 10 months ago
這份 dnsmasq 設定檔 用於 管理 DNS 和 DHCP 服務,提供 本機網路名稱解析、靜態 IP 配置、DNS 轉發、快取與封鎖特定域名。它設定了 Google、Hinet 作為上游 DNS,開啟 DNS 查詢日誌,並定義 DHCP 位址範圍、靜態 IP 綁定與特定域名解析。適用於 內部網路架構、加速 DNS 解析、提升隱私安全及廣告封鎖 等場景。
1 bogus-priv # Block fake private IP responses
2 no-resolv # Ignore /etc/resolv.conf for upstream DNS
3 dns-forward-max=150 # Limit parallel DNS queries to 150
4 clear-on-reload # Clear cache when dnsmasq reloads
5 domain-needed # Ignore queries without a domain name
6 no-negcache # Do not cache negative (non-existent) DNS responses
7 no-poll # Do not poll /etc/resolv.conf for changes
8 strict-order # Use upstream DNS servers in the order they are listed
9
10 # AdGuard DNS 封鎖廣告和追蹤器。
Újabb Régebbi