teleren/devto huggingface dataset:
What is the best linux distro for coding and working 2022 ??
Published: 2022-07-17 14:12:51

I work in tech and my new companie is Linux only, i know that a lot of dev are usine Linux  but i´ve Nevers understand why, because wsl or new windows terminal is kind of cool,and the "i control everything " is not an True argument in my opinion, 
Im using Ubuntu i think it´s cool but i´m asking what is the best and whyy ??
Most needed commands for "SED" and "Vim" in linux.
Tags: linux, help, bash
Published: 2022-07-17 14:00:00

## SED
SED command in UNIX stands for stream editor and it can perform lots of functions on file like searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening them, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it.

**Let's explore some powerful commands**

**sed options,**

**-n** is for viewing the changes(will not update the file with the changes).

 **-i**  is used to update the changes.


1) How to delete a specific word in a file

`# sed -i  's/devops//g' filename.txt` 
 _It will delete the word "devops" from the file filename.txt_

2) How to change word in a file

`# sed -i 's/centos/ubuntu/g' filename.txt`
  _All word changes from centos to ubuntu_

3)  How to delete a file containing specific word

`# sed -i '/_linux_/d' file.txt
`
_It will delete the line containing the word "linux"_

4) How to list all the specific words in a file

`# sed -n '/_docker_/p' filename.txt`
_It will list all the lines containing word docker_

5)How to delete matching line and 2 lines after matching line

`# sed -i '/_NAME_/,+2d' filename.txt`

6) How to replace all uppercase characters of the text with lowercase characters

`# sed -i 's/\(.*\)/\L\1/ filename.txt'`

7) How to view only a specific range of lines in a file

`sed -n '5,10p' filename.txt`

8) How to replace words inside range of line 

`# sed -i '60,80 s/centos/ubuntu/g'`
  _Centos will change to ubuntu between lines 60-80_

9) How to insert 5 spaces to the left of every lines

` # sed -i 's/^/     /' filename.txt`

10) how to delete particular line using sed

`sed -i '10d' filename.txt`  _It will delete 10th line_



## VIM

Vim is a text editor for Unix that comes with Linux, BSD, and macOS. It is known to be fast and powerful, partly because it is a small program that can run in a terminal (although it has a graphical interface). It is mainly because it can be managed entirely without menus or a mouse with a keyboard.

**Let's explore some powerful commands**

1) How to delete all lines in a file
 _Inside the vim editor_.

`dG`

2) How to delete a specific line 

`dd`

3) How to delete range of lines

`:3,5d `
  _It will delete lines from line number 3 to line 
  number 5_

4) How to delete current line to end of line

`:.,$d `

5) How to delete current line to beginning of line

`dgg`

6) How to remove the next three lines from the current line

`3dd` - delete 3 lines
`5dd` -  delete 5 lines

7) How to search a specific word in vim

`/string_name`

8) How to get to a specific line 

`:_line_number_`
   eg- :50    _It will redirect to line 50_

9) Save a file

`:wq!`

10) exit without saving a file

`:q!`

Enjoy Learning🚀🐧
Non-CS person explains Dynamic Programming (DP)
Tags: career
Published: 2022-07-17 13:39:25

## Summary
| Method                    | Pro                   | Con                   | Time Complexity                                                  | Space Complexity |
|---------------------------|-----------------------|-----------------------|------------------------------------------------------------------|------------------|
| 1. Recursion              | Intuitive             | May Exceed Time Limit | O(d^N), where d = number of choice at each recursion step        | O(1)             |
| 2. Memoization (Top-Down) | Intuitive, Saves Time | May Stack Overflow    | O(N), all repeat function calls are retrieved from memo/dp table | O(N)             |
| 3. Tabulation (Bottom-Up) | Saves Time            | Non-Intuitive         | O(N)                                                             | O(1) to O(N)     |


Here's hoping this post will document learnings to help you guys consistently solve DP Hard problems.

* [Neetcode Problem List](https://neetcode.io/)
* [Memoization VS Tabulation](https://www.baeldung.com/cs/tabulation-vs-memoization#:~:text=While%20the%20memoization%20algorithms%20are,are%20generally%20harder%20to%20design.)
* [Memoization (1D, 2D, and 3D)](https://www.geeksforgeeks.org/memoization-1d-2d-and-3d/)

> If I had to count the number of times I solved Fibonacci...

## EXAMPLE 1: Climbing Stairs (Leetcode: Easy)
[Here](https://leetcode.com/problems/climbing-stairs/discuss/2295552/Mastering-DP-Starts-Here) is my solution.

**IDEA**
1. Recursion is intuitive but will TLE.
2. Memoization reduces runtime complexity but might Stack Overflow.
3. Tabulation reduces runtime complexity but it's hard to figure out the iteration formula.

## EXAMPLE 2: Out of Boundary Paths (Leetcode: Medium)
3D-memoization works here. No need to go extreme mode into Tabulation.
```
dp = [[[-1] * (maxMove + 1) for _ in range(n+1)] for _ in range(m+1)]
        
        def dfs(r,c,k):
            if k < 0:
                return 0
            if r < 0 or c < 0 or r == m or c == n:
                return 1
            
            if dp[r][c][k] != -1:
                return dp[r][c][k]
            
            dp[r][c][k] = dfs(r-1,c,k-1) + dfs(r+1,c,k-1) + dfs(r,c-1,k-1) + dfs(r,c+1,k-1)
            return dp[r][c][k]
        
        return dfs(startRow, startColumn, maxMove) % (10 ** 9 + 7)
```

## TODO
**solve more problems and distil concepts**
1207. Leetcode Solution in cpp
Tags: cpp
Published: 2022-07-17 13:37:49

```
class Solution {
public:
    bool uniqueOccurrences(vector<int>& A) {
        unordered_map<int, int> m;
        for (int n : A) m[n]++;
        unordered_set<int> s;
        for (auto &p : m) {
            if (s.count(p.second)) return false;
            s.insert(p.second);
        }
        return true;
    }
};
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/unique-number-of-occurrences/
821. Leetcode Solution in JavaScript
Tags: javascript
Published: 2022-07-17 13:36:30

```
var shortestToChar = function(S, C) {
    let len = S.length, ans = new Uint16Array(len)
    ans[0] = S.charAt(0) === C ? 0 : 10001
    for (let i = 1; i < len; i++) 
        ans[i] = S.charAt(i) === C ? 0 : ans[i-1] + 1
    for (let i = len - 2; ~i; i--)
        ans[i] = Math.min(ans[i], ans[i+1] + 1)
    return ans
};
```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/shortest-distance-to-a-character/
2122. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-17 13:35:17

```
class Solution {
public:
    vector<int> recoverArray(vector<int>& A) {
        sort(begin(A), end(A));
        int N = A.size() / 2;
        vector<int> ans;
        ans.reserve(N);
        for (int i = 1; i <= N + 1; ++i) {
            int k = A[i] - A[0];
            if (k == 0 || k % 2) continue;
            k /= 2;
            ans.clear();
            int pos = 0;
            for (int j = 0; j < A.size(); ++j) {
                if (pos == ans.size()) ans.push_back(A[j] + k);
                else {
                    int d = A[j] - ans[pos];
                    if (d == k) ++pos;
                    else if (d < k) ans.push_back(A[j] + k);
                    else break;
                }
            }
            if (pos == N) return ans;
        }
        return {};
    }
};
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/recover-the-original-array/
1224. Leetcode Solution in Java
Tags: java
Published: 2022-07-17 13:33:35

```
class Solution {
    public int maxEqualFreq(int[] nums) {
        if (nums == null || nums.length == 0)
            return 0;
        int maxLength = 1;
        Map<Integer, Integer> numFrequencyMap = new HashMap<Integer, Integer>();
        Map<Integer, Integer> frequencyCountMap = new HashMap<Integer, Integer>();
        int length = nums.length;
        for (int i = 0; i < length; i++) {
            int num = nums[i];
            int frequency = numFrequencyMap.getOrDefault(num, 0);
            int newFrequency = frequency + 1;
            numFrequencyMap.put(num, newFrequency);
            if (frequency > 0) {
                int count = frequencyCountMap.get(frequency) - 1;
                if (count > 0)
                    frequencyCountMap.put(frequency, count);
                else
                    frequencyCountMap.remove(frequency);
            }
            int newCount = frequencyCountMap.getOrDefault(newFrequency, 0) + 1;
            frequencyCountMap.put(newFrequency, newCount);
            if (isPossible(frequencyCountMap))
                maxLength = i + 1;
        }
        return maxLength;
    }

    public boolean isPossible(Map<Integer, Integer> frequencyCountMap) {
        if (frequencyCountMap.size() > 2)
            return false;
        List<Integer> list = new ArrayList<Integer>(frequencyCountMap.keySet());
        if (list.size() == 1) {
            int key = list.get(0);
            if (key == 1)
                return true;
            int count = frequencyCountMap.get(key);
            return count == 1;
        } else {
            int min = list.get(0), max = list.get(1);
            if (min > max) {
                int temp = min;
                min = max;
                max = temp;
            }
            if (max - min == 1 && frequencyCountMap.get(max) == 1)
                return true;
            else if (min == 1 && frequencyCountMap.get(min) == 1)
                return true;
            else
                return false;
        }
    }
}
```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/maximum-equal-frequency/
664. Leetcode Solution in Java
Tags: java
Published: 2022-07-17 13:32:31

```
class Solution {
    private int[][] dp;
    public int strangePrinter(String s) {
        int len = s.length();
        dp = new int[len + 1][len + 1];
        return turn(s, 1, len);
    }
    private int turn(String s, int i, int j){
        if(i > j) return 0; //empty string.
        else if(dp[i][j] > 0) return dp[i][j]; //Cached
        else{
            //Give the fall back.
            dp[i][j] = turn(s, i, j - 1) + 1;
            for(int k = i; k < j; k++){
                if(s.charAt(j - 1) == s.charAt(k - 1))
                    dp[i][j] = Math.min(turn(s, i, k) + turn(s, k + 1, j - 1), dp[i][j]);
            }
            return dp[i][j];
        }
    }
}
```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/strange-printer/
1665. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-17 13:31:27

```
class Solution {
public:
    int minimumEffort(vector<vector<int>>& A) {
        int N = A.size(), ans = 0, cur = 0;
        sort(begin(A), end(A), [&](auto &a, auto &b) { return (a[1] - a[0]) > (b[1] - b[0]); });
        for (int i = 0; i < N; ++i) {
            if (cur < A[i][1]) {
                ans += A[i][1] - cur;
                cur = A[i][1];
            }
            cur -= A[i][0];
        }
        return ans;
    }
};
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/
3 Javascript utility functions to show you why they matter
Tags: javascript, beginners, programming, tutorial
Published: 2022-07-17 13:29:01

Many developers, especially juniors and beginners push understanding js utility functions like map(), reduce() to the side not realising that once you _get it_ you will start seeing ways to use them to improve your code **everywhere**.


##What are JS utility functions?


A utility function is : 

- A standalone function ( it is not a member of any class and is in the global namespace )

- Has no side effects ( It does not change any of it parameters or any global variable )

- It output is directly dependent on it input.


## Why and When Utility Functions?


As mentioned earlier, utility functions are **highly reuseable** to perform common tasks.

They simplify things by making it easier to refactor code and minimize it.

Utility functions are generic snippets that will make your code more efficient.

Utilizing utility function is a great way to remain consistent across your projects and when you want to modify the underlying functionality, you only need to modify it from one place.


## Do something an X number of times


A prevalent task to do in javascript is to repeat something many times.
Using the `times(_numberOfTimes_ , _function_)` will do exactly that in a clean, practical way.

You can implement this functionality by using _. helper library.

## Remove duplicates from an array

There are many utility functions for modifying arrays as you would expect which you can find on [here](https://underscorejs.org/#arrays)
One useful one is `removeDuplicates(array)` it returns a new array with all the duplicates stripped away.


## Find the difference of two arrays


Finds the repeating values in both arrays and return them in a string just by typing a simple one liner `intersection(arr1,arr2, ...args)`

Utility functions are a sea of information and it is very easy to get lost in it, so becareful and be wary of the bloat that you may unintentionally add with implementing all these libraries like lodash.

Personally, I recommend that you build your own lightweight utility functions library, adding only the ones you find extremely useful.
Today I created Screenshot maker in Python
Tags: python, automation, pyautogui, tkinter
Published: 2022-07-17 13:26:15


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


#Why automate?
By automating everyday processes, it was as if I was “gaining” time. If a daily task that takes 5 minutes to do is automated, in 5 business days, you will have 25 minutes more to do something else. In a month, 1 hour and 40 minutes; in a year, 20 hours…Multiply that by more tasks or users and you have considerable numbers.


#why Python?

- General purpose language

- easiest programming language

- Easy for automation


**If you want the code, you can visit here:**
https://github.com/Chiki1601/Python-Screenshot-taker
Spring Boot WebSecurityConfiguration?
Tags: security, java, beginners, help
Published: 2022-07-17 13:03:46

Hello everyone! I'm a new developer learning the Spring Boot framework right now, and I'm at a really hard sticking point with authentication and authorization with Spring Security. It seems like the old WebSecurityConfigurerAdapter is now depreciated and they want us to use WebSecurityConfiguration instead. The problem is I cannot find any tutorials or resources that seem to make sense on how to implement this new Class instead of the old one. The Spring documentation has only served to confuse the ever loving heck out of me. All of the tutorials on Youtube or Google seem to be older and directed towards setting up with the depreciated Class instead of the new one.

I'm trying to implement security for a basic login flow with BCrypt as a Password Encoder. I have a MySQL db that I connected to with data-jpa and I would like to go to the next step of making users login and create accounts if they don't exist.

It seems like I need to do some sort of filter chain, but I can't seem to find the right resource. Can anyone provide a little bit of direction for me? It's definitely been a hard sticking point in my learning. Any time I try to implement anything I wind up with tons of errors or circular dependencies. This seems like something that should only be a couple of blocks of code to implement.
Input Label Animation | HTML & CSS
Tags: html, css, beginners
Published: 2022-07-17 12:34:41

{% youtube m4Ybr7OUoEo %}

In this video I go over how to create this input animation using only HTML and CSS. I use CSS grid for the layout and then I add hover effects for the  transitions.
I show you the full front end coding tutorial, where I create the structure of the elements in HTML and then write all of the styling and effects with CSS from scratch, step-by-step!

***

🛴 Follow me for more on:
YouTube:        https://bit.ly/3oBQbc0
Facebook:       https://bit.ly/3cp2S5W
Instagram[New]: https://bit.ly/3Ihh2EB
Difference between map(), every(), forEach() or difference between every(), some(), filter(), map(), reduce(), reduceRight()
Published: 2022-07-17 12:34:05

Article: [stackoverflow](https://stackoverflow.com/questions/7340893/what-is-the-difference-between-map-every-and-foreach)


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

---

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rv3wbwodb3ri5xj8eyo6.PNG)
Secure you shell commands history
Tags: security, rust, linux, devops
Published: 2022-07-17 12:28:57


Secrets can be everywhere, even in your shell history commands. 
I created a small tool that detects and clean those commands from your history. You can even stash your history commands before you share your screen and pop the history when you finish.

Appreciate your feedback 
https://github.com/rusty-ferris-club/shellclear
HA Proxy For MySQL Master – Slave
Tags: haproxy, mysql, masterslave
Published: 2022-07-17 12:23:30

There are scenarios where we have to provide the high ability to MySQL database instances and we use the Master and Slave replication method of MySQL database.

In the same case to segregate the Read and Write database traffic. We widly use HA- Proxy. It is a feature rich open source Load blancing tool with many unique features like reverse proxy but in out case we are going to use it only for Hight aviliblity purpose.

_**root@haproxy01:~# haproxy -v
HA-Proxy version 2.0.13-2ubuntu0.3 2021/08/27 - https://haproxy.org/
How to Install it?
You simply use yum or apt commands to install it
sudo apt install -y haproxy**_
 

Read more: https://thedbadmin.com/ha-proxy-for-mysql-master-slave/
How to Trigger React Error Boundary with React Developer Tools
Tags: guide, react, tips
Published: 2022-07-17 11:46:16

---
title: How to Trigger React Error Boundary with React Developer Tools
published: true
description: 
tags: guide, react, tips
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wqf7na5ayoq1mj0u2j75.png
---

## What is a React Error Boundary?
According to react.js documentation, Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them. ([Read more](https://reactjs.org/docs/error-boundaries.html))

## Use case
We want to test how our application handles error states. Using the React Developer Tools, we won't be needing to manually force an error state in our code for each component we want to test. Instead, we can just select a component from the tool and force it to be in an error state.

## Prerequisites
- React Developer Tools chrome extension
  - [installation](https://chrome.google.com/webstore/detail/react-developer-tools)
- A working React App with React Error Boundary

## Demo
1. Start your React Application and open it on your Google Chrome web browser. (make sure you already have React Developer Tools chrome extension installed)

2. Open your Chrome Developer Tools and navigate to **Components** tab.
    ```
    shift + CTRL + J (Windows/Linux).
    option + ⌘ + J (macOS)
    ```
3. Select a component within the Error Boundary in the tree.
  - Notice the (!) icon. Hovering it should show a help dialog **"Force the selected component into an errored state"**

    ![Chrome Developer Tools with an open Components tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3rwp4j5skdcb0l4a4n3z.png)
4. Click on the (!) icon
  - This will force your app to be in an errored state
    ![React App in Error state](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k3w269zkl88e4etcf52i.png)
Complete game development blog #2: Pathfinding and distance calculation finished
Tags: beginners, csharp, unity3d, gamedev
Published: 2022-07-17 11:31:11

Sometimes it's good to be humbled and reminded that you need to take a brake and really look at what you're doing from the outside in.

So I had finished my amazing idea of not having to do the calculations for the movement distances for my characters, since I was using the A* Pathfinder and thought I could just use the distance it calculated. And it worked, but the numbers seemed off. Traveling sideways doubled the distance compared to traveling straight up. I was racking my brain on this problem for the longest time until the obvious hit me.

My game is isometric. The pathfinder is not.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpvih4j6s6gygnxiuynx.png)
This image shows how the pathfinder calculated what tiles were inside a certain distance. It looks all well and good at first glance until you realize travelling vertically you can go up 3 tiles, but horizontally only a single tile! The pathfinder doesn't know or care what perspective the plane is under it, it only knows it exists in 2d space and that it needs to go from point A to point B through a grid of dots, while avoiding any obstacles.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyr9rkw0b2qoj08eu8ri.png)
This is what I didn't realize I wanted. A circle existing on the isometric plane.

Luckily it wasn't a difficult fix. The pathfinder provides a list of points it goes through, so it was as simple as converting those points into tile coordinates and applying a little bit of everyone's favorite theorem from high school.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6vily6a1ijooiy54wuqw.png) After adding all the parabolas together you get the correct distance. 

PS: There probably could have been a way I could have set the grid of dots the pathfinder goes through to be isometric, but that's for someone else to figure out, this works for me.