teleren/devto huggingface dataset:
Connection Pooling in Database
Tags: webdev, database, node, javascript
Published: 2022-04-19 04:17:40

As a developer, you may not have spent a lot of time thinking about database connections. A single database connection is not expensive, but as things scale up, problems can arise. So let’s dive into the world of connection pooling, and take a look at how it can help us build more performant applications


## A typical way of database connection

Before we get into pooling, let’s quickly review what happens when your application connects to the database to perform a database operation:

1. The application uses a database driver to open a connection.
2. A network socket is opened to connect the application and the database.
3. The user is authenticated(means database user).
4. The operation completes and the connection may be closed.

As we can see, the opening and closing of the connection and the network socket is a several step process that requires computing resources. However, not closing the connection and keeping it open all time also consumes resources.


## Why pool database connections?
For a simple application typical way of connecting databases may suffice
but when your application gets some amount of users, a simple database operation might take a few seconds. 
Also, the constant opening and closing of connections for each database operation 
will consume too many resources. 

Often, it makes sense to find a way of keeping connections open and passing them from operation to operation as they’re needed, rather than opening and closing a brand new connection for each operation.

![pool_connections.jpeg](https://cdn.hashnode.com/res/hashnode/image/upload/v1650200163301/eo7py3gyD.jpeg)


## What is database connection pooling?

Database connection pooling is a way to reduce the cost of opening and closing connections by maintaining a “pool” of open connections that can be passed from database operation to database operation as needed.

## How to create and configure connection pools?

For an example, I'll take **PostgreSQL **and **sequelize **ORM to demonstrate. <br>
But almost all kinds of database or ORM supports connection pooling. <br>

*below code snippet contains some defaults values*

```
pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000,
  }
``` 

- `max->` maximum number of clients pool can extend concurrently.
- `min ->` minimum  number of clients pool can extend 
 concurrently. 
- `acquire ->` The maximum time (in milliseconds) that pool will try to get connection before throwing error.
- `idle ->` The maximum time (in milliseconds) that a connection can be idle or  wait for any database operation before being released.

These are the minimal configurations needed to get started quickly. <br>
You always look back and add more configuration as per your requirement. <br>
 


Thank You for reading.     
Feel free to share your thoughts on the comments section.                                                                                                                 
Follow me for more such content like this.
VS Code Tip of the Week: Drag & Drop Images and Links into Markdown Files
Tags: vscode, markdown, vscodetips, vscodeextension
Published: 2022-04-19 03:52:09

This week's tip of the week is care of Matt Bierner from the Twitters. Using [VS Code Insiders edition](https://code.visualstudio.com/insiders/)? You can now drag and drop images and links into markdown files. I previously used the [Markdown Paste extension](https://marketplace.visualstudio.com/items?itemName=telesoho.vscode-markdown-paste-image) to accomplish this, so it's nice to see it's native to VS Code now.

{% embed https://twitter.com/mattbierner/status/1514706989867175949 %}

Thanks for the tip, Matt!
Github Copilot's pros and cons
Tags: discuss, productivity
Published: 2022-04-19 03:45:52

![Cp-img](https://www.zdnet.com/a/img/resize/7e4dabe5b6f34528a7d20ee64416168bca09f142/2021/06/29/bd54eff3-c9c7-4cf0-b714-606d46cc4cc7/githubcopilot.jpg?fit=bounds&auto=webp)
##What is Copilot:

GitHub Copilot is an artificial intelligence tool developed by GitHub and OpenAI to assist users of Visual Studio Code, Visual Studio, Neovim, and JetBrains integrated development environments by autocompleting code.
While there are jokes about copilot stealing jobs, it can help a developer boost productivity.In this blog we will see how much can copilot help you to be more productive.

##Copilot's advantages:

Copilot can help you in various ways but the most notable ones are listed below.

**1. Importing cdn quickly:**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rjc4ym9hv84voupkuhc9.png)
 Just write the library name and 'cdn' in a comment then pressing enter and copilot will fetch it for you

**2. Boilerplate code:**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w3xlrmgog9r2tzeeh6zk.png)
A GUI window with a framework or a language?
welp easy

**3. Algorithms:**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bb8k39b9rdmdiachiuwt.png)
Quickly get an algorithm by typing the name in any programming language,and it's that easy and quite handy.

**4. Quick snippets:**
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8h79p22r1jtotb9ux7d2.png)
something like a for loop,switch statement and many more.

**5. Solving a problem:**
let's say you are creating a div at runtime alongisde other elements with some data you fetched, copilot, can do it for you or let's say you are getting an error copilot can solve it for you.
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/egj91a5u8uohn2chw6zp.png)

**6. Helping you learn:**
Copilot will significantly help you in learning.It will solve problems and doubts with well commented code.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqg0t07ryou5716trej4.png)
 
##Copilot's disadvantages

1.Copilot is expensive, right now I'm using the insider build which is free until Copilot fully rolls out.
2.Sometimes Copilot generates code with partial error
3.Slow code completion 
4.Flow interruption. The need to review code suggestions from Github copilot may cause a break in flow while working on projects.
5.There would be code suggested by the copilot that you might not understand.
6.There is also a controversy around the legality of the training process of the copilot as thoughts are that this infringes on copyrights by default. 

##My thoughts:

Copilot is awesome but there a few disadvantages that cannot be overlooked while writitng this blog copilot exposed someone's API key and another private company's server address.It is NOT acceptable under any circumstances.Also overtime we would get lazy using Copilot but putting those aside Copilot can be a great helping hand and learning partner for you.

[Buy me a coffee](https://www.buymeacoffee.com/tawhid)
online editor convert html to android app for free
Tags: html, javascript, webdev, css
Published: 2022-04-19 03:41:12

[EditorGapp](https://editorgapp.com/html)

EditorGapp online editor to convert your html css js to android app in a few minutes for free 


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


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfbs0vj7qjwaihcp8vf0.png)
Change Primary Key and Timestamps in Laravel 8
Tags: laravel, php, timestamps, tutorial
Published: 2022-04-19 03:28:40

Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/laravel/change-primary-key-and-timestamps-in-laravel-8

By default, eloquent assume that each model has a primary key column named id. But if you need to change the primary key with your own custom column name you can change it using the **protected $primaryKey** a property on your model.


See the below example:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'employee_id';
}
```

Additionally, Eloquent assumes that the primary key is an auto-increment integer. But if your primary key is not auto-increment like if you are using UUID then you need to change your Eloquent **$incrementing** property to false.


```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'employee_id';

    /**
     * Indicates if the model's ID is auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;
}
```

By default, Eloquent assumes created_at and updated_at columns exist on your tables. But if you want to not manage these by Eloquent, set the **$timestamps** property on your model to false.

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;
}
```

If your project database used another framework previously. And want to use the Laravel framework luckily we don't need to rename your created_at and updated_at columns you just define it with your current column names to the model.

 

See the below example:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    const CREATED_AT = 'last_created';
    const UPDATED_AT = 'last_updated';
}
```

Now you have ideas already on how to change your Laravel model primary keys and timestamps. I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/laravel/change-primary-key-and-timestamps-in-laravel-8 if you want to download this code.

Happy coding :)
Playing with REMIX
Tags: remix, solidity, replit
Published: 2022-04-19 03:26:20

## This REMIX IDE is AmAZing!

I started playing with this a few days ago and it reminded me of repl.it but it is geared for the EVM and teaching people about solidity. I know repl.it recently started letting people play and learn solidity. But if you are interested in solidity and Web3, I highly recommend checking out [REMIX](https://remix.ethereum.org)
Road to FullStack developer
Tags: programming, softwaredevelopment, beginners, discuss
Published: 2022-04-19 03:14:31

As developers we believe that being a FullStack  and having a lot of knowledge in many areas is similar to being a god.  Many of us want to become a FullStack developer, in order to do  that is important to understand the many  things. 

At the beginning we need to focus our learning path on a specific area, I’ve decided to start with Frontend but also it’s important to know how things are connected  to a Backend. Here's a list of things that I started to learn lately: 

- Understand an entire codebase based on big projects.
- Learn collaborative tools as Git, this includes how to work with different versions of the same project and solving merge conflicts.
- Get the knowledge of testing, this is one of the most important things to become a FullStack developer, there’s always a way to optimize things.
- Be faster, there are tools like Vim or Emacs that work basically as keybindings this allow us to write code faster and focus on the real problem.

### It isn’t all about know everything

There are many areas on software engineering, many of them includes a lot of knowledge but we don’t have to focus on learning a lot of technologies, perhaps  a better way to learn is understanding how are things connected and the way it works. 

For example, in Machine Learning there’s a lot of background we need to know first starting from the basics cause in that field we can find many other areas like Big data, Algorithm optimization, Data structures, Recommendation systems and many other things. 

So, the next time that you feel like you don’t know anything start by understanding  the workflow of things

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixbu8vtv8m97l6f4wb1r.jpg)
Can community solve imposter syndrome?
Tags: discuss, beginners, career, leadership
Published: 2022-04-19 02:29:28

I don't believe imposter syndrome is something that can just go away. Often people ask me how to get rid of imposter syndrome, and from my experience, it continues to manifest in various ways. However, I believe there are methods to manage imposter syndrome. Two months ago, I spoke to a group of recent boot camp graduates about my tumultuous journey into tech and my struggles with imposter syndrome. I shared with them that I've dealt with imposter syndrome by accepting it: knowing it would happen, understanding where it was coming from, and finding resources via the internet to help me navigate challenging situations. Many times, those resources came in the form of community:



- Resilient Coders, a free coding boot camp for black and brown folk
- Hack.Diversity, a talent connector for black and brown folk
- Code2040 Tech Trek, a free opportunity I received to tour tech companies in San Francisco back in 2017
- G{Code} - an organization I helped build which introduces women of color and nonbinary people of color to code
- These resources reminded me that I was not the only one of my kind.

After I gave the talk, I saw a post recapping the event from one of the attendees, which included a reflection of the talk. I thought their takeaway was so poignant and insightful that I had to share it with others. Quay Weston, a Product Designer at Paylocity, wrote

"Imposter syndrome is easy to set in when we lean too far into this culture of individualism. You are much less likely to feel like an imposter in community where your principles and values are shared. In community, you realize that you don't have to know everything bc someone else might. You don't have to do it all bc someone else can. You don't have to have it all because things are shared. Collectivity evades that. In teams/communities, it is made clear that we are all learning and when we approach a new challenge that I don't understand alone, we can commit to solving it together. Find your community."

If you're constantly second-guessing your abilities, it might be that you need a place of belonging.

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

❤️
Save/Load Tensorflow & sklearn pipelines from local and AWS S3 using Joblib
Tags: tensorflow, sklearn, aws, machinelearning
Published: 2022-04-19 02:09:37

After a lot of struggle doing this, I finally found a simple way.
## IMPORTANT: 
I've discovered that if you want to be able to save a model/pipeline and have it be importable without encountering `ModuleNotFoundError`s when you try to load it again, then you need to be sure that your model is built in the same place that it's getting saved. In the case of a neural network, this means compiling, fitting, and saving in the same module. This has been a big headache for me, so I hope you can avoid it.

We can write and read `Tensorflow` and `sklearn` models/pipelines using `joblib`.

## Local Write / Read
```python
from pathlib import Path
path = Path(<local path>)

# WRITE
with path.open("wb") as f:
    joblib.dump(model, f)

# READ
with path.open("rb") as f:
    f.seek(0)
    model = joblib.load(f)
```

We can do the same thing on AWS S3 using a `boto3` client:

## AWS S3 Write / Read

```python
import tempfile
import boto3
import joblib

s3_client = boto3.client('s3')
bucket_name = "my-bucket"
key = "model.pkl"

# WRITE
with tempfile.TemporaryFile() as fp:
    joblib.dump(model, fp)
    fp.seek(0)
    s3_client.put_object(Body=fp.read(), Bucket=bucket_name, Key=key)

# READ
with tempfile.TemporaryFile() as fp:
    s3_client.download_fileobj(Fileobj=fp, Bucket=bucket_name, Key=key)
    fp.seek(0)
    model = joblib.load(fp)

# DELETE
s3_client.delete_object(Bucket=bucket_name, Key=key)
```
Best and Worst Cases of Machine Learning Algorithms ?
Tags: machinelearning, deeplearning, algorithms, datascience
Published: 2022-04-19 01:43:50

## KNN Algorithms :

**Best Cases :**

 • If dimensionality (no of features) is low then this
works best.

• If you know the right distance measure then
KNN is a good option.

**Worst Cases :**

 • If dimensionality (no of features) is low then this
works best.

• If you know the right distance measure then
KNN is a good option.

## Naive Bayes Algorithm :

**Best Cases* :*

 • If the Conditional independence assumption of
naive Bayes is true then it performs very well.

• Naive Bayes is the default algorithm when solving
text classification problems.

• Naive Bayes is often used when you have
categorical features (binary)

• Great interpretability, feature importance, low run
time.

**Worst Cases :**

 • If the Conditional independence assumption of
naive Bayes is false then its performance
deteriorates.

• Naive Bayes is not often used when you have real
value features.

• Easily get's overfitted when Laplace smoothing is
not done correctly.

## Logistic Regression Algorithm :

**Best Cases :**

• It works best when data is almost linearly
separable and it is good if you have a low latency
requirement.

• It is good for interpretability and feature
importance using weights (coefficients).

• Less impact of outliers because of the sigmoid.

• If dimensionality is large it works well.

**Worst Cases :**

• It works badly when data is not linearly separable.

• When data is imbalanced.

• Missing values.

• No multi-class classification for the base model.

• When multicollinearity exists these models will
not work properly.

## Linear Regression Algorithm :

**Best Cases :**

• It is good for interpretability and feature
importance using weights (coefficients).

• If Feature engineering is done then this model
can work better.

**Worst Cases :**

• Outliers impact a lot.

• When multicollinearity exists these models will
not work properly.

## SVM Algorithm :

**Best Cases :**

• If you can find the right kernel then thins works at its
best.

• This can be applied to non-linear problems.

• Interpretability and feature importance is easy for
linear SVM's.

• The impact of outliers is less.

• If dimensionality is large then SVM works like a charm.

**Worst Cases :**

•Interpretability and feature importance is hard for
kernel SVM's.

• If training data is large, training time is high.

## Decision Tree Algorithm :

**Best Cases :**

• Multi-class classification is possible.

• Interpretability and feature importance.

**Worst Cases :**

• Imbalanced data impacts a lot.

• If dimensionality is large then training time is high.

• If you use one-hot encoding then training time will
be high.

• Outliers will impact the model.
Proof by Induction
Published: 2022-04-19 01:35:28

### Statement

{% katex %}
 x^n - y^n = (x-y)(x^{n-1}+x^{n-2}y+\cdots+xy^{n-2}+y^{n-1})
{% endkatex %}

### Proof

Suppose n=1:

{% katex %}
x - y = (x-y)*1 = x-y
{% endkatex %}

Suppose the statement is true for all k < n:

{% katex inline %}
\quad (x^k - y^k)(x + y) = x^{k+1} + x^ky - xy^k - y^{k+1}
{% endkatex %}

{% katex inline %}
\quad x^{k+1} - y^{k+1} = (x^k - y^k)(x+y)-x^ky+xy^k
{% endkatex %}

{% katex inline %}
\quad x^{k+1} - y^{k+1} = (x-y)(x^{k-1} + x^{k-2}y 
+ \cdots + xy^{k-2} + y^{k-1})(x+y)-xy(x^{k-1}+y^{k-1})
{% endkatex %}

{% katex inline %}
\quad x^{k+1} - y^{k+1} = (x-y)(x^{k-1} + x^{k-2}y 
+ \cdots + xy^{k-2} + y^{k-1})(x+y)-xy(x^{k-1}-y^{k-1})
{% endkatex %}

{% katex inline %}
\quad x^{k+1} - y^{k+1} = (x-y)(x^{k-1} + x^{k-2}y 
+ \cdots + xy^{k-2} + y^{k-1})(x+y)-xy(x-y)(x^{k-2}+x^{k-3}y+\cdots+xy^{k-3}+y^{k-2})
{% endkatex %}

{% katex inline %}
\quad x^{k+1} - y^{k+1} = (x-y)(x^{k-1} + x^{k-2}y 
+ \cdots + xy^{k-2} + y^{k-1})(x+y)-(x-y)(x^{k-1}+x^{k-2}y^2+\cdots+x^2y^{k-2}+y^{k-1})
{% endkatex %}

{% katex inline %}
\quad x^{k+1} - y^{k+1} = (x-y)(x^k+x^{k-1}y+\cdots+x^2y^{k-2}+xy^{k-1}+x^{k-1}y+x^{k-2}y^2+\cdots+xy^{k-1}+y^k-x^{k-1}y-x^{k-2}y^2-\cdots-x^2y^{k-2}-xy^{k-1})
{% endkatex %}

{% katex inline %}
\quad x^{k+1} - y^{k+1} = (x-y)(x^k+x^{k-1}y+\cdots+x^2y^{k-2}+xy^{k-1}+y^k) \blacksquare
{% endkatex %}
6º semana da Jornada Dev
Published: 2022-04-19 00:55:52

Essa semana eu aproveitei um cupom de desconto da skillshare para mudar um pouco o que tenho feito.

E o desafio dessa semana, foi desenvolver um algoritmo para criar Personagens: [Clique aqui](https://github.com/Gracielle-Sampaio/Algoritmo/tree/main/desafio)

Aproveite também um mês grátis na [Skillshare](https://skl.sh/3KzSruR)
One click login using MetaMask with django-restframework and Web3
Tags: django, blockchain, python, tutorial
Published: 2022-04-19 00:51:42

So, for a while now, I was looking for a way to create login and signup flow using blockchain and during my search I came across this fine article which details the authentication flow with great detail.
https://www.toptal.com/ethereum/one-click-login-flows-a-metamask-tutorial`` 

But one problem its not in python 😤. Also you had to a lot tedious things to get it work. Only if some one would write a reusable application with all the boring bits already done.
Well lucky for you dear reader. I am that guy and I wrote this nifty little DRF app to solve this problem.

 PYPI link : https://pypi.org/project/django-metamask-auth/

To get started go to the [github repo](https://github.com/wassafshahzad/django-metamask-auth) and follow the getting started guide.

Hopefully this helps some you and I will be working on an npm package for the front side, keep a look out for that as well and don't forget to star the repo.
Some notes about Amazon EKS IAM OIDC Provider
Tags: eks, oidc
Published: 2022-04-18 23:52:55

## Step 1
`iam:*OpenIDConnectProvider*` permissions are not required when creating an EKS cluster with `CreateCluster`, which creates an **OpenID Connect provider URL** (OpenID Connect issuer URL) for the cluster (e.g. https://oidc.eks.ap-southeast-2.amazonaws.com/id/ABCABC111222333444ABCABC11122233). 

And in CloudTrail, there are no `*OpenIDConnectProvider*` events logged.

## Step 2
After (1), the cluster has an OpenID Connect issuer URL associated with it.  To use IAM roles for service accounts, an IAM OIDC provider must exist for the cluster. See [here](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html).

Then you need to run `ekctl utils associate-iam-oidc-provider`, e.g.
```
$ eksctl utils associate-iam-oidc-provider --cluster=k-test-oicd --approve --region=ap-southeast-2 --profile test-oidc
```

A **Open ID Provider** with the same URL as (1) is created.

For this step, this role needs to have at least the following permissions.
```
iam:CreateOpenIDConnectProvider
iam:GetOpenIDConnectProvider
iam:TagOpenIDConnectProvider
```

CloudTrail does NOT show the events as well (e.g. `CreateOpenIDConnectProvider`).