python-challenge

Docker timezone 時區問題

Docker Timezone 時區問題 方法一: 將本機的時間帶到 image 當中 when docker run some-image 1 -v /etc/localtime:/etc/localtime:ro docker-compsoe.yml 1 2 3 4 5 services: some-container: volumes: - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro 方法二(推薦): 設定環境變數 when docker run some-image 1 -e "TZ=Asia/Taipei" docker-compose.yml 1 2 3 4 sevices: some-container: environment: TZ: Asia/Taipei 例外 如果使用到 alpine 版本 則需要自行重新 build image Dockerfile 先添加以下兩行,再進行上述操作 1 2 RUN apk update && \ apk add -U tzdata

August 15, 2022 · 1 min · 66 words · GeminiXiang
python-challenge

Python 腦筋急轉彎

題目: 讓以下function回傳 True 原文: https://www.reddit.com/r/Python/comments/cje5yh/short_python_challenge_make_this_return_true/ 1 2 3 4 5 6 def check(x): if x+1 is 1+x: return False if x+2 is not 2+x: return False return True 解答一: -7 在 Python 中,整数 -5 到 256 會預先分配到記憶體, 此時 -7 + 1 得到的 -6,恰好在這範圍之外, 才會出現 -6 is not -6 的情況 解答二: 自定義class 透過實現 add,讓他可以與integer互動, 但其實就是拿來判斷 integer 後,回傳適當的 boolean (有點作弊XDD) 1 2 3 4 5 6 class Test(int): def __add__(self, v): if v == 1: return 0 else: return v

August 15, 2022 · 1 min · 78 words · GeminiXiang