https://github.com/jorgechato/warmup
A simple repository with a bunch of exercises, from algorithms, to designs.
https://github.com/jorgechato/warmup
algorithm design docker travis-ci
Last synced: about 1 month ago
JSON representation
A simple repository with a bunch of exercises, from algorithms, to designs.
- Host: GitHub
- URL: https://github.com/jorgechato/warmup
- Owner: jorgechato
- Created: 2019-02-09T12:09:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-10T23:02:08.000Z (almost 7 years ago)
- Last Synced: 2024-12-28T01:12:47.259Z (12 months ago)
- Topics: algorithm, design, docker, travis-ci
- Language: Python
- Size: 10.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Warmup
[](https://travis-ci.org/jorgechato/warmup)
In this repository there are 2 Algorithms exercises, 1 Design pattern and 1 Architecture design.
All the modules are in a CI/CD pipeline to run the tests. The architecture module is integrated into the deployment process with docker and heroku.
## Algorithms
### Palindrome
#### Run
```zsh
# Run palindrome
$ python -m algorithms.palindrome
# Run tests
$ python -m algorithms.palindrome_tests -v
```
### Unique triplets sum == 0
#### Run
```zsh
# Run unique triplets sum == 0
$ python -m algorithms.triplets
# Run tests
$ python -m algorithms.triplets_tests -v
```
## Design Patterns
### Object pool library
- `opool_sample` is the first iteration of the Pool.
- `opool` object pool library (Use case: database connection)
- `opool_demo` demo of how to use the library.
- `opool_tests` unit tests.
**Advantages**
- It offer a significant performance boost.
- It manages the connections and provides a way to reuse and share them.
- Object pool pattern is used when the rate of initializing a instance of the class is high.
#### Use
```python
from design.opool import Pool
pool = Pool([1, 2, 3])
# Lease an object from the pool
# Context manager is the way to use it.
with pool.lease() as val:
# ...
# use val as the object
# ...
```
#### Run
```zsh
# Run library
$ python -m design.opool_demo
# Run tests
$ python -m design.opool_tests -v
```
## Architecture Designs
### Short URL
#### Install & Run
```zsh
# Run library
$ python FLASK_APP=architecture/app flask run
```
```zsh
# Short the URL
$ curl -X PUT "https://warmup-short-url.herokuapp.com/shorten" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"url\": \"http://jorgechato.com\"}"
{"__this": "http://warmup-short-url.herokuapp.com/shorten", "original": "http://jorgechato.com", "short": "http://warmup-short-url.herokuapp.com/rfWfV"}
# Get the original URL
$ curl -X PUT "https://warmup-short-url.herokuapp.com/original" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"shorted\": \"http://warmup-short-url.herokuapp.com/rfWfV\"}"
{"__this": "http://warmup-short-url.herokuapp.com/original", "original": "http://jorgechato.com", "short": "http://warmup-short-url.herokuapp.com/rfWfV"}
```
#### Deploy
This module is automated by the CI/CD
```zsh
# Build docker
$ docker build -t short-url:latest .
$ docker run -p 8000:8000 --name short-url short-url:latest
```
You can check [the heroku deployment](https://warmup-short-url.herokuapp.com) tho.
**What is a distributed system?**
A distributed system is a network that consists of autonomous computers that are connected using a distribution middleware. They help in sharing different resources and capabilities to provide users with a single and integrated coherent network.
**What kind of difficulties commonly found when building a distributed system?**
- Security is a big challenge in a distributed environment, especially when using public networks.
- Fault tolerance could be tough when the distributed model is built based on unreliable components.
- Coordination and resource sharing can be difficult if proper protocols or policies are not in place.
**How do you solve these difficulties?**
- Enabling security layers like MFA.
- Automated Middleware Specialization approach could solve this issue.
- The ressource sharing could be solved with a reactive platform or a data streaming like Kafka.
---
## Requirements
### Must have
- [python 3.x](https://www.python.org/downloads/)
- pip3
### We recommend you
- [anaconda](https://anaconda.org/anaconda/python)
#### Install dependencies
```bash
# with anaconda
$ conda env create -f environment.yml # create virtual environment
$ conda activate warmup # enter VE
# or
$ source activate warmup
(warmup) $ conda deactivate # exit VE
```