diff --git a/README.md b/README.md index fd3fa9f..b7f37ca 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,13 @@ - [ ] Contents generator optimize and new feature - [ ] 依照筆記量釋出不同顏色標籤 - [ ] 偵測筆記較少的 md 標記為`尚未完成 + - 實作 + - [X] 完成 Progressor 類別設計 - [ ] 架構優化 - [ ] Keyword 自動生成 - 從文本當中超連結自動爬入字串,以較為泛用的方式前處理並提取關鍵詞 - [ ] auto-gen module 建置於 pre-commit phase 自動執行產生目錄 + - [ ] 閱讀狀況數據統計報表 ### Operations - [ ] 撰寫 CONTRIBUTING @@ -48,64 +51,77 @@ $ pre-commit uninstall # Contents - reading - 1. [vscode.md](https://github.com/ShemYu/learning-resource/blob/master//vscode.md) + 1. [vscode.md](https://github.com/ShemYu/learning-resource/blob/read/reading/vscode.md) - Data science - 1. [Data science… without any data.md](https://github.com/ShemYu/learning-resource/blob/master/Data%20science/Data%20science%E2%80%A6%20without%20any%20data.md) - 1. [資料科學五大 Q&A:如何成為資料科學家?資料科學產業的未來?.md](https://github.com/ShemYu/learning-resource/blob/master/Data%20science/%E8%B3%87%E6%96%99%E7%A7%91%E5%AD%B8%E4%BA%94%E5%A4%A7%20Q%26A%EF%BC%9A%E5%A6%82%E4%BD%95%E6%88%90%E7%82%BA%E8%B3%87%E6%96%99%E7%A7%91%E5%AD%B8%E5%AE%B6%EF%BC%9F%E8%B3%87%E6%96%99%E7%A7%91%E5%AD%B8%E7%94%A2%E6%A5%AD%E7%9A%84%E6%9C%AA%E4%BE%86%EF%BC%9F.md) + 1. [Data science… without any data.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Data%20science/Data%20science%E2%80%A6%20without%20any%20data.md) + 1. [資料科學五大 Q&A:如何成為資料科學家?資料科學產業的未來?.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Data%20science/%E8%B3%87%E6%96%99%E7%A7%91%E5%AD%B8%E4%BA%94%E5%A4%A7%20Q%26A%EF%BC%9A%E5%A6%82%E4%BD%95%E6%88%90%E7%82%BA%E8%B3%87%E6%96%99%E7%A7%91%E5%AD%B8%E5%AE%B6%EF%BC%9F%E8%B3%87%E6%96%99%E7%A7%91%E5%AD%B8%E7%94%A2%E6%A5%AD%E7%9A%84%E6%9C%AA%E4%BE%86%EF%BC%9F.md) - Data scientist roadmap - 1. [Data scientist roadmap.md](https://github.com/ShemYu/learning-resource/blob/master/Data%20scientist%20roadmap/Data%20scientist%20roadmap.md) + 1. [Data scientist roadmap.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Data%20scientist%20roadmap/Data%20scientist%20roadmap.md) - Design Pattern - Domain-Driven Design - 1. [1_初探.md](https://github.com/ShemYu/learning-resource/blob/master/Design%20Pattern/Domain-Driven%20Design/1_%E5%88%9D%E6%8E%A2.md) + 1. [1_初探.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Design%20Pattern/Domain-Driven%20Design/1_%E5%88%9D%E6%8E%A2.md) - Docker - 1. [3_Docker 基本運作.md](https://github.com/ShemYu/learning-resource/blob/master/Docker/3_Docker%20%E5%9F%BA%E6%9C%AC%E9%81%8B%E4%BD%9C.md) - 1. [Docker compose.md](https://github.com/ShemYu/learning-resource/blob/master/Docker/Docker%20compose.md) - 1. [Docker入門.md](https://github.com/ShemYu/learning-resource/blob/master/Docker/Docker%E5%85%A5%E9%96%80.md) + 1. [3_Docker 基本運作.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Docker/3_Docker%20%E5%9F%BA%E6%9C%AC%E9%81%8B%E4%BD%9C.md) + 1. [Docker compose.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Docker/Docker%20compose.md) + 1. [Docker入門.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Docker/Docker%E5%85%A5%E9%96%80.md) - Git - 1. [CICD初探.md](https://github.com/ShemYu/learning-resource/blob/master/Git/CICD%E5%88%9D%E6%8E%A2.md) - 1. [版本號的基本常識.md](https://github.com/ShemYu/learning-resource/blob/master/Git/%E7%89%88%E6%9C%AC%E8%99%9F%E7%9A%84%E5%9F%BA%E6%9C%AC%E5%B8%B8%E8%AD%98.md) + 1. [CICD初探.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Git/CICD%E5%88%9D%E6%8E%A2.md) + 1. [版本號的基本常識.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Git/%E7%89%88%E6%9C%AC%E8%99%9F%E7%9A%84%E5%9F%BA%E6%9C%AC%E5%B8%B8%E8%AD%98.md) - Github pages - 1. [Github pages - 輕鬆架設靜態網頁.md](https://github.com/ShemYu/learning-resource/blob/master/Git/Github%20pages/Github%20pages%20-%20%E8%BC%95%E9%AC%86%E6%9E%B6%E8%A8%AD%E9%9D%9C%E6%85%8B%E7%B6%B2%E9%A0%81.md) + 1. [Github pages - 輕鬆架設靜態網頁.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Git/Github%20pages/Github%20pages%20-%20%E8%BC%95%E9%AC%86%E6%9E%B6%E8%A8%AD%E9%9D%9C%E6%85%8B%E7%B6%B2%E9%A0%81.md) - Linux - 1. [鳥哥 Shell script.md](https://github.com/ShemYu/learning-resource/blob/master/Linux/%E9%B3%A5%E5%93%A5%20Shell%20script.md) + 1. [鳥哥 Shell script.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Linux/%E9%B3%A5%E5%93%A5%20Shell%20script.md) - Programing - 1. [Locust preformance testing tool.md](https://github.com/ShemYu/learning-resource/blob/master/Programing/Locust%20preformance%20testing%20tool.md) - 1. [何謂DevOps.md](https://github.com/ShemYu/learning-resource/blob/master/Programing/%E4%BD%95%E8%AC%82DevOps.md) + 1. [Locust preformance testing tool.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Programing/Locust%20preformance%20testing%20tool.md) + 1. [何謂DevOps.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Programing/%E4%BD%95%E8%AC%82DevOps.md) + - 前端 + 1. [後端怎麼區分.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Programing/%E5%89%8D%E7%AB%AF/%E5%BE%8C%E7%AB%AF%E6%80%8E%E9%BA%BC%E5%8D%80%E5%88%86.md) + - img + 1. [20210312181535.png](https://github.com/ShemYu/learning-resource/blob/read/reading/Programing/%E5%89%8D%E7%AB%AF/img/20210312181535.png) - Python - 1. [Anaconda.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Anaconda.md) - 1. [Flask.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Flask.md) - 1. [如何用 Python 撰寫 APP.md](https://github.com/ShemYu/learning-resource/blob/master/Python/%E5%A6%82%E4%BD%95%E7%94%A8%20Python%20%E6%92%B0%E5%AF%AB%20APP.md) - 1. [如何處理比 memory 更大的資料.md](https://github.com/ShemYu/learning-resource/blob/master/Python/%E5%A6%82%E4%BD%95%E8%99%95%E7%90%86%E6%AF%94%20memory%20%E6%9B%B4%E5%A4%A7%E7%9A%84%E8%B3%87%E6%96%99.md) - 1. [親自動手寫一個 Python libary.md](https://github.com/ShemYu/learning-resource/blob/master/Python/%E8%A6%AA%E8%87%AA%E5%8B%95%E6%89%8B%E5%AF%AB%E4%B8%80%E5%80%8B%20Python%20libary.md) + 1. [Flask.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Flask.md) + 1. [如何用 Python 撰寫 APP.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/%E5%A6%82%E4%BD%95%E7%94%A8%20Python%20%E6%92%B0%E5%AF%AB%20APP.md) + 1. [如何處理比 memory 更大的資料.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/%E5%A6%82%E4%BD%95%E8%99%95%E7%90%86%E6%AF%94%20memory%20%E6%9B%B4%E5%A4%A7%E7%9A%84%E8%B3%87%E6%96%99.md) + 1. [親自動手寫一個 Python libary.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/%E8%A6%AA%E8%87%AA%E5%8B%95%E6%89%8B%E5%AF%AB%E4%B8%80%E5%80%8B%20Python%20libary.md) - Basic - 1. [cmd `python` 預設使用 python3.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Basic/cmd%20%60python%60%20%E9%A0%90%E8%A8%AD%E4%BD%BF%E7%94%A8%20python3.md) - 1. [Decorator.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Basic/Decorator.md) - 1. [PIP.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Basic/PIP.md) - 1. [Python 在 DevOps 中的應用.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Basic/Python%20%E5%9C%A8%20DevOps%20%E4%B8%AD%E7%9A%84%E6%87%89%E7%94%A8.md) + 1. [.gitingore.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/.gitingore.md) + 1. [Anaconda.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/Anaconda.md) + 1. [Decorator.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/Decorator.md) + 1. [Enum.ipynb](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/Enum.ipynb) + 1. [PIP.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/PIP.md) + 1. [Python 在 DevOps 中的應用.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/Python%20%E5%9C%A8%20DevOps%20%E4%B8%AD%E7%9A%84%E6%87%89%E7%94%A8.md) + 1. [Python 當中的 switch case.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/Python%20%E7%95%B6%E4%B8%AD%E7%9A%84%20switch%20case.md) + 1. [`python` command 預設使用 Python3.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/%60python%60%20command%20%E9%A0%90%E8%A8%AD%E4%BD%BF%E7%94%A8%20Python3.md) + 1. [函式基本概念.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/%E5%87%BD%E5%BC%8F%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5.md) + 1. [底線與命名規則.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/%E5%BA%95%E7%B7%9A%E8%88%87%E5%91%BD%E5%90%8D%E8%A6%8F%E5%89%87.md) - Class - 1. [Meta class.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Class/Meta%20class.md) - 1. [__new__ and __init__.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Class/__new__%20and%20__init__.md) + 1. [Meta class.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Class/Meta%20class.md) + 1. [__new__ and __init__.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Class/__new__%20and%20__init__.md) + - Error handling + 1. [Professional Error Handling With Python.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Error%20handling/Professional%20Error%20Handling%20With%20Python.md) - High quality code - 1. [Code quality.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Code%20quality.md) - 1. [Common practice of famous project.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Common%20practice%20of%20famous%20project.md) - 1. [PEP8.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/PEP8.md) + 1. [Code quality.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Code%20quality.md) + 1. [Common practice of famous project.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Common%20practice%20of%20famous%20project.md) + 1. [PEP8.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/PEP8.md) - Coding style - 1. [black.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Coding%20style/black.md) - 1. [Coding style.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Coding%20style/Coding%20style.md) - 1. [pylint.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Coding%20style/pylint.md) + 1. [black.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Coding%20style/black.md) + 1. [Coding style.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Coding%20style/Coding%20style.md) + 1. [pylint.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Coding%20style/pylint.md) - pre-commit - 1. [1_調研 pre-commit.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Coding%20style/pre-commit/1_%E8%AA%BF%E7%A0%94%20pre-commit.md) - 1. [2_pre-commit.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Coding%20style/pre-commit/2_pre-commit.md) - 1. [3_pre-commit 三度調研.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Coding%20style/pre-commit/3_pre-commit%20%E4%B8%89%E5%BA%A6%E8%AA%BF%E7%A0%94.md) + 1. [1_調研 pre-commit.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Coding%20style/pre-commit/1_%E8%AA%BF%E7%A0%94%20pre-commit.md) + 1. [2_pre-commit.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Coding%20style/pre-commit/2_pre-commit.md) + 1. [3_pre-commit 三度調研.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Coding%20style/pre-commit/3_pre-commit%20%E4%B8%89%E5%BA%A6%E8%AA%BF%E7%A0%94.md) - Docs - 1. [pydocstyle.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Docs/pydocstyle.md) + 1. [pydocstyle.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Docs/pydocstyle.md) - Testing - 1. [Flaky test.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Testing/Flaky%20test.md) - 1. [Pytest Coverage.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Testing/Pytest%20Coverage.md) - 1. [Pytest doctest.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Testing/Pytest%20doctest.md) - 1. [Pytest notebook.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Testing/Pytest%20notebook.md) - 1. [Pytest 測試實戰.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Testing/Pytest%20%E6%B8%AC%E8%A9%A6%E5%AF%A6%E6%88%B0.md) - 1. [初探Tox.md](https://github.com/ShemYu/learning-resource/blob/master/Python/High%20quality%20code/Testing/%E5%88%9D%E6%8E%A2Tox.md) + 1. [Flaky test.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Testing/Flaky%20test.md) + 1. [Pytest Coverage.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Testing/Pytest%20Coverage.md) + 1. [Pytest doctest.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Testing/Pytest%20doctest.md) + 1. [Pytest notebook.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Testing/Pytest%20notebook.md) + 1. [Pytest 測試實戰.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Testing/Pytest%20%E6%B8%AC%E8%A9%A6%E5%AF%A6%E6%88%B0.md) + 1. [初探Tox.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/High%20quality%20code/Testing/%E5%88%9D%E6%8E%A2Tox.md) - Pyproject - 1. [How to setup.py.md](https://github.com/ShemYu/learning-resource/blob/master/Python/Pyproject/How%20to%20setup.py.md) + 1. [How to setup.py.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Pyproject/How%20to%20setup.py.md) + - Signals + 1. [基本概念.md](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Signals/%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5.md) diff --git a/autogencontents/base/base_class.py b/autogencontents/base/base_class.py index b042e6a..8ec575b 100644 --- a/autogencontents/base/base_class.py +++ b/autogencontents/base/base_class.py @@ -51,10 +51,10 @@ def __init__(self, sec: Section, name): self.section = sec self.name = name # https://github.com/{OWNER_NAME}/{REPO_NAME}/blob/master/{PATH_TO_READING}/{READING_NAME} - self.url = "https://github.com/{}/{}/blob/master/{}/{}".format( + self.url = "https://github.com/{}/{}/blob/read/{}/{}".format( _OWNER_NAME, _REPO_NAME, - parse.quote("/".join(self.section.dirname_list[1:])), + parse.quote("/".join(self.section.dirname_list)), parse.quote(self.name), ) diff --git a/images/11881ed3d7b00ac9eb04565cb7b4b234bf7636505961198bebdb782f1d59bad2.png b/images/11881ed3d7b00ac9eb04565cb7b4b234bf7636505961198bebdb782f1d59bad2.png new file mode 100644 index 0000000..c8c8328 Binary files /dev/null and b/images/11881ed3d7b00ac9eb04565cb7b4b234bf7636505961198bebdb782f1d59bad2.png differ diff --git a/images/335fca4737ff8e86906e950d82059ddb5467eee98821edfd92eb047a6fb4662c.png b/images/335fca4737ff8e86906e950d82059ddb5467eee98821edfd92eb047a6fb4662c.png new file mode 100644 index 0000000..b6a0523 Binary files /dev/null and b/images/335fca4737ff8e86906e950d82059ddb5467eee98821edfd92eb047a6fb4662c.png differ diff --git a/images/b15944ec962e75bb73d815023828a1a7271d954a490dc07c9413f8130c87361e.png b/images/b15944ec962e75bb73d815023828a1a7271d954a490dc07c9413f8130c87361e.png new file mode 100644 index 0000000..7bfde37 Binary files /dev/null and b/images/b15944ec962e75bb73d815023828a1a7271d954a490dc07c9413f8130c87361e.png differ diff --git a/images/ca9d6512d3f47a7bdeb50ce25b5fb70f1ee36fdcad28606f4c70af893f058db5.png b/images/ca9d6512d3f47a7bdeb50ce25b5fb70f1ee36fdcad28606f4c70af893f058db5.png new file mode 100644 index 0000000..ddb53d6 Binary files /dev/null and b/images/ca9d6512d3f47a7bdeb50ce25b5fb70f1ee36fdcad28606f4c70af893f058db5.png differ diff --git a/reading/API/Dependencies injection.md b/reading/API/Dependencies injection.md new file mode 100644 index 0000000..e69de29 diff --git a/reading/API/Python API framework - FastAPI.md b/reading/API/Python API framework - FastAPI.md new file mode 100644 index 0000000..8396ab7 --- /dev/null +++ b/reading/API/Python API framework - FastAPI.md @@ -0,0 +1,7 @@ +# FastAPI + +## 設定更多欄位相關資訊 + +欄位相關的 `title`, `descriptions`, `validation` 資訊 + +[ref.](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#declare-more-metadata) diff --git "a/reading/Data science/Model serving/\345\210\235\346\216\242.md" "b/reading/Data science/Model serving/\345\210\235\346\216\242.md" new file mode 100644 index 0000000..4959b84 --- /dev/null +++ "b/reading/Data science/Model serving/\345\210\235\346\216\242.md" @@ -0,0 +1,20 @@ +# Model serving + +## What is serving + +Serving is how you apply a ML model after you've training. + +Most common way is RPC server. + +### Goals of model serving + +- Online, low latency +- Multiple model in a single process +- Multiple version of a model laoded over time +- Compute cost varies in real-time to meet product demand + - auto-scale with CloudML, Docker and K8S +- Aim for the efficiency of mini-batching at training time ... + - except with requests arriving asynchronously + +## Reference +- [Machine Learning Model Serving Overview (Seldon Core, KFServing, BentoML, MLFlow)](https://medium.com/everything-full-stack/machine-learning-model-serving-overview-c01a6aa3e823) \ No newline at end of file diff --git a/reading/Git/.gitingore.md b/reading/Git/.gitingore.md new file mode 100644 index 0000000..dfe297d --- /dev/null +++ b/reading/Git/.gitingore.md @@ -0,0 +1,144 @@ +# Python .gitignore +## 資源 +> ### [Github Python.gitignore](https://github.com/github/gitignore/blob/master/Python.gitignore) +> Github 官方提供的基本配置,包含了所有 Python 常用的相關模塊,其中需被 ignore 的檔案配置 +```yml +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ +``` \ No newline at end of file diff --git a/reading/Git/0_Git basic.md b/reading/Git/0_Git basic.md new file mode 100644 index 0000000..eb79835 --- /dev/null +++ b/reading/Git/0_Git basic.md @@ -0,0 +1,58 @@ +# Git basic knowladge +Git 是一款版本控管框架,且已經成為現今市場的主流,所有的軟體都透過 Git 的相關延伸做版本控管,因此我們要先了解版本控管。 +# 為什麼要做版本控管 +版本控管的目的很簡單,就是針對每次更新改版,為了確保每一次更動,不至於導致不可恢復的結果,因此版本控管就誕生了。 +![picture 1](../../images/ca9d6512d3f47a7bdeb50ce25b5fb70f1ee36fdcad28606f4c70af893f058db5.png) +然而衍伸出的問題也不只如此,一款大型專案不可能只有一個開發者,因此在合作時,必須要有一套邏輯去統整大家寫的 code,去避免發生每次把 code 互相合併時發生衝突。 +每次當有人想加入進行更新時,也可以隨時取得在管理處取得最新版本的程式,再進行開發,避免許多重工的問題。 + +那我們為什麼需要 `git`,傳統的版本控管做法是把檔案照這樣貼,我相信大家都有經歷過這樣的事情: +![picture 2](../../images/11881ed3d7b00ac9eb04565cb7b4b234bf7636505961198bebdb782f1d59bad2.png) +即便命名成這樣肉眼就能分辨時間與版本,但是在比較版本間的不同,與復原特定區塊程式時,卻不是這麼方便,僅能稱作檔案管理。 +選擇 `Git` 的原因便是因為它提供了簡單、快速、輕量的框架,在不造成負擔的情況下又能幫助開發者做到: +- 取得或上傳你的代碼 +- 依據版本管理代碼 +- 逐版本 highlight 不同處讓 code review 更加效率 +- 以分支(branch)的概念,輔助合作開發 + +# Git 是什麼 + +1. 免費、開源的版本控管軟體,base on Linux +2. 速度快、體積小 +3. 分散式系統,不需總是與伺服器做溝通,儘管仍有共用的伺服器,但是在不使用 push 指令上傳到代碼倉庫前,所有的 local 版控都是無需網路連線的 + +# Git 基本指令 + +`Git` 雖然有 command line interface 供使用者從 Terminal 進行操作,但是若不太熟悉 command line 也無須擔心,現在有很多軟體代為操作這些指令,只須熟悉指令代表的意涵即可。 + +以下方便初學者實作,皆以 `Vscode` 舉例 + +## clone + +藉由 repo_url 從 repository(非 local repo) 引入(克隆)至本機,預設取用所有版本、分支底下的資訊。 +### Usage +以 [Pandas](https://github.com/pandas-dev/pandas) 為例: +#### Vscode +- `CTRL`+`SHIFT`+`P` 並輸入指令 `git clone` + ![picture 1](../../images/b15944ec962e75bb73d815023828a1a7271d954a490dc07c9413f8130c87361e.png) +- 輸入 repo url + ![picture 2](../../images/335fca4737ff8e86906e950d82059ddb5467eee98821edfd92eb047a6fb4662c.png) + +## commit + + + +## push + +## pull + +## fetch + +## checkout + +## merge + +# Branch 的概念 + +分支(Branch) 是專案管理重要的一環,除了前面以時間軸來管理版本的維度外,`Branch` 提供了平行管理專案的方式: + diff --git "a/reading/Programing/\345\211\215\347\253\257/img/20210312181535.png" "b/reading/Programing/\345\211\215\347\253\257/img/20210312181535.png" new file mode 100644 index 0000000..a765f98 Binary files /dev/null and "b/reading/Programing/\345\211\215\347\253\257/img/20210312181535.png" differ diff --git "a/reading/Programing/\345\211\215\347\253\257/\345\276\214\347\253\257\346\200\216\351\272\274\345\215\200\345\210\206.md" "b/reading/Programing/\345\211\215\347\253\257/\345\276\214\347\253\257\346\200\216\351\272\274\345\215\200\345\210\206.md" new file mode 100644 index 0000000..78f9143 --- /dev/null +++ "b/reading/Programing/\345\211\215\347\253\257/\345\276\214\347\253\257\346\200\216\351\272\274\345\215\200\345\210\206.md" @@ -0,0 +1,19 @@ +# 前端與後端的差異 + +## 前端 + +- 在客戶端裝置上運行 +- 通常是跟資料呈現邏輯、簡單的資料驗證(email格式)有關 +- 使用者體驗 + - 介面設計 + - 互動 + +## 後端 +- 在伺服器端執行 +- 通常是較為複雜的資料驗證、處理 +- 資料庫讀寫 +- 資料庫設計規劃 +- 資料庫建置 +- API 規劃設計 + +![picture 1](../../../images/326931bee0d80242e3203d9c2e3d25bf2b85214d3b461955c16682c8d7aa38c8.png) diff --git a/reading/Python/API framework/Flask.md b/reading/Python/API framework/Flask.md new file mode 100644 index 0000000..063e022 --- /dev/null +++ b/reading/Python/API framework/Flask.md @@ -0,0 +1,25 @@ +# Flask + +Micro framework for building API. + +## Abstract + +Flask is the first API micro framework which provide a fast and easy way to build a API service. + +Just looks at it's documentation contents, You'll easily found out that the "micro" is their core principle. + +--- +> ### Note +> [Ref.](https://flask.palletsprojects.com/en/2.0.x/foreword/#what-does-micro-mean) +> ... The “micro” in microframework means Flask aims to keep the core simple but extensible. ... +--- + +Flask aslo be a framework that inspired the author of **FastAPI**. + +--- +> ### Note +> [Ref.](https://fastapi.tiangolo.com/alternatives/#flask) +> Be a micro-framework. Making it easy to mix and match the tools and parts needed. +> Have a simple and easy to use routing system. +--- + diff --git a/reading/Python/Anaconda.md b/reading/Python/Basic/Anaconda.md similarity index 51% rename from reading/Python/Anaconda.md rename to reading/Python/Basic/Anaconda.md index 1d40275..afceb22 100644 --- a/reading/Python/Anaconda.md +++ b/reading/Python/Basic/Anaconda.md @@ -2,14 +2,20 @@ # Abstract -Anaconda(簡稱 conda) 是 Python 其中一種建構虛擬環境的方式, -特色在於 conda 會把環境建置在系統目錄當中, -而非一般虛擬環境建構於專案目錄之下, -相比之下 conda 環境移植性較好, -但獨立性也較差。 - -> 如果需求偏向跨 project 共用環境,使用 Conda 就較為適合, -> 但是 Conda 也提供安裝於指定目錄的方法,與使用 virtualenv 的方式雷同 +`Anaconda`(一般也簡稱 `conda`) 是 Python 的虛擬環境的框架之一,特色在於 conda 會把環境建置在系統目錄當中,而非一般虛擬環境建構於專案目錄之下,相比之下 conda 環境移植性較好,但獨立性也較差。 + +優勢: +- 環境移植性高 + 跨專案共用環境時很方便 +- 易用性高 + 經整合專案 +缺點: +- Conda 虛擬環境較為肥大 +> [缺點補充文獻: 還我乾淨環境!怒砍Anaconda ! 手動移除windows Anaconda 殘留檔案!](https://medium.com/%E8%AA%A4%E9%97%96%E6%95%B8%E6%93%9A%E5%8F%A2%E6%9E%97%E7%9A%84%E5%95%86%E7%AE%A1%E4%BA%BAzino/%E9%82%84%E6%88%91%E4%B9%BE%E6%B7%A8%E7%92%B0%E5%A2%83-%E6%80%92%E7%A0%8Danaconda-%E6%89%8B%E5%8B%95%E7%A7%BB%E9%99%A4windows-anaconda-%E6%AE%98%E7%95%99%E6%AA%94%E6%A1%88-666d88eae69d) + +> ## 虛擬環境是什麼 +> 一般程式都是在系統環境下執行,倘若在同個系統開發多個專案,使用許多不同的 module 進行開發,便會無法區分這些專案分別相依於哪些 module,且可能發生套件(module)衝突。 +> 使用虛擬環境是進行開發的基本觀念,不管是不是使用 conda,只要使用了基本的虛擬環境框架(virtualenv, pyenv, ...) ,就可以在獨立環境下開發專案外,也能輕鬆匯出相依套件(例如 python 常用的 requirements.txt) # Installation ## Windows @@ -32,15 +38,18 @@ conda update conda ``` --- -## Virtual environment CRUD +## Virtual environment [CRUD](https://zh.wikipedia.org/wiki/%E5%A2%9E%E5%88%AA%E6%9F%A5%E6%94%B9) ### Create ### Basic + + +Create by env_name, and specific python.version(optional) ```bash $ conda create --name {env_name} python={python.version} ``` - env_name - Customize env_name for ```activate```. + Activate environment ```bash # Win @@ -77,7 +86,7 @@ $ conda env create -f environment.yml > 使用 yaml 則是使用 `conda env create`。 ### Create to specific path - +This method could create the virtual environment in a specific path or in project. ```bash $ conda create --prefix ./envs ``` @@ -110,7 +119,7 @@ $ conda env remove --name {env_name} ## Install package 基本上就是以 ```conda``` 取代 ```pip```, -但建議**盡量使用pip**安裝 Package +但建議**盡量使用pip**安裝 Package 確保套件的完整性與正確性。 ### Conda install ```bash diff --git a/reading/Python/Basic/Decorator.md b/reading/Python/Basic/Decorator.md index 4b7e187..dcfe702 100644 --- a/reading/Python/Basic/Decorator.md +++ b/reading/Python/Basic/Decorator.md @@ -1,8 +1,178 @@ # What is Decorator +- 中文名稱叫做**裝飾器**,好啦這不重要 +- 輸入 function,在其外層增加一些點綴,再回傳這個 function,名符其實吧 +- Decorator 可以是一個 function 也可以是一個 class,依照需求變動 + +馬上看看範例更有感覺: +```python +def print_func_name(func): + def wrap(): + print("Now use function '{}'".format(func.__name__)) + func() + return wrap + + +def dog_bark(): + print("Bark !!!") -- Decorator 是 Python 當中的避免重工的一種語法,能藉由傳遞 function 做參數的方式大量簡化程式碼。 -- Decorator 可以是一個 function 也可以是一個 class,主要目的相同,皆為避免重工。 +def cat_miaow(): + print("Miaow ~~~") + + +if __name__ == "__main__": + print_func_name(dog_bark)() + # > Now use function 'dog_bark' + # > Bark !!! + + print_func_name(cat_miaow)() + # > Now use function 'cat_miaow' + # > Miaow ~~~ +``` +上述案例當中的 `print_func_name` 就是一個裝飾器,但其實有 `syntax candy`: +```python +def print_func_name(func): + def warp(): + print("Now use function '{}'".format(func.__name__)) + func() + return warp + + +@print_func_name +def dog_bark(): + print("Bark !!!") + + +@print_func_name +def cat_miaow(): + print("Miaow ~~~") + + +if __name__ == "__main__": + dog_bark() + # > Now use function 'dog_bark' + # > Bark !!! + + cat_miaow() + # > Now use function 'cat_miaow' + # > Bark !!! +``` +只要用簡單的 `@` 就可以讓 Decorator 輕鬆地套用在 function 上。 +> ### 補充: `sytax candy` 中文稱語法糖或語法糖衣,意旨原本需要複雜的語法完成的邏輯,用更為簡單的方式實現 + +# Deocrator 的執行優先性 +Decorator 的優先性是比較需要注意的部分,雖然不難理解但若沒有了解過很容易弄錯 +```python +def print_func_name(func): + def warp_1(): + print("Now use function '{}'".format(func.__name__)) + func() + return warp_1 + + +def print_time(func): + import time + def warp_2(): + print("Now the Unix time is {}".format(int(time.time()))) + func() + return warp_2 + + +@print_func_name +@print_time +def dog_bark(): + print("Bark !!!") + + +@print_time +@print_func_name +def cat_miaow(): + print("Miaow !!!") + + +if __name__ == "__main__": + dog_bark() + # > Now use function 'warp_2' + # > Now the Unix time is 1541239747 + # > Bark !!! + + cat_miaow() + # > Now the Unix time is 1541239747 + # > Now use function 'cat_miaow' + # > Miaow !!! +``` +以 syntax candy 的形式來看,可能不好理解,但若以一般語法來看,應該就不難理解為什麼: +`print_time(print_func_name(cat_miao))` + +# Decorator 可以是一個 Class +Decorator 不局限於 function 的形式,Decorator 也可以是一個 Class: +```python +class Dog: + def __init__(self, func): + self.talent = func + + def bark(self): + print("Bark !!!") + + +@Dog +def dog_can_pee(): + print("I can pee very hard......") + + +@Dog +def dog_can_jump(): + print("I can jump uselessly QQQ") + + +@Dog +def dog_can_poo(): + print("I can poo like a super pooping machine!") + + + +if __name__ == "__main__": + dog_1 = dog_can_pee + dog_1.talent() + # > I can pee very hard...... + + dog_2 = dog_can_jump + dog_2.talent() + # > I can jump uselessly QQQ + + dog_3 = dog_can_poo + dog_3.talent() + # > I can poo like a super pooping machine! +``` +上述例子便是把 input 進入 Dog 類別的 function 動態設定成一個 function,便可透過統一介面( `Dog.talent` )呼叫 + +# Decorator 甚至可以帶入參數 +```python +import time + + +def print_func_name(time): + def decorator(func): + def warp(): + print("Now use function '{}'".format(func.__name__)) + print("Now Unix time is {}.".format(int(time))) + func() + return warp + return decorator + + +@print_func_name(time=(time.time())) +def dog_bark(): + print("Bark !!!") + + + +if __name__ == "__main__": + dog_bark() + # > Now use function 'dog_bark' + # > Now Unix time is 1541296864.2953653. + # > Bark !!! +``` # What is class method diff --git a/reading/Python/Basic/Enum.ipynb b/reading/Python/Basic/Enum.ipynb new file mode 100644 index 0000000..cedf54a --- /dev/null +++ b/reading/Python/Basic/Enum.ipynb @@ -0,0 +1,211 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.1-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "python3", + "display_name": "Python 3.9.1 64-bit ('uap': conda)", + "metadata": { + "interpreter": { + "hash": "5b137cdaa85d94f5bb8a937fafc18250e815bb77e5329a665b644e0046044e61" + } + } + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "from enum import Enum # Enum is std library of Python" + ] + }, + { + "source": [ + "# 枚舉類型\n", + "- 繼承 Enum 建立類別\n", + "- Enum 會針對枚舉當中的成員,逐一初始化(`__init__`)\n", + "- 枚舉當中的成員的 value 不得重複,否則會無法從 value 取回正確的成員名稱" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "# 繼承 Enum 建立類別\n", + "class Similarity1(Enum):\n", + " hamming_distance = (\"_hamming_distance\")\n", + " test = (\"_hamming_distance\")\n", + "\n", + " def __init__(self, method_):\n", + " self.method = getattr(self, method_)\n", + "\n", + " def _hamming_distance(self, x, y):\n", + " return x + y\n" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "3" + ] + }, + "metadata": {}, + "execution_count": 42 + } + ], + "source": [ + "Similarity1.hamming_distance.method(1,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'hamming_distance'" + ] + }, + "metadata": {}, + "execution_count": 47 + } + ], + "source": [ + "# 取回錯誤的 name\n", + "Similarity1.test.name" + ] + }, + { + "source": [ + "# 類別靜態方法\n", + "- 撰寫起來較為快速直觀\n", + "- 要使用下標取得成員需撰寫 `__getitem__` 類方法" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [], + "source": [ + "class Similarity2():\n", + " @staticmethod\n", + " def hamming_distance(x, y):\n", + " return x + y" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "3" + ] + }, + "metadata": {}, + "execution_count": 49 + } + ], + "source": [ + "Similarity2.hamming_distance(1, 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "def if_this_is_a_function_need_to_swtich_case(some_condition=\"hamming_distance\"):\n", + " # Enum interface let it be subscriptable\n", + " result1 = Similarity1[some_condition].method(1, 2)\n", + " # Class staticmethod is not subscriptable\n", + " result2 = getattr(Similarity2, some_condition)(1, 2)\n", + " return result1, result2\n" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(3, 3)" + ] + }, + "metadata": {}, + "execution_count": 51 + } + ], + "source": [ + "if_this_is_a_function_need_to_swtich_case()" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "output_type": "error", + "ename": "TypeError", + "evalue": "'type' object is not subscriptable", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mSimilarity2\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"hamming_distance\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m: 'type' object is not subscriptable" + ] + } + ], + "source": [ + "Similarity2[\"hamming_distance\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/reading/Python/Basic/Function's arguments.md b/reading/Python/Basic/Function's arguments.md new file mode 100644 index 0000000..77828e0 --- /dev/null +++ b/reading/Python/Basic/Function's arguments.md @@ -0,0 +1,40 @@ +# Function's arguments + +## Position arguments, Named arguments + +### Position arguments + +用引入順序(位置)做判斷的參數,或稱 `arguments`, `args`: + +```python +def function_a(a, b, c): + pass + +function_a(1, 2, 3) +``` + +### Named argumenst + +用關鍵字為他命名的參數,或稱 `keyword arguments`, `kwargs`: + +```python +def function_b(a=None, b=None, c=None): + ... + +function_b(a=1, b=2, c=3) +``` + +### Mixing + +前兩者混合時,需注意 position arguments 需在 named arguments 的**前面**(由於 positions arguments 需藉由位置判斷,如果不做規範會混亂): + +```python +def function_mix(a, b, c=None): + ... +``` + +## 不固定的參數介接方式 + +```python +def get() +``` \ No newline at end of file diff --git a/reading/Python/Basic/PIP.md b/reading/Python/Basic/PIP.md index b7002ad..dfc571d 100644 --- a/reading/Python/Basic/PIP.md +++ b/reading/Python/Basic/PIP.md @@ -1,10 +1,15 @@ # PIP install 入門 +`pip` 是 Python standard module 之一,主要用來做 module 相關的工作,例如最常用的 `pip install` 就是用來安裝 module 的 command;`pip freeze > requirements.txt` 用來將現在環境當中安裝的套件及版本匯出至 `requirement.txt` 當中。 +pip 的安裝是藉由使用者給的 module name,從 [pypi server](https://pypi.org/) 上搜尋同名稱的 module 進行下載安裝,使用者也能藉由 options 更換成不同的 pypi server。 + +> ## [Pypi server](https://zh.wikipedia.org/wiki/PyPI) +> PyPI(英語:Python Package Index,簡稱PyPI)是Python的正式第三方( official third-party)軟體包的軟體存儲庫,它類似於CPAN(Perl的存儲庫)。一些軟體包管理器例如pip,就是默認從PyPI下載軟體包。用戶通過PyPI可以下載超過235,000個Python軟體包。 ## 常用指令 - 安裝 Install - ```bash + ```bash- $ pip install {module_name} ``` - 更新 Update diff --git "a/reading/Python/Basic/Python \347\225\266\344\270\255\347\232\204 switch case.md" "b/reading/Python/Basic/Python \347\225\266\344\270\255\347\232\204 switch case.md" new file mode 100644 index 0000000..8fa3446 --- /dev/null +++ "b/reading/Python/Basic/Python \347\225\266\344\270\255\347\232\204 switch case.md" @@ -0,0 +1,55 @@ +# Switch case in Python +大家有這個經驗嗎,想要撰寫一隻程式統一街口,給定使用者參數選擇運算用的底層邏輯,因此寫出這樣的方法: + +```python +def _similarity_fun(x, y, similarity_func): + if isinstance(similarity_func, str): + if similarity_func == "hamming_distance": + result = hamming_distance(x, y) + elif similarity_func == "levenshtein_distance": + result = levenshtein_distance(x, y) + elif similarity_func == "levenshtein_similarity": + result = levenshtein_similarity(x, y) + elif similarity_func == "jcro_similarity": + result = _jcro_similarity(x, y) + elif similarity_func == "jaro_winkler_similarity": + result = _jaro_winkler_similarity(x, y) + elif similarity_func == "damerau_levenshtein_distance": + result = _damerau_levenshtein_distance(x, y) + elif similarity_func == "common_sequence_distance": + result = _common_sequence_distance(x, y) + elif similarity_func == "jaccard_score": + result = jaccard_score(x, y) + elif similarity_func == "jaccard_distance": + result = jaccard_distance(x, y) + elif similarity_func == "manhattan_distance": + result = manhattan_distance(x, y) + elif similarity_func == "euclidean_distance": + result = euclidean_distance(x, y) + elif similarity_func == "euclidean_distance_square": + result = euclidean_distance_square(x, y) + elif similarity_func == "euclidean_distance_centred": + result = euclidean_distance_centred(x, y) + elif similarity_func == "cosine_similarity": + result = cosine_similarity(x, y) + elif similarity_func == "cosine_distance": + result = cosine_distance(x, y) + else: + raise ValueError("Not yet support similarity function") + else: + result = similarity_func(x, y) + return result +``` +上面這種寫法除了**複雜度**過高外,也存在使用上的問題,例如今天這個方法的複雜度是否有高到使用者會願意去記住你的參數(輸入的 string name),還是使用者記得數學邏輯會自己寫一個方式來算。這種時候學過其他語言的朋友可能會說: + + 可以用 Swtich case 阿,怎麼不用 Swtich case + +但實際上在 Python 程式語言當中,其實不存在 Swtich case 語法,因此我會建議使用物件導向的方式解決這種問題,以物件導向方式限制使用者的輸入: +```python +class Similarity(): + @classmethod + def method1(cls, x, y): + return dosomething.. +``` + +祥見 [Enum code example](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/Enum.ipynb) \ No newline at end of file diff --git "a/reading/Python/Basic/`python` command \351\240\220\350\250\255\344\275\277\347\224\250 Python3.md" "b/reading/Python/Basic/`python` command \351\240\220\350\250\255\344\275\277\347\224\250 Python3.md" new file mode 100644 index 0000000..b9a5730 --- /dev/null +++ "b/reading/Python/Basic/`python` command \351\240\220\350\250\255\344\275\277\347\224\250 Python3.md" @@ -0,0 +1,14 @@ +# 解決 macos 底下 `python` 指令使用 python2.7 的問題 + +首先通過以下文章了解到問題成因: +> 我們來查看 /usr/local/bin 目錄下,你會發現並沒有 Python 3 提供的 python 可執行檔,而只有 python3 執行檔,因此當你輸入 python 時, Mac 因為來到 /usr/local/bin 目錄下沒有找到 python 可執行檔,才會保持原先的狀態,近一步往下一個位置找,並找到內建的版本,直接使用內建的 python 2.7。 +> ##### [Python - 安裝 Python3 在 Mac 上 (Python 3.6.5 為例)](https://note.koko.guru/python-install-python3-on-mac.html) + +換句話說就是因為抓不到 `./bin/python`,因此系統自作主張從 `/usr/bin/` 底下找到了內建的 `Python2.7` 來使用,導致了這個錯誤。 +因此若要修正他,僅需把當前裝置上的 Python3 路徑找到,並將所在的 `../bin` 加入環境變數 `$PATH` 當中,便能解決此問題。 + + +# Referenece + +1. [How to switch between python 2.7 to python 3 from command line? +](https://stackoverflow.com/questions/18058389/how-to-switch-between-python-2-7-to-python-3-from-command-line) \ No newline at end of file diff --git "a/reading/Python/Basic/cmd `python` \351\240\220\350\250\255\344\275\277\347\224\250 python3.md" "b/reading/Python/Basic/cmd `python` \351\240\220\350\250\255\344\275\277\347\224\250 python3.md" deleted file mode 100644 index 26b4be8..0000000 --- "a/reading/Python/Basic/cmd `python` \351\240\220\350\250\255\344\275\277\347\224\250 python3.md" +++ /dev/null @@ -1,5 +0,0 @@ - -# Referenece - -1. [How to switch between python 2.7 to python 3 from command line? -](https://stackoverflow.com/questions/18058389/how-to-switch-between-python-2-7-to-python-3-from-command-line) \ No newline at end of file diff --git "a/reading/Python/Basic/\345\207\275\345\274\217\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/reading/Python/Basic/\345\207\275\345\274\217\345\237\272\346\234\254\346\246\202\345\277\265.md" new file mode 100644 index 0000000..8ef8073 --- /dev/null +++ "b/reading/Python/Basic/\345\207\275\345\274\217\345\237\272\346\234\254\346\246\202\345\277\265.md" @@ -0,0 +1,24 @@ +# What is function +函式是程式語言當中**降低重工**的一大語法,寫出優質的函示能**提升整體軟體架構**以及**提升可維護性**、**可讀性**,是合作必備的基礎技能。 +以下重點介紹參考文獻的這五個重點,並寫下重點心得: +- 函式(Function)結構 + > 函式基本結構與知識 +- 函式(Function)參數 + > 如何帶入參數,提供函式變量 +- 函式(Function) *args、**kwargs運算子 + > Position args, Named kwargs 是什麼,參數引入的方式 +- 函式(Function)種類 + > return or not +- 函式(Function)變數範圍(Scope) + > 函式的生命週期 + +> # Note +> ## 生命週期 +> 變數、函式都有生命週期,所謂的生命周期指的就是該函式、變數,可以被呼叫(還活著的感覺)的範圍,超出生命週期代表無法被呼叫(如同死了),一般分為: +> 1. 全域 Global +> 1. 局域 Local +> ## 重工 +> 重複代碼一直撰寫稱之為重工,重複使用到的相同代碼若需維護,需要在多處進行維護,此種情況稱為**可維護性低**。因此將重複代碼整合成一個 function 統一進行維護管理,是**提升可維護性**。 +> ## Reference +> [函式的五個基本常識](https://www.learncodewithmike.com/2019/12/python-function.html) +> 在寫程式碼時有一個非常重要的觀念是DRY(Don’t Repeat Yourself),意思是避免同樣的程式碼重複出現在很多個地方,除了可讀性很低外,也不易維護。所以要適當的進行封裝,來達到程式碼的重用性(Reusable)。 \ No newline at end of file diff --git "a/reading/Python/Basic/\345\272\225\347\267\232\350\210\207\345\221\275\345\220\215\350\246\217\345\211\207.md" "b/reading/Python/Basic/\345\272\225\347\267\232\350\210\207\345\221\275\345\220\215\350\246\217\345\211\207.md" new file mode 100644 index 0000000..28fdab9 --- /dev/null +++ "b/reading/Python/Basic/\345\272\225\347\267\232\350\210\207\345\221\275\345\220\215\350\246\217\345\211\207.md" @@ -0,0 +1,80 @@ +# 底線家族的秘密 +菜鳥時期,在開發前 trace code 階段,初次接觸到別人程式時,就發現類別相關語法,運用了大量的 `_`,當時啥都不懂整個霧煞煞,稍微查了一下才發現 Python 當中**底線家族**是十分重要的變數命名規則之一。 + +### Medium +> ### 原文 [Python Tricks — 底線家族的秘密](https://medium.com/python-language/python-tricks-%E5%BA%95%E7%B7%9A%E5%AE%B6%E6%97%8F%E7%9A%84%E7%A7%98%E5%AF%86-d84a2ce9cde6) + +第一篇我閱讀了這篇 Medium,是由主管轉帖給我,讓我好好理解 Python 底線的運用,其中介紹了許多關於底線的運用情境、規則,是否有特殊意涵等,整理為以下幾項: + +## 單底線 (Undersocre, _) +- 顧名思義**就是一個底線**,其他啥都沒 +- Shell 環境下: **最後一次的執行結果** +- 當不需要某回傳值,以 `_` 表示就**無需儲存為變數,占用記憶體空間** + +## 前底線 (_single_leading_underscore) +- 代表著 C++, JAVE 當中的 **Private** +> ## Python.org +> “Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a method or a data member) +- 僅是一種慣例,並**不強制隱藏**,因此仍能從外部進行 CRUD +- `import *` 會被忽略,但仍可強制 import,或透過 `__all__`(後續介紹) 定義可 import + +## 後底線 (single_trailing_underscore_) +- 如果你把語言保留關鍵字(Keyword) 作為變數名稱使用,則須加上此種底線 +- 非強制性,僅為一種命名規則或代碼風格建議 + +## 前雙底線 (__double_leading_underscore) +- 又稱為 **dunder** +- 為直譯器為**避免發生衝突**的命名方式,此種變數命名於類別當中,便自動直譯為 `_Class__varName` 的形式 + +## 前後雙底線 (__double_leading_and_trailing_underscore__) +- 保留**特殊用途**的 function name +- 可依據用途,供使用者作**複寫**,例如初始化物件時的 `__init__` +> ## Python.org +> `__double_leading_and_trailing_underscore__`: “magic” objects or attributes that live in user-controlled namespaces. E.g. `__init__`, `__import__` or `__file__`. Never invent such names; only use them as documented +- 又稱為 **Magic method** +# Magic method of Python + +Magic method 指的是 Pyhton 為類別預定義的一些常用方法,例如定義類別的字串形式、實作時執行的方法、運算單元處理的方法等。 + +```python +class Example(): + def __init__(self): + # 實作時觸發 + def __str__(self): + # 字串形式 + return "Str type of class" + def __add__(self, value): + return self.A + value +``` +--- +## `__init__` 及 `__new__` 差別是什麼 +其中最常使用的就是 `__init__`,實作 class 時會觸發的方法。 +雖然並非必須使用,但往往會遇到實作時需要處裡的類別,例如從生日計算年齡、從體重身高推算 BMI,甚至給定資料路徑,初始化先 loading 資料進物件當中,在依據使用者需求作客製化處理等。 + +```python +class human(): + def __init__(self, birth): + self.age = time.today().year - self.birth.year + self.birthday = birth +``` + +跟 `__init__` 十分相近的則是 `__new__`,不同的是 init 是在類別實作成物件時觸發,而 new 是在實作類別本身時就會觸發,也因此他的引數不是代表該實作**物件**本身的 `self`,而是代表**類別**本身的 `cls`。 + +```python +class human(): + def __new__(cls, name, age): + print("Do when you new a `class`.") + return super(human, cls).__new__(cls, name, age) +``` + +在以下文章當中有詳細關於 `__init__`, `__new__` 的調用邏輯,可供參考。 +> ## [Python 中的 `__init__` 和 `__new__`](https://www.zlovezl.cn/articles/__init__-and__new__-in-python/) +> `__init__` 和 `__new__` 最主要的区别在于: +> - `__init__` 通常用于初始化一个新实例,控制这个初始化的过程,比如添加一些属性, 做一些额外的操作,发生在类实例被创建完以后。它是实例级别的方法。 +> - `__new__` 通常用于控制生成一个新实例的过程。它是类级别的方法。 + +在 Python 的官方文件當中,`__new__` 被說明為以下兩種用途: +- 當你在繼承一些無法複寫的類別時,可以使用 `__new__` 來做一種自定義 +- 實作自定義之 `metaclass` + +--- \ No newline at end of file diff --git a/reading/Python/Class/0_Python class.md b/reading/Python/Class/0_Python class.md new file mode 100644 index 0000000..d8192e1 --- /dev/null +++ b/reading/Python/Class/0_Python class.md @@ -0,0 +1,3 @@ +# Python 類別設計 + +https://chenhh.gitbooks.io/parallel_processing/content/cython/python_class.html \ No newline at end of file diff --git a/reading/Python/Class/Magic or Dunder method in Python.md b/reading/Python/Class/Magic or Dunder method in Python.md new file mode 100644 index 0000000..fd6eb26 --- /dev/null +++ b/reading/Python/Class/Magic or Dunder method in Python.md @@ -0,0 +1,111 @@ +# Magic or Dunder method in Python + +此篇會簡單介紹類別常用的 Magic method 及相關範例,參考文獻如下: +- [Magic method in Python](https://www.tutorialsteacher.com/python/magic-methods-in-python) + +--- +## `__new__` + +Python 當中的類別到物件實作過程: + +1. `__new__` +2. `__init__` + +因此在設計了上述兩者的類別,Python 會先將類別 new 出物件,再藉由 init 實作,導致了以下結果: + +```python +class Employee: + def __new__(cls): + print ("__new__ magic method is called") + inst = object.__new__(cls) + return inst + def __init__(self): + print ("__init__ magic method is called") + self.name='Satya' +``` + +```bash +>>> emp = Employee() +__new__ magic method is called +__init__ magic method is called +``` + +--- +## `__str__` + +類別的字串型態之呈現邏輯,形同對該類別實作之物件使用 `str()` 方法。 + +```python +num = 12 +str(num) # '12' +``` + +複雜一點的範例: +```python +class Employee: + def __init__(self): + self.name='Swati' + self.salary=10000 + def __str__(self): + return 'name='+self.name+' salary=$'+str(self.salary) +``` +```python +e1 = Employee() +print(e1) # name=Swati salary=$10000 +``` +--- +## `__add__` + +定義物件如何執行相加的動作。 +```python +class distance: + def __init__(self, x=None,y=None): + self.ft=x + self.inch=y + def __add__(self,x): + temp=distance() + temp.ft=self.ft+x.ft + temp.inch=self.inch+x.inch + if temp.inch>=12: + temp.ft+=1 + temp.inch-=12 + return temp + def __str__(self): + return 'ft:'+str(self.ft)+' in: '+str(self.inch) +``` +```python +d1=distance(3,10) +d2=distance(4,4) +print("d1= {} d2={}".format(d1, d2)) +# d1= ft:3 in: 10 d2=ft:4 in: 4 +d3=d1+d2 +print(d3) +# ft:8 in: 2 +``` +--- +## `__ge__` + +代表 `>=` 運算符 + +```python +class distance: + def __init__(self, x=None,y=None): + self.ft=x + self.inch=y + def __ge__(self, x): + val1=self.ft*12+self.inch + val2=x.ft*12+x.inch + if val1>=val2: + return True + else: + return False +``` +```python +d1 = distance(2,1) +d2 = distance(4,10) +print(d1 >= d2) +# False +``` +--- + +更多 Magic methods in Python 請見[參考文獻](https://www.tutorialsteacher.com/python/magic-methods-in-python)。 \ No newline at end of file diff --git a/reading/Python/Class/Meta class.md b/reading/Python/Class/Meta class.md index 686526b..37db7f9 100644 --- a/reading/Python/Class/Meta class.md +++ b/reading/Python/Class/Meta class.md @@ -11,6 +11,10 @@ class MyClass(metaclass=MyMeta): class MySubclass(MyClass): pass + +if __name__ == "__main__": + MyClass = MyMeta() + my_object = MyClass() ``` 簡單的定義三種不同的類別: diff --git a/reading/Python/Error handling/Professional Error Handling With Python.md b/reading/Python/Error handling/Professional Error Handling With Python.md new file mode 100644 index 0000000..6b9b1a1 --- /dev/null +++ b/reading/Python/Error handling/Professional Error Handling With Python.md @@ -0,0 +1,112 @@ +# Professional Error Handling With Python +## 心得 +文中有簡單介紹 Python 有哪些 Exceptions,並教學如何撰寫自定義 Exception,以及自定義的 Exception 類別當中,一般可以實作哪些參數,如何作錯誤處理,想了解 Error Handling 基礎知識建議看過此篇。 + +> ## [Professional Error Handling With Python](https://code.tutsplus.com/tutorials/professional-error-handling-with-python--cms-25950) +> In this tutorial you'll learn how to handle error conditions in Python from a whole system point of view. Error handling is a critical aspect of design, and it crosses from the lowest levels (sometimes the hardware) all the way to the end users. If you don't have a consistent strategy in place, your system will be unreliable, the user experience will be poor, and you'll have a lot of challenges debugging and troubleshooting. +> +> The key to success is being aware of all these interlocking aspects, considering them explicitly, and forming a solution that addresses each point. + +## Python Excetions +``` +BaseException + + +-- SystemExit + + +-- KeyboardInterrupt + + +-- GeneratorExit + + +-- Exception + + +-- StopIteration + + +-- StandardError + + | +-- BufferError + + | +-- ArithmeticError + + | | +-- FloatingPointError + + | | +-- OverflowError + + | | +-- ZeroDivisionError + + | +-- AssertionError + + | +-- AttributeError + + | +-- EnvironmentError + + | | +-- IOError + + | | +-- OSError + + | | +-- WindowsError (Windows) + + | | +-- VMSError (VMS) + + | +-- EOFError + + | +-- ImportError + + | +-- LookupError + + | | +-- IndexError + + | | +-- KeyError + + | +-- MemoryError + + | +-- NameError + + | | +-- UnboundLocalError + + | +-- ReferenceError + + | +-- RuntimeError + + | | +-- NotImplementedError + + | +-- SyntaxError + + | | +-- IndentationError + + | | +-- TabError + + | +-- SystemError + + | +-- TypeError + + | +-- ValueError + + | +-- UnicodeError + + | +-- UnicodeDecodeError + + | +-- UnicodeEncodeError + + | +-- UnicodeTranslateError + + +-- Warning + + +-- DeprecationWarning + + +-- PendingDeprecationWarning + + +-- RuntimeWarning + + +-- SyntaxWarning + + +-- UserWarning + + +-- FutureWarning + + +-- ImportWarning + + +-- UnicodeWarning + + +-- BytesWarning + +``` \ No newline at end of file diff --git a/reading/Python/High quality code/Testing/Pytest asyncio.md b/reading/Python/High quality code/Testing/Pytest asyncio.md new file mode 100644 index 0000000..b479fba --- /dev/null +++ b/reading/Python/High quality code/Testing/Pytest asyncio.md @@ -0,0 +1 @@ +[github](https://github.com/pytest-dev/pytest-asyncio) \ No newline at end of file diff --git a/reading/Python/High quality code/Testing/Pytest fixture and conftest.md b/reading/Python/High quality code/Testing/Pytest fixture and conftest.md new file mode 100644 index 0000000..7099491 --- /dev/null +++ b/reading/Python/High quality code/Testing/Pytest fixture and conftest.md @@ -0,0 +1,7 @@ +# Pytest fixture and conftest + +當測試中有需要重複使用或讀取的資料,可以藉由 `pytest.fixture` 讓各個測試共用,減少重複讀取檔案的 Loading。 + +## Scope + +## 內置 fixture \ No newline at end of file diff --git "a/reading/Python/High quality code/Testing/Pytest \346\270\254\350\251\246\345\257\246\346\210\260.md" "b/reading/Python/High quality code/Testing/Pytest \346\270\254\350\251\246\345\257\246\346\210\260.md" index 2553457..a557062 100644 --- "a/reading/Python/High quality code/Testing/Pytest \346\270\254\350\251\246\345\257\246\346\210\260.md" +++ "b/reading/Python/High quality code/Testing/Pytest \346\270\254\350\251\246\345\257\246\346\210\260.md" @@ -14,10 +14,11 @@ Pytest 有以下幾項優點: 原生 assert 的運用 ```python - # Pytest - assert a == b - # unittest - self.assertEqual(a, b) + def test_is_equal(a, b): + # Pytest + assert a == b + # unittest + self.assertEqual(a, b) ``` 1. 可讀性強 @@ -53,24 +54,28 @@ Pytest 有以下幾項優點: - 偵測方式 : 從當前目錄底下搜尋 ```test_``` 開頭或是 ```_test``` 結尾之測試程式檔案進行測試 - +- 指定目錄 + ```bash $ pytest {Options} {test_path} ``` -- 指定目錄 +- 指定 function or class 透過```::```指定程式當中的方法或類別,可同時指定多個目錄或檔案 ```bash - $ python {*.py or path/u/want}::{function_name or ClassName} + $ pytest {*.py or path/u/want}::{function_name or ClassName} ``` + +- 指定 Class 當中之 function + 或甚至指定類別當中的特定方法 ```bash $ pytest {*.py or path/u/want}::{ClassName}::{function_of_the_Calss} ``` - 例如 + Example ``` $ pytest tests/creature/animal.py::Dog::eat ``` @@ -140,23 +145,30 @@ Pytest 會逐測試程式當中每個 function ,依照測試結果標記為以 ### **skip** ```python -@pytest.mark.skip(reason="not done") +@pytest.mark.skip(reason="Module update, not finish yet.") def test_function_1(): - do something + ... ``` ### **skipif** ```python @pytest.mark.skipif(version < "0.2.0", reason="not support until ver. 0.2.0") def test_function_2(): - do something + """Test for version < 0.2.0""" + ... +``` +### **Customize mark** +自行定義的標籤,用以分類測試 +```python +@pytest.mark.load +def test_loading(): + ... ``` - ### **xfail** -預期測試失敗,例如想測試是否輸入錯誤的變數型態、 +預期測試失敗,用以測試是否會 raise Exception。 ```python -@pytest.mark.xfail(reason="not done") +@pytest.mark.xfail(reason="Its suppost to be failed.") def test_function_1(): - do something + raise Exception ``` 也由於 XPASS 的定義較為模糊,可以在 pytest.ini 中設定為嚴格模式,將 XPASS 視為 FAILED。 @@ -206,29 +218,32 @@ def test_of_something(): ## Parametrized testing -When testing some method should repeatly call the same method, you can use pytest decorater `@pytest.mark.parametrize` to loop the same method with different parameters. +When testing some method should repeatly call the same method, you can use pytest decorater `@pytest.mark.parameterize` to loop the same method with different parameters. -當有些較為繁瑣,必須重複執行的測試,需要藉由 testcase 完整覆蓋測試邏輯時,可以藉由 `@pytest.mark.parametrize` 對同一個 method 迴圈輸入指定的參數。 +當有些較為繁瑣,必須重複執行的測試,需要藉由 testcase 完整覆蓋測試邏輯時,可以藉由 `@pytest.mark.parameterize` 對同一個 method 迴圈輸入指定的參數。 ```python -import ptest -@pytest.mark.parametrize('num', [1, 2, 3, 4, 5, 6, 7, 8, 9]) +import pytest + +num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] + +@pytest.mark.parameterize('num', num_list) def test_is_odd(num): assert num%2 == 0 ``` -You can assign multi arguments for sure. + -當然也可以輸入多個參數。 + ```python -@pytest.mark.parametrize('num1, num2', - [ - (1, 2), - (3, 4), - (5, 6) - ] - ) +args_list = [ + (1, 2), + (3, 4), + (5, 6) +] + +@pytest.mark.parameterize('num1, num2', args_list) def test_add(num1, num2): assert add(num1, num2) == num1+num2 ``` @@ -239,6 +254,17 @@ fixture 是提供 pytest 測試前後配置的模塊,提供完整的測試配 conftest.py 也可以不只存在一個,conftest 生命週期為其所在位置之子目錄,可以把其視為該層級底下之 fixture 倉庫。 +```python +@pytest.fixture(scope="session") +def data_file(): + with open("data/file.txt", "r") as f: + return f.read() +``` +```python +def test_funtion_a(data_file): + function_a(data_file) + ... +``` # Configuration of pytest diff --git a/reading/Python/High quality code/Testing/Why we test.md b/reading/Python/High quality code/Testing/Why we test.md new file mode 100644 index 0000000..139ec53 --- /dev/null +++ b/reading/Python/High quality code/Testing/Why we test.md @@ -0,0 +1,11 @@ +# Why we testing + +## Abstract + +測試在開發環節當中我認為是可小可大,小從簡單驗證預期書出結果,大至開發模式規模的測試。但不論何種測試,都是對程式穩定性有保證,且大大提升可靠度,好的測試我個人認為甚至是可以增加開發效率。 + +## 測試框架 + +Python 官方有提供測試框架 unittest,但測試語法需繼承測試類別,再用類別方法 assertTrue, aasertFalse。 + +Pytest 提供開源、容易上手的語法,且不同於 unittest 使用自定義方法進行檢查輸出結果,Pytest 使用原生的斷言 `assert` 進行判斷。且 Pytest 開源,因此相關插件資源豐富。 \ No newline at end of file diff --git a/reading/Python/Pyproject/How to setup.py.md b/reading/Python/Pyproject/How to setup.py.md index 65ebcfc..ddc7bd5 100644 --- a/reading/Python/Pyproject/How to setup.py.md +++ b/reading/Python/Pyproject/How to setup.py.md @@ -1 +1,5 @@ -# How to setup.py \ No newline at end of file +# How to setup.py + +# Reference + +- [編寫自己的 setup.py](https://zhuanlan.zhihu.com/p/25202530) \ No newline at end of file diff --git "a/reading/Python/Signals/\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/reading/Python/Signals/\345\237\272\346\234\254\346\246\202\345\277\265.md" new file mode 100644 index 0000000..7128f5c --- /dev/null +++ "b/reading/Python/Signals/\345\237\272\346\234\254\346\246\202\345\277\265.md" @@ -0,0 +1,30 @@ +# Whats Signals, Dispatch + +Signal 如同其名是一種訊號的概念,用專業術語來解釋的話: + +> a `receiver` (or `listener`) may `subscribe` (or `listen`) to the `signal` of a `sender`. When the `sender` sends (or `broadcasts`) a `signal`, the `receiver` is called +> 接收對象會持續監聽到來自特定對象(Sender)的訊號;當該對象發出(廣播出)訊號的同時,接收對象就會被呼叫。 + +簡單來說,便是藉由代碼連接 receiver, sender,針對特定方法進行 callback。 + +> # Dispatch: signal broadcasting in python +> Signals are useful when two otherwise unrelated pieces of code depend on each other. The general pattern is that a receiver (or listener) may subscribe (or listen) to the signal of a sender. When the sender sends (or broadcasts) a signal, the receiver is called. + +PyPubSub 文件當中提及了一些使用 signal pattern 的優點: + +- Sender/Receiver 不需要互相 import 對方 +- Sender 也無須控管: + - 誰會拿到 Signal + - Receiver 會做什麼 + - 甚至是否有 Receiver 的存在 +- 反之 Receiver 也是 + +# Lazy Evaluation Pattern + +Lazy Evaluation Pattern 是一個經典 usecase,倘若有一個變量 x,且有一個相依 function F,當 x 發生變化時,倘若 F, x 是定義在完全不同的 module 當中,在 x 發生變化時,要取得 F(x) 的成本就非常高了。 + +你可能會 import module,在每次 x 可能變動時做檢查,發生變動時觸發 F 做更動,你可能完成了一個邏輯達到 `x 更新時自動執行 F(x)`,但倘若今天有個新的 function F2 要達到同樣的目的,開發成本與執行成本就倍數增大。 + +這就是為什麼 Signal 的概念出現;倘若將物件的責任獨立開,x 變動時只要發出 Signal,而 Receiver 的責任便是接收到 Signal 時便執行,那上述需求就簡化許多。 + +初次開發我們只需幫 x 的物件裝上發信器(dispatcher),並將接收器指定接收特定 `signal`。 \ No newline at end of file diff --git a/tutorial/tetsu/Data type/basic.ipynb b/tutorial/tetsu/Data type/basic.ipynb new file mode 100644 index 0000000..bcb87f0 --- /dev/null +++ b/tutorial/tetsu/Data type/basic.ipynb @@ -0,0 +1,98 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "python3", + "display_name": "Python 3", + "language": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "source": [ + "# 基本的變數型態\n", + "- int: 整數\n", + "- float: 小數,浮點數\n", + "- str: 字串" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "int" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ], + "source": [ + "# int\n", + "a = 1 \n", + "type(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "70\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'0b1000110'" + ] + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "# 常用的 int 內建函式\n", + "a = 70\n", + "print(a)\n", + "bin(a)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# float\n", + "a = \"是" + ] + } + ] +} \ No newline at end of file diff --git a/tutorial/tetsu/TetsuHelloWorld.ipynb b/tutorial/tetsu/TetsuHelloWorld.ipynb new file mode 100644 index 0000000..72a6204 --- /dev/null +++ b/tutorial/tetsu/TetsuHelloWorld.ipynb @@ -0,0 +1,209 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "python3", + "display_name": "Python 3", + "language": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "source": [ + "### `str.join([list_of_str])` \n", + "將 `str` 插入 input 的元件中間, \n", + "並回傳整併起來的字串" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'0,1,2,3,4,5,6,7,8,9'" + ] + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "anotation = \",\"\n", + "anotation.join([str(i) for i in range(10)])" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'0,1,2,3,4,5,6,7,8,9'" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ], + "source": [ + "\",\".join([str(i) for i in range(10)])" + ] + }, + { + "source": [ + "### 以前的作法\n", + "冗長,而且串接方式邏輯上不通順" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10'" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "result = \"\" # 設定 result 是一個空字串\n", + "for i in range(10): # i = 0, 1, 2, ..., 9\n", + " result = result + str(i) + \", \"\n", + "result = result + \"10\"\n", + "result" + ] + }, + { + "source": [ + "### 現在的作法\n", + "快速,邏輯上比較好理解" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1, 2, 3, 4, 5, 6, 7, 8, 9, 10'" + ] + }, + "metadata": {}, + "execution_count": 19 + } + ], + "source": [ + "element_list = [] # 宣告空陣列\n", + "for i in range(1, 11): # 1, 2, ..., 10, start=從哪開始\n", + " element_list.append(str(i)) # 把 i 塞進 element_list\n", + "seperator = \", \" # 用 `, ` 來組合 element_list 當中的元件\n", + "seperator.join(element_list)" + ] + }, + { + "source": [ + "# 應用場景\n", + "想呈現不同格式的日期 \n", + "例如: \n", + "2021-01-01 \n", + "2021,01,01 \n", + "2021/01/01 \n", + "2021 01 01 " + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "2021-01-01\n2021,01,01\n2021/01/01\n2021 01 01\n" + ] + } + ], + "source": [ + "seperators = [\"-\", \",\", \"/\", \" \"] # 因為是多個,所以變數名稱多一個 s 也是 common practice\n", + "for seperator in seperators: # 利用 for _ in list 可以依序取出 list 當中的資料\n", + " year = \"2021\"\n", + " month = \"01\"\n", + " day = \"01\"\n", + " date = [year, month, day]\n", + " result = seperator.join(date)\n", + " print(result)" + ] + }, + { + "source": [ + "# 強行回到主題 HELLO WORLD" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "hello world\n" + ] + } + ], + "source": [ + "word_list = [\"hello\", \"world\"]\n", + "print(\" \".join(word_list))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/tutorial/tetsu/roadmap.md b/tutorial/tetsu/roadmap.md new file mode 100644 index 0000000..6af1520 --- /dev/null +++ b/tutorial/tetsu/roadmap.md @@ -0,0 +1,37 @@ +# 哲宇的軟體工程師之路 + +[![hackmd-github-sync-badge](https://hackmd.io/goZNYwiwTty5oHOmh9X7pQ/badge)](https://hackmd.io/goZNYwiwTty5oHOmh9X7pQ) + +## Skill + +| Name | Lv. | Description | +| ------ | --- | ------------------------------- | +| Python | 1 | 環境安裝, "Hello fucking world" | +| Git | 1 | 我申請了帳號 | + +## 裝備 + +| Name | Lv. | Description | +| ---- | --- | ----------- | +| IDE | 1 | VScode 安裝 | + + +## 新手村 +Basic environment installation for being a programer. +- [x] 1. Python 環境建置 +- [x] 2. VSCode 安裝開啟 +- [x] 3. Github 帳號申請 +- [ ] 4. 前端 or 後端 +- [x] 5. 印出 "hello world" + +## 伊斯魯德島 +- [ ] 1. 確定想走的大致職涯方向 +- [ ] 2. 持續打題 +- [ ] 3. 在一個 Python 環境,透過`pip`指令安裝`padnas` + [pip lv.1](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/PIP.md) +- [ ] 4. 安裝好虛擬環境框架,anaconda + [Anaconda 基礎技能 lv.1](https://github.com/ShemYu/learning-resource/blob/read/reading/Python/Basic/Anaconda.md) +- [ ] 5. 了解 Python 專案架構 + Keywords: docs, bin, package, module, ... + 自己查資料 +- [ ] 6. initial at least 1 `Repository` \ No newline at end of file