teleren/devto huggingface dataset:
I'm creating an INTERNET
Tags: discuss, devjournal, python, programming
Published: 2022-07-08 09:48:43

Well, it's not as hard as you might think. (Also, according to my 1 month old brain, this is not clickbait)
<br>
### So why this post?
I'm doing a post every month or so to update you on my progress!

![Internet def](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csgzlbxs9mkdwayavlss.png)
<br>
### Estimated deadline
10 years so dont even care about this too much in your life.
<br>
### Languages and packages:
Socket on Python. On github after the bare bones development is completed.
<br>
## Milestones and foreshadowing posts
- Basic system
- UWA development phase
- GitHub deployment (alpha and beta)
- First website
- Device optimization
- Noice look
- Community feedback
- Official launch and server
Active learning tutorial
Published: 2022-07-08 09:46:45

Hey there everyone, hope everyone’s having a fantastic Friday 😊 Today we’ll discuss active learning and show you some cool things that can be done using our active learning interface. Active learning is useful especially in situations where there is a lot of data to be labelled, which can be prioritised to label the data in an efficient manner. In our active learning interface, you can apply few-shot learning for heuristics. These are very valuable for weak supervision as you can integrate them with labeling functions or other heuristics. We integrate HuggingFace embeddings so you can use your favourite transformer models for embeddings. They typically require only little training data to get a reasonable precision.

If you want to learn more about this, we have uploaded a full tutorial on our Youtube channel, check it out here - https://www.youtube.com/watch?v=VfQapj5TtUQ&ab_channel=KernAI

Subscribe to our newsletter 👉🏼 https://www.kern.ai/pages/open-source and stay up to date with the release so you don’t miss out on the chance to win a GeForce RTX 3090 Ti for our launch
Evidence-Based Management: How to Define Goals and Measure Them
Tags: management, productivity, podcast, agile
Published: 2022-07-08 09:46:45

{% youtube dKnzkavQy8Y %}

Hi!
Let’s focus on software project development, concrete on evidence-based management, that provides organizations with the ability to measure the value they deliver to customers. 

What's it all about? Simply speaking, it enables to make rational, fact-based decisions: bringing conversations from the level of individual preferences and opinions to the level of empirical evidence, logic and insights. 

In the end it’s all about improving outcomes, reducing risks, and optimizing investments. 

Sounds like you need such in your project management? Watch our video.

Enjoy! You can also read the article at [Frontend House](https://frontendhouse.com/experts-zone/evidence-based-management-how-to-define-goals-and-measure-them-experts-zone-5).
Read & share secret confessions with a community of Tech Imposters
Tags: webdev, codenewbie, showdev, javascript
Published: 2022-07-08 09:45:05

["Tech Imposters Anonymous"](https://tech-imposters.com/) is a platform to read & share anonymous confessions by a community of Tech Imposters.

The project aims to promote a more transparent and supportive mindset around productivity in tech and embrace “failspiration”.

> We are no “10x” Developers, no “Ninjas” and no “Rockstars”. We are Human Beings who screw things up and who sometimes question if we are good enough.

Should you feel inspired to submit your own confession, head over the site. :)

**Tech**

The project was built with Vanilla JavaScript and Node and is using WebSockets (socket-io) and p5.js to create a collaborative drawing experience.
Code snippet: a simple rate limiter
Tags: typescript, javascript
Published: 2022-07-08 09:44:53

This code snippet is different from my previous one: [A performant async queue](https://dev.to/pyrsmk/code-snippet-a-performant-async-queue-kdb). Even if it works quite the same way.

The big difference is that it runs functions after some wait time, instead of waiting some time **after** functions have finished to run.

There's also an NPM package: [dumb-limiter](https://github.com/pyrsmk/dumb-limiter).

{% gist https://gist.github.com/pyrsmk/4c0082fa69b1f50e0e489a787bc9c606 %}
698. Leetcode Solution in Java
Tags: java
Published: 2022-07-08 09:32:31

```
class Solution {
    public boolean canPartitionKSubsets(int[] nums, int k) {
        int sum = 0;
        for (int num : nums)
            sum += num;
        if (sum % k != 0)
            return false;
        int subsum = sum / k;
        Arrays.sort(nums);
        int length = nums.length;
        if (nums[length - 1] > subsum)
            return false;
        boolean[] used = new boolean[length];
        return backtrack(nums, k, subsum, 0, 0, used);
    }

    private boolean backtrack(int[] nums, int k, int subsum, int cur, int start, boolean[] used) {
        if (k == 0)
            return true;
        if (cur == subsum)
            return backtrack(nums, k - 1, subsum, 0, 0, used);
        int length = nums.length;
        for (int i = start; i < length; i++) {
            if (!used[i] && nums[i] + cur <= subsum) {
                used[i] = true;
                if (backtrack(nums, k, subsum, nums[i] + cur, i + 1, used))
                    return true;
                used[i] = false;
            }
        }
        return false;
    }
}
```


#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/partition-to-k-equal-sum-subsets/
508. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:28:37

```
/**
 * 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:
  vector<int> findFrequentTreeSum(TreeNode* root) {
    vector<int> ans;
    unordered_map<int, int> count;
    int maxCount = 0;

    sumDownFrom(root, count);

    for (const auto& [_, freq] : count)
      maxCount = max(maxCount, freq);

    for (const auto& [sum, freq] : count)
      if (freq == maxCount)
        ans.push_back(sum);

    return ans;
  }

 private:
  int sumDownFrom(TreeNode* root, unordered_map<int, int>& count) {
    if (!root)
      return 0;

    const int sum = root->val + sumDownFrom(root->left, count) +
                    sumDownFrom(root->right, count);
    ++count[sum];
    return sum;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/most-frequent-subtree-sum/
519. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:27:01

```
class Solution {
 public:
  Solution(int n_rows, int n_cols)
      : rows(n_rows), cols(n_cols), total(n_rows * n_cols) {}

  vector<int> flip() {
    // all candidates are used out
    if (used.size() == total)
      return {};

    int index = rand() % total;
    while (used.count(index))
      index = ++index % total;
    used.insert(index);

    return {index / cols, index % cols};
  }

  void reset() {
    used = {};
  }

 private:
  unordered_set<int> used;
  int rows;
  int cols;
  int total;
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/random-flip-matrix/
515. Leetcode Solution in JavaScript
Tags: javascript
Published: 2022-07-08 09:25:54

```
var largestValues = function(root) {
    if(!root) return []
    const output = []
    let queue = []
    queue.push(root)
    while(queue.length) {
        const len = queue.length
        // Keep track of the max per level
        let max = -Infinity
        for(let i = 0; i < len; i++){
            const cur = queue.shift()
            max = Math.max(max, cur.val)
            if(cur.left) queue.push(cur.left)
            if(cur.right) queue.push(cur.right)
        }
        // Add the max to the output array
        output.push(max)
    }
    return output
};
```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/find-largest-value-in-each-tree-row/
513. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:24:48

```
/**
 * 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 findBottomLeftValue(TreeNode* root) {
    queue<TreeNode*> q{{root}};
    TreeNode* node = nullptr;

    while (!q.empty()) {
      node = q.front();
      q.pop();
      if (node->right)
        q.push(node->right);
      if (node->left)
        q.push(node->left);
    }

    return node->val;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/find-bottom-left-tree-value/
554. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:23:35

```
class Solution {
 public:
  int leastBricks(vector<vector<int>>& wall) {
    int maxCount = 0;
    unordered_map<int, int> count;

    for (const auto& row : wall) {
      int prefix = 0;
      for (int i = 0; i < row.size() - 1; ++i) {
        prefix += row[i];
        maxCount = max(maxCount, ++count[prefix]);
      }
    }

    return wall.size() - maxCount;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/brick-wall/
482. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:22:22

```
class Solution {
 public:
  string licenseKeyFormatting(string S, int K) {
    string ans;
    int length = 0;

    for (int i = S.length() - 1; i >= 0; --i) {
      if (S[i] == '-')
        continue;
      if (length > 0 && length % K == 0)
        ans += "-";
      ans += toupper(S[i]);
      ++length;
    }

    reverse(begin(ans), end(ans));
    return ans;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/license-key-formatting
481. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:21:08

```
class Solution {
 public:
  int magicalString(int n) {
    string s = " 122";

    for (int i = 3; i <= n; ++i)
      if (i & 1)
        s.append(s[i] - '0', '1');
      else
        s.append(s[i] - '0', '2');

    return count(begin(s), begin(s) + n + 1, '1');
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/magical-string/
478. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 09:19:55

```
class Solution {
private:
    double radius, x_center, y_center, area;
    mt19937 rng{random_device{}()};
    uniform_real_distribution<double> uni{0, 1};
public:
    Solution(double radius, double x_center, double y_center) : radius(radius), x_center(x_center), y_center(y_center) {
    }
    
    vector<double> randPoint() {
        double x0 = x_center - radius;
        double y0 = y_center - radius;
        while (true) {
            double x = x0 + uni(rng) * 2 * radius;
            double y = y0 + uni(rng) * 2 * radius;
            if (sqrt(pow(x - x_center, 2) + pow(y - y_center, 2)) > radius) continue;
            return { x, y };
        }
    }
};
/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(radius, x_center, y_center);
 * vector<double> param_1 = obj->randPoint();
 */
```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/generate-random-point-in-a-circle/
Standardize imports with ESLint
Tags: codequality, eslint
Published: 2022-07-08 09:18:41

Adding this configuration will significantly improve the readability of our imports since they will follow a standard which we will define in said rule, let's see some small examples.
___

### Requirements

**In this article it will be assumed that ESLint is already configured in the project**, if you do not have any configuration you must follow the official documentation that I attach here: [ESLint configuring](https://eslint.org/docs/latest/user-guide/configuring/).

We will also need to install the following library with npm or yarn:

Npm:
```bash
npm install eslint-plugin-import --save-dev
```

Yarn:
```bash
yarn add -D eslint-plugin-import
```

___

### Imports without rule 🤨

As can be seen, the ordering and grouping that is followed does not follow any criteria and what is even worse is that in other files they will follow different or even opposite criteria.

```js
import React from 'react'
import AnotherComponent from './AnotherComponent'
import dayjs from 'dayjs';
import styles from './styles.module.scss'
import _ from 'lodash';
```

___

### ESLint to rescue 🛟

Within our ESLint configuration file we will add the following rule, in this example I will use a configuration of my preference, if you need more information I will leave you here a link to the [official documentation](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md).

```json
{
  "import/order": [
    "error",
    {
      "newlines-between": "always",
      "groups": [
        ["builtin"],
        ["external"],
        ["parent", "internal", "sibling", "index", "unknown"]
      ],
      "alphabetize": {
        "order": "asc",
        "caseInsensitive": true
      }
    }
  ]
}
```

It is important to note that to fix all the "errors" in existing imports that this rule will cause, it is recommended to use the [--fix flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) to automate the resolution of said "errors".
___

### Imports with rule 🥰

We can see that everything is much more readable since with a simple glance we will be able to identify the imports of external and internal packages that are used in said file and the best thing is that in this way we unify criteria in all the imports of our application.

```js
import dayjs from "dayjs";
import _ from "lodash";
import React from 'react'

import AnotherComponent from './AnotherComponent'
import styles from './styles.module.scss'
```

You can see more complex examples [here](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md).

___

### Conclusions

As we have seen, adding this rule gives us a very good cost vs benefit since with a very basic configuration we obtain the great benefit of being able to have a standard in all the imports of our project, something that is really useful if you work with several people.
___

Thanks for reading me 😊
464. Leetcode Solution in Java
Tags: java
Published: 2022-07-08 09:18:34

```
class Solution {

    public boolean canIWin(int choose, int total) {


        if (choose>=total)


            return true;


        if (choose*(choose+1)/2<total)


            return false;


       


        Boolean memo[] = new Boolean[1<<(choose+1)];


        return dp(0, 0, choose, total, memo);


    }


    private boolean dp(int cur, int used, int choose, int total, Boolean[] memo) {


        if (memo[used]!=null) 


            return memo[used];


        for (int i=choose; i>0; i--) {


            if ((used&(1<<i))==0) {


                if (cur+i>=total) {


                    memo[used] = true;


                    return true;


                }


                if (!dp(cur+i, used|(1<<i), choose, total, memo)) {


                    memo[used] = true;


                    return true;


                }


            }


        }


        memo[used] = false;


        return false;


    }

}

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/can-i-win/
447. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:16:33

```
class Solution {
 public:
  int numberOfBoomerangs(vector<vector<int>>& points) {
    int ans = 0;

    for (const auto& p : points) {
      unordered_map<int, int> distCount;
      for (const auto& q : points) {
        const int dist = getDist(p, q);
        ++distCount[dist];
      }
      for (const auto& [_, freq] : distCount)
        ans += freq * (freq - 1);  // C(freq, 2)
    }

    return ans;
  }

 private:
  int getDist(const vector<int>& p, const vector<int>& q) {
    return pow(p[0] - q[0], 2) + pow(p[1] - q[1], 2);
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/number-of-boomerangs/
416. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 09:15:19

```
class Solution {
 public:
  bool canPartition(vector<int>& nums) {
    const int sum = accumulate(begin(nums), end(nums), 0);
    if (sum & 1)
      return false;
    return knapsack(nums, sum / 2);
  }

 private:
  bool knapsack(const vector<int>& nums, int subsetSum) {
    const int n = nums.size();
    // dp[i][j] := true if j can be formed by nums[0..i)
    vector<vector<bool>> dp(n + 1, vector<bool>(subsetSum + 1));
    dp[0][0] = true;

    for (int i = 1; i <= n; ++i) {
      const int num = nums[i - 1];
      for (int j = 0; j <= subsetSum; ++j)
        if (j < num)
          dp[i][j] = dp[i - 1][j];
        else
          dp[i][j] = dp[i - 1][j] || dp[i - 1][j - num];
    }

    return dp[n][subsetSum];
  }
};

```


#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/partition-equal-subset-sum/
414. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 09:14:14

```
class Solution {
 public:
  int thirdMax(vector<int>& nums) {
    long max1 = LONG_MIN;  // the maximum
    long max2 = LONG_MIN;  // 2nd maximum
    long max3 = LONG_MIN;  // 3rd maximum

    for (const int num : nums)
      if (num > max1) {
        max3 = max2;
        max2 = max1;
        max1 = num;
      } else if (max1 > num && num > max2) {
        max3 = max2;
        max2 = num;
      } else if (max2 > num && num > max3) {
        max3 = num;
      }

    return max3 == LONG_MIN ? max1 : max3;
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/third-maximum-number/
Code snippet: How to test and understand DOM events better with this simple HTML snippet
Tags: html, javascript
Published: 2022-07-08 09:14:13

Because sometimes we don't understand what's going on with DOM events (even more on mobiles), here's an HTML page to test and understand things.

You just have to save it as an HTML file and load it in your browser (by drag-n-droping it for example). At the end of this file there's a list of events that are bypassed to avoid generating a lot of output. You can add/remove events from this list, based on what you want to test. And, of course, you can add/remove HTML tags (just after the `<body>` tag): add a button, a select, anything you need so you can understand more deeply how DOM events are triggered when interacting with a web page 🦄

{% gist https://gist.github.com/pyrsmk/b564c90714bf5a92fb53aecfa30c80eb %}
443. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 09:13:03

```
class Solution {
 public:
  int compress(vector<char>& chars) {
    int ans = 0;

    for (int i = 0; i < chars.size();) {
      const char letter = chars[i];
      int count = 0;
      while (i < chars.size() && chars[i] == letter) {
        ++count;
        ++i;
      }
      chars[ans++] = letter;
      if (count > 1)
        for (const char c : to_string(count))
          chars[ans++] = c;
    }

    return ans;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/string-compression/
442. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:12:05

```
class Solution {
 public:
  vector<int> findDuplicates(vector<int>& nums) {
    vector<int> ans;

    for (const int num : nums) {
      nums[abs(num) - 1] *= -1;
      if (nums[abs(num) - 1] > 0)
        ans.push_back(abs(num));
    }

    return ans;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/find-all-duplicates-in-an-array/
455. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 09:10:55

```
class Solution {
 public:
  int findContentChildren(vector<int>& g, vector<int>& s) {
    sort(begin(g), end(g));
    sort(begin(s), end(s));

    int i = 0;
    for (int j = 0; j < s.size() && i < g.size(); ++j)
      if (g[i] <= s[j])
        ++i;

    return i;
  }
};
```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/assign-cookies/
468. leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 09:08:36

```
class Solution {
 public:
  string validIPAddress(string IP) {
    string digit;
    istringstream iss(IP);

    if (count(begin(IP), end(IP), '.') == 3) {
      for (int i = 0; i < 4; ++i)  // make sure we have 4 parts
        if (!getline(iss, digit, '.') || !isIPv4(digit))
          return "Neither";
      return "IPv4";
    }

    if (count(begin(IP), end(IP), ':') == 7) {
      for (int i = 0; i < 8; ++i)  // make sure we have 8 parts
        if (!getline(iss, digit, ':') || !isIPv6(digit))
          return "Neither";
      return "IPv6";
    }

    return "Neither";
  }

 private:
  static inline string validIPv6Chars = "0123456789abcdefABCDEF";

  bool isIPv4(const string& digit) {
    if (digit.empty() || digit.length() > 3)
      return false;
    if (digit.length() > 1 && digit[0] == '0')
      return false;

    for (const char c : digit)
      if (c < '0' || c > '9')
        return false;

    const int num = stoi(digit);
    return 0 <= num && num <= 255;
  }

  bool isIPv6(const string& digit) {
    if (digit.empty() || digit.length() > 4)
      return false;

    for (const char c : digit)
      if (validIPv6Chars.find(c) == string::npos)
        return false;

    return true;
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/validate-ip-address/
470. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:06:49

```
// The rand7() API is already defined for you.
// int rand7();
// @return a random integer in the range 1 to 7


class Solution {
 public:
  int rand10() {
    int num = 40;

    while (num >= 40)
      num = (rand7() - 1) * 7 + rand7() - 1;

    return num % 10 + 1;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/implement-rand10-using-rand7/
467. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-08 09:05:34

```
class Solution {
 public:
  int findSubstringInWraproundString(string p) {
    int maxLength = 1;
    vector<int> count(26);  // substrings end at i

    for (int i = 0; i < p.length(); ++i) {
      if (i > 0 && (p[i] - p[i - 1] == 1 || p[i - 1] - p[i] == 25))
        ++maxLength;
      else
        maxLength = 1;
      const int index = p[i] - 'a';
      count[index] = max(count[index], maxLength);
    }

    return accumulate(begin(count), end(count), 0);
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/unique-substrings-in-wraparound-string/
492. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 08:58:55

```
class Solution {
 public:
  vector<int> constructRectangle(int area) {
    int width = sqrt(area);

    while (area % width)
      --width;

    return {area / width, width};
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/construct-the-rectangle/