teleren/devto huggingface dataset:
13 Javascript one-liner tricks with Arrays.
Tags: javascript, webdev
Published: 2022-07-01 18:25:19


1.Calculate the sum of all the values in an array

```
const arr= [1,4,5,7];
const arrSum = arr.reduce((a,b)=>a+b);
// valSum --  17
```

2.Generating array from a function arguments

```
function generateArray() {
    return Array.from(arguments);
}
f(1,2,4))
//result -- [1,2,4]
```

3.Sorting the value of an array in ascending order.

```
const sortArrayValues = (values) => {
    if(!Array.isArray(values)){
      return null
    }
    return  values.sort((a,b)=>a-b);
 }
```

4.Reverse the values of an array

```
const fruits= ['Banana','Orange','Melon','Grape'];
const reverseFruits = fruits.reverse();
//result ['Grape','Melon','Orange','Banana'];
```

5.Removing the duplicates in an array

```
let fruits = ['banana','mango','apple','sugarcane','mango','apple']

let uniqueFruits = Array.from(new Set(fruits));

 // uniqueFruits -- [ 'banana', 'manago', 'apple', 'sugarcane' ]
```
6.Emptying an array.

```
let fruits = [3,'mango',6,9,'mango','apple']
  
fruits.length = 0;
```

7.Convert an array to an Object.

```
const arrayVal= ['Tokyo', 'Belfast','Birmigham', 'Lagos']

const fruitsObj = {...arrayVal};
```
8.Merging multiple arrays into one.

```
let fruits = ['banana','manago','apple'];
let meat = ["Poultry","beef","fish"]
let vegetables = ["Potato","tomato","cucumber"];
let food = [...fruits,...meat,...vegetables];
  
// food  -- ['banana',  'manago','apple',   'sugarcane','manago',  'apple','Poultry', 'beef','fish',    'Potato','tomato',  'cucumber'
```
9.Replace a specific value in an array

```
var fruits2 = ['apple', 'sugarcane', 'manago'];
    
fruits2.splice(0,2,"potato","tomato");
    
// fruits2  ['potato', 'tomato', 'apple', 'sugarcane', 'manago']
```

10.Mapping array from objects without maps

```
const friends = [
      {name:"John", age:22},
      {name:"Peter", age:23},
      {name:"bimbo",age:34},
      {name:"mark",age:45},
      {name:"Esther",age:21},
      {name:"Monica",age:19}
  ];
  
 let friendNames = Array.from(friends,({name})=>name);
  
 // friendNames --['John', 'Peter', 'bimbo', 'mark', 'Esther', 'Monica' ]
```

11.Filling an array with data

```
let newArray = new Array(8).fill("3");
  
// result -- ['3', '3', '3', '3','3', '3', '3', '3']
```

12.Merging only duplicates values in two arrays

```
let arrOne = [0,3,4,7,8,8];
let arrTwo = [1,2,3,4,8,6];

const duplicatedValue = [...new Set(arrOne)].filter(item=>arrTwo.includes(item));
// duplicatedValue -- [ 3, 4, 8]
```
13.Remove falsy values in an array.

```
const mixedValues = [undefined,"blue",0,"",NaN,true,,"white",false];
const filteredArray = mixedArray.filter(Boolean);
//result [ 'blue', true, 'white' ]
```
TypeScript Generics 101
Tags: typescript, webdev, javascript
Published: 2022-07-01 18:22:13

New to TypeScript and get your head to understand what Generics do? This short article if for you.

## Generics?

Generics is simply a way to build code components that work with different data types without losing information about that data type. Such components are reusable; they can take in an input of any data type and produce the required output. This allows the component to be flexible.

## Without Generics

Here is a TypeScript functions that echos out whatever it's given. without applying the generic method, you'd have to specify the type of the argument or use the `any` type.

```typescript
// Specific type
function echo(arg: number): number {
    return arg
}

// Using the 'any' type
function echo(arg: any): any {
    return arg
}
```

Using specific types will only hold information about that type. Using the 'any' type seems generic but it loses information about the type of data passed in. If you pass a string with a type of 'any,' Typescript will translate the returned type as 'any'; not a string.

## The Generic Way

The generic way would be to capture the argument despite the type and denote what is being returned. The 'Type' variable does that. it's a special variable for data type rather than values.

```typescript
// Using the 'Type' variable
function echo<Type>(arg: Type): Type {
    return arg;
}
```

The 'Type' variable captures a range of types and holds the information for later use thus making the 'echo' function generic.

## Calling Generic Functions

A generic function can be called in two ways. The first is to pass the 'Type' variable argument and the function. This way you explicitly set 'Type' to be a string.

```typescript
let output = echo<string>("Romeo");
```

The second way is by calling the function and only passing the argument. Typescript will infer the types automatically for you.

```typescript
let output = echo("Romeo");
```

> Always use the first way when working on complex code because TypeScript may fail to infer the proper type.

### The End
Now you know the 101 of TypeScript Generics. Cheers!
Introduction: Hello World!
Tags: webdev, beginners, introduction, womenintech
Published: 2022-07-01 18:17:31

Hey babes! I made this blog thinking about how hard it really is to be a successful woman in technology. Starting out in tech is hard and to suffer from the social stigma and the gender inequality as well is simply maddening. 
This blog won’t be exactly linear but I will try to make some roadmaps on how to navigate it in the easiest and most comfortable way. I hope this blog guides you in how to become ‘that girl’ that is simply on top of everything. I’m still in the way to become that girl myself and would love to share this journey with you. Let’s start!
Can Someone Explain Git Push and Git Pull?
Tags: discuss, anonymous, career
Published: 2022-07-01 18:09:04

_This is an anonymous post sent in by a member who does not want their name disclosed. Please be thoughtful with your responses, as these are usually tough posts to write. Email sloan@dev.to if you'd like to leave an anonymous comment or if you want to ask your own anonymous question._ 

***


Hey, I'm new to coding and I'd really love some help - can you please explain to me the difference between Git Push and Git Pull? Thank you.
Host a Website on AWS EC2 Instance
Tags: aws, ec2, cloud
Published: 2022-07-01 18:08:56

Through this blog I'll provide a step-by-step guide through which you can host your static website on an AWS EC2 Instance.

So the services that we'll using are **EC2 Instance** and **S3 Bucket** _(Used to store the code files)_.

####1. The first step is to create an S3 bucket
######Couple of important things to note are:
* The bucket name is required to be unique and if you are planning to connect a domain name make sure your domain & bucket name are the same.
* Also make sure you uncheck **Block all public access** otherwise the bucket won't be accessible.

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

####2. The next step is upload the code files
Inside the bucket click on the upload button and upload the respective code files onto the bucket. 

####3. Change permission
In order for the bucket to be accessible we also need to make a change in the the permission section by modifying the bucket policy with the following code:
```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion"
            ],
            "Resource": [
                "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"
            ]
        }
    ]
}
```
Here you need to replace _DOC-EXAMPLE-BUCKET_ with your bucket name.

####4. Now it's time to create an EC2 Instance
I've created a basic instance within the free-tier eligibility.

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

####5. Connecting to the instance
The connection with instance is established using **ssh**, you can use the following command and replace the **IP** with your respective **IP** and **Key**.
```
ssh -i "peterawsjan.pem" ec2-user@18.221.22.171
```

####6. Setting up the web server
First of all let's grab the sudo permission by entering
```
sudo su
```
Now its time to set things up, our EC2 Instance will act as an Server so for that we install httpd.
```
yum install httpd
```

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

Now that's done we need to pull data from our S3 bucket to the html folder of our Instance for that lets change directory.
```
cd  /var/www/html/
```
To fetch data from S3 bucket we need the **object url** which can be found in **index.html** file in the S3 section of the AWS console.
```
wget "your object URL"
```
Once you fetch it the type will be **.zip** and you need to unzip and move
```
uzip "your folder name"
mv "your folder name"* .
```

#####That's it now its time to start our server.
```
service httpd.service
```

You can access your hosted website by searching your Instances IP address.

I really hope this blog helped you host your website using EC2 Instance, Thank you.
What was your win this week?
Tags: discuss, weeklyretro
Published: 2022-07-01 17:44:50

---
title: What was your win this week?
published: true
description: Got to all your meetings on time? Started a new project? Fixed a tricky bug?
tags: discuss, weeklyretro
cover_image: https://cl.ly/188e843c2985/download/Image%202019-02-15%20at%202.36.37%20PM.png
---

Hey there! 


Looking back on this past week, what was something you were proud of accomplishing?

All wins count — big or small 🎉

Examples of 'wins' include:

- Starting a new project
- Fixing a tricky bug
- Trying out a new recipe... or whatever else might spark joy ❤️ 

---

Have a wonderful weekend!


![woman dancing and saying "rolling intoo the wekend](https://media.giphy.com/media/OBIEYut6DYt4Tc6ugK/giphy-downsized-large.gif)
Looking for Study Buddy to become a self taught Web Developer
Tags: beginners, webdev, computerscience, help
Published: 2022-07-01 17:23:19

Hi There,

I'm follow Vincent's roadmap (https://dev.to/vincentntang/recommended-learning-path-for-a-self-taught-web-developer-react-nodejs-3b53) to become a self taught web developer. I'm currently working full time for an a utility company as an Electrical Engineer. My current job is busy during the day, but I usually have the evening and the whole weekend for myself to study.

I've try to study myself and found it is difficult to stick to my plan after my day job. I'm looking for a study buddy (or buddies) to motivate each other and catch up with each other possibly once or twice a week. I'm currently studying Javascript, HTML and CSS.
Request buffering with reverse proxies
Tags: devops
Published: 2022-07-01 17:14:52

## What is a reverse proxy?

A reverse proxy is a server that forwards requests from the client to another server.

![Flow chart describing relationship between client, reverse proxy, and upstream server.  The client is on the left with an arrow pointing towards the reverse proxy, which is in the center of the flow chart.  The reverse proxy points towards the upstream server, which is on the right.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/leahl8u922jdon4xqad9.png)

## Why use reverse proxies

There are several reasons you might want to use a reverse proxy:

- Load balancing - a reverse proxy can be used to distribute requests across a number of servers.
- Caching - caching and serving content from a reverse proxy can increase performance.
- Security - using a reverse proxy will obscure architectural details of your backend infrastructure as well as server identities (the IP of the origin server for instance).
- Maintainability - in the event that your upstream server moves, you would only need to update the value of the upstream server in a single place.
- Request buffering - Minimizes upstream server execution time.

### A closer look at request buffering

![Flow chart describing relationship between client, reverse proxy, and upstream server.  The client is on the left with an arrow pointing towards the reverse proxy, which is in the center of the flow chart.  This relationship is described as "slow request".  The reverse proxy points towards the upstream server, which is on the right.  This relationship is described as "fast request".](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1keq8t993tm0ypxyvplg.png)

Let’s take the example of a client on a slow connection trying to upload a large file (an image for instance) to a server.  When the server receives this request it will be blocked until it receives the entire request & processes it.  Essentially, the servers execution time will be directly affected by the connection speed of the client.

A reverse proxy will wait to receive all of the request from the client before forwarding it to the upstream server.  This means that the actual execution time on the server is greatly reduced, as this server-to-server request is much faster than the client-to-server request.

This pattern can be particularly useful when your upstream server has strict execution time limitations.  For example, [Netlify’s synchronous serverless functions](https://docs.netlify.com/functions/overview/#default-deployment-options) have an execution limit of 10 seconds, which begins as soon as the http connection is opened.  Using a reverse proxy in this case could decrease the risk of hitting that execution limit.
How To Install SQL Server on Ubuntu
Tags: sql, ubuntu, dotnet, tutorial
Published: 2022-07-01 17:10:51

In this post, we'll learn How to Install Microsoft SQL Server on Ubuntu VPS Server. and we will see how to connect and manage it remotely using SQL Server Management Studio on windows.

## Let's Get a VPS Server

In this tutorial, I will use VULTR, and if you wanna follow with me a test, you can use [this link](https://learnwithhasan.com/refer/vultr) to get 100$ free credits for two weeks!

**Create a new VPS**
![vultr create server](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7fvkx96x2fa49rhu48l.png)
 

1. Select Cloud compute.
2. Select any region you want.
3. Select Ubuntu as the OS.
4. Enter server name (anything you want)
5. Click deploy

VULTR will install, deploy, and prepare this Ubuntu Linux server in your account. And when it's finished, you will see the IP address, the username, and the password.

![vultr vps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbhcuz7uc0bzv83f231a.png)

**Great! we have an Ubuntu Server ✅** Let's Start the installation.

we will be using [putty SSH client](https://www.putty.org/) to connect and manage our server.

Open putty, enter the server IP, and connect:
![putty connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdho4nlqs95y3lss5d6t.png)

Enter "root" as the user name, and get the password from Vultr Dashboard.
 

## Install SQL Server

The first command is wget command:
`wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -`

**Adding SQL server package**
`sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"`

_NOTE: This may change depending on the Ubuntu version you are working with._

**Update SQL Server**
`sudo apt-get update `

`sudo apt-get install -y mssql-server`

**Configuration command **
`sudo /opt/mssql/bin/mssqql-conf setup`

Now Continue the wizard:
1. Select your edition, I will go with express.
2. Accept Terms (Y)

**Set The SQL Server Password**

And Congratulations! SQL Server is now starting 🎉 


**SQL Server Run Check Command:**
`systemctl status mssql-server --no-pager`

![Sql server on ubuntu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpmsb7c2es1ed3wb3bgw.png)

And it's running perfectly.🚀🚀🚀



## Managing With SQL Server Management Studio

**Setting up SQL Server Remote Port**

in putty, run this command:
`Sudo iptables -A INPUT -p tcp –dport 1433 -j ACCEPT` 

Now we can connect to SQL server from our local PC.

Open SQL Management Studio, Enter your server IP.
![sql server management studio](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ncviysrjti2a4ykyfqy.png)
 
Enter "sa" for the user name, and enter your sql server password that you chose in the setup.

**Connect!**
Yay, it did work!!!👌


I'll be answering questions in the comments below if you have any.


****
How to create a LAMP Server on AWS
Tags: aws, beginners, tutorial
Published: 2022-07-01 16:48:15

Hello Amazing people :wave: Here's a beginner friendly project to get-started with public cloud services

Some prerequisities: Basic Understanding of linux commands, networking and cloud


### Let's get started


### Phase1: Linux Server setup on AWS
- Login `AWS portal` -> Go to `EC2 services` -> `Launch an instance`
- Select instance AMI `Red Hat Linux 8` or `Rocky Linux 8`
- Create a new security group to allow `HTTP`, `HTTPS` & `SSH`
- Create a `key-pair` -> Launch the instance
- Connect instance with `ssh` using local terminal
```
  ssh -i <key-pair.pem file> ec2-user@<instance public ipv4 address>
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ip73mew993edcf0a798h.png)

### Phase2: Apache Server setup
- Connect instance with ssh
- Install the `apache server` with `dnf` package manager command
```
  sudo dnf install httpd -y && sudo systemctl start httpd
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sb47f17cxly73enxtiqd.png)
- Go to the public IPv4 address to view the apache server
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8czx73hxrm9ii588jsp2.png)

### Phase3: Database Server setup
- Install the latest `mariadb database server` setup with `dnf` package manager command
```
  sudo dnf install mariadb-server -y
```
- Start the server
```
  sudo systemctl start mariadb && mysql_secure_installation
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hn7f4hxy00vuyctc4fou.png)
- Log in mysql database and check the databases to ensure database setup

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

### Phase 4: PHP Server Module
- Enable the `php module` and install with `dnf` package manager command
```
  sudo dnf module enable php:7.4 && sudo dnf install php
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/211btb24sunt62za1n3c.png)
- Start `php-fpm` module to optimize and restart to apply changes 
```
  sudo systemctl start php-fpm && sudo systemctl restart httpd php-fpm
```
- Go to <Public IPv4 Address>/phpinfo.php to ensure php module installation. If you are not able to view phpinfo webpage, ensure the file is in the correct directory, or create one with terminal
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58fxbnval1haq8ubgwqp.png)

### Completion
That's it, the LAMP Server is up and running!:partying_face:

If you want to have a more detailed step-by-step procedure, please checkout my [Github](https://github.com/miihirsawant-git/aws-lamp-server) page or feel free to to reach out on [Twitter](https://twitter.com/miihirsawant).
Virtual Machines
Tags: virtualmachines, ec2, computeengine
Published: 2022-07-01 17:01:57

**Virtual Machine**


We have a process known as server virtualization which is a process of dividing a physical server into multiple unique and isolated virtual servers where each virtual server can run its own operating systems independently. Before we have one physical server on which each application was hosted. As an example, if we have one server then we have only one operating system there and one application will be hosted and that will be serving the request of the users. But, now after the server virtualization concept and the concept of virtual machines(VM) what we have got that single server will be now virtualized which means on this single server itself we will be able to run a lot of virtual machines. There will be one physical server but all of the machines that are running on this single server they will be known as the virtual machines. They won't be present physically but they will be inside the server. So, basically earlier this single server was used for just one purpose but since now the virtualization has happened that means many VMs can run on single server. Depending on the capacity the physical server we can determine what are the number of virtual machines that can be there on a single server. So, basically earlier it was just used for one purpose now it can be used for multiple purposes. Because on a single physical server, we can have multiple virtual machines for different applications and operating systems. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9r9wm5dwfjpu33xp1srl.png)
PHP CRUD Generator - Admin dashboard builder for any MySQL database
Tags: bootstrap, php, database, sql
Published: 2022-07-01 16:58:01

PHP CRUD Generator designs your website administration panel with a simple and user-friendly UI page.

PHP CRUD Generator's smart engine analyzes your MYSQL database in depth: primary and foreign keys, all kinds of relationships.

PHPCG uses the best currently available tools to generate advanced and powerful back-end user panels: all types of fields available, filter lists, built-in jQuery plugins, files and images upload, user management, access rights, and profiles.

https://www.phpcrudgenerator.com