Skip to content

Commit

Permalink
update first page
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcodeforce committed Jul 2, 2024
1 parent a3b3c5e commit d5ca7de
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 40 deletions.
6 changes: 5 additions & 1 deletion algorithms/binarySearch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
Binary search works on sorted arrays. Binary search begins by comparing the middle element of the array with the target value. If the target value matches the middle element, its position in the array is returned. If the target value is less than the middle element, the search continues in the lower half of the array. If the target value is greater than the middle element, the search continues in the upper half of the array.
Binary search works on sorted arrays. Binary search begins by comparing the middle element
of the array with the target value. If the target value matches the middle element,
its position in the array is returned. If the target value is less than the middle element,
the search continues in the lower half of the array. If the target value is greater than the
middle element, the search continues in the upper half of the array.
O(log N)
"""
Expand Down
1 change: 1 addition & 0 deletions algorithms/duplicates_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

def duplicate_in(nums)-> bool:
# Use an array to keep encountered values
encounters = []
for i in nums:
if i not in encounters:
Expand Down
85 changes: 58 additions & 27 deletions docs/coding/dev-env.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Development environments

Apple Mac OS uses python for its own operations, so it is very important to isolate the development environment from the operation of the OS to avoid compromising the integrity of the whole system. So virtualenv can be used, but in today world, docker and pipenv are the way to go as they:
Apple Mac OS uses Python for its own operations, so it is very important to isolate the development environment from the operation of the OS to avoid compromising the integrity of the whole system. So virtual env must be used.

## Virtual env

The goals are:

* avoid installing softwares and libraries not often used on the native OS
* describe the dependencies on library so programs developed 5 years ago should still run
Expand All @@ -9,14 +13,19 @@ Apple Mac OS uses python for its own operations, so it is very important to isol
* use docker compose for each project to manage component dependencies
* if needed pipenv can be used to set up virtual environment to isolate dependencies

Clone this project
Classical venv creation:

```shell
git clone https://github.com/jbcodeforce/python-code
cd python-code
```sh
python -m venv .venv
# for MAC / Linux users
source ./venv/bin/activate
# for Windows
source ./venv/Scripts/activate
```

## Use the different docker images
Then for each projects define a requirement.txt

### Use the different docker images

The [DockerfileForEnv](https://github.com/jbcodeforce/python-code/blob/master/DockerfileForEnv) in the current project defines an image for running python 3.7 with Flask, pytest, panda and other basic libraries.

Expand All @@ -39,7 +48,37 @@ The docker image includes `pipenv` for improving the dependency management.

The other Dockerfile for astrophysic is [Here](https://github.com/jbcodeforce/python-code/blob/master/astronomy/Dockerfile)

## Use pipenv
#### Using graphics inside the python container

The approach is to run graphics program inside python interpreter, but the windows will appear on the host machine (the Mac). To do so we need a bidirectional communication between the docker container and the Mac. This is supported by the `socat` tool. To install it the first time do the following:

```shell
brew install socat
```

When installed, open a new terminal and start socat with the command:

```shell
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
```

As the container is running X window system, we need to also install a X system on Mac. This is done via the `Xquartz` program:

```shell
brew install xquartz
```

Then start Xquartz from the application or using

```shell
open -a Xquartz
```

A white terminal window will pop up. The first time Xquartz is started, open up the `preferences` menu and go to the `security` tab. Then select “allow connections from network clients” to check it `on`.

See [this note from Nils De Moor](https://cntnr.io/running-guis-with-docker-on-mac-os-x-a14df6a76efc) for more information.

### Use pipenv

[Pipenv](https://github.com/pypa/pipenv) offers the last best practices from other language to manage virtual environment and dependencies for Python. Adding and removing packages is also updating the dependencies descriptor file: Pipfile. It basically combine pip and virtualenv. It helps addressing build inconsistency that requirements.txt brings.

Expand Down Expand Up @@ -85,33 +124,25 @@ Python 3.7.4 (default, Jul 9 2019, 00:06:43)

Use `exit()` to get out of the python interpreter, and Ctrl D for getting out of the Docker container.

## Using graphics inside the python container

The approach is to run graphics program inside python interpreter, but the windows will appear on the host machine (the Mac). To do so we need a bidirectional communication between the docker container and the Mac. This is supported by the `socat` tool. To install it the first time do the following:

```shell
brew install socat
```
## vscode

When installed, open a new terminal and start socat with the command:
To start a new Python project:

```shell
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
```
1. create folder on the OS file system, then start `code <created_dir_name>`
1. Verify Python extensions: The microsoft extension includes debugger and pylance. Install also pylint as a linter.
1. In case of change the Python environment: in footer bar

As the container is running X window system, we need to also install a X system on Mac. This is done via the `Xquartz` program:

```shell
brew install xquartz
```

Then start Xquartz from the application or using
* [Product doc](https://code.visualstudio.com/docs)
* [Tricks](https://code.visualstudio.com/docs/getstarted/tips-and-tricks)

```shell
open -a Xquartz
```
* Ctrl+shift P to open command palette
* Ctrl K + ctrl T for changing the theme for all windows

A white terminal window will pop up. The first time Xquartz is started, open up the `preferences` menu and go to the `security` tab. Then select “allow connections from network clients” to check it `on`.
Settings are at user level, so at the workspaces and windows level, or at workspace level.

See [this note from Nils De Moor](https://cntnr.io/running-guis-with-docker-on-mac-os-x-a14df6a76efc) for more information.
* [Command short cut sheet Windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf) [mac](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf)
* [Article on theme customization per workspace](https://medium.com/@juris.savos/setting-a-per-project-colour-scheme-in-vscode-89cc5836b1de) and [theme color](https://code.visualstudio.com/api/references/theme-color)

19 changes: 7 additions & 12 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This repository regroup Python codes and notes from my own self-training and stu

**Advantages:**

* Since 2022 may be the 1st most used programming language
* A lot of libraries, used a lot by data scientists, data pipeline and web dev.
* Since 2022 Python is maybe the 1st most used programming language
* A lot of libraries, used by a lot of data scientists, data pipeline and web dev.
* Combines functional and Object Oriented Programming, with support to dynamic class creation and dynamic function call.
* Language of choices for Machine Learning development
* Raspberry PI language of choice
* Even new libraries are done to implement server side user interface, with project like Streamlit, [gradio.app](https://www.gradio.app/docs/), [Nice gui](https://nicegui.io/); [taipy](taipy.io)
* Even new libraries are done to implement server side user interface, with project like Streamlit, [gradio.app](https://www.gradio.app/docs/), [Nice gui](https://nicegui.io/); [taipy](https://taipy.io)

**Disadvantages:**

Expand All @@ -27,16 +27,11 @@ Use blank to indent code block. The coding style is known as PEP8.

[3.12 Release Product documentation](https://docs.python.org/3.12/library/index.html)

Use virtual environment to avoid impacting operating system python own libraries.
[For dev environment setting see the coding note](./coding/dev-env.md).

```sh
# create one virtual env: it can be reused between a lot of project.
python -m venv .venv
# on windows
source .venv/Scripts/activate
# on Mac
source .venv/activate
```
### VSCode and python extension

[See dedicated getting started summary](./coding/dev-env.md/#vscode)

## Python readings

Expand Down

0 comments on commit d5ca7de

Please sign in to comment.