Miscellaneous practice code in Python and things I've used.
Just one of the things I'm learning. https://github.com/hchiam/learning
You can create share-able online live demos with trinket.io (similar to CodePen for JS/HTML/CSS).
https://github.com/hchiam/learning-python/blob/master/python-built-ins-worth-learning.md
To run python linter pylint on a file (for example pylint_example.py), run this in the CLI:
pylint pylint_example.pyOr even better, you can auto-run that command every time you save a file in the folder. To do that, do pip3 install rerun and then run this in the CLI:
rerun "pylint pylint_example.py; python3 pylint_example.py"This works just like nodemon for JS/Node.js.
I use pyright to do static type checking in VSCode.
You can see an example of (gradual) type annotations here.
The MI combines lines of code, cyclomatic complexity, and the Halstead volume metric (i.e. number of variables, operations, decision paths, and lines of code). After you pip install radon, you can get the MI score of your code:
radon mi your_code.py -sSimilar to how I use plato for JavaScript code.
More tools for things like refactoring code (rope) and tracking project code complexity (wily): https://realpython.com/python-refactoring/
pip uninstall matplotlib
pip install matplotlibpretty print pprint: https://www.geeksforgeeks.org/pprint-data-pretty-printer-python/
all([True, False]): https://www.w3schools.com/python/ref_func_all.asp
any([True, False]): https://www.w3schools.com/python/ref_func_any.asp
from __future__ import newkeywordthing: https://stackoverflow.com/questions/7075082/what-is-future-in-python-used-for-and-how-when-to-use-it-and-how-it-works
import inspect: https://stackoverflow.com/questions/3711184/how-to-use-inspect-to-get-the-callers-info-from-callee-in-python
print(wikipedia.summary('web query')): https://pypi.org/project/wikipedia/ (see example for other params & methods)
brew install python to upgrade python to the latest version https://stackoverflow.com/questions/74214615/how-to-update-python-version-in-terminal
brew link --overwrite python@3.12alias py='python3.12'in .bash_profile (alias bas='source ~/.bash_profile') sopy --versionoutputs something likePython 3.12.2
python3 -m http.server 8000 to quickly set up a basic local server that serves index.html at http://localhost:8000/
- or
python -m SimpleHTTPServer 8000for older python versions - consider bash script:
alias srv='python3 -m http.server 8000'
- https://github.com/hchiam/hchiam-example-pypi-project
- https://github.com/hchiam/webScraper
- Maching Learning: https://github.com/hchiam/machineLearning
- NLP with spaCy and textacy: https://github.com/hchiam/nlp_spacy_textacy
- One of my experimental programming languages: https://github.com/hchiam/please (for coding by voice)
- Flask: https://github.com/hchiam/learning-flask
- A genetic algorithm: https://github.com/hchiam/cogLang-geneticAlgo
- https://github.com/hchiam/cognateLanguage
- Code and notes based on Udacity course AI for Robotics: https://github.com/hchiam/ai_for_robotics
- Cirq for quantum computer circuits: https://github.com/hchiam/learning-cirq
- https://github.com/hchiam/autotest
- https://github.com/hchiam/audioMonitorQt
- LZW compression algorithm https://github.com/hchiam/learning-lzw