teleren/devto huggingface dataset:
Day 5: Conditional Rendering and Lists in React
Tags: react, javascript, learning
Published: 2024-05-10 16:46:30

## 🚀 Check Out My YouTube Channel! 🚀
Hi everyone! If you enjoy my content here on Dev.to, please consider subscribing to my YouTube channel [devDive with Dipak](https://www.youtube.com/@DevDivewithDipak). I post practical full-stack development videos that complement my blog posts. Your support means a lot!

Welcome to Day 5 of our React.js learning journey! Today, we'll explore how to implement conditional rendering and work with lists in React. These concepts are essential for building dynamic and interactive user interfaces.

### Conditional Rendering in React

Conditional rendering allows you to show or hide components based on certain conditions. In React, you can achieve conditional rendering using JavaScript expressions within JSX. Let's look at an example:

```jsx
function Greeting({ isLoggedIn }) {
  return isLoggedIn ? <p>Welcome back!</p> : <p>Please log in.</p>;
}

function App() {
  const isLoggedIn = true;

  return (
    <div>
      <Greeting isLoggedIn={isLoggedIn} />
    </div>
  );
}
```

In this example, the `Greeting` component renders a different message based on the value of `isLoggedIn`. If `isLoggedIn` is `true`, it displays "Welcome back!", otherwise it shows "Please log in."

### Rendering Lists in React

Lists are a common feature in web applications, and React provides a simple way to render lists of elements dynamically. You can use the `map` method to iterate over an array and render components for each item. Here's an example:

```jsx
function TodoList({ todos }) {
  return (
    <ul>
      {todos.map(todo => (
        <li key={todo.id}>{todo.text}</li>
      ))}
    </ul>
  );
}

function App() {
  const todos = [
    { id: 1, text: 'Learn React' },
    { id: 2, text: 'Build a project' },
    { id: 3, text: 'Deploy to production' }
  ];

  return (
    <div>
      <h2>My Todo List</h2>
      <TodoList todos={todos} />
    </div>
  );
}
```

In this example, the `TodoList` component receives an array of todos and uses the `map` method to render a list of todo items dynamically.

### Conclusion

Today, you've learned how to implement conditional rendering and work with lists in React. Conditional rendering allows you to show or hide components based on conditions, while rendering lists dynamically enables you to display collections of elements efficiently.

By mastering these concepts, you can create more interactive and engaging user interfaces in your React applications. Stay tuned for Day 6, where we'll explore more advanced topics in React development.

---

I hope this blog post has provided you with a clear understanding of how to implement conditional rendering and work with lists in React. Feel free to experiment with these concepts in your own projects to solidify your knowledge. Good luck with your React.js learning journey!
Kinh nghiệm cá cược trực tuyến để luôn chiến thắng - Sunwin
Published: 2024-05-10 16:45:21

Để có được kinh nghiệm chơi 笠 cá cược thể thao chuyên nghiệp và hiệu quả, bạn cần lưu ý một số điểm sau:


Tìm hiểu kỹ về các môn thể thao mình quan tâm 🏉. Đừng chọn cá cược một cách ngẫu nhiên mà hãy thu thập thông tin về đội bóng, các cầu thủ, mùa giải,... để có cơ sở phán đoán chính xác hơn.


Xây dựng chiến lược cá cược đặt cược cho từng loại kèo như: tỉ số châu Á, tổng điểm, cửa đen,... Điều chỉnh chiến lược khi cần thiết.


Kiểm soát tỷ lệ thắng thua, không nên đặt tiền bừa vào mọi trận. Dành ra một phần quỹ cho những trận có khả năng thua cao hơn.


Luôn cập nhật thông tin mới nhất về cầu thủ chấn thương, kỷ luật,...ảnh hưởng trực tiếp đến kết quả trận đấu.


Tận dụng các ưu đãi của nhà cái như tiền cược miễn phí, hoàn tiền khi thua,...để giảm thiểu rủi ro khi chơi lâu dài.


Luôn giữ tinh thần thoải mái, không đánh liều khi thấy may mắn. Biết xoay sở để lấy lại vốn khi gặp thua để tiếp tục chơi.


Chia nhỏ số tiền c - i95swibwtp - https://sunwin35.com/kinh-nghiem-choi/page/2/
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvjwnvsz0lmsk69zguff.jpeg)
React Day Berlin
Tags: webdev, javascript, programming, react
Published: 2024-05-10 16:44:19

React Day Berlin's 6th edition is back on December 13 & 16! 🎉 Dive into the Reactverse, connect with 800+ devs, listen to 45+ talks, and unwind at the afterparty with DJs & live coders 🎶All this in the vibrant EU tech hub city - Berlin! Grab your ticket: https://reactday.berlin
2530. Maximal Score After Applying K Operations
Tags: php, algorithms, leetcode, programming
Published: 2024-05-10 16:17:52

2530\. Maximal Score After Applying K Operations

Medium

You are given a **0-indexed** integer array `nums` and an integer `k`. You have a **starting score** of `0`.

In one **operation**:

1. choose an index `i` such that `0 <= i < nums.length`,
2. increase your **score** by `nums[i]`, and
3 replace `nums[i]` with `ceil(nums[i] / 3)`.

Return the maximum possible **score** you can attain after applying **exactly** `k` operations.

The ceiling function `ceil(val)` is the least integer greater than or equal to `val`.



**Example 1:**

- **Input:** nums = [10,10,10,10,10], k = 5
- **Output:** 50
- **Explanation:** Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.

**Example 2:**

- **Input:** nums = [1,10,3,3,3], k = 3
- **Output:** 17
- **Explanation:** You can do the following operations:
  - Operation 1: Select i = 1, so nums becomes [1,**4**,3,3,3]. Your score increases by 10.
  - Operation 2: Select i = 1, so nums becomes [1,**2**,3,3,3]. Your score increases by 4.
  - Operation 3: Select i = 2, so nums becomes [1,1,**1**,3,3]. Your score increases by 3.
  - The final score is 10 + 4 + 3 = 17.



**Constraints:**

- `1 <= nums.length, k <= 105`
- `1 <= nums[i] <= 109`


**Solution:**

```
class Solution {

    /**
     * @param Integer[] $nums
     * @param Integer $k
     * @return Integer
     */
    function maxKelements($nums, $k) {
        $pq = new SplMaxHeap(); // Building Max Heap
        $ans = 0;
        foreach($nums as $num){
            $pq->insert($num);
        }
        $sum = 0;
        for($i=0; $i<$k; $i++){
            $t = $pq->extract();
            $sum += (int)$t;
            $pq->insert((int)($t+2)/3); // taking ceil value
        }
        return $sum;
    }
}
```


**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
2570. Merge Two 2D Arrays by Summing Values solution
Tags: php, algorithms, leetcode, programming
Published: 2024-05-10 16:17:45

2570\. Merge Two 2D Arrays by Summing Values solution

Easy

You are given two **2D** integer arrays nums1 and nums2.


* <code>nums1[i] = [id<sub>i</sub>, val<sub>i</sub>]</code> indicate that the number with the id <code>id<sub>i</sub></code> has a value equal to <code>val<sub>i</sub></code>.
* <code>nums2[i] = [id<sub>i</sub>, val<sub>i</sub>]</code> indicate that the number with the id <code>id<sub>i</sub></code> has a value equal to <code>val<sub>i</sub></code>.


Each array contains **unique** ids and is sorted in **ascending** order by id.

Merge the two arrays into one array that is sorted in ascending order by id, respecting the following conditions:

* Only ids that appear in at least one of the two arrays should be included in the resulting array.

* Each id should be included **only once** and its value should be the sum of the values of this id in the two arrays. If the id does not exist in one of the two arrays then its value in that array is considered to be `0`.

Return <i>the resulting array</i>. The returned array must be sorted in ascending order by id.


**Example 1:**

**Input:** nums1 = [[1,2],[2,3],[4,5]], nums2 = [[1,4],[3,2],[4,1]]
**Output:** [[1,6],[2,3],[3,2],[4,6]]
**Explanation:** The resulting array contains the following:
- id = 1, the value of this id is 2 + 4 = 6.
- id = 2, the value of this id is 3.
- id = 3, the value of this id is 2.
- id = 4, the value of this id is 5 + 1 = 6.

**Example 2:**

**Input:** nums1 = [[2,4],[3,6],[5,5]], nums2 = [[1,3],[4,3]]
**Output:** [[1,3],[2,4],[3,6],[4,3],[5,5]]
**Explanation:** There are no common ids, so we just include each id with its value in the resulting list.

**Constraints:**

* <code>1 <= nums1.length, nums2.length <= 200</code>
* <code>nums1[i].length == nums2[j].length == 2</code>
* <code>1 <= id<sub>i</sub>, val<sub>i</sub> <= 1000</code>
* Both arrays contain unique ids.
* Both arrays are in strictly ascending order by id.

**Solution:**

```
class Solution {

    /**
     * @param Integer[][] $nums1
     * @param Integer[][] $nums2
     * @return Integer[][]
     */
    function mergeArrays($nums1, $nums2) {
        $result = [];
        $i = $j = 0;
        while ($i < count($nums1) || $j < count($nums2)) {
            if ($j == count($nums2) || ($i < count($nums1) && $nums1[$i][0] < $nums2[$j][0])) {
                if ($result && $result[count($result) - 1][0] == $nums1[$i][0]) {
                    $result[count($result) - 1][1] += $nums1[$i][1];
                } else {
                    $result[] = $nums1[$i];
                }
                $i++;
            } else {
                if ($result && $result[count($result) - 1][0] == $nums2[$j][0]) {
                    $result[count($result) - 1][1] += $nums2[$j][1];
                } else {
                    $result[] = $nums2[$j];
                }
                $j++;
            }
        }
        return $result;
    }
}
```


**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
3121. Count the Number of Special Characters II
Tags: php, algorithms, leetcode, programming
Published: 2024-05-10 16:17:17

3121\. Count the Number of Special Characters II

Easy

You are given a string `word`. A letter `c` is called **special** if it appears **both** in lowercase and uppercase in `word`, and `every` lowercase occurrence of `c` appears before the **first** uppercase occurrence of `c`.

Return the number of **special** letters in `word`.

**Example 1:**

- **Input:** word = "aaAbcBC"
- **Output:** 3
- **Explanation:** The special characters are `'a'`, `'b'`, and `'c'`.

**Example 2:**

**Input:** word = "abc"
**Output:** 0
**Explanation:** There are no special characters in `word`.

**Example 3:**

**Input:** "AbBCab"
**Output:** [0,1]
**Explanation:** There are no special characters in `word`.

**Constraints:**

- <code>1 <= word.length <= 2 * 10<sup>5</sup></code>
- `word` consists of only lowercase and uppercase English letters.

**Solution:**
```
class Solution {

    /**
     * @param String $word
     * @return Integer
     */
    function numberOfSpecialChars($word) {
        $first = array_fill(0, ord('z') + 1, 0);
        $last = array_fill(0, ord('z') + 1, 0);
        for ($i = 1; $i <= strlen($word); ++$i) {
            $j = ord($word[$i - 1]);
            if ($first[$j] == 0) {
                $first[$j] = $i;
            }
            $last[$j] = $i;
        }
        $ans = 0;
        for ($i = 0; $i < 26; ++$i) {
            if ($last[ord('a') + $i] && $first[ord('A') + $i] && $last[ord('a') + $i] < $first[ord('A') + $i]) {
                ++$ans;
            }
        }
        return $ans;
    }
}
```


**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
3122. Minimum Number of Operations to Satisfy Conditions
Tags: php, leetcode, programming, algorithms
Published: 2024-05-10 16:17:04

3122\. Minimum Number of Operations to Satisfy Conditions

Medium

You are given a 2D matrix `grid` of size `m x n`. In one **operation**, you can change the value of **any** cell to **any** non-negative number. You need to perform some operations such that each cell `grid[i][j]` is:

- Equal to the cell below it, i.e. `grid[i][j] == grid[i + 1][j]` (if it exists).
- Different from the cell to its right, i.e. `grid[i][j] != grid[i][j + 1]` (if it exists).

Return the **minimum** number of operations needed.


**Example 1:**


- **Input:** grid = [[1,0,2],[1,0,2]]
- **Output:** 0
- **Explanation:** 

    ![examplechanged](https://assets.leetcode.com/uploads/2024/04/15/examplechanged.png)


All the cells in the matrix already satisfy the properties.

**Example 2:**

- **Input:** grid = [[1,1,1],[0,0,0]]
- **Output:** 3
- **Explanation:**

  ![example21](https://assets.leetcode.com/uploads/2024/03/27/example21.png)

The matrix becomes `[[1,0,1],[1,0,1]]` which satisfies the properties, by doing these 3 operations:

- Change `grid[1][0]` to 1.
- Change `grid[0][1]` to 0.
- Change `grid[1][2]` to 1.


**Example 3:**

- **Input:** `grid = [[1],[2],[3]]`
- **Output:** 2
- **Explanation:**

  ![changed](https://assets.leetcode.com/uploads/2024/03/31/changed.png)

There is a single column. We can change the value to 1 in each cell using 2 operations.


**Constraints:**

- `1 <= n, m <= 1000`
- `0 <= grid[i][j] <= 9`


**Solution:**

```
class Solution {

    /**
     * @param Integer[][] $grid
     * @return Integer
     */
    function minimumOperations($grid) {
        $m = count($grid);
        $n = count($grid[0]);
        $f = array_fill(0, $n, array_fill(0, 10, INF));
        
        for ($i = 0; $i < $n; ++$i) {
            $cnt = array_fill(0, 10, 0);
            for ($j = 0; $j < $m; ++$j) {
                $cnt[$grid[$j][$i]]++;
            }
            if ($i == 0) {
                for ($j = 0; $j < 10; ++$j) {
                    $f[$i][$j] = $m - $cnt[$j];
                }
            } else {
                for ($j = 0; $j < 10; ++$j) {
                    for ($k = 0; $k < 10; ++$k) {
                        if ($k != $j) {
                            $f[$i][$j] = min($f[$i][$j], $f[$i - 1][$k] + $m - $cnt[$j]);
                        }
                    }
                }
            }
        }
        return min($f[$n - 1]);
    }
}
```


**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
3123. Find Edges in Shortest Paths
Tags: php, leetcode, programming, algorithms
Published: 2024-05-10 16:16:33

3123\. Find Edges in Shortest Paths

Hard

You are given an undirected weighted graph of `n` nodes numbered from `0` to `n - 1`. The graph consists of `m` edges represented by a `2D` array `edges`, where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> with weight <code>w<sub>i</sub></code>.

Consider all the shortest paths from node `0` to node `n - 1` in the graph. You need to find a boolean array `answer` where `answer[i]` is `true` if the edge `edges[i]` is part of **at least** one shortest path. Otherwise, `answer[i]` is `false`.

Return the array `answer`.

**Note** that the graph may not be connected.


**Example 1:**

![graph35drawio-1](https://assets.leetcode.com/uploads/2024/03/05/graph35drawio-1.png)

- **Input:** n = 6, edges = [[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]
- **Output:** [true,true,true,false,true,true,true,false]
- **Explanation:** The following are **all** the shortest paths between nodes 0 and 5:
  - The path `0 -> 1 -> 5`: The sum of weights is `4 + 1 = 5`.
  - The path `0 -> 2 -> 3 -> 5`: The sum of weights is `1 + 1 + 3 = 5`.
  - The path `0 -> 2 -> 3 -> 1 -> 5`: The sum of weights is `1 + 1 + 2 + 1 = 5`.


**Example 2:**

![graphhhh](https://assets.leetcode.com/uploads/2024/03/05/graphhhh.png)

- **Input:** n = 4, edges = [[2,0,1],[0,1,1],[0,3,4],[3,2,2]]
- **Output:** [true,false,false,true]
- **Explanation:** There is one shortest path between nodes 0 and 3, which is the path `0 -> 2 -> 3` with the sum of weights `1 + 2 = 3`.


**Constraints:**

- <code>2 <= n <= 5 * 10<sup>4</sup></code>
- <code>m == edges.length</code>
- <code>1 <= m <= min(5 * 10<sup>4</sup>, n * (n - 1) / 2)</code>
- <code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code>
- <code>a<sub>i</sub> != b<sub>i</sub></code>
- <code>1 <= w<sub>i</sub> <= 10<sup>5</sup></code>
- There are no repeated edges.

**Solution:**

```
class Solution {

    /**
     * @param String $s
     * @param Integer $k
     * @return Integer
     */
    public function longestIdealString($s, $k) {
        // dp[$i] := the longest subsequence that ends in ('a' + $i)
        $dp = array_fill(0, 26, 0);

        for ($i = 0; $i < strlen($s); $i++) {
            $c = $s[$i];
            $charIndex = ord($c) - ord('a');
            $dp[$charIndex] = 1 + $this->getMaxReachable($dp, $charIndex, $k);
        }

        return max($dp);
    }

    private function getMaxReachable($dp, $i, $k) {
        $first = max(0, $i - $k);
        $last = min(25, $i + $k);
        $maxReachable = 0;
        for ($j = $first; $j <= $last; $j++) {
            $maxReachable = max($maxReachable, $dp[$j]);
        }
        return $maxReachable;
    }
}
```


**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
Learning AWS Day by Day — Day 60 — Amazon Elastic Kubernetes Service (EKS)
Tags: aws, cloud, cloudcomputing, beginners
Published: 2024-05-10 16:08:12

Exploring AWS !!

Day 60

Amazon Elastic Kubernetes Service (EKS)

Amazon EKS is a managed certified Kubernetes conformant service, which makes it easier to build, secure, manage, operate and maintain Kubernetes clusters on AWS. Now, what conformant is, it is in accordance with a set of specifications.
Integrates with services like CloudWatch, Auto Scaling Groups, and IAM to provide scaling and monitoring for your containerized applications.
Also integrates with App Mesh, providing a Kubernetes native experience to use service mesh features and bring observability, traffic controls and security features to applications.
EKS provides highly available and scalable control plane.
You can choose the underlying compute power to run your containers, either EC2 or Fargate.

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

Features:
Provision : EKS provisions some resources in support of the containerized applications: Load balancers, Compute Resources (workers), Application container instances (pods).
Configure: supports customization of workers, when using EC2 for supplying compute power, also supports runtime customization for pods.
Deploy: same strategies as Kubernetes
Scale: scales workers with Auto scaler, and pods with Horizontal and Vertical auto scaler.
Monitoring: logs are sent to CloudWatch for monitoring, also integrates with CloudTrail to provide track of actions performed.
3. Longest Substring Without Repeating Characters
Tags: php, leetcode, algorithms, programming
Published: 2024-05-10 15:46:08

3\. Longest Substring Without Repeating Characters

Medium

Given a string `s`, find the length of the **longest substring** without repeating characters.

**Example 1:**

- **Input:** s = "abcabcbb"
- **Output:** 3
- **Explanation:** The answer is "abc", with the length of 3.

**Example 2:**

- **Input:** s = "bbbbb"
- **Output:** 1
- **Explanation:** The answer is "b", with the length of 1.

**Example 3:**

- **Input:** s = "pwwkew"
- **Output:** 3
- **Explanation:** The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.

**Example 4:**

- **Input:** s = ""
- **Output:** 0

**Constraints:**

- <code>0 <= s.length <= 5 * 10<sup>4</sup></code>
- `s` consists of English letters, digits, symbols and spaces.

**Solution:**

```
class Solution {

    /**
     * @param String $s
     * @return Integer
     */
    function lengthOfLongestSubstring($s) {
        $lastIndices = array_fill(0, 256, -1);
        $maxLen = 0;
        $curLen = 0;
        $start = 0;

        for ($i = 0; $i < strlen($s); $i++) {
            $cur = $s[$i];
            $curAscii = ord($cur);

            if ($lastIndices[$curAscii] < $start) {
                $lastIndices[$curAscii] = $i;
                $curLen++;
            } else {
                $lastIndex = $lastIndices[$curAscii];
                $start = $lastIndex + 1;
                $curLen = $i - $start + 1;
                $lastIndices[$curAscii] = $i;
            }

            if ($curLen > $maxLen) {
                $maxLen = $curLen;
            }
        }

        return $maxLen;
    }
}
```


**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
What are web components ?
Published: 2024-05-10 16:04:02

[Web components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web pages and web apps. These custom components and widgets built on the [Web Component](https://www.frontendeng.dev/blog/48-what-are-web-components) standards work across modern browsers and can be used with any JavaScript library or framework that works with HTML.




[1](https://developer.mozilla.org/en-US/docs/Web/API/Web_components)
[2](https://www.frontendeng.dev/blog/48-what-are-web-components)
Blurry no more: Understanding image resolution
Tags: resolution, technology, opensource, performance
Published: 2024-05-10 16:03:48

**Introduction**
In the context of screens and monitors, pixels can be defined as _tiny individual squares that light up to create an image_. The resolutions(144p,240p,360p,480p,720p,1080p,4k and 8k) signifies number of pixels. Higher resolution means there will be more number of pixels which results in a clearer image. We can say it as the physics of how the light works.
Now let's get introduced to _Pixel Upscaling_. 
_Pixel Upscaling_ basically refers to the process where a video existing with a lower resolution(144p or 240p) is converted to a high resolution(1080p or 4k). This is done by analyzing the existing pixels and creating new pixels which will fill the gap.

**Upscaling Techniques**
Clever algorithms are used to estimate what new pixels can be added to fill in the gaps and create a higher resolution image.

Some common upscaling techniques:
_Nearest Neighbour Interpolation_ - This method copies the nearest existing pixel to create new ones. It is simple, speed, computationally efficient and no new data is created. It simply relies on existing information or pixels.

_Deep Learning Upscaling_ - It makes use of Artificial Intelligence to analyze the video and create more detailed new pixels. This method includes steps like Training the Model, Analyzing the low-resolution input, Creation of new pixels and Data Enhancement. This technique is computationally expensive.

_Bilinear Interpolation_ - This method takes the average color of the four nearest neighbouring pixels to create new pixels.  It produces smoother results than nearest neighbour but may blur the details.

**Conclusion**
The world of video is constantly evolving with upscaling technology being at the top. The most low-resolution videos can be enjoyed in stunning detail. So next time when you watch an old video, remember the power of upscaling. It bridges the gap between the past and the present. 

> The future of video is not just about capturing high-resolution content, it's about making everything we have captured look its absolute best.