teleren/devto huggingface dataset:
Types Generator
Published: 2022-07-14 07:20:48

Types generator is a utility  tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single object JSON into this Types generator. Types Generator will auto-generate the TS interfaces for you.

You can past array objects also. 
App link:  [Types Generator](https://vineethtrv.github.io/typesgenerator/)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8cnax1ejzkqsrxw352i.gif)
How long should blog articles be
Tags: writing, watercooler
Published: 2022-07-14 07:18:49

When you start exploring the blogging world, mainly technical writing, you'll encounter this question often.

Some questions that might pop up on your journey:

From your perspective, you might be wondering how long it should be to rank better.

If you write for other publications, they tell you it should be at least 1500 or 2000 words.

And you might be exploring other articles and see various lengths, which might confuse you about what is best.

But how long should your articles be?

## The simple answer

Make your article as long as it needs to be to explain the solution.

To me, it's absolute nonsense that a blog should be x amount of words to rank.
Trust me on this one, I have 250+ number one ranking articles, and they are "short".

This is old-school thinking and often by those articles that still suggest meta keywords are a thing (and no, they are not).

I know what you are thinking, but you are a simple tech blogger, not an SEO expert. And that's right, but I'm also a stubborn simple tech blogger.

I do what I think works best, which has not been disappointing so far.

## What does matter?

I've noticed the only thing that matters with content these days is: "Does the user like it".

I'm stating "like it" as it can be a range of situations.

- Your article is fun to read, so people read till the end
- Your article solves an issue, and the person is happy
- Your article clears some thoughts, and they agree

I don't particularly know how Google knows when these are true, but it seems they do.

It could be the person stops searching for specific terms, and google has understood your article has helped them with that.

> Note: The above is just a brain dump, not proven

But, I can tell you that you should focus on making the user experience enjoyable.

To me, that means giving people an answer to a question. But for some, it might be to explain how something works in detail. Or perhaps even tell your story in your own words.

## Conclusion

How long should blog articles be?
"As long as it takes, to make it enjoyable".

A very vague answer, but stick to writing what you think is the correct amount to explain what you are describing.
Don't try and fill your articles with words that don't add anything.

In my vision, there is no minimum but also no maximum words for blog articles.
There are only enjoyable articles and non-enjoyable articles.

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
1072. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 06:14:38

```
class Solution {
 public:
  int maxEqualRowsAfterFlips(vector<vector<int>>& matrix) {
    const int m = matrix.size();
    const int n = matrix[0].size();
    int ans = 0;
    vector<int> flip(n);
    unordered_set<int> seen;

    for (int i = 0; i < m; ++i) {
      if (seen.count(i))
        continue;
      int count = 0;
      for (int j = 0; j < n; ++j)
        flip[j] = 1 ^ matrix[i][j];
      for (int k = 0; k < m; ++k)
        if (matrix[k] == matrix[i] || matrix[k] == flip) {
          seen.insert(k);
          ++count;
        }
      ans = max(ans, count);
    }

    return ans;
  }
};

```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows/
How to Fix and Clean Code Style in laravel 9
Tags: laravel, php, laravelpint, webdev
Published: 2022-07-14 06:13:37

In this section we will see how fix laravel 9 code and clean and  PHP-CS-Fixer style. We can use Laravel Pint package to fix our code style stays clean and consistent.   Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent.

### Requirement 
**PHP 8.0+**
**Laravel 9**

Install pint you laravel 9 project
```cmd
composer require laravel/pint --dev
```
Once Pint has been installed, the pint binary will be available in your project's vendor/bin directory:

Before run pint
```php
public function index()
{
    $categories = Category::latest()->paginate(10);
    return view('category.index', compact('categories'));
}
```

After run  ./vendor/bin/pint

```cmd
./vendor/bin/pint
```

![laravel clean code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jx3sejyilcs5dl5epxnx.png)

After run pint
```php
public function index()
{
    $categories = Category::latest()->paginate(10);
    
    return view('category.index', compact('categories'));
}
```
**laravel Running Pint**
When running Pint, it will output a list of files that have been fixed. It is possible to see the changes made in more detail using the -v option:

```cmd
./vendor/bin/pint -v
```
In addition, if you would like Pint to simply inspect your code for style errors without actually changing the files, you may use the --test option:

```cmd
./vendor/bin/pint --test
```
For details vist [https://github.com/laravel/pint](https://github.com/laravel/pint)
133. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 05:58:09

```
class Solution {
 public:
  Node* cloneGraph(Node* node) {
    if (!node)
      return nullptr;

    queue<Node*> q{{node}};
    unordered_map<Node*, Node*> map{{node, new Node(node->val)}};

    while (!q.empty()) {
      Node* u = q.front();
      q.pop();
      for (Node* v : u->neighbors) {
        if (!map.count(v)) {
          map[v] = new Node(v->val);
          q.push(v);
        }
        map[u]->neighbors.push_back(map[v]);
      }
    }

    return map[node];
  }
};

```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/clone-graph/
1054. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 06:13:12

```
class Solution {
 public:
  vector<int> rearrangeBarcodes(vector<int>& barcodes) {
    vector<int> ans(barcodes.size());
    vector<int> count(10001);
    int i = 0;  // ans' index

    for (const int b : barcodes)
      ++count[b];

    const auto maxIt = max_element(begin(count), end(count));
    const int maxNum = maxIt - begin(count);

    auto fillAns = [&](int num) {
      while (count[num]-- > 0) {
        ans[i] = num;
        i = i + 2 < barcodes.size() ? i + 2 : 1;
      }
    };

    fillAns(maxNum);
    for (int num = 1; num < 10001; ++num)
      fillAns(num);

    return ans;
  }
};

```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/distant-barcodes/
1011. Leetcode Solution in Javascript
Tags: javascript
Published: 2022-07-14 06:10:28

```
var shipWithinDays = function(weights, D) {
    function getDays(capacity) {
        let days = 1, total = 0;

        // See how many days it will take to unload all the weights given the current capacity
        for(let n of weights) {
            total += n;
            // Increase days only when we will exceed the capacity
            if(total > capacity) {
                total = n;
                days++;
            }
        }
        return days;
    }

    // Start is the minimum capacity of one day which is the max of all the weights
    // End is the max capacity we could load on one day which is the sum of all the weights
    let start = Math.max(...weights), 
        end = weights.reduce((acc, cur) => acc + cur, 0);

    // The min cacpaity needed is between start and finish
    while(start < end) {
        const mid = Math.floor((end+start)/2);
        // See how many days it would take to unload all the weigths given mid as the current capacity
        const days = getDays(mid);
        // If capacity at mid took more than D days to load, then we can add more weigth on the ships each day which means we need to increase the daily capacity
        if(days > D) start = mid+1;
        // mid might be our answer so we cannot set end to mid-1
        else end = mid;
    }
    return end;
};
```
#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/
1007. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 06:08:20

```
class Solution {
 public:
  int minDominoRotations(vector<int>& A, vector<int>& B) {
    const int n = A.size();
    vector<int> countA(7);
    vector<int> countB(7);
    vector<int> countBoth(7);

    for (int i = 0; i < n; ++i) {
      ++countA[A[i]];
      ++countB[B[i]];
      if (A[i] == B[i])
        ++countBoth[A[i]];
    }

    for (int i = 1; i <= 6; ++i)
      if (countA[i] + countB[i] - countBoth[i] == n)
        return n - max(countA[i], countB[i]);

    return -1;
  }
};

```
#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/minimum-domino-rotations-for-equal-row/
1003. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 06:07:14

```
class Solution {
 public:
  bool isValid(string s) {
    stack<char> stack;

    for (const char c : s)
      if (c == 'c') {
        if (stack.size() < 2)
          return false;
        if (stack.top() != 'b')
          return false;
        stack.pop();
        if (stack.top() != 'a')
          return false;
        stack.pop();
      } else {
        stack.push(c);
      }

    return stack.empty();
  }
};

```
#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/
543. Leetcode Solution in Java
Tags: java
Published: 2022-07-14 05:50:55

```
class Solution {
    int ans=1;
    public int diameterOfBinaryTree(TreeNode root) {
        goDeep(root);
        // The number of edges is required and not nodes
        return ans-1;
    }
    private int goDeep(TreeNode root){
        if(root==null)return 0;

        int left = goDeep(root.left);
        int right = goDeep(root.right);
        // Global answer
        ans = Math.max(ans,1+left+right);
        
        // Value that can be used by parent
        return Math.max(left,right)+1;
    }
}
```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/diameter-of-binary-tree/
109. Leetcode Solution in Java
Tags: java
Published: 2022-07-14 06:05:30

```
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public TreeNode sortedListToBST(ListNode head) {
        if(head == null) return null;
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode slow = dummy;
        ListNode fast = dummy;
        ListNode pre = null;
        while(fast != null && fast.next != null){
            pre = slow;
            slow = slow.next;
            fast = fast.next.next;
        }
        pre.next = null;
        TreeNode ret = new TreeNode(slow.val);
        ret.left = sortedListToBST(dummy.next);
        ret.right = sortedListToBST(slow.next);
        return ret;
    }
}

```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/
106. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 06:01:20

```
class Solution {
 public:
  TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
    unordered_map<int, int> inToIndex;

    for (int i = 0; i < inorder.size(); ++i)
      inToIndex[inorder[i]] = i;

    return build(inorder, 0, inorder.size() - 1, postorder, 0,
                 postorder.size() - 1, inToIndex);
  }

 private:
  TreeNode* build(const vector<int>& inorder, int inStart, int inEnd,
                  const vector<int>& postorder, int postStart, int postEnd,
                  const unordered_map<int, int>& inToIndex) {
    if (inStart > inEnd)
      return nullptr;

    const int rootVal = postorder[postEnd];
    const int rootInIndex = inToIndex.at(rootVal);
    const int leftSize = rootInIndex - inStart;

    TreeNode* root = new TreeNode(rootVal);
    root->left = build(inorder, inStart, rootInIndex - 1, postorder, postStart,
                       postStart + leftSize - 1, inToIndex);
    root->right = build(inorder, rootInIndex + 1, inEnd, postorder,
                        postStart + leftSize, postEnd - 1, inToIndex);
    return root;
  }
};

```
#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
131. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 05:59:55

```
class Solution {
 public:
  vector<vector<string>> partition(string s) {
    vector<vector<string>> ans;
    dfs(s, 0, {}, ans);
    return ans;
  }

 private:
  void dfs(const string& s, int start, vector<string>&& path,
           vector<vector<string>>& ans) {
    if (start == s.length()) {
      ans.push_back(path);
      return;
    }

    for (int i = start; i < s.length(); ++i)
      if (isPalindrome(s, start, i)) {
        path.push_back(s.substr(start, i - start + 1));
        dfs(s, i + 1, move(path), ans);
        path.pop_back();
      }
  }

  bool isPalindrome(const string& s, int l, int r) {
    while (l < r)
      if (s[l++] != s[r--])
        return false;
    return true;
  }
};
```
#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/palindrome-partitioning/
166. Leetcode Solution in Java
Tags: java
Published: 2022-07-14 05:56:36

```
public class Solution {
    public String fractionToDecimal(int numerator, int denominator) {
        long n = numerator, d = denominator;
        if (n % d == 0) {
            return n / d + "";
        }
        boolean neg = false;
        if ((n < 0 && d > 0) || (n > 0 && d < 0)) {
            neg = true;
        }
        if (n < 0) {
            n = -n;
        }
        if (d < 0) {
            d = -d;
        }
        HashMap<Long, Integer> index = new HashMap<Long, Integer>();
        String result = "";
        result += n / d + ".";
        n = n % d;
        while (n != 0) {
            if (index.containsKey(n)) {
                //recurring
                result = result.substring(0, index.get(n)) + "(" + result.substring(index.get(n)) + ")";
                break;
            }
            index.put(n, result.length());
            result += n*10/d;
            n = n*10 % d;
        }
        if (neg == true) {
            result = '-' + result;
        }
        return result;
    }
}
```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/fraction-to-recurring-decimal
437. Leetcode Solution in Java
Tags: java
Published: 2022-07-14 05:54:16

```
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
  public int pathSum(TreeNode root, int sum) {
    if (root == null)
      return 0;
    return dfs(root, sum) + pathSum(root.left, sum) + pathSum(root.right, sum);
  }

  private int dfs(TreeNode root, int sum) {
    if (root == null)
      return 0;
    return (sum == root.val ? 1 : 0) +
        dfs(root.left, sum - root.val) +
        dfs(root.right, sum - root.val);
  }
}

```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/path-sum-iii/
543. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 05:51:39

```
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
 public:
  int diameterOfBinaryTree(TreeNode* root) {
    int ans = 0;
    maxDepth(root, ans);
    return ans;
  }

 private:
  int maxDepth(TreeNode* root, int& ans) {
    if (!root)
      return 0;

    const int l = maxDepth(root->left, ans);
    const int r = maxDepth(root->right, ans);
    ans = max(ans, l + r);
    return 1 + max(l, r);
  }
};
```
#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/diameter-of-binary-tree/
What is the difference between Python's equality operators?
Tags: python, beginners, programming
Published: 2022-07-14 05:48:06

Python provides two very similar equality operators used for comparisons:

- The double equals (`==`), also known as the equality operator
- The `is` keyword, also known as the identity operator

Although similar to one another, the double equals (`==`) and the `is` keyword are used for different comparison purposes and yield different results.

The main difference between the two is that the `is` keyword checks for reference equality while the double equals (`==`) operator checks for value equality. In other words, `is` will return `True` if two variables both refer to the same object in memory (aka. identity), whereas the double equals operator will evaluate to `True` if the two objects have the same value.

Here are some examples to clear up any confusion:

```py
a = [1, 2, 3]
b = a
c = [x for x in a]

print([
  a == b, # True
  a is b, # True
  a == c, # True
  a is c  # False
])

x = 'hi'
y = x
z = 'HI'.lower()

print([
  x == y, # True
  x is y, # True
  x == z, # True
  x is z  # False
])
```

---

_Do you like short, high-quality code snippets and articles? So do we! Visit [30 seconds of code](https://www.30secondsofcode.org/) for more articles like this one or follow us on [Twitter](https://twitter.com/30secondsofcode) for daily JavaScript, React and Python snippets!_ 👨‍💻
105. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 05:45:47

```
class Solution {
public:
    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
        if(preorder.empty()) return nullptr;
        
        TreeNode* root = new TreeNode(preorder[0]);
        
        int split = find(inorder.begin(), inorder.end(), preorder[0]) - inorder.begin();
        
        vector<int> linorder(inorder.begin(), inorder.begin()+split);
        vector<int> lpreorder(preorder.begin()+1, preorder.begin()+1+linorder.size());
        root->left = buildTree(lpreorder, linorder);
        
        vector<int> rpreorder(preorder.begin()+1+linorder.size(), preorder.end());
        vector<int> rinorder(inorder.begin()+split+1, inorder.end());
        root->right = buildTree(rpreorder, rinorder);
        
        return root;
    }
};
```

#Leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
How to change(Hide) the Nginx Server Signature?
Tags: nginx, ubuntu, bash, config
Published: 2022-07-14 05:33:55

![nginx](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5sgz1o85a7a19klwv3r.png)
 Exact version number in response header in our server makes vulnerable because known version may have well known vulnerable to attacker. That's the reason we have to hide this signature. Here is the way how we can do that -

I assume that you have already install nginx. And you know certain thing about nginx. We have to install a package which is nginx-extras by -

```bash
sudo apt install nginx-extras
```
And then in nginx conf file we have to add two lines in `http` section
```bash
http{
##########
}
```
```bash 
sudo nano /etc/nginx/nginx.conf 
```
```bash
http{

########
        server_tokens off;
        more_set_headers 'Server: None of your business';
}
```
Then we have to save this file via `Ctrl+x` and `Enter`
Then we can check is there any error in our config file by 

```bash
sudo nginx -t
```
![nginx](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ba0tvqtqhtr505jbnb8i.png)

If syntax is OK. Then we can restart nginx by -
```bash
sudo service nginx restart
```
![nginx response header](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjx4mw250u93kdedqo8v.png)
 
Voila! <span class="emoji-outer emoji-sizer"><span class="emoji-inner" style="background: url(chrome-extension://gaoflciahikhligngeccdecgfjngejlh/emoji-data/sheet_apple_32.png);background-position:59.9882491186839% 85.95769682726204%;background-size:5418.75% 5418.75%" data-codepoints="1f60e"></span></span>
What music genre do you listen to when coding?
Tags: discuss, music, watercooler
Published: 2022-07-14 05:28:42

And share with us your favorite track!

---

For me, I listen to vocals-less music because otherwise it catches my attention to much and keep from think well about my code. My prefered genres so far, depending on the mood: ambient, psybient, psytrance, progressive house, as well as classical music and movie soundtracks.