teleren/devto huggingface dataset:
211. Leetcode Solution in Java
Tags: java
Published: 2022-07-08 08:07:36

```
class TrieNode {
  public TrieNode[] children = new TrieNode[26];
  public boolean isWord = false;
}

class WordDictionary {
  public void addWord(String word) {
    TrieNode node = root;
    for (final char c : word.toCharArray()) {
      final int i = c - 'a';
      if (node.children[i] == null)
        node.children[i] = new TrieNode();
      node = node.children[i];
    }
    node.isWord = true;
  }

  public boolean search(String word) {
    return dfs(word, 0, root);
  }

  private TrieNode root = new TrieNode();

  private boolean dfs(String word, int s, TrieNode node) {
    if (s == word.length())
      return node.isWord;
    if (word.charAt(s) != '.') {
      TrieNode next = node.children[word.charAt(s) - 'a'];
      return next == null ? false : dfs(word, s + 1, next);
    }

    // word.charAt(s) == '.' -> search all 26 children
    for (int i = 0; i < 26; ++i)
      if (node.children[i] != null && dfs(word, s + 1, node.children[i]))
        return true;

    return false;
  }
}


/**
 * Your WordDictionary object will be instantiated and called as such:
 * WordDictionary obj = new WordDictionary();
 * obj.addWord(word);
 * boolean param_2 = obj.search(word);
 */
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/design-add-and-search-words-data-structure/
260. Leetcode Soluiton in Java
Tags: java
Published: 2022-07-08 08:05:30

```
class Solution {
  public int[] singleNumber(int[] nums) {
    final int xors = Arrays.stream(nums).reduce((a, b) -> a ^ b).getAsInt();
    final int lowbit = xors & -xors;
    int[] ans = new int[2];

    // seperate nums into two groups by the lowbit
    for (final int num : nums)
      if ((num & lowbit) > 0)
        ans[0] ^= num;
      else
        ans[1] ^= num;

    return ans;
  }
}

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/single-number-iii/
284. Leetcode Soluiton in Java
Tags: java
Published: 2022-07-08 07:59:20

```
// Java Iterator interface reference:
// https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html

import java.util.Iterator;

class PeekingIterator implements Iterator<Integer> {
    private Integer preFetch = null;
    private Iterator<Integer> iterator;

    public PeekingIterator(Iterator<Integer> iterator) {
        // initialize any member here.
        this.iterator = iterator;
        if (this.iterator.hasNext())
            preFetch = this.iterator.next();
    }

    // Returns the preFetch element in the iteration without advancing the iterator.
    public Integer peek() {
        return preFetch;
    }

    // hasNext() and preFetch() should behave the same as in the Iterator interface.
    // Override them if needed.
    @Override
    public Integer next() {
        Integer toReturn = preFetch;
        preFetch = iterator.hasNext() ? iterator.next() : null;
        return toReturn;
    }

    @Override
    public boolean hasNext() {
        return preFetch != null;
    }
}
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/peeking-iterator/
147. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 07:57:20

```
class Solution {
 public:
  ListNode* insertionSortList(ListNode* head) {
    ListNode dummy(0);
    ListNode* prev = &dummy;  // the last (largest) of the sorted list

    while (head) {                  // current inserting node
      ListNode* next = head->next;  // cache next inserting node
      if (prev->val >= head->val)   // `prev` >= current inserting node
        prev = &dummy;              // move `prev` to the front
      while (prev->next && prev->next->val < head->val)
        prev = prev->next;
      head->next = prev->next;
      prev->next = head;
      head = next;  // update current inserting node
    }

    return dummy.next;
  }
};

```
#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/insertion-sort-list
146. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 07:54:26

```
struct Node {
  int key;
  int value;
  Node(int key, int value) : key(key), value(value) {}
};

class LRUCache {
 public:
  LRUCache(int capacity) : capacity(capacity) {}

  int get(int key) {
    if (!keyToIterator.count(key))
      return -1;

    const auto& it = keyToIterator[key];
    // move it to the front
    cache.splice(begin(cache), cache, it);
    return it->value;
  }

  void put(int key, int value) {
    // no capacity issue, just update the value
    if (keyToIterator.count(key)) {
      const auto& it = keyToIterator[key];
      // move it to the front
      cache.splice(begin(cache), cache, it);
      it->value = value;
      return;
    }

    // check the capacity
    if (cache.size() == capacity) {
      const auto& lastNode = cache.back();
      // that's why we store `key` in `Node`
      keyToIterator.erase(lastNode.key);
      cache.pop_back();
    }

    cache.emplace_front(key, value);
    keyToIterator[key] = begin(cache);
  }

 private:
  const int capacity;
  list<Node> cache;
  unordered_map<int, list<Node>::iterator> keyToIterator;
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/lru-cache/
WordPress Password Hash Generator
Tags: passwordhash, passwordgenerator, hashpassword
Published: 2022-07-08 07:28:59


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

[WordPress Password Hash generator](https://wprefers.com/wordpress-password-hash-generator/) generates a hash password, the encrypted form of password for WordPress. The password hash is stored in databases as hashes for security reasons. This is because if a WordPress site is hacked, an attacker can easily read all user passwords, which is why the WordPress engine uses advanced hashing algorithms to generate different hashes for each password so that an attacker cannot read it even if he gets his hands on database.

**What is WPrefers WordPress Password Hash Generator?**
WPRefers developed WordPress Password Hash Generator, which is an online simple tool that can generate a hash for any password instantly. If you need to change your WordPress password for some reason, such as forgetting your admin panel password, enter a new password in our tool and click generate button. Password hash generated along with proper SQL Query which you can then copy. This tool generates an only hash for WordPress v3 and v4. v5 and newer versions.

With Update, WPRefers introduce a random password generator now you can generate an even stronger password for the WordPress user. Click on the Random button and you will get a random password generator with Password Strength Meter. Now you can be sure about the password strength along with a strong password and save your user login.
148. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 07:53:23

```
class Solution {
 public:
  ListNode* sortList(ListNode* head) {
    const int length = getLength(head);
    ListNode dummy(0, head);

    for (int k = 1; k < length; k *= 2) {
      ListNode* curr = dummy.next;
      ListNode* tail = &dummy;
      while (curr) {
        ListNode* l = curr;
        ListNode* r = split(l, k);
        curr = split(r, k);
        auto [mergedHead, mergedTail] = merge(l, r);
        tail->next = mergedHead;
        tail = mergedTail;
      }
    }

    return dummy.next;
  }

 private:
  int getLength(ListNode* head) {
    int length = 0;
    for (ListNode* curr = head; curr; curr = curr->next)
      ++length;
    return length;
  }

  ListNode* split(ListNode* head, int k) {
    while (--k && head)
      head = head->next;
    ListNode* rest = head ? head->next : nullptr;
    if (head)
      head->next = nullptr;
    return rest;
  }

  pair<ListNode*, ListNode*> merge(ListNode* l1, ListNode* l2) {
    ListNode dummy(0);
    ListNode* tail = &dummy;

    while (l1 && l2) {
      if (l1->val > l2->val)
        swap(l1, l2);
      tail->next = l1;
      l1 = l1->next;
      tail = tail->next;
    }
    tail->next = l1 ? l1 : l2;
    while (tail->next)
      tail = tail->next;

    return {dummy.next, tail};
  }
};

```


#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/sort-list/
178. Leetcode Solution in Mysql
Tags: mysql
Published: 2022-07-08 07:51:49

```
# Write your MySQL query statement below
select score,
    (select count(distinct score) + 1 
     from scores ss 
     where ss.score > s.score) `rank`
from scores s
order by score desc
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/rank-scores/
181. Leetcode Solution in Mysql
Tags: mysql
Published: 2022-07-08 07:46:53

```
# Write your MySQL query statement below


SELECT E1.Name as 'Employee'
FROM Employee as E1, Employee as E2
WHERE E1.ManagerId = E2.Id AND E1.Salary > E2.Salary;
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/employees-earning-more-than-their-managers/
Share your references with co-workers easily
Tags: sideprojects, webdev, productivity, showdev
Published: 2022-07-08 07:43:12

Hello! If you are looking for a solution of that problem, check out my side project [Linkeeper](https://linkeeper.io)!

## What Linkeeper can do for you

### Save Link privately with your Inbox
![Linkeeper My Links](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7yp8a1wxh1c05vfgj7z4.png)

### Add a Link
![Fill the form](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4s9o394eqhbj2u1tpma3.png)

### OR, save it via [Chrome Extension](https://chrome.google.com/webstore/detail/linkeeper-chrome-extensio/ledecjjpdbaagochkbpoaggigmmcgopa)
![Save via Chrome Extension](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8xto6usczgqhvk83s430.png)

### Link created!
![Link created!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mi4c5ixu1gqgcvb2azym.png)

### You can filter them by a tag
![Filter the list with a tag](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g1fbuewvobssdb0ot2p.png)

### OR (nested) tags
![Filter the list with nested tags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yiuy7rgn1hlxc5ou2m50.png)

### Organize links by projects
![Move the link from an Inbox to a specific project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/laqpr1ao1kxhj8h15zio.png)

### Copy your shareable project link
![Copy Share project link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygfbx2mrq8xdopca1d2g.png)

### Done! Now, send to your co-workers!
![Project link copied!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2jot2mvx77gv9dxewr0l.png)

### Try Linkeeper
1. Go sign up in [Linkeeper hompage](https://linkeeper.io)
2. Login
3. Go install [Chrome Extension](https://chrome.google.com/webstore/detail/linkeeper-chrome-extensio/ledecjjpdbaagochkbpoaggigmmcgopa)
4. Save what you've googled!

<a href="https://www.buymeacoffee.com/swimmingkiim" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/arial-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
Release 0.25.0 of Spellcheck (GitHub) Action - a maintenance release including a security fix
Tags: release, opensource, githubaction, spelling
Published: 2022-07-08 07:41:15

---
title: Release 0.25.0 of Spellcheck (GitHub) Action - a maintenance release including a security fix
published: true
description: Baby step maintenance, Docker base image updated and security issue addressed
tags: release, opensource, githubaction, spelling
---
I have just returned after a 3-day hike in Sweden, so some time at the computer is most welcome, since my legs are pretty worn.

The release of 0.25.0 of the [GitHub Spellcheck Action](https://github.com/marketplace/actions/github-spellcheck-action) consists of PRs from two bots. One bumps the base image for the Docker image, so as always to not fall too much behind on maintenance doing baby steps.

The other one is a fix to a recently discovered security issue in the Python library `lxml`.

The proposed fix from Snyk was to bump the required version from 4.6.5 to 4.9.1. The Snyk report is available here:

- [SNYK-PYTHON-LXML-2940874](https://security.snyk.io/vuln/SNYK-PYTHON-LXML-2940874)

In addition there are descriptions as both CVE and CWE:

- [CVE-2022-2309](https://www.cve.org/CVERecord?id=CVE-2022-2309)
- [CWE-476](https://cwe.mitre.org/data/definitions/476.html)

I am not sure how relevant and critical the issue is in the context of this GitHub action, but I always tend to take these things seriously - better safe than sorry.

## Change Log

### 0.25.0, 2022-07-08, maintenance release, update recommended

- `lxml` requirement bumped from version 4.6.5 to 4.9.1 addressing a security issue [SNYK-PYTHON-LXML-2940874](https://security.snyk.io/vuln/SNYK-PYTHON-LXML-2940874) / [CVE-2022-2309](https://www.cve.org/CVERecord?id=CVE-2022-2309) / [CWE-476](https://cwe.mitre.org/data/definitions/476.html) via PR [#104](https://github.com/rojopolis/spellcheck-github-actions/pull/104) from @snyk-bot

- Docker image updated to Python 3.10.5 slim from 3.10.4 slim via PR [#102](https://github.com/rojopolis/spellcheck-github-actions/pull/102) from @dependabot
Embedded Systems Weekly #108
Published: 2022-07-08 07:39:03

A new Friday, a new issue! I hope you'll enjoy #108 as much as I enjoyed doing it.

Thank you to [ReimuNotMoe](https://twitter.com/ReimuNotMoe) for the header's picture.

Happy reading!

### Articles 
[Learning A New Microcontroller](https://www.embeddedrelated.com/showarticle/1455.php)
The main idea of the article is to describe a structured and repeatable process to learn a new microcontroller. The last advice, [Keep An Engineering Notebook](https://www.embeddedrelated.com/showarticle/1455.php#Keep_An_Engineering_Notebook), is for me one of the most important advice all juniors should follow from day one.

[EDLA: remote logic analyser using ESP32 and Web protocols](https://iosoft.blog/2022/04/11/edla/)
This is an open source design ([software and hardware](https://github.com/jbentham/edla)) of a remote logic analyser. It has 16 digital inputs and the designer claims that it can sample 20 mega-samples per second (MS/s) and store up to 250 kilo-samples.

[JT89 FPGA Clone of sn76489an hardware by Jose Tejada](https://github.com/jotego/jt89)
The FPGA clone is coded in Verilog. If the SN76489 vaguely reminds you something, it is the Texas Instruments chip used for sound generation on the BBC Micro, the Sega Megadrive, the Master System and some more...

[Richi´s Lab](https://www.richis-lab.de/index.htm)
This week I discovered the Richi´s Lab website with dozens of beautiful die shots. A pleasure for the eyes!

[Need A Logic Analyzer? Use Your Pico!](https://hackaday.com/2022/03/02/need-a-logic-analyzer-use-your-pico/)
A Raspberry Pi Pico can now be turned into a reasonably high speed logic analyzer. To be more precise, it has 21 digital channels at up to 120 MHz and 3 ADC channels at up to 500 KHz.

[ZipCPU Lesson: If it's not tested, it doesn't work.](https://zipcpu.com/zipcpu/2022/07/04/zipsim.html)
An interesting REX from the ZipCPU project. The article describes how from a bug missed by the tests they improved the whole test process.

### Jobs
[Zaack, Développeur Linux Embarqué, Full-time, Achère 78260 France](https://jobs.embedsysweekly.com/job/k2K0a9Bn/d-veloppeur-linux-embarqu)
Créée en 2017, Zaack est une Jeune Entreprise Innovante dans le contrôle de la Qualité de l’Air Intérieure (QAI).
Filiale Recherche et Innovation du groupe Igienair spécialiste de la qualité de l’air, Zaack propose un environnement dynamique avec le défi supplémentaire de satisfaire la clientèle d’un grand groupe!

### Misc
[Hardening Attack Surfaces with Formally Proven Binary Format Parsers](https://www.microsoft.com/en-us/research/publication/hardening-attack-surfaces-with-formally-proven-binary-format-parsers/)
Microsoft released EverParse3D. It's a generator of formally proven binary format parsers. It generates C code and it looks like it can address any legacy binary format. Can it bring something to Linux kernel development?
"Hello World" in Solidity
Tags: solidity, blockchain
Published: 2022-07-08 07:21:20

The "Hello World" program is most likely the first thing you would learn when trying to learn a new language.

Here's what a "Hello World" smart contract in Solidity looks like:

```solidity
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

contract HelloWorld{
    string public greeting = "Hello World";
}
```
## What is Solidity?

Solidity is statically typed, object-oriented, and high-level language for building smart contracts.

## Code Walkthrough

- Solidity files take the extension **.sol**
- **// SPDX-License-Identifier: MIT** - specifies the license used by this contract. It's not mandatory but it's important since smart contracts are open source.
- **pragma solidity 0.8.0;** - specifies the version of solidity that should be used during the compilation of the contract. It's required for the code to run. Other variations like **pragma solidity ^0.8.0;**, **pragma solidity >=0.8.0;**,**pragma solidity <=0.8.0;** and **pragma solidity >=0.4.22 <0.8.0;** can also be used to specify versions greater or equal to 0.8.0, versions greater or equal to version(same as the previous), versions less than or equal to 0.8.0 and versions greater than or equal to 0.4.22 but less than 0.8.0 respectively.
- **contract HelloWorld {...}** - creates a code block for writing the logic of the smart contract. This is similar to defining classes in object-oriented programming languages.
- **string public greeting = "Hello World";**  - as a statically-typed language the data type needs to be specified. Here, a string is used. The **public** keyword is a visibility modifier. And, the **greeting** is the variable name. **public makes** it possible for the variable greeting to be called a getter function **greeting()**

## Conclusion

Congratulations!! you just wrote your first [smart contract](https://blockchaintotheworld.com/understanding-smart-contracts/) in solidity. Go ahead and try the code on [Remix](http://remix.ethereum.org/).

Just as this is your first, this is also our first post on here. First of many.

Good luck on your journey.

This post was originally published [here](https://blockchaintotheworld.com/hello-world-in-solidity/) on Blockchaintotheworld.com
How Fast Do Comets Travel? Full Guide You Need To Know?
Tags: webdev, beginners, tutorial
Published: 2022-07-08 07:20:30


![Fast Do Comets Travel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwh5at0oihs93flocxki.jpg)
How Fast Do Comets Travel? Comets are one of the most beautiful sights in the night sky. They also happen to be one of the most mysterious. While we know that they originate from somewhere beyond our solar system, how exactly do they travel so quickly?

The nucleus and coma combine to produce the comet’s head. At 2,000 miles per hour, the comet is heading away from the sun. About 2,000 miles per hour is an average speed for comets heading distant from the sun. However, when they approach the massive star, their speed increases. Comets may reach.
ow Fast do comets travel?
The short answer? At speeds faster than any human has ever traveled. Fast enough to see a comet coming from anywhere on Earth with the right telescope and an observant eye. No roads or railroads lead to a comet’s arrival—they show up suddenly one day out of nowhere.

Seeing a comet for the first time can be something extraordinary. From when they appear to their speed of travel. Here is everything you need to know about visiting a comet for the first time.
Read More: [Fast Do Comets Travel](https://africanmillionairemindset.com/how-fast-do-comets-travel-full-guide-you-need-to-know/)
How to insert an element at a specific array index with JavaScript
Tags: javascript, webdev, beginners
Published: 2022-07-08 07:06:06

In this article, I'll teach you how to add an element to a JavaScript array but set it to a specific position.

Let's set the stage. I have a sidebar menu with a couple of items in it.

```js
const sidebarMenu = ['home', 'about', 'contact'];
```

However, for premium users, I want to add the courses menu. It has to show right before the contact item.

## Add an element to an array at a specific index with JavaScript

To add this item, we can use the [`splice` method](https://daily-dev-tips.com/posts/vanilla-javascript-slice-vs-splice/). This method has multiple powers and can even be used to delete items.
So be very careful when setting the parameters.

To set an item, we can use the first parameters to define the position, and everything after that is the items we push.

```js
if (premiumUser) {
  sidebarMenu.splice(2, 0, 'courses');
}
```

Our `sidebarMenu` now has the following content: `[ 'home', 'about', 'courses', 'contact' ]`.

So let's see what the numbers mean:

- the first one (`2`): start position
- second one (`0`): delete count
- the rest: items to add

It's important to note that JavaScript arrays start at zero, so when defining the start position, you must keep that in mind.

Our array counts like this:

- 0: Home
- 1: About
- 2: Contact

With the splice method, we technically say:
Add an item at position two, don't remove any existing elements, and the element to add is 'courses'.

## Adding multiple elements

A super cool thing about splice is that it has no limit to how many items it can add.
So we can even add multiple items.

```js
if (premiumUser) {
  sidebarMenu.splice(2, 0, 'courses', 'profile');
}

// [ 'home', 'about', 'courses', 'profile', 'contact' ]
```

### 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)
177. Leetcode Solution in Mysql
Tags: mysql
Published: 2022-07-08 07:04:56

```
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
  SET N = N - 1;
  RETURN (
      # Write your MySQL query statement below.

      select distinct e.Salary
      from Employee e
      order by e.Salary desc
      limit N, 1

  );
END
```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/nth-highest-salary/
89. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 06:57:03

```
class Solution {
 public:
  vector<int> grayCode(int n) {
    vector<int> ans{0};

    for (int i = 0; i < n; ++i)
      for (int j = ans.size() - 1; j >= 0; --j)
        ans.push_back(ans[j] | 1 << i);

    return ans;
  }
};

```

#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/gray-code/
73. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-08 06:54:34

```
class Solution {
 public:
  void setZeroes(vector<vector<int>>& matrix) {
    const int m = matrix.size();
    const int n = matrix[0].size();
    bool shouldFillFirstRow = false;
    bool shouldFillFirstCol = false;

    for (int j = 0; j < n; ++j)
      if (matrix[0][j] == 0) {
        shouldFillFirstRow = true;
        break;
      }

    for (int i = 0; i < m; ++i)
      if (matrix[i][0] == 0) {
        shouldFillFirstCol = true;
        break;
      }

    // store the information in the 1st row/col
    for (int i = 1; i < m; ++i)
      for (int j = 1; j < n; ++j)
        if (matrix[i][j] == 0) {
          matrix[i][0] = 0;
          matrix[0][j] = 0;
        }

    // fill 0s for the matrix except the 1st row/col
    for (int i = 1; i < m; ++i)
      for (int j = 1; j < n; ++j)
        if (matrix[i][0] == 0 || matrix[0][j] == 0)
          matrix[i][j] = 0;

    // fill 0s for the 1st row if needed
    if (shouldFillFirstRow)
      for (int j = 0; j < n; ++j)
        matrix[0][j] = 0;

    // fill 0s for the 1st col if needed
    if (shouldFillFirstCol)
      for (int i = 0; i < m; ++i)
        matrix[i][0] = 0;
  }
};

```


#leetcode
#challenge
here is the link for the problem:
https://leetcode.com/problems/set-matrix-zeroes/