teleren/devto huggingface dataset:
Selection sort algorithm 
Tags: algorithms, beginners, programming, computerscience
Published: 2021-12-29 20:41:11

Let's look at the "<a href ="https://dev.to/top/week">top</a>" tab on dev.to, there is a list with the most popular articles on the portal. To display it, first we need to sort all articles by number of views. To do that we can use Selection sort algorithm.

The principle of this algorithm is very simple - we search the list of articles looking for the one with the highest number of views, then we copy it to the first index in the newly created list and remove this item from the old list. We repeat these steps until we have a sorted list.

```python
def findBiggest(arr):
    biggest = arr[0]
    biggest_index = 0

    for i in range(1, len(arr)):
        if arr[i] > biggest:
            biggest = arr[i]
            biggest_index = i
    return biggest_index


def selectionSort(arr):
    newArr = []
    
    for i in range(len(arr)):
        biggest = findBiggest(arr)
        newArr.append(arr.pop(biggest))
    return newArr


print(selectionSort([51, 32, 63, 2, 101])) # [101, 63, 51, 32, 2]
```

The algorithm although simple is very slow with a large amount of data, so the dev.to developers surely used something faster. The speed of this algorithm specified in Big O notation is O(n2), since we have to search every element in the list.

More about Big O notation you can read in my previous post <a href="https://dev.to/quentindamianino/big-o-notation-418h">here</a>
Memoization in Recursion (JS)
Tags: javascript, programming, react, html
Published: 2021-12-29 19:15:36

**_What is Memoization ?_**

- _**In a non technical words**_: Assume, you want to watch one movie, and you downloaded that movie (2TB) and you watched.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5u0k8xblotmuqxoh0ofi.gif)

After one day, again you want to watch that same movie because its quite interesting. so what you will do now?
Again you will download (2TB) ? or you will watch from your already downloaded file?


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmxg3h89a5sua2wgkabo.gif)

---


**_In a Technical Words_**:- It is an optimization technique that speeds up applications by storing the results of expensive function calls and returning the cached result when the same inputs occur again.

---
Before get into the **memoization** deeply, lets understood the **recursion** first.so we will have a better understanding, where we can use our memoization.

---
**_Recursion_**: Recursion is a technique to iterate over the function repeatedly. untill we get a result or untill the condition satisfied.


**_fibonacci program with recursion:_**

``` javascript
function fib(n) {
  if(n<=2) {
    return 1;
  }
  else {
    return  fib(n-1)+fib(n-2)
  }
}
console.log(fib(40));
```

In the above code, we are using recursion concept to calculate fibonacci. so fib(n) will be repeated most of the times. 
**eg:-** fib(40) = fib(40-1)+fib(40-2)
               fib(39)+fib(38)

- And this tree will go further. and lot of fib(4),fib(5), fib(6), fib(n),etc..... series need to calculate. 

- Assume fib(4), we calculate and **we stored it in cache** and again if fib(4) came in that tree. we **don't need to calculate again**. Just we need to return it from the cache. So this will improve the response time as well.

---
**_fibonacci program with recursion and memoization:_**

``` javascript
let previousValue = []
function fib(n) {
  if(previousValue[n] != null) { //memoization
    return previousValue[n];
  }
  if(n<=2) {
    return 1;
  }
  else {
    result =  fib(n-1)+fib(n-2)
  }
  previousValue[n] = result  //memoization
  return result
}
console.log(fib(40))
```

And you guys can take both the programs and you guys can check that, which one is having a **better response time**.


Thanks for your time!!
Cheers!!
The Ultimate Guide You Need To Publish Your Python Package In Just 3 Easy Steps
Tags: python, poetry, pypi, codenewbie
Published: 2021-12-29 20:34:04

A reply to [The Ultimate Guide You Need To Publish Your Python Package In Just 9 Easy Steps](https://dev.to/audarya07/the-ultimate-guide-you-need-to-publish-your-python-package-in-just-9-easy-steps-39o5), using poetry instead of a `setup.py` script.

I will focus on the steps only, you can read a better and fuller [article here](https://johnfraney.ca/posts/2019/05/28/create-publish-python-package-poetry/).

## Install all the things
I am assuming you have python and poetry installed, if you do not have it, [install](https://python-poetry.org/docs/#installation) it.


## 1. Create a package
``` bash
$ poetry new sample-package
Created package sample-package in sample-package
```

This will create the project layout:
``` text
sample-package/
├── sample-package/
│   └── __init__.py
├── tests/
│   ├── __init__.py
│   └── test_sample-package.py
├── pyproject.toml
└── README.rst 
```

## 2. Describe your package in `pyproject.toml`

Here is where you say what your package does and define dependencies.

For example:
``` toml
[tool.poetry]
name = "sample-package"
version = "0.0.1"
description = "Sample Description for your sample file"
authors = ["John Doe <john@doe.com>"]

[tool.poetry.dependencies]
# Updated Python version
python = "^3.6"

[tool.poetry.dev-dependencies]
pytest = "^3.0"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
```

## X. Write Your Package
There isn't a reason to publish an empty package, make sure it does something.

## 3. Publish it!
After your package works, all test pass, etc., you want to make it available to the world, lets build:
``` bash
$ poetry build
```

### Testing Publish via TestPyPi
This is optional, highly recommended.

Add Test PyPi as a package repository
``` bash
$ poetry config repositories.testpypi https://test.pypi.org/legacy/
```

Publish it to Test PyPi:
``` bash
$ poetry publish -r testpypi
```

Install it from Test PyPi
``` bash
pip install --index-url https://test.pypi.org/simple/ flake8-markdown
```

### Really Publish it
If all is good, and ready to make it public:
``` bash
poetry publish
```

# NOTES
1. If you are new to Poetry, [read the docs ](https://python-poetry.org/docs/)
2. You need an account in Test PyPi and PyPi, [register](https://pypi.org/account/register/) if you haven't
The Line Between Willingness to Learn and Shiny Object Syndrome
Tags: devjournal, tooling, beginners, programming
Published: 2021-12-29 20:31:22

I've been thinking a lot recently about shiny object syndrome, "a pop-cultural, psychological concept where people focus on a shiny, new object, in other words whatever is most current, trendy, or the latest concept, regardless of how valuable or helpful it may ultimately be" [Wikipedia](https://en.wikipedia.org/wiki/Shiny_object_syndrome)

[Stuff in tech](https://ourworldindata.org/technological-progress) tends to develop exponentially. We feel the [FOMO](https://www.urbandictionary.com/define.php?term=Fomo) when we see another developer on twitter gushing about their experience with some new tooling on the bleeding edge of programming. 

On the other hand, because knowledge's power increases in the capacity that it's shared, it's important for the development of our field that we remain open to both teaching and learning new things. 

So what's the difference between chasing after shiny objects and maintaining the growth of knowledge? I maintain that it lies in a pause. This is the pause between becoming aware of a new tool, and implementing it. 

In this pause, we can ask questions that can help us decide whether to adopt the new tool. I recommend these: 

1. Why am I interested in this? Is it because it is helpful to me in some way, or because I see a lot of other people using it? 

2. What does the tool do? Will it further the goals of my project? My team? 

3. What's the risk involved in adopting this? If it's a personal project, do I have the time to invest in learning this new tooling? If it's a team project, how well-established is this piece of new tech? If we make it a dependency, what's the risk of it failing? What effect would that have on the project as a whole? 

I'm sure there are more good questions to ask, but these are a few I've come up with. Let me know if you have more to add!
Deploy .NET Core worker Service on Linux
Tags: aspnetcore, linux, csharp
Published: 2021-12-29 20:00:09

In the [previous post](https://dev.to/uthmanrahimi/deploy-aspnet-core-applications-on-centos-8-43n2), we learned how to deploy an `ASP.NET Core` Application on `Linux` and configure it, in this post we are going to learn about deploying a `Worker Service` on a `Linux` machine.

## What is Worker Service?
Before talking about our main topic, for those of you who do not know what is a `worker service`, let's learn about what is `worker service`.
`Worker Service` is a built-in feature in .NET Core for creating background services. One example of using `Worker Service` is running periodical schedules like sending `newsletter` emails for clients every morning. To learn more about `worker service`, refer to this [link](https://docs.microsoft.com/en-us/dotnet/core/extensions/workers).

We assume that you have created a `Worker Service` and now you want to deploy it on a Linux machine. First of all, as you learned in the previous article, we need to create a new service file, so use the below command to create a service file:

```
sudo nano /etc/systemd/system/appbackground.service
```
and edit its content with the following content to it:

```
[Unit]
Description=Your description 

[Service]
Type=notify
WorkingDirectory=/home/centos/Desktop/services/

ExecStart=/usr/bin/dotnet /home/centos/Desktop/services/myapp.WorkerServic$


Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target

```
Then  press `ctrl+x` to save its content and run the following commands:

```
sudo systemctl daemon-reload
sudo systemctl start appbackground.service
```
If you get an error after running `sudo systemctl start appbackground.service` you will need to add a small change to your `worker service` project.

Install `Microsoft.Extensions.Hosting.Systemd` by `nuget`:

```
dotnet add package Microsoft.Extensions.Hosting.Systemd
```
Then change `CreateHostBuilder` in `program.cs` like below:

```
 public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseSystemd() // this method must be added
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddHostedService<appWorker>();
                });
    }
```
After applying this change, get a new publish of your project and put it in the path on the `Linux` then run start its service.
CRUD Operation
Published: 2021-12-29 19:50:54

CRUD Operation:
CRUD stands for Create, Read, Update and Delete. CRUD operation is a widely used operation in the database.
The importance of a database for dynamically representing a website is immense. And all the information sent to this database is again taken from this database to show any information on the website with the help of this CRUD operation.

Currently two types of database systems are used. A relational database such as SQL, SQL Server. On the other hand, non-relational database systems such as MongoDB.
Databases are created using a variety of backend applications. The codes for such a well-known backend application node JS.

Create Operation: Databases are created in the database using the Create operation. Inside it, information can be sent in the form of various collections. All collections of such orders are in one place. All product collections in one place etc.

Read Operation: Any data is read easily through read operation.

Update Operation: Any Data is update easily throw update operation.you can update your data of your database,you will use update operation.

Delete Operation: 
You can delete any data from Database,you will use delete operation.
Only press delete button,you can delete data from Database.
Docker: Simplicidade e praticidade - Parte 1
Tags: docker, devops, container
Published: 2021-12-29 19:47:04

## Um guia de sobrevivência - Parte 1

Criar uma máquina virtual e instalar nela tudo que você precisa, seja essa maquina um ambiente de produção, qualidade ou desenvolvimento é muito bom. Então, esqueça máquinas pesadas com vários gigabytes de disco ou RAM, temos imagens pequenas e mínimas que podem ser executadas como containers e te ajudar muito no seu dia.

Essa é a primeira parte de um guia de sobrevivência para montar imagens, containers, fazer pull e push para um repositório, criar Dockerfile, Docker Compose etc.

Docker é claro é a ferramenta que vou usar. 
Dizem que existem outras, mas qual?

#### Cenário: Quero rodar um container.
Por exemplo, rodar um container com um banco de dados.
1 - Baixar uma imagem:`docker pull`. Esse comando é especifico para baixar uma imagem. Veja o exemplo a seguir:

```
docker pull mysql/mysql-server:latest 
```
Faz o download da uma versão da imagem do MySQL.

```
docker images
```
Lista as imagens que estão disponíveis no seu computador.

![Imagens que tenho disponível em meu computador](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg0uekclweexneguv6oi.png)
2 - Montar e rodar um container
Agora que você já tem uma imagem oficial, põe ela pra rodar. Use o comando `docker run`.

```
docker run --name="mysqltest" -d mysql/mysql-server:latest  
```
Pronto, já tem um container rodando.
Use o comando `docker container ls` para listar os containers.

![Container listado através do comando docker container ls](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ismfmf0vu8p208gs33i4.png)

#### Cenário: Quero remover os containers e imagens.
1 - Parar o container
Para "stopar" container use o comando `docker kill`

```
 docker kill $(docker ps -q)
```
No exemplo acima é executado um comando que "stopa" todos os containers que estão rodando no momento.
No caso do exemplo abaixo, só havia um container em execução na minha maquina.
![Container parado por ação do comando acima](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chg9o8kbpq99compuq3e.png)

2 - Remover as imagens
Para remover as imagens que estão na sua máquina use o comando `docker rmi`, veja exemplo:
```
docker rmi $(docker images -a -q) -f
```
Ao executar esse comando você deve receber uma mensagem como essa:

```
Untagged: mysql/mysql-server:latest
Untagged: mysql/mysql-server@sha256:91170bd4e012f0bf46b5141a38b612427b37692e8465cdffe9b0ca2d74d37d8a
Deleted: sha256:d2e6e9727b37928be30fb11361d1246dcc816e6b5fb55d6ef30281ff5e3884df

```

### Conclusão

Neste post eu mostrei como é simples baixar imagens e executar containers baseados nessas imagens.
No [Docker Hub](https://hub.docker.com/) você encontra milhares e milhares de imagens prontas que você pode usar de imediato.
No próximo post vou mostrar mais sobre a iteração com esses containers e como tirar mais proveito durante a execução. 

Link do [MySQL](https://hub.docker.com/r/mysql/mysql-server) no Docker Hub
Link do [Nginx](https://hub.docker.com/_/nginx) no Docker Hub
Terraform Boilerplate: Provider block for every AWS region
Published: 2021-12-29 19:31:07

---
title: Terraform Boilerplate: Provider block for every AWS region
published: true
description: Just some boilerplate HCL
tags: 
//cover_image: https://direct_url_to_image.jpg
---

Boilerplate HCL for your module writing needs! Did I miss any?

```terraform
provider "aws" {}

#### NORTHERN VIRGINIA : us-east-1
provider "aws" {
  region = "us-east-1"
  alias = "us-east-1"
}

#### OHIO : us-east-2
provider "aws" {
  region = "us-east-2"
  alias = "us-east-2"
}

#### NORTHERN CALIFORNIA : us-west-1
provider "aws" {
  region = "us-west-1"
  alias = "us-west-1"
}

#### OREGON : us-west-2
provider "aws" {
  region = "us-west-2"
  alias = "us-west-2"
}

#### CANADA : ca-central-1
provider "aws" {
  region = "ca-central-1"
  alias = "ca-central-1"
}

#### MUMBAI : ap-south-1
provider "aws" {
  region = "ap-south-1"
  alias = "ap-south-1"
}

//#### OSAKA_LOCAL : ap-northeast-3
provider "aws" {
  region = "ap-northeast-3"
  alias = "ap-northeast-3"
}

#### SEOUL : ap-northeast-2
provider "aws" {
  region = "ap-northeast-2"
  alias = "ap-northeast-2"
}

#### SINGAPORE : ap-southeast-1
provider "aws" {
  region = "ap-southeast-1"
  alias = "ap-southeast-1"
}

#### SYDNEY : ap-southeast-2
provider "aws" {
  region = "ap-southeast-2"
  alias = "ap-southeast-2"
}

#### TOKYO : ap-northeast-1
provider "aws" {
  region = "ap-northeast-1"
  alias = "ap-northeast-1"
}


#### FRANKFHURT : eu-central-1
provider "aws" {
  region = "eu-central-1"
  alias = "eu-central-1"
}

#### IRELAND : eu-west-1
provider "aws" {
  region = "eu-west-1"
  alias = "eu-west-1"
}

#### LONDON : eu-west-2
provider "aws" {
  region = "eu-west-2"
  alias = "eu-west-2"
}

//#### MILAN : eu-south-1
provider "aws" {
  region = "eu-south-1"
  alias = "eu-south-1"
}

#### PARIS : eu-west-3
provider "aws" {
  region = "eu-west-3"
  alias = "eu-west-3"
}

#### STOCKHOLM : eu-north-1
provider "aws" {
  region = "eu-north-1"
  alias = "eu-north-1"
}

####  SAO PAULO : sa-east-1
provider "aws" {
  region = "sa-east-1"
  alias = "sa-east-1"
}
```

Including these but I had trouble if I included 
```terraform
//#### SOUTH AFRICA : af-south-1
provider "aws" {
  region = "af-south-1"
  alias = "af-south-1"
}

//#### HONG KONG : ap-east-1
provider "aws" {
  region = "ap-east-1"
  alias = "ap-east-1"
}

//####  MIDDLE EAST: me-south-1
provider "aws" {
  region = "me-south-1"
  alias = "me-south-1"
}
```
Dec 29: Dev Holidays Guide ⛄️
Tags: stateofdevs, bahhumbugtip, mentalhealth, tips
Published: 2021-12-29 19:30:44

Bah Humbug Tips are my own way of coping & recovering from burnout & holiday stress.

###🎄  Today's Bah Humbug Tip of the Day. 
{% twitter 1476246645222248449 %}

######🎁 Today's Options 
{% twitter 1476246650947391488 %}

You can find more tips here & on [Twitter](https://twitter.com/stateofdevs). Let me know in the comments if any of these tips helps.

> If you're struggling w/ burnout & open to sharing your story, please [take the State Of Devs survey](https://stateofdevs.com/helps/dev). 🗳 Thanks!
Form Lib 1.10 released
Tags: javascript, dom, node, form
Published: 2021-12-29 19:15:38

---
title: Form Lib 1.10 released
published: true
description: Monsterjs Form Lib Release Note
tags: javascript, dom, nodejs, form
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ejfvziu74f1dk5racmn.png
series: Form Lib Release
---

Today we have released the latest edition of our Form Lib. Our library offers us the possibility to link forms with data. In addition, we have programmed here various controls that are not available in the standard. 

Only the highlights are described here. The full functionality can be found in the [documentation](https://monsterjs.org/en/doc/components/form/1.10.0/).

This release builds on [Monster 1.29](https://monsterjs.org) and contains minor improvements. 

## New Tab control

{% twitter 1475900331804532739 %}

```javascript
const node = document.createElement('monster-tabs');
document.getElementById('container').appendChild(s);
``` 

or 

```html
<monster-tabs>
   <div data-monster-button-label="1th tab">
      tab content
   </div>
</monster-tabs>
```


_hope you enjoy it!_



## References

* [https://dev.to/schukai/monster-128-released-e4b](Monster 1.29 released)
* [Forms, nothing but forms](https://dev.to/schukai/manage-forms-with-monster-4nf5)
* [documentation](https://monsterjs.org/en/doc/components/form/1.10.0/)
* [project home](https://monsterjs.org)
* [form example](https://monsterjs.org/en/doc/1.29.0/tutorial-form-example.html)
* [we are hiring developers](https://about.schukai.com/de/jobs/)
Monster 1.29 released
Tags: javascript, dom, node
Published: 2021-12-29 19:05:44

---
title: Monster 1.29 released
published: true
description: Monsterjs Release  
tags: javascript, dom, nodejs
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s8ogr940uqj7wm4dowe.png
series: Monster-Release
---

Today we released the latest edition of our Monster project. Monster is a collection of javascript classes that we need for daily work in [our](https://www.schukai.com/en/) web projects.

Besides small helper functions and classes, it also provides useful functions to enable reactive programming.

Monster is available via jsdelivr and npm.

Only the highlights are described here. The full functionality can be found in the [documentation](https://monsterjs.org/en/doc/1.29.0/).

## New class DeadMansSwitch

With the help of the dead man switch you can execute a function after a certain time. this is useful for example if you don't know how many events will be fired, but you only want to react to the last one of a series.

```javascript
import {DeadMansSwitch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.0

/dist/modules/util/deadmansswitch.js';

const deadmansswitch = new DeadMansSwitch(100, ()=>{
  console.log('yeah!')
  // ↦ "yeah!"
})

deadmansswitch.touch(); // from here wait again 100 ms
deadmansswitch.touch(200); // from here wait 200 ms
```



_hope you enjoy it!_



## References

- [npm](https://www.npmjs.com/package/@schukai/monster) 
- [jsdelivr](https://www.jsdelivr.com/package/npm/@schukai/monster)
- [we are hiring developer](https://about.schukai.com/de/jobs/)
NODEJS
Published: 2021-12-29 18:54:35


What is nodeJS? Difference between nodeJS and Javascript?
Ans: NodeJs is a javascript runtime powered by v8 engine . Javascript is a programming language on the other hand nodeJs is a runtime of javascript . javascript runs on any web browser with the help of node js javascript can be run outside of the browser. Javascript is basically used on the client side . it is used on the server side. Js is used for frontend development node js is used for server side development.
.Why did you use node and mongo with your react project?
Ans: node js is suitable for i/o intensive tasks and node js works in non blocking i/o , asynchronous way it handles multiple requests at a time without any blocking . and mongodb is a no sql database system that means it does not create multiple tables like relational databases and it is good to use with node js . For high data load and for handling multiple request  and to make my web application suitable for use to user i used nodejs as my backend and mongodb as my database with my react application.
.What are the difference between sql and nosql?
Ans: sql is a relational database management system. No sql is no relational data system. Sql is not suitable for hierarchical data no sql is suitable for hierarchical data . in sql schema are predefined but  in nosql the schema are dynamic . sql is suitable for complex queries  it is not suitable for complex queries. Sql have multiple tables where nosql dont have multiple table . Sql Vertically scalable no sql horizontally scalable.sql is Complex to develop no sql is easy to develop .

How Node Js work?
ans:Node is completely event-driven.the node js server always accept request  Basically the server consists of one thread processing one event after another. A new request coming in is one kind of event. The server starts processing it and when there is a blocking IO operation, it does not wait until it completes and instead registers a callback function.