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
| 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