Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions homewor/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
psql-db:
image: 'postgres:14'
container_name: psql-db1
environment:
- PGPASSWORD=123456
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=123456
ports:
- '5434:5432'





9 changes: 9 additions & 0 deletions homewor/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.10.2-alpine3.15
# Create directories
RUN mkdir -p /root/workspace/src
COPY ./hw.py /root/workspace/src
# Switch to project directory
WORKDIR /root/workspace/src
# Install required packages
RUN pip install --upgrade pip
RUN pip install requests bs4 html5lib psycopg2-binary
Binary file added homewor/docs/gitflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 131 additions & 0 deletions homewor/docs/introduction_to_docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Introduction to Docker

## Video : Introduction to Docker and Containers


Docker is a container management service. The keywords of Docker are develop, ship and run anywhere. The whole idea of Docker is for developers to easily develop applications, ship them into containers which can then be deployed anywhere.

[![Video : Introduction to Docker and Containers](https://i3.ytimg.com/vi/JSLpG_spOBM/hqdefault.jpg)](https://www.youtube.com/watch?v=JSLpG_spOBM&ab_channel=RyanSchachte)

<br />

## Features of Docker

- Docker has the ability to reduce the size of development by providing a smaller footprint of the operating system via containers.

- With containers, it becomes easier for teams across different units, such as development, QA and Operations to work seamlessly across applications.

- You can deploy Docker containers anywhere, on any physical and virtual machines and even on the cloud.

- Since Docker containers are pretty lightweight, they are very easily scalable.

<br />

## Docker post-installation setup
Do the optional procedure configuration to work better with Docker.

### Run Docker as non-root user
To create the docker group and add your user:
1. Create the docker group.
```
sudo groupadd docker
```
2. Add your user to the docker group.
```
sudo usermod -aG docker $USER
```

3. Activate the changes to groups:
```
newgrp docker
```
4. Verify that you can run docker commands without sudo.
```
docker images
```

<br />

## Docker Commands
Docker is a containerization system which packages and runs the application with its dependencies inside a container. There are several docker commands you must know when working with Docker.
### 1. Docker version
To find the installed docker version
Command:
```
docker --version
```
##### **_Docker version 20.10.12, build e91ed57_**


<br>

### 2. Downloading image
To work with any ocker image we need to download the docker image first.<br />
Command:
```
docker pull <IMAGE>
```
Example of pulling alpine:latest image
```
docker pull alpine:latest
```
_Note: You may find 1000s of docker images in [Docker Hub](https://hub.docker.com/)_

<br>

### 3. List all the docker images
To list all the images that is locallt available in the host machine, simply run the below command. This will list all the docker images in the local system.
<br />
Command:
```
docker images
```
```
Example:
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest c059bfaa849c 6 weeks ago 5.59MB
```
<br>

### 4. Run docker image
The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command.
<br>
Command:
```
docker run [options] <IMAGE>
```
> Explore here: [https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04)


Example of running alpine:latest image, the options -t allows us to access the terminal and -i gets stdin stream added. Basicaly using -ti adds the terminal driver.
```
docker run -t -i alpine:latest
```
OR
```
docker run -ti alpine:latest
```
_Note: You can use Ctrl+D to come out from the docker image._

<br />

## Create docker image for python:3.10.2-alpine3.15

Create a new file called _**Dockerfile**_ and then paste the below content
```
FROM python:3.10.2-alpine3.15
# Create directories
RUN mkdir -p /root/workspace/src
# Switch to project directory
WORKDIR /root/workspace/src
```
Goto the directory where you created **Dockerfile**
```
docker build ./ -t simple_python
```
You may check the image you created using `docker images` command

Run the _**simple_python**_ image you created
```
docket run -ti simple_python
```
58 changes: 58 additions & 0 deletions homewor/docs/introduction_to_git_commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Introduction to Git
<br />

### Setting up github:

```
Make a repository in GitHub

Go to GitHub.com and login.
Click the green “New Repository” button
Repository name: myrepo
Public
Check Initialize this repository with a README
Click the green “Create repository” button
Copy the HTTPS clone URL to your clipboard via the green “Clone or Download” button.
Clone the repository to your computer

git clone [email protected]:[username]/[repository_name].git

Make a local change, commit, and push

git add <file path> //here the file path is which file you modified ready the file for commit
git commit -m "A commit from my local computer" //here you commit the changes
git push origin <brachname> //here you push the changes to your remote repository and brach name is in which brach you pushing this
```
<br />

### General git flow:
![git flow](gitflow.png)

```
Basic commands of git:

git init
the command git init is used to create an empty Git repository.

git add
Add command is used after checking the status of the files, to add t hose files to the staging area.
Before running the commit command, "git add" is used to add any new or modified files.

git commit
The commit command makes sure that the changes are saved to the local repository.
The command "git commit –m <message>" allows you to describe everyone and help them understand what has happened.

git status
The git status command tells the current state of the repository.
The command provides the current working branch. If the files are in the staging area, but not committed, it will be shown by the git status.
Also, if there are no changes, it will show the message no changes to commit, working directory clean.

git config
The git config command is used initially to configure the user.name and user.email. This specifies what email id and username will be used from a local repository.
```

### Creating a pull request
A pull request – also referred to as a merge request – is an event that takes place in software development when a contributor/developer is ready to begin the process of merging new code changes with the main project repository.

>Refer this link (from "Create a New Branch") : https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github

175 changes: 175 additions & 0 deletions homewor/docs/introduction_to_postgresql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Introduction to PostgreSQL
```
Key Features of PostgreSQL:
- Free to download
- Compatible with Data Integrity
- Compatible with multiple data types
- Highly extensible
- Secure
- Highly Reliable
```
<br />


### JOINS
```
- The CROSS JOIN
- The INNER JOIN
- The LEFT OUTER JOIN
- The RIGHT OUTER JOIN
- The FULL OUTER JOIN
```

![Pictorial Representation of JOINS](https://i.stack.imgur.com/4zjxm.png)

<br />

```
The CROSS JOIN
A CROSS JOIN matches every row of the first table with every row of the second table
SELECT ... FROM table1 CROSS JOIN table2 …
SELECT EMP_ID, NAME, DEPT FROM COMPANY CROSS JOIN DEPARTMENT;

The INNER JOIN
A INNER JOIN creates a new result table by combining column values of two tables (table1 and table2) based upon the join-predicate. The query compares each row of table1 with each row of table2 to find all pairs of rows, which satisfy the join-predicate. When the join-predicate is satisfied, column values for each matched pair of rows of table1 and table2 are combined into a result row.
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_filed = table2.common_field;

SELECT EMP_ID, NAME, DEPT FROM COMPANY INNER JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.EMP_ID;

The LEFT OUTER JOIN
The OUTER JOIN is an extension of the INNER JOIN. SQL standard defines three types of OUTER JOINs: LEFT, RIGHT, and FULL and PostgreSQL supports all of these.
In case of LEFT OUTER JOIN, an inner join is performed first. Then, for each row in table T1 that does not satisfy the join condition with any row in table T2, a joined row is added with null values in columns of T2. Thus, the joined table always has at least one row for each row in T1.

SELECT ... FROM table1 LEFT OUTER JOIN table2 ON conditional_expression ...

SELECT EMP_ID, NAME, DEPT FROM COMPANY LEFT OUTER JOIN DEPARTMENT
ON COMPANY.ID = DEPARTMENT.EMP_ID;

The RIGHT OUTER JOIN
First, an inner join is performed. Then, for each row in table T2 that does not satisfy the join condition with any row in table T1, a joined row is added with null values in columns of T1. This is the converse of a left join; the result table will always have a row for each row in T2.
SELECT ... FROM table1 RIGHT OUTER JOIN table2 ON conditional_expression ...

SELECT EMP_ID, NAME, DEPT FROM COMPANY RIGHT OUTER JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.EMP_ID;

The FULL OUTER JOIN
First, an inner join is performed. Then, for each row in table T1 that does not satisfy the join condition with any row in table T2, a joined row is added with null values in columns of T2. In addition, for each row of T2 that does not satisfy the join condition with any row in T1, a joined row with null values in the columns of T1 is added.
The following is the syntax of FULL OUTER JOIN −
SELECT ... FROM table1 FULL OUTER JOIN table2 ON conditional_expression ...
Based on the above tables, we can write an inner join as follows −
SELECT EMP_ID, NAME, DEPT FROM COMPANY FULL OUTER JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.EMP_ID;

```
<br />

```
Things to Note
- You can do select with limit
- You are able to do group by, order by ,having clauses, etc.
- Your not able to limit delete and update directly. You need to use inner query
> delete from student where sid in (select id from table limit 10)
> update from student set city=”mangalore”where sid in (select id from table limit 10)
```
<br />

## Create PostgresSql docker container
- Add below container in existing **_docker-compose.yml_** file
```
psql-db:
image: 'postgres:14'
container_name: psql-db
environment:
- PGPASSWORD=123456
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=123456
ports:
- '5434:5432'
```


- Get the containers up.
```
docker-compose up -d
```

- Login to the container.
```
docker exec -it psql-db bash
```

- Login to postgres database
```
psql -U postgres
```

# Example
- Create database demo
```
CREATE DATABASE demo;
\c demo
```
- Create table zoo_1 and zoo_2
```
CREATE TABLE zoo_1 (
id INT PRIMARY KEY,
animal VARCHAR (100) NOT NULL
);
CREATE TABLE zoo_2 (
id INT PRIMARY KEY,
animal VARCHAR (100) NOT NULL
);
```
- Insert row
```
INSERT INTO zoo_1(id, animal)
VALUES
(1, 'Lion'),
(2, 'Tiger'),
(3, 'Wolf'),
(4, 'Fox');

INSERT INTO zoo_2(id, animal)
VALUES
(1, 'Tiger'),
(2, 'Lion'),
(3, 'Rhino'),
(4, 'Panther');
```
- Run following queries
- Inner Join
```
SELECT
zoo_1.id id_a,
zoo_1.animal animal_a,
zoo_2.id id_b,
zoo_2.animal animal_b
FROM
zoo_1
INNER JOIN zoo_2 ON zoo_1.animal = zoo_2.animal;
```
- Left Join
```
SELECT
zoo_1.id,
zoo_1.animal,
zoo_2.id,
zoo_2.animal
FROM
zoo_1
LEFT JOIN zoo_2 ON zoo_1.animal = zoo_2.animal;
```
- Right Join
```
SELECT
zoo_1.id,
zoo_1.animal,
zoo_2.id,
zoo_2.animal
FROM
zoo_1
RIGHT JOIN zoo_2 ON zoo_1.animal = zoo_2.animal;
```

> Write a query for RIGHT OUTER JOIN and FULL OUTER JOIN.
Loading