teleren/devto huggingface dataset:
EC2, Lambda, or Elastic Beanstalk?
Tags: aws, lambda, api
Published: 2023-03-07 10:07:11

So, you have a simple node.js applicaiton that takes input an image from S3, applies some operations on it, and then saves it in another S3. 

Here are the options that you might need to consider:

- **EC2**: You can launch an instance with Linux AMI, download dependencies on the instance and launch it to communicate from and to the S3 buckets. 
However, you need to handle:
  - _Scaling_
  - _High Availability_
  - _OS Patching_
  
    If you want to let _AWS manage all this for you_ , Check the 
  second option!
- **Lambda function**: Using Lambda function, you can put the code and add the triggers. In this way, it is fully _SERVERLESS_ approach, you only care about the triggers logic and the code you upload.
But, you need more control over the underlying resources? use the third option. 
- **Elastic Beanstalk**: Deploy your code without worrying about the underlying infrastructure, using more traditional application model.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwg1o8n9dr4pdhvu8mrx.png)
Now that you can distinguish between each of the solutions, you will choose the one that mostly fits your situation!
If you want to build a **IaaS**, go with **_EC2_**.
If you want to build a **FaaS ( Function as a Service!)**, go with **_Lambda_**!
And, you guessed it. If you want to build a **PaaS**, go with **_Beanstalk_**!

Let me know what do you think in the comments!:)

Thanks for reading! I hope you found this post helpful in your journey of AWS!

Feel free to reach me out on the following:
LinkedIn: https://www.linkedin.com/in/lara-wehbe/
Email: larawehbee@outlook.com
Build an Infinite Nested Comments System in React JS | System Design + Code
Tags: react, frontend, javascript, tutorial
Published: 2023-03-07 10:05:26


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wis2nrwkpj4ryoxruts6.png)
Are you looking to create a comments section that can handle unlimited levels of nesting? Look no further! In this step-by-step tutorial, I will show you how to build an infinitely nested comments system in React JS. You'll learn how to implement dynamic rendering, manage state using React Hooks, create a custom hook, add a reply, edit, delete, save, cancel functionalities, and optimize performance for large comment threads. By the end of the video, you'll have a fully functional commenting system that can handle any level of nested replies.

{% embed https://www.youtube.com/watch?v=EGXnsGenlCg %}


If you are interested in react, JavaScript, or frontend development in general, Do checkout and subscribe [xplodivity ](https://www.youtube.com/@xplodivity/videos) on YouTube.
GitHub Actions: Setting up CI for a Node project
Tags: devops, githubactions, coveralls, node
Published: 2023-03-07 10:00:35


CI/CD (Continuous Integration/Continuous Delivery/Development) is now an essential part of all kind of software projects. Today I am going to work you through setting up CI/CD with GitHub Actions.

**Setting up CI**
To use a GitHub action for building your repository at each push (on all branches), all you have to do is to place a YAML file under .github/workflows and commit it with your repo.

```
mkdir .github
cd .github
mkdir workflows
cd workflows
```
Inside the created `.yml` file, Add the following.
```
# This workflow will do a clean install of node dependencies, build the source code and run tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: CI Pipeline

# trigger build when pushing, or when creating a pull request
on: [push, pull_request]

jobs:
  build:

    # run build on latest ubuntu
    runs-on: ubuntu-latest

    steps:
    # this will check out the current branch (https://github.com/actions/checkout#Push-a-commit-using-the-built-in-token)
    - uses: actions/checkout@v3
    # installing Node
    - name: Use Node.js 16.16.0
      uses: actions/setup-node@v3
      with:
        # this will use the latest Node 16 version
        node-version: 16.16.0
    # install dependencies using clean install to avoid package lock updates
    - run: npm ci
    # build the project if necessary
    - run: npm run build --if-present
    # finally run the test
    - run: npm test
```
What this workflow basically does is,

- checkout the branch
- install node (on ubuntu)
- install the dependencies of your project and build it if necessary
- finally, run the tests

Comments are added on every line explaining the setup.

After! Commit & push your work and head over to the Actions section of your repo where you can see all executed workflows…

![GitHub Action execution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rpu1iqtk1mpov5uv4v2.png)
And Click on the workflow to view detailed results

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

And Voila, you have a working GitHub Action workflow now.
<img width="100%" style="width:100%" src="https://media.giphy.com/media/1BFEEIo4h1BuTH8eqP/giphy.gif">
Paracetamol.ts💊| #27: Explica este código TypeScript
Tags: typescript, javascript, spanish, webdev
Published: 2023-03-07 10:00:00

## **<center>Explica este código TypeScript</center>**
#### <center>**Dificultad:** <mark>Intermedio</mark> </center>

```ts
let y: number[] | string[];
```

¿Cuál de los siguientes arreglos **no** es asignable a `y`?

- A. `[]`
- B. `[1, 2, 3]`
- C. `["uno", "dos", "tres"]`
- D. `[1, "dos", 3]`

{% spoiler **Respuesta** %} 

✅ D. `[1, "dos", 3]`

La sintaxis de `y` solo acepta valores:
* Arreglos **solo** de números.
* Arreglos **solo** de cadenas de texto.

No acepta arreglos mixtos, la sintaxis para arreglos mixtos sería:
`let y:(number | string)[];`

{% endspoiler %}

---

Puedes ver el último reto acá:

{% link https://dev.to/duxtech/paracetamolts-26-explica-este-codigo-typescript-5665?preview=3640df63d2f913079ca70982f8f3e0a17ac832696257dafe11756dfaf62bbcb8f6ce9fe2244743e9430158839302c0d31cba00207a29e242ac139896 %}
Cloud Computing: The Key to Scaling Your Applications
Tags: cloud, computerscience
Published: 2023-03-07 10:00:00

Cloud computing is a type of computing that delivers scalable resources, such as storage, computing power, and software, over the internet. By using cloud computing, developers can achieve scalability, flexibility, and cost-effectiveness in their applications.

## **What is Cloud Computing?**

Cloud computing is a type of computing that delivers scalable resources, such as storage, computing power, and software, over the internet. Cloud computing services are provided by companies such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP).

Cloud computing has several characteristics, such as:

- On-demand self-service
- Scalable resources
- Pay-as-you-go pricing
- Virtualized resources

Cloud computing allows users to access resources, such as storage and computing power, through the internet without the need to invest in and maintain their own infrastructure.

## **The Benefits of Cloud Computing**

Cloud computing provides numerous benefits for software development, including:

- **Scalability:** By delivering scalable resources over the internet, cloud computing can handle an increasing amount of load and traffic without a decrease in performance.
- **Flexibility:** By delivering scalable resources over the internet, cloud computing can be more flexible and easier to maintain.
- **Cost-effectiveness:** By delivering scalable resources over the internet, cloud computing can be more cost-effective than investing in and maintaining your own infrastructure.
- **Disaster recovery:** By delivering scalable resources over the internet, cloud computing provides disaster recovery options, allowing for faster recovery in case of failure.

## **An Example: A Social Media Platform**

An example of cloud computing is a social media platform. The platform uses cloud computing services such as AWS to deliver scalable resources, such as storage and computing power, over the internet. The platform stores user data, such as pictures and videos, in the cloud, and it uses computing power from the cloud to process and display the data to the user.

By using cloud computing, the social media platform can handle a large number of users and a high volume of traffic without a decrease in performance, and it can be more flexible and cost-effective than investing in and maintaining its own infrastructure.

## **Conclusion**

Cloud computing is a type of computing that delivers scalable resources, such as storage, computing power, and software, over the internet. By using cloud computing, developers can achieve scalability, flexibility, and cost-effectiveness in their applications. Cloud computing is becoming more and more popular in today's world, it allows for more efficient use of resources, a more robust and scalable solution, and a more cost-effective way to handle the growth of your application. Start exploring the world of cloud computing and see how it can benefit your software development process. Cloud computing can be a powerful tool to handle the complexity of modern systems and adapt to new requirements.
A Short Handbook for TypeScript
Tags: webdev, typescript, javascript, programming
Published: 2023-03-07 09:59:55

TypeScript is a programming language that extends JavaScript by adding types. Types are annotations that describe the kind of data that a variable can hold, such as numbers, strings, booleans, arrays, objects, functions, etc.

In this post let’s explore the noteworthy ways to declare and use types, functions, interfaces, generics, and classes in TypeScript.

## BENIFITS OF USING TYPES

You might be wondering why bother with types if JavaScript works fine without them, after all!

With TypeScript, you can avoid common errors like typos, null pointer exceptions, or incorrect function calls. You can also refactor your code with confidence, knowing that any changes will be checked by the compiler and flagged if they break something. TypeScript also helps you write more expressive and concise code by providing features like interfaces, generics, unions, intersections, and more. These features allow you to define and manipulate types in powerful ways that are not possible in plain JavaScript. In short, TypeScript makes your life easier as a developer by making your code safer, cleaner, and smarter.

## HOW TO USE BASIC TYPES

For TypeScript, there are several built-in types that you can use to define variables, functions, and objects. Here are some examples of TypeScript types and how to use them:


```
// boolean type
let isDone: boolean = false;

// number types (integer and floating-point)
let decimal: number = 6;
let hex: number = 0xf00d;
let binary: number = 0b1010;
let octal: number = 0o744;

// string type
let color: string = "blue";
let fullName: string = `Bob Bobbington`;
let sentence: string = `Hello, my name is ${fullName}.`;

// array type
let list: number[] = [1, 2, 3];
let list2: Array<number> = [1, 2, 3];

// tuple type
let x: [string, number];
x = ["hello", 10];

// enum type
enum Color {
  Red,
  Green,
  Blue,
}
let c: Color = Color.Green;

// any type
let notSure: any = 4;
notSure = "maybe a string instead";
notSure = false;

// void type (function that returns no value)
function warnUser(): void {
  console.log("This is my warning message");
}

// null and undefined types
let u: undefined = undefined;
let n: null = null;
```

Read the complete [post on my blog](https://bit.ly/3EYyrla).
Calling OpenAI API from Crystal Language
Tags: openai, crystal
Published: 2023-03-07 09:59:25

If you want to use OpenAI API from Crystal Language, you can use the following code. (Note that you need a paid API KEY to call OpenAI API.) Make sure to set the environment variable so that `ENV["OPENAI_ACCESS_TOKEN"]` works.


```crystal
require "option_parser"
require "http/client"
require "json"

data = {
  "model"       => "text-davinci-003",
  "prompt"      => "Hi!",
  "max_tokens"  => 10,
  "temperature" => 0,
}

OptionParser.parse do |parser|
  parser.on("-m INT", "--max-tokens INT") { |v| data["max_tokens"] = v.to_i }
end

data["prompt"] = ARGV.join(" ")

url = "https://api.openai.com/v1/completions"
api_key = ENV["OPENAI_ACCESS_TOKEN"]
headers = HTTP::Headers{
  "Authorization" => "Bearer #{api_key}",
  "Content-Type"  => "application/json",
}
response = HTTP::Client.post(url, body: data.to_json, headers: headers)

if response.status.success?
  response_data = JSON.parse(response.body)
  puts response_data["choices"][0]["text"]
else
  puts "Error: #{response.status_code} #{response.status}"
end
```

## How to use?

```sh
crystal run file_name.cr -- Are you fine?
crystal run file_name.cr -- -m 20 Are you fine?
```

Or, after build,

```sh
executable_file Are you fine?
executable_file -m 20 Are you fine?
```

Have a nice day!
How to Configure SSL on PostgreSQL
Tags: postgres, database, ssl, sercurity
Published: 2023-03-07 09:31:27

Configuring PostgreSQL with SSL involves several steps, including:
 

Generate SSL Certificate

The first step is to generate an SSL certificate that will be used to secure the communication between the client and the server.
This can be done using a tool such as OpenSSL.
For example, to generate a self-signed certificate, you can use the following command:
openssl req -new -x509 -nodes -out server.crt -keyout server.key
This will generate a certificate and a private key file in the current directory.

Configure PostgreSQL Server

The next step is to configure the PostgreSQL server to use SSL.
Open the postgresql.conf file and uncomment the ssl line and set its value to on.
Also, uncomment the ssl_cert_file and ssl_key_file lines and set their values to the paths of the certificate and private key files generated in step 1.
Configure PostgreSQL Client

The PostgreSQL client must also be configured to use SSL to communicate with the server.
Open the pg_hba.conf file and add an entry for SSL connections.
For example:
read more: https://thedbadmin.com/how-to-configure-ssl-on-postgresql/
openGauss Delaying Entering the Maximum Availability Mode
Published: 2023-03-07 09:05:28

## Availability
This feature is available since openGauss 3.0.0.

## Introduction
The primary node can be delayed to enter the maximum availability mode.

## Benefits
When the primary node detects that the standby node exits due to network instability or other reasons and the maximum availability mode is enabled on the primary node, the primary node remains in the maximum protection mode within a specified time window. After the time window expires, the primary node enters the maximum availability mode.

This prevents the primary node from frequently switching between the maximum protection mode and maximum availability mode due to factors such as network jitter and intermittent process disconnection.

## Description
If most_available_sync is set to on, when synchronous standby nodes are faulty in primary/standby scenarios and the number of configured synchronous standby nodes is insufficient (for details, see the meaning of synchonous_standby_name), setting keep_sync_window will retain the maximum protection mode within the time window specified by keep_sync_window. That is, committing transactions on the primary node is blocked, delaying the primary node to enter the maximum availability mode.

If synchronous standby nodes recover from faults and the number of synchronous standby nodes meets the configuration requirements, transactions are not blocked.

## Enhancements
None.

## Constraints
This feature takes effect only when the maximum availability mode is enabled.

Enabling this feature may affect the RPO. If the primary node is faulty within the configured timeout window, its transactions are committed locally but not synchronized to the faulty synchronous standby nodes.

This feature does not apply to cascaded standby nodes.

## Dependencies
This feature depends on the maximum availability mode.
How to stop Homebrew auto update on mac terminal
Tags: mac, homebrew
Published: 2023-03-07 08:55:44

![redis-install-command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5v1ztbenhw26usmfllo0.png)

## Introduction

I wanted to install redis on my mac but the issue faced by me while install is that it took too much time. So thought of disabling it.

Homebrew is an opensource package manager on mac and most of the people use it to install various tools and software to on mac.

Let's find how to disable the auto-update on homebrew. 




## How to disable it 
There are multiple ways to disable it. Let's look at some ways.

```
HOMEBREW_NO_AUTO_UPDATE=1 brew install <formula>
```

```
export HOMEBREW_NO_AUTO_UPDATE=1
```
If you are using the above method then you need to make this article/commands handly so that you can access it easily.

## Disable Permanently 
You can disable `auto-update` in terminal permanently by setting the environment variable in `.bashrc` or `.zshrc` file.

### For bash
```bash
$ vim ~/.bashrc
export HOMEBREW_NO_AUTO_UPDATE=1
```

```
source ~/.bashrc
```

### For zsh
```zsh
$ vim ~/.zshrc
export HOMEBREW_NO_AUTO_UPDATE=1
```
```
source ~/.zshrc
```
openGauss Delayed Replay
Published: 2023-03-07 09:02:50

## Availability
This feature is available since openGauss 1.1.0.

## Introduction
The time for a standby node to replay can be delayed.

## Benefits
By default, the standby server restores the Xlog records from the primary server as soon as possible. This function allows you to delay the time for a standby node to replay Xlog records. In this case, you can query a copy that records data before a period of time, which helps correct errors such as misoperations.

## Description
The GUC parameter recovery_min_apply_delay can be used to set the delay time so that a standby server can replay Xlog records from the primary server after a delay time.

Value range: an integer ranging from 0 to INT_MAX. The unit is ms.

Default value: 0 (no delay)

## Enhancements
None

## Constraints
The recovery_min_apply_delay parameter is invalid on the primary node. It must be set on the standby node to be delayed.
The delay time is calculated based on the timestamp of transaction commit on the primary server and the current time on the standby server. Therefore, ensure that the clocks of the primary and standby servers are the same.
Operations without transactions are not delayed.
After the primary/standby switchover, if the original primary server needs to be delayed, you need to manually set this parameter.
When synchronous_commit is set to remote_apply, synchronous replication is affected by the delay. Each commit message is returned only after the replay on the standby server is complete.
Using this feature also delays hot_standby_feedback, which may cause the primary server to bloat, so be careful when using both.
If a DDL operation (such as DROP or TRUNCATE) that holds an AccessExclusive lock is performed on the primary server, the query operation on the operation object on the standby server will be returned only after the lock is released during the delayed replay of the record on the standby server.
Dependencies
None
openGauss Cascaded Standby Server
Published: 2023-03-07 09:01:45

## Availability
This feature is available since openGauss 1.1.0.

## Introduction
A cascaded standby server can be connected to a standby server based on the one-primary-multiple-standby architecture.

## Benefits
The one-primary-multiple-standby architecture cannot support a flexible structure in special service scenarios. The multi-equipment room deployment cannot meet requirements of the complete structure in the HA switchover scenario (three instances in the primary-standby equipment rooms and two or three instances in the standby-standby equipment rooms). If the number of standby servers increases, the primary server may be overloaded. Queries that have low real-time requirements can be implemented on cascaded standby servers. Therefore, the cascading backup capability is required.

## Description
The primary server replicates logs to the standby server in synchronous or asynchronous mode. The standby server replicates logs to the cascaded standby server only in asynchronous mode.

In the current one-primary-multiple-standby architecture, the primary server uses the WAL sender process (walsender) to replicate logs to the standby server. The standby server uses the WAL receiver process (walreceiver) to receive and then flushes logs to local disks. The standby server reads redo logs to complete data replication between the primary and standby servers. There is a one-to-one mapping between walsender and walreceiver on the primary and standby servers. Logs are sent between the standby and cascaded standby servers in asynchronous mode using walsender and walreceiver, reducing the streaming replication pressure on the primary server.

## Enhancements
None

## Constraints
A cascaded standby server can only replicate data from a standby server and cannot directly replicate data from the primary server.
A cascaded standby server does not support data build from a standby server. Currently, data can be built only from the primary server. If the standby server is fully built, the cascaded standby server needs to be fully built.
The cascaded standby node is in asynchronous replication mode.
The cascaded standby server cannot be promoted.
The cascaded standby server cannot be notified.
Currently, the overall architecture of the primary-standby-cascaded standby cluster cannot be queried. You need to find the standby server through the primary server and then find the cascaded standby server based on the standby server.
A cascaded standby server cannot own another cascaded standby server.
When the ultimate RTO is enabled, no cascaded standby server is supported.
Dependencies
None
openGauss High Availability Based on the Paxos Protocol
Published: 2023-03-07 08:59:48

## Availability
This feature is available since openGauss 2.1.0.

## Introduction
After the DCF mode is enabled, database nodes support Paxos-based replication and quorum capabilities. Primary database node selection and log replication are performed based on Paxos. Compression and flow control are supported during the replication to prevent high bandwidth usage. It supports multiple types of nodes based on the Paxos protocol and the node roles can be adjusted as required. You can query the instance status in the current database.

## Description
During log replication, DCF supports log compression before transmission to reduce network bandwidth usage.
DCF supports passive nodes, which do not participate in node election and only synchronize and replay logs. When this type of nodes is heavily loaded during log synchronization, flow control is performed.
DCF supports logger nodes, which participate in node election and voting. However, the logger nodes only replicate DCF logs. Xlogs are not replicated and redo is not performed.
DCF supports online switchover between follower and passive nodes. That is, without interrupting services, a node can switch over between the follower and passive roles.
DCF supports forcible startup of the minority of nodes. In case that the majority of database instances are faulty, a minority of standby nodes are selected and forcibly promoted to primary, and other normal standby nodes replicate logs from the primary nodes.
DCF supports primary node selection. When the original primary node is faulty, a new primary node is automatically selected from the remaining standby nodes on the premise that data consistency is ensured.

## Enhancements
None.

Constraints
To use this function, you need to enable DCF during installation and deployment.

Dependencies
None.
How to use Locomotive Scroll with Svelte ?
Tags: javascript, svelte, webdev, programming
Published: 2023-03-07 08:59:24

I want to use Locomotive Scroll in my Svelte project but I didn't see any example of it. I only saw people using Locomotive Scroll with Sveltekit. So I wonder if using Loco Scroll with Svelte is different from regular JS ?