teleren/devto huggingface dataset:
1206. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-06 13:54:44

```
struct Node {
  int val;
  shared_ptr<Node> next;
  shared_ptr<Node> down;
  Node(int val = -1, shared_ptr<Node> next = nullptr,
       shared_ptr<Node> down = nullptr)
      : val(val), next(next), down(down) {}
};

class Skiplist {
 public:
  bool search(int target) {
    for (auto node = dummy; node; node = node->down) {
      advance(node, target);
      if (node->next && node->next->val == target)
        return true;
    }
    return false;
  }

  void add(int num) {
    // collect nodes that before the insertion point
    stack<shared_ptr<Node>> nodes;
    for (auto node = dummy; node; node = node->down) {
      advance(node, num);
      nodes.push(node);
    }

    shared_ptr<Node> down;
    bool shouldInsert = true;
    while (shouldInsert && !nodes.empty()) {
      auto prev = nodes.top();
      nodes.pop();
      prev->next = make_shared<Node>(num, prev->next, down);
      down = prev->next;
      shouldInsert = rand() & 1;
    }

    // create a topmost new level dummy pointing to existing dummy
    if (shouldInsert)
      dummy = make_shared<Node>(-1, nullptr, dummy);
  }

  bool erase(int num) {
    bool found = false;
    for (auto node = dummy; node; node = node->down) {
      advance(node, num);
      if (node->next && node->next->val == num) {
        node->next = node->next->next;
        found = true;
      }
    }
    return found;
  }

 private:
  shared_ptr<Node> dummy = make_shared<Node>(-1);

  void advance(shared_ptr<Node>& node, int target) {
    while (node->next && node->next->val < target)
      node = node->next;
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/design-skiplist/
How to Build Todo App With Vanilla JavaScript
Tags: javascript, beginners, tutorial, webdev
Published: 2022-07-06 13:54:43

{% youtube BWmL66b9bOo %}

How to Build Todo App With Vanilla JavaScript

This video will show you how to build a todo app using vanilla javascript

[Live Website](https://codewithsadee.github.io/taskbuddy)
[Github Repo](https://github.com/codewithsadee/taskbuddy)

---

HI 👋
I'm Sadee (webdev)
In this channel I make videos about Complete Responsive website.
You can checkout my channel 👇

📺 My Channel : [codewithsadee](https://www.youtube.com/channel/UC1PZHWV6VvICTL1LgFUZq6g)
🔔 Subscribe : [subscribe now](https://www.youtube.com/channel/UC1PZHWV6VvICTL1LgFUZq6g?sub_confirmation=1)

---

🔗 Essential links
-----------------------------
[Starter file](https://drive.google.com/file/d/1-s7MIRF1akpsvSEVz6tlqnjT-p-eGfYL/view?usp=sharing)

---

⏱️ Timestamps
-----------------------------
0:00 - Demo
3:47 - File structure
4:19 - Project initial
9:51 - Structure & styles
43:51 - Javascript functionalities
1:11:33 - Media queries

---

[![Become a patreon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fnjl14kdm5qf08hu5lop.png)](https://www.patreon.com/bePatron?u=62535867)
1203. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-06 13:51:37

```
class Solution {
 public:
  vector<int> sortItems(int n, int m, vector<int>& group,
                        vector<vector<int>>& beforeItems) {
    vector<vector<int>> graph(n + m);
    vector<int> inDegree(n + m);

    // build graph by remapping k-th group to k + n imaginary node
    for (int i = 0; i < group.size(); ++i) {
      if (group[i] == -1)
        continue;
      graph[group[i] + n].push_back(i);
      ++inDegree[i];
    }

    for (int i = 0; i < beforeItems.size(); ++i)
      for (const int b : beforeItems[i]) {
        const int u = group[b] == -1 ? b : group[b] + n;
        const int v = group[i] == -1 ? i : group[i] + n;
        if (u == v) {  // already in the same group
          graph[b].push_back(i);
          ++inDegree[i];
        } else {
          graph[u].push_back(v);
          ++inDegree[v];
        }
      }

    // topology
    vector<int> ans;

    for (int i = 0; i < n + m; ++i)
      if (inDegree[i] == 0)  // inDegree[i] == -1 means visited
        dfs(graph, i, inDegree, n, ans);

    return ans.size() == n ? ans : vector<int>();
  }

 private:
  void dfs(const vector<vector<int>>& graph, int u, vector<int>& inDegree,
           int n, vector<int>& ans) {
    if (u < n)
      ans.push_back(u);

    inDegree[u] = -1;  // mark as visited

    for (const int v : graph[u])
      if (--inDegree[v] == 0)
        dfs(graph, v, inDegree, n, ans);
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies/
1187. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-06 13:50:13

```
class Solution {
 public:
  int makeArrayIncreasing(vector<int>& arr1, vector<int>& arr2) {
    // dp[i] := min steps to reach i at previous round
    unordered_map<int, int> dp{{-1, 0}};

    sort(begin(arr2), end(arr2));

    for (const int a : arr1) {
      unordered_map<int, int> nextDp;
      for (const auto& [val, steps] : dp) {
        // it's possible to use the value in arr1
        if (a > val)
          nextDp[a] = min(nextDp.count(a) ? nextDp[a] : INT_MAX, steps);
        // also try the value in arr2
        const auto it = upper_bound(begin(arr2), end(arr2), val);
        if (it != cend(arr2))
          nextDp[*it] =
              min(nextDp.count(*it) ? nextDp[*it] : INT_MAX, steps + 1);
      }
      if (nextDp.empty())
        return -1;
      dp = move(nextDp);
    }

    int ans = INT_MAX;
    for (const auto& [_, steps] : dp)
      ans = min(ans, steps);
    return ans;
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/make-array-strictly-increasing/
1178. Leetcode Soluiton in CPP
Tags: cpp
Published: 2022-07-06 13:49:01

```
class Solution {
 public:
  vector<int> findNumOfValidWords(vector<string>& words,
                                  vector<string>& puzzles) {
    vector<int> ans;
    unordered_map<int, int> binaryCount;

    for (const string& word : words) {
      int mask = 0;
      for (char c : word)
        mask |= 1 << c - 'a';
      ++binaryCount[mask];
    }

    for (const string& puzzle : puzzles) {
      int valid = 0;
      const int n = puzzle.length() - 1;
      for (int i = 0; i < (1 << n); ++i) {
        int mask = 1 << puzzle[0] - 'a';
        for (int j = 0; j < n; ++j)
          if (i & 1 << j)
            mask |= 1 << puzzle[j + 1] - 'a';
        if (binaryCount.count(mask))
          valid += binaryCount[mask];
      }
      ans.push_back(valid);
    }

    return ans;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/number-of-valid-words-for-each-puzzle/
1172. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-06 13:47:40

```
class DinnerPlates {
 public:
  DinnerPlates(int capacity) : capacity(capacity) {
    minHeap.push(0);
  }

  void push(int val) {
    const int index = minHeap.top();
    // add new stack on demand
    if (index == stacks.size())
      stacks.push_back({});
    // push the new value
    stacks[index].push(val);
    // if the stack pushed is full, remove its candidacy from minHeap
    if (stacks[index].size() == capacity) {
      minHeap.pop();
      // if minHeap is empty, the next available stack index is stacks.size()
      if (minHeap.empty())
        minHeap.push(stacks.size());
    }
  }

  int pop() {
    // remove empty stacks from back
    while (!stacks.empty() && stacks.back().empty())
      stacks.pop_back();
    if (stacks.empty())
      return -1;
    return popAtStack(stacks.size() - 1);
  }

  int popAtStack(int index) {
    if (index >= stacks.size() || stacks[index].empty())
      return -1;
    // if the stack is going to have space, add its candiday to minHeap
    if (stacks[index].size() == capacity)
      minHeap.push(index);
    const int val = stacks[index].top();
    stacks[index].pop();
    return val;
  }

 private:
  const int capacity;
  vector<stack<int>> stacks;
  // min stacks to push
  priority_queue<int, vector<int>, greater<>> minHeap;
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/dinner-plate-stacks/
1163. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-06 13:46:14

```
class Solution {
 public:
  string lastSubstring(string s) {
    int i = 0;
    int j = 1;
    int k = 0;  // number of same characters of s[i:] and s[j:]

    while (j + k < s.length()) {
      if (s[i + k] == s[j + k]) {
        ++k;
      } else if (s[i + k] > s[j + k]) {
        // now s[i:i + k] == s[j:j + k] and s[i + k] > s[j + k] means that
        // we should start from s[j + k] to find a possible larger substring
        j += k + 1;
        k = 0;
      } else {
        // now s[i:i + k] == s[j:j + k] and s[i + k] < s[j + k] means that
        // either starting from s[i + k + 1] or s[j] has a larger substring
        i = max(i + k + 1, j);
        j = i + 1;
        k = 0;
      }
    }

    return s.substr(i);
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/last-substring-in-lexicographical-order/
1147. Leetcode Solution in JAVA
Tags: java
Published: 2022-07-06 13:45:02

```
class Solution {
    public int longestDecomposition(String text) {
        int chunks = 0;
        int low = 0, high = text.length() - 1;
        int prevLow = low, prevHigh = high;
        int nextLow = 0;
        while (low < high) {
            while (low < high && text.charAt(low) != text.charAt(high))
                low++;
            if (low == high)
                low--;
            nextLow = low + 1;
            while (low >= prevLow) {
                if (text.charAt(low) == text.charAt(high)) {
                    low--;
                    high--;
                } else
                    break;
            }
            if (low < prevLow) {
                chunks += 2;
                prevLow = nextLow;
            } else
                high = prevHigh;
            low = nextLow;
            prevHigh = high;
        }
        if (prevLow <= prevHigh)
            chunks++;
        return chunks;
    }
}
```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/longest-chunked-palindrome-decomposition/
1000. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-06 13:43:51

```
class Solution {
 public:
  int mergeStones(vector<int>& stones, int K) {
    const int n = stones.size();
    this->K = K;

    // dp[i][j][k] := min cost to merge stones[i..j] into k piles
    dp.resize(n, vector<vector<int>>(n, vector<int>(K + 1, kMax)));
    prefix.resize(n + 1);

    partial_sum(begin(stones), end(stones), begin(prefix) + 1);

    const int cost = mergeStones(stones, 0, n - 1, 1);
    return cost == kMax ? -1 : cost;
  }

 private:
  constexpr static int kMax = 1e9;
  int K;
  vector<vector<vector<int>>> dp;
  vector<int> prefix;

  int mergeStones(const vector<int>& stones, int i, int j, int k) {
    if ((j - i + 1 - k) % (K - 1))
      return kMax;
    if (i == j)
      return k == 1 ? 0 : kMax;
    if (dp[i][j][k] != kMax)
      return dp[i][j][k];
    if (k == 1)
      return mergeStones(stones, i, j, K) + prefix[j + 1] - prefix[i];

    for (int m = i; m < j; m += K - 1)
      dp[i][j][k] = min(dp[i][j][k], mergeStones(stones, i, m, 1) +
                                         mergeStones(stones, m + 1, j, k - 1));

    return dp[i][j][k];
  }
};

```

#leetcode
#challenge
here is the link for the problem:

https://leetcode.com/problems/minimum-cost-to-merge-stones/
Thinking about creating an NFT collection with a paper wallet system?
Tags: nft, blockchain, crypto
Published: 2022-07-06 13:43:38

Sorry, too late, it has already been done.  I met Jeremiah at The Atlanta Blockchain Center last week.  He calls himself an NFT Archeologist.  He researches and uncovers really "old" NFT collections.  Here is one he found from all the way back in 2018 that used a paper wallet system:

"The first ERC721 IPCs from this contract were minted on March 15th 2018. At the time, IPCs were claimed physically, mostly by mail, using the innovative Paper Wallet system."

What is fascinating to me is how the code we write for these NFT collections continues to live on.  It is not like deploying a web application, it fails, and then you stop paying for the hosting costs.  There is literally no way to delete the NFT smart contract.

https://medium.com/@jeremiahdlong/unpause-immortal-player-characters-2018-historic-paper-wallet-nfts-with-on-chain-innovation-cbeee084927d
1001. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-06 13:42:22

```
class Solution {
 public:
  vector<int> gridIllumination(int N, vector<vector<int>>& lamps,
                               vector<vector<int>>& queries) {
    vector<int> ans;
    unordered_map<int, int> rows;
    unordered_map<int, int> cols;
    unordered_map<int, int> diag1;
    unordered_map<int, int> diag2;
    unordered_set<pair<int, int>, pairHash> lampsSet;

    for (vector<int>& lamp : lamps) {
      int i = lamp[0];
      int j = lamp[1];
      if (lampsSet.insert({i, j}).second) {
        ++rows[i];
        ++cols[j];
        ++diag1[i + j];
        ++diag2[i - j];
      }
    }

    for (const auto& q : queries) {
      int i = q[0];
      int j = q[1];
      if (rows[i] || cols[j] || diag1[i + j] || diag2[i - j]) {
        ans.push_back(1);
        for (int y = max(0, i - 1); y < min(N, i + 2); ++y)
          for (int x = max(0, j - 1); x < min(N, j + 2); ++x)
            if (lampsSet.erase({y, x})) {
              --rows[y];
              --cols[x];
              --diag1[y + x];
              --diag2[y - x];
            }
      } else
        ans.push_back(0);
    }

    return ans;
  }

 private:
  struct pairHash {
    size_t operator()(const pair<int, int>& p) const {
      return p.first ^ p.second;
    }
  };
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/grid-illumination/
Gradle Tutorial - Crash Course [Video]
Tags: java, tutorial, devops
Published: 2022-07-06 13:41:50

Ever looked for a comprehensive tutorial to Gradle that is fun and entertaining at the same time?

[In this Marco Codes video](https://youtu.be/gKPMKRnnbXU), you'll learn how to use Gradle like a professional: From using the Gradle wrapper, using Gradle together with IDEs and Gradle basics like build.gradle and settings.gradle, to running commands (clean build) as well as understanding multi-project Gradle builds - by the end of it, there won't be many questions left when it comes to Gradle.

{% embed https://youtu.be/gKPMKRnnbXU %}
Software engineering : principle of precedence
Published: 2022-07-06 13:40:28

I am writing PWA that bears resemblance to DESMOS but available offline for kids that has limited-internet access . Besides the **npm** structure for package development, etc. I had to revise some of the principles of "software engineering" such as precedence , which by convention is (_listed from highest to lowest precedence_) :

- 1st lookup for environment variable[s] (if any) in CLI : user-level, could be admin but not-mandatory, when...

- 2nd lookup for local configuration : user-level, could be admin but not-mandatory, when...

- 3rd, lookup for global configuration : system-level, super-user

As this is "live" document , more practical side will coming soon, stay tuned !
🔥 What does the css parent selector :has in for us?
Tags: css, html, webdev
Published: 2022-07-06 13:37:23

`:has` is a parent selector pseudo-class*. It lets you change the parent element properties if it has (`:has`) a specific child or a specific element following it. 

> A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, `:hover` can be used to change a button's color when the user's pointer hovers over it.

Here is a simple example of `:has` pseudo-class:

```css
.parent:has(.child){
  color: blue;
}
```
What this means is that if the `.parent` element contains `.child` element, then change the text color of the parent element to blue. This was not possible to implement with `css` before. But thanks to `:has` selector, now we can add this logic directly in `css` and modify `.parent` based on what it `:has` as a child.


> At the time of writing this article `:has` pseudo-class only works in Safari 15.4 and in Chrome Canary. [Can i use](https://caniuse.com/css-has)

### Example
I am using a screenshot here so that you don't have to open the codepen in compatible browsers ;) 

#### Empty Button vs Button with an SVG

![Screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5b74due2rn1i7uykel6l.png)

Instead of having 2 variations of buttons with or without an icon, you can simply use the `:has` attribute on the parent.

```css
button:has(svg) {
  background: #bd3c91;
}
```

There is lot more to `:has` selector. If you are interested in more usecases, let me know in the comments and i will add more practical usecases. 

{% embed https://dev.to/hunzaboy %}
Kotlin Springboot アノテーション
Tags: kotlin, springboot
Published: 2022-07-06 13:35:19


# アノテーション

https://zenn.dev/tm35/articles/05e74b6dd9f831

tm35 さんの記事を参考にした

## これはなに？

クラスの上につけて、クラスに機能をつけるもの。 

## @GetMapping ( "/your/root" )

https://zenn.dev/tm35/articles/05e74b6dd9f831#%40getmapping(%22%E3%83%91%E3%82%B9%22)

その URL に来たときに下の function が動くようになる。

## @PostMapping, @DeleteMapping

その URL で POST や DELETE が動いた時に
下の function が動くようになる。

## @RequestParam

https://zenn.dev/tm35/articles/05e74b6dd9f831#%40requestparam

引数にこれを書くと、URL からクエリを取って変数に入れられる。
@GetMapping と一緒に使うもの。
Can you list out some amazing things Javascript can do
Tags: javascript, discuss, programming, beginners
Published: 2022-07-06 13:33:37

I recently found out, using javascript i can find out the battery level of the current systems, i was really fascianted when i find out.

It wasnt that long ago, may be 2 - 3 days max i think.

I know javascript can do much more amazing things that i can never imagine.

As a javascript developer, i know you're already aware of a lot of features like in this case _navigator.getBattery()_

A code snippet from stackoverflow to find out your current batterl level:

`navigator.getBattery().then(function(battery) {

    var level = battery.level;

    console.log(level);
});`

I want to now more what javascript can do, which will excite me more to continue my journey.

can you list out some amazing things javascript can do like in the above case.
StepZen Dashboard: Analyze and Query Your Endpoints
Published: 2022-07-06 13:23:01

At StepZen we want to make it as simple as possible to create a secure, and performant GraphQL API. To give you insights on how performant your GraphQL API actually is and to make it even easier to get started building, the [StepZen Dashboard](https://stepzen.com/account) is releasing two key new features.

1.  Request Totals and Times on StepZen GraphQL endpoints
2.  JavaScript, cURL, and Python code samples to query StepZen GraphQL endpoints

Let's have a look at these new features, and how to use them.

Request Totals and Times
------------------------

To help a user review and analyze individual StepZen endpoints, we added three different metrics to each endpoint.

1.  Queries The total number of queries run against an endpoint.
    
2.  Median Response Time 50% of queries have higher latency and 50% of queries have lower latency than this value. It can also be referred to as the 50% latency.
    
3.  95%-ile Response Time 95% of queries have lower latency than this value and 5% have higher latency. If performing properly, this number should have a higher value than the Median Response Time.
    

These measurements assess the consistency of all queries being executed on an individual endpoint. With that, we understand there are more data points StepZen developers are interested in. Further statistics are on the roadmap. If you would like to tell us what else you would like to see, reach out to us on [discord](https://discord.gg/9k2VdPn2FR).

![endpoints page](https://stepzen.com/images/blog/endpoints-page.png)

JavaScript, cURL, and Python Code Samples
-----------------------------------------

To query a deployed StepZen GraphQL endpoint, a developer must execute a proper request to an endpoint. To developer's avail, the new StepZen dashboard provides a "connect" no-code solution that generates three different code samples for you to execute a GraphQL query!

In real time of selecting the "connect" button, StepZen will introspect your GraphQL endpoint, find a sample query, and allow you to input variables to properly execute the query.

![curl code sample](https://stepzen.com/images/blog/curl-code.png)

Querying a StepZen GraphQL endpoint is as easy as introspecting and building one. The "connect" no-code solution takes querying a StepZen endpoint a step further by providing a sample query for you to properly call a StepZen endpoint.

Next Steps?
-----------

We have our sights on providing more analytics and capabilities to StepZen developers. To that point, you are the developer analyzing your endpoints so tell us what you want to see next! [Discord](https://discord.gg/9k2VdPn2FR) is the best way to reach out to us.

Follow us on [Twitter](https://twitter.com/stepzen_dev) or [join our Discord community](https://discord.gg/9k2VdPn2FR) to stay updated about our latest developments.
Angular & RxJS Tips #1: HttpClient & Async Pipe
Tags: rxjs, angular, javascript, typescript
Published: 2022-07-06 13:22:06

In this video I show you how to make a Http request using the async pipe.


---

🔗  Follow me on:

* [YouTube](https://www.youtube.com/c/FabioBiondi)
* [LinkedIn](https://www.linkedin.com/in/fabiobiondi)
* [Twitch](https://www.twitch.tv/fabio_biondi)
* [Twitter](https://www.twitch.tv/fabio_biondi)
EthairBalloons is now available for Python!
Tags: ethereum, web3, blockchain, python
Published: 2022-07-06 13:12:55

---
title: EthairBalloons is now available for Python!
published: true
description: A strictly typed ORM library for Ethereum blockchain
tags: ethereum, web3, blockchain, python
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

Yes! 
It is finally there.
The much-loved ORM library for the Ethereum Blockchain is now available for Python.

## What is EthAir Balloons ?
EthAir Balloons is a strictly typed ORM library for Ethereum blockchain. It allows you to use Ethereum blockchain as a persistent storage in an organized and model-oriented way without writing custom complex Smart contracts.

Until now, EthairBalloons was only [available for JavaScript](https://github.com/petrosDemetrakopoulos/ethairballoons) and you could install it via npm (`npm install --save ethairballoons`)

However, from now on there is an official Python version too.
you can check it out on this [GitHub repository](https://github.com/petrosDemetrakopoulos/ethairballoons.py) and install it via `pip install ethairballoons`

{% embed https://github.com/petrosDemetrakopoulos/ethairballoons.py %}.