teleren/devto huggingface dataset:
Day 57: a GraphQL practice project
Published: 2022-06-04 23:55:16

Hi!
Today mainly was a resting day I didn't do anything code related until the evening where I got started with the Typescript GraphQL tutorial from `howtographql` where they hacker news clone api using TypeScript, GraphQL, Apollo-server and nexus. they made this beginner friendly tutorial that I started working on today and currently everything is going smoothly as I already created some of my own schemas. 
Today I also got started using `pnpm` which is a better version of `npm` as a package manager and from the first impressions I think it's great.
Tomorrow may be a busy one as the plan is to finish with this practice project and get started working on the real project assigned for the next week. I discovered many new technologies this week hopefully I will get some time for articles next week.

signing off...
Single Number
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 23:30:39

Given a **non-empty** array of integers `nums`, every element appears _twice_ except for one. Find that single one.

You must implement a solution with a linear runtime complexity and use only constant extra space.

**Example 1:**

**Input:** nums = \[2,2,1\]
**Output:** 1

**Example 2:**

**Input:** nums = \[4,1,2,1,2\]
**Output:** 4

**Example 3:**

**Input:** nums = \[1\]
**Output:** 1

**Constraints:**

*   `1 <= nums.length <= 3 * 104`
*   `-3 * 104 <= nums[i] <= 3 * 104`
*   Each element in the array appears twice except for one element which appears only once.

**SOLUTION:**

    class Solution:
        def singleNumber(self, nums: List[int]) -> int:
            n = nums[0]
            for num in nums[1:]:
                n = n ^ num
            return n
Remove All Adjacent Duplicates In String
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 23:00:41

You are given a string `s` consisting of lowercase English letters. A **duplicate removal** consists of choosing two **adjacent** and **equal** letters and removing them.

We repeatedly make **duplicate removals** on `s` until we no longer can.

Return _the final string after all such duplicate removals have been made_. It can be proven that the answer is **unique**.

**Example 1:**

**Input:** s = "abbaca"
**Output:** "ca"
**Explanation:** 
For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move.  The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca".

**Example 2:**

**Input:** s = "azxxzy"
**Output:** "ay"

**Constraints:**

*   `1 <= s.length <= 105`
*   `s` consists of lowercase English letters.

**SOLUTION:**

    class Solution:
        def removeDuplicates(self, s: str) -> str:
            stack = []
            for c in s:
                if len(stack) == 0 or c != stack[-1][0]:
                    stack.append([c, 1])
                else:
                    stack[-1][1] += 1
                    if stack[-1][1] == 2:
                        stack.pop()
            return "".join([c[0] * c[1] for c in stack])
Duplicate Zeros
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 22:30:42

Given a fixed-length integer array `arr`, duplicate each occurrence of zero, shifting the remaining elements to the right.

**Note** that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.

**Example 1:**

**Input:** arr = \[1,0,2,3,0,4,5,0\]
**Output:** \[1,0,0,2,3,0,0,4\]
**Explanation:** After calling your function, the input array is modified to: \[1,0,0,2,3,0,0,4\]

**Example 2:**

**Input:** arr = \[1,2,3\]
**Output:** \[1,2,3\]
**Explanation:** After calling your function, the input array is modified to: \[1,2,3\]

**Constraints:**

*   `1 <= arr.length <= 104`
*   `0 <= arr[i] <= 9`

**SOLUTION:**

    class Solution:
        def duplicateZeros(self, arr: List[int]) -> None:
            n = len(arr)
            i = 0
            while i < n:
                if arr[i] == 0:
                    arr.insert(i + 1, 0)
                    i += 1
                i += 1
            while len(arr) > n:
                arr.pop()
Machine Learning Is Widely Adopted
Published: 2022-06-04 22:04:31


Machine learning is not science fiction. [Best machine learning course](https://www.igmguru.com/machine-learning-ai/machine-learning-certification-training/) is already widely used by businesses across all sectors to advance innovation and increase process efficiency. In 2021, 41% of companies accelerated their rollout of AI as a result of the pandemic. These newcomers are joining the 31% of companies that already have AI in production or are actively piloting AI technologies.
•	Data security: Machine learning models can identify data security vulnerabilities before they can turn into breaches. By looking at past experiences, machine learning models can predict future high-risk activities so risk can be proactively mitigated.
•	Finance: Banks, trading brokerages and fintech firms use machine learning algorithms to automate trading and to provide financial advisory services to investors. Bank of America is using a chatbot, Erica, to automate customer support.
•	Healthcare: ML is used to analyze massive healthcare data sets to accelerate discovery of treatments and cures, improve patient outcomes, and automate routine processes to prevent human error. For example, IBM’s Watson uses data mining to provide physicians data they can use to personalize patient treatment.
•	Fraud detection: AI is being used in the financial and banking sector to autonomously analyze large numbers of transactions to uncover fraudulent activity in real time. Technology services firm Capgemini claims that fraud detection systems using machine learning and analytics minimize fraud investigation time by 70% and improve detection accuracy by 90%.
•	Retail: AI researchers and developers are using ML algorithms to develop AI recommendation engines that offer relevant product suggestions based on buyers’ past choices, as well as historical, geographic and demographic data.
First Unique Character in a String
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 22:00:47

Given a string `s`, _find the first non-repeating character in it and return its index_. If it does not exist, return `-1`.

**Example 1:**

**Input:** s = "leetcode"
**Output:** 0

**Example 2:**

**Input:** s = "loveleetcode"
**Output:** 2

**Example 3:**

**Input:** s = "aabb"
**Output:** -1

**Constraints:**

*   `1 <= s.length <= 105`
*   `s` consists of only lowercase English letters.

**SOLUTION:**

    import heapq
    
    class Solution:
        def firstUniqChar(self, s: str) -> int:
            n = len(s)
            freq = [[0, n] for i in range(26)]
            beg = ord('a')
            for i in range(n):
                freq[ord(s[i]) - beg][0] += 1
                freq[ord(s[i]) - beg][1] = min(i, freq[ord(s[i]) - beg][1])
            uniques = [el for el in freq if el[0] == 1]
            k = len(uniques)
            if k > 0:
                unique = min(uniques, key = lambda el: el[1])
                return unique[1]
            return -1
Looking for a solid Templating engine for document generation built in JavaScript
Tags: javascript, node, opensource
Published: 2022-06-04 21:56:57

I am about to begin the journey nof my next saas product and I am in need of some advice / direction as to a Templating engine to use for document generation within my app.

Ideally Id like to use a word doc or Google doc as a the base template, and then merge data with the template, resulting in a generated pdf.

TIA
My first project :)
Tags: computerscience, python, beginners
Published: 2022-06-04 21:48:58

Ive been learning how to code on Codecademy's Computer Science career path, and just finished my first portfolio project; a program that helps you choose a film camera to buy (one of hobbies). 

At first I had trouble coming up with an idea for this project –– I originally though the camera picking tool was too easy. Now having worked on it, I ended up learning quite a bit, so think the project choice was actually quite great. 

Here's the link to the code!
https://github.com/homeroochoa47/First_portfolio_Project.git

Cheers!
Edit Distance
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 21:30:40

Given two strings `word1` and `word2`, return _the minimum number of operations required to convert `word1` to `word2`_.

You have the following three operations permitted on a word:

*   Insert a character
*   Delete a character
*   Replace a character

**Example 1:**

**Input:** word1 = "horse", word2 = "ros"
**Output:** 3
**Explanation:** 
horse -> rorse (replace 'h' with 'r')
rorse -> rose (remove 'r')
rose -> ros (remove 'e')

**Example 2:**

**Input:** word1 = "intention", word2 = "execution"
**Output:** 5
**Explanation:** 
intention -> inention (remove 't')
inention -> enention (replace 'i' with 'e')
enention -> exention (replace 'n' with 'x')
exention -> exection (replace 'n' with 'c')
exection -> execution (insert 'u')

**Constraints:**

*   `0 <= word1.length, word2.length <= 500`
*   `word1` and `word2` consist of lowercase English letters.

**SOLUTION:**

    class Solution:
        def md(self, word1, word2, i1, i2):
            if (i1, i2) in self.cache:
                return self.cache[(i1, i2)]
            if i1 == len(word1):
                return len(word2) - i2
            if i2 == len(word2):
                return len(word1) - i1
            if word1[i1] == word2[i2]:
                self.cache[(i1, i2)] = self.md(word1, word2, i1 + 1, i2 + 1)
                return self.cache[(i1, i2)]
            else:
                self.cache[(i1, i2)] = 1 + min(self.md(word1, word2, i1 + 1, i2 + 1), self.md(word1, word2, i1, i2 + 1), self.md(word1, word2, i1 + 1, i2))
                return self.cache[(i1, i2)]
        
        def minDistance(self, word1: str, word2: str) -> int:
            self.cache = {}
            return self.md(word1, word2, 0, 0)
Master of Linked Lists data structure
Tags: algorithms, beginners, tutorial, programming
Published: 2022-06-04 21:17:22

## Master anything however it's so confusing

---

I'm going to tell you the **secret** of Mastering anything you want however is so hard to understand.

## The story of how I realized this powerful method
I started a challenge on one of problem-solving websites
for solving 2 or 3 problems each day and after 2 months I realized that I'm a **Master** :zap: of using and solving problems that have **Linked list** and I solve it very quick without any hinting, otherwise on any problem with any data structure
like **graph** I start struggling and google stuff and the topic is so confusing in my head, So I started to learn **graph** with the same way I studied **linked list**

---

## Know the science first :mortar_board:
When you try to learn anything you should start understand the concept and the science of this thing.

and those some tricks that will help you find out.

- Head up to google and try to search why they did this thing.
- start compare it to something that do the same like linked list **VS** arrays.
- look for difference between them.

## Baby steps :hatching_chick:

When you do anything for your first time you should go slow as possible as you can.
It's will help you to clear your thinking of many things you will face while learning.

---

## Imagine it

While you try to understand something confusing to you, The best thing to do it's to imagine how it would be like in the real world.

**Relate it** to thing you know very will

---

## Teach someone :book:

even you didn't learn a lot you have to do **multiple teaching**

in the early step 
- Teach someone know the topic will
   
- Talk to your rubber duck (any cute thing) and explain what you learned 

- try to explain it to one who has the intention to learn this topic 

## Practice on the topic a lot

- innovate when you practice
when you solving a problem and you got a solution try to solve it again later days when you forgot the other solution you will find this so impressive,

Because your mind will be more different and more smarter than the before days   



---
If you know a trick don't miss to share it with us in the comments
Diferencia entre parámetros y argumentos en una función
Tags: functions, programming, c, spanish
Published: 2022-06-04 21:13:59

[You can read the english version of this post by clicking here](https://dev.to/jfitech/difference-between-parameters-and-arguments-in-a-function-1j14)

Cuando comencé a aprender a programar (en Java) usando un libro de mi biblioteca cercana, siempre mencionaban "parámetros" y "argumentos", pero nunca entendí la diferencia.

Algunos de ustedes como programadores deben haberse preguntado en algún momento, ¿cuál es la diferencia entre un parámetro y un argumento en una función?

Miremos la diferencia:
- Al **declarar una función**, los datos que esta recibe (generalmente van entre paréntesis en la mayoría de los lenguajes de programación) se les llama **parámetros**.

- Al **invocar (llamar) una función**, los datos que le pasamos a esta se les conoce como **argumentos**.

Vamos a usar un ejemplo de código en C para dejar las cosas más claras:
```
1  #include <stdio.h>
2 
3  int addTwoNumbers(int x, int y) {
4     int sum = x + y;
5
6     return sum;
7  }
8
9  int main(void) {
10    int a = 5;
11    int b = 7;
12    
13    int c = addTwoNumbers(a, b)
14
15    printf("The sum of the two numbers is: %d\n");
16 
17    return 0;
18 }
```

- En la línea 3 del bloque de código declaramos una función llamada `addTwoNumbers`, los **parámetros** que toma son dos variables de tipo `int` llamadas `x` y `y`:
```
3 addTwoNumbers(int x, int y)
```

- Invocamos la función `addTwoNumbers` en la línea 13, y pasamos las variables `a` y `b` como **argumentos**:
```
13 addTwoNumbers(a, b)
```
Number of Steps to Reduce a Number in Binary Representation to One
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 21:00:41

Given the binary representation of an integer as a string `s`, return _the number of steps to reduce it to_ `1` _under the following rules_:

*   If the current number is even, you have to divide it by `2`.
    
*   If the current number is odd, you have to add `1` to it.
    

It is guaranteed that you can always reach one for all test cases.

**Example 1:**

**Input:** s = "1101"
**Output:** 6
**Explanation:** "1101" corressponds to number 13 in their decimal representation.
Step 1) 13 is odd, add 1 and obtain 14. 
Step 2) 14 is even, divide by 2 and obtain 7.
Step 3) 7 is odd, add 1 and obtain 8.
Step 4) 8 is even, divide by 2 and obtain 4.  
Step 5) 4 is even, divide by 2 and obtain 2. 
Step 6) 2 is even, divide by 2 and obtain 1.  

**Example 2:**

**Input:** s = "10"
**Output:** 1
**Explanation:** "10" corressponds to number 2 in their decimal representation.
Step 1) 2 is even, divide by 2 and obtain 1.  

**Example 3:**

**Input:** s = "1"
**Output:** 0

**Constraints:**

*   `1 <= s.length <= 500`
*   `s` consists of characters '0' or '1'
*   `s[0] == '1'`

**SOLUTION:**

    class Solution:
        def numSteps(self, s: str) -> int:
            steps = 0
            while s != "1":
                if s[-1] == "0":
                    s = s[:-1]
                else:
                    i = len(s) - 1
                    carry = 1
                    while carry > 0 and i >= 0:
                        curr = int(s[i]) + carry
                        s = s[:i] + str(curr % 2) + s[i+1:]
                        carry = curr // 2
                        i -= 1
                    if carry > 0:
                        s = "1" + s
                steps += 1
            return steps
DEV EVENTO
Tags: webdev, programming
Published: 2022-06-04 20:41:46

Não perca as novidades que estarão presentes na próxima edição do maior evento hands-on do Brasil sobre desenvolvimento de software. Saiba quais tecnologias, ferramentas e práticas estão sendo mais utilizadas por profissionais que são referência na área.
https://t.igti.com.br/click?o=705&a=75596
Count Numbers with Unique Digits
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 20:30:39

Given an integer `n`, return the count of all numbers with unique digits, `x`, where `0 <= x < 10n`.

**Example 1:**

**Input:** n = 2
**Output:** 91
**Explanation:** The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99

**Example 2:**

**Input:** n = 0
**Output:** 1

**Constraints:**

*   `0 <= n <= 8`

**SOLUTION:**

    class Solution:
        def countUnique(self, n, used, first):
            if n == 0:
                return 0
            ctr = 0
            beg = 0
            if first:
                beg = 1
            for i in range(beg, 10):
                if i not in used:
                    ctr += 1 + self.countUnique(n - 1, used.union({i}), False)
            return ctr
        
        def countNumbersWithUniqueDigits(self, n: int) -> int:
            return self.countUnique(n, set(), True) + 1
Free icons for your website
Tags: webdev, beginners, css, codenewbie
Published: 2022-06-04 20:21:36

🔥**Tutorial [Video](https://youtu.be/YW8m7WQo3P0)**
🔥 **YouTube Channel [Link](https://www.youtube.com/channel/UCoBv49GWlBRjDSRa3Aa_X4w?sub_confirmation=1)**

 _<u>Font Awesome</u>_ yeah this website **_provides premium and free icons for your website._** You can use these code in Html, rect.js, vue.js and many more.

🔥website [link](https://fontawesome.com/)

{% embed https://www.youtube.com/watch?v=YW8m7WQo3P0&ab_channel=sycocoders %}

👆**Must Watch this video**
Create an object from a string variable in PHP
Tags: webdev, php, web, tutorial
Published: 2022-06-04 20:09:45

In PHP, objects can be created from string variables. It provides a very convenient way for you to define rules in text and handle requests dynamically. In this post, we show you how to do it.

## Create an object from a string variable


Supposed we have a class called `Rectangle`, it is for a rectangle shape and it calculates its area.

```php
class Rectangle
{
    private $length;
    private $width;
    
    public function setLength($l) {
        $this->length = $l;
    }
    
    public function setWidth($w) {
        $this->width = $w;
    }
    
    public function setLengthWidth($l, $w) {
         $this->length = $l;
         $this->width = $w;
    }
    
    public function getArea() {
        return $this->length * $this->width;
    }
    
}
```

You can use a string variable to create the `Rectangle` object like this:

```php
$className = "Rectangle";
$class = new $className();
``` 

Also, a function in a class can be called by using a string variable. If you want to call the function `setLength()` and `setWidth()` in the class `Rectangle`, you can do as follows:

```php
$length = 10;
$width = 3;

$setLength = "setLength";
$setWidth = "setWidth";

$class->{$setLength}($length);
$class->{$setWidth}($width);
```

Or, you can just use a string in the `{}` to call a function like this:

```php
$class->{"setLengthWidth"}($length, $width);
```

To calculate the Rectangle's area, the function `getArea()` can be called as follows:

```php
echo "The area is: " . $class->{"getArea"}(); // The area is: 30
```

## Create rules and call functions dynamically

Here, we show you an example how to call functions dynamically based on the request.
...

For the rest of the content, please go to the link below:
[https://www.codebilby.com/blog/a42-create-object-from-variable-name](https://www.codebilby.com/blog/a42-create-object-from-variable-name)
Word Subsets
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 20:00:44

You are given two string arrays `words1` and `words2`.

A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.

*   For example, `"wrr"` is a subset of `"warrior"` but is not a subset of `"world"`.

A string `a` from `words1` is **universal** if for every string `b` in `words2`, `b` is a subset of `a`.

Return an array of all the **universal** strings in `words1`. You may return the answer in **any order**.

**Example 1:**

**Input:** words1 = \["amazon","apple","facebook","google","leetcode"\], words2 = \["e","o"\]
**Output:** \["facebook","google","leetcode"\]

**Example 2:**

**Input:** words1 = \["amazon","apple","facebook","google","leetcode"\], words2 = \["l","e"\]
**Output:** \["apple","google","leetcode"\]

**Constraints:**

*   `1 <= words1.length, words2.length <= 104`
*   `1 <= words1[i].length, words2[i].length <= 10`
*   `words1[i]` and `words2[i]` consist only of lowercase English letters.
*   All the strings of `words1` are **unique**.

**SOLUTION:**

    from collections import Counter
    
    class Solution:
        def isSubset(self, ctr1, ctr2):
            for c in ctr1:
                if ctr2[c] < ctr1[c]:
                    return False
            return True
        
        def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:
            univ = Counter()
            for w in words2:
                curr = Counter(w)
                for c in curr:
                    univ[c] = max(univ[c], curr[c])
            return [w for w in words1 if self.isSubset(univ, Counter(w))]
Difference between parameters and arguments in a function
Tags: functions, programming, c
Published: 2022-06-04 19:45:48

[Puede leer la versión en español de este post haciendo click aquí](https://dev.to/jfitech/diferencia-entre-parametros-y-argumentos-en-una-funcion-1hoj)

When I first started learning how to program (in Java) using a book from my local library, they would always mention "parameters" and "arguments", but I never quite understood the difference.

Some of you as programmers may have wondered at some point, what is the difference between a parameter and an argument in a function?

Let's take a look at a the difference:

- When **declaring a function** the data it takes (usually goes inside parentheses in most programming languages) is called **parameters**.

- When **invoking (calling) a function** the data we pass to it is referred to as **arguments**.

We are going to use a code example in C to make things more clear:

```
1  #include <stdio.h>
2 
3  int addTwoNumbers(int x, int y) {
4     int sum = x + y;
5
6     return sum;
7  }
8
9  int main(void) {
10    int a = 5;
11    int b = 7;
12    
13    int c = addTwoNumbers(a, b)
14
15    printf("The sum of the two numbers is: %d\n");
16 
17    return 0;
18 }
```

- On line 3 of the code block we declared a function called `addTwoNumbers`, the **parameters** it takes are two `int` type variables named `x` and `y`:
```
3  addTwoNumbers(int x, int y)
```


- We invoke the `addTwoNumbers` function on line 13, and we pass the `a` and `b` variables as **arguments**:
```
13 addTwoNumbers(a, b)
```
Prefix-only modules in Nodejs 18
Published: 2022-06-04 19:36:26

Nodejs 18 comes with the 𝗻𝗼𝗱𝗲: prefix to import modules from the core modules.
Conventional modules like 𝗳𝘀 and 𝗼𝘀, for example, would work as usual without the prefix. Though a new core module has emerged, where using the 𝗻𝗼𝗱𝗲: prefix is mandatory.

This prefix allows the node team to release new core modules without any name conflicts with existing modules in the community.

It works with all core node modules, so using it with userland imports won't work.

The 𝗻𝗼𝗱𝗲:𝘁𝗲𝘀𝘁 module is still experimental, so there might be some changes coming its way, including the name.


![prefix-only nodejs modules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bftf55he6r5zhrcwm8tw.png)


Original post: https://www.linkedin.com/posts/activity-6938930546290909184-yd-b