teleren/devto huggingface dataset:
Painless conditional classes with classnames package
Tags: webdev, react, beginners, tutorial
Published: 2022-06-04 10:39:02

Hey folks today's post is a small one but i'm going to share with you a pretty neat way to manage your conditional styles. 

If you ever worked on conditional classes, chances are you pulled your head trying to put those class names all together with ternary operators and what's not. Today I'll introduce a simple and better way to write conditional classes, Our savior is classnames. 

classnames is a simple JavaScript utility for conditionally joining classNames together

First let's see the problem here with a button as an example

```jsx
const [active, setActive] = useState(false);
<button 
	onClick={() => setActive(true)} 
	className=`btn ${active ? "btn-active" : "btn primary"}`
	>
	Click Me
	</button>
```

The code above works fine, However we can agree that it looks **ugly**, If you use CSS modules it may look a bit more readable but it would still look ugly. Especially if you have multiple classes  

That's where [classnames](https://www.npmjs.com/package/classnames) package comes into play 

```jsx
import classnames from "classnames"

const [active, setActive] = useState(false);

const btnStyles = classnames({
	btn: true, 
	btn-active: active
})

<button 
	onClick={() => setActive(true)} 
	className={btnStyles} >
	Click Me
	</button>
```

You can see that the syntax is pretty straightforward, classnames will add the 'btn-active' class is active is set to true 

Here is the general syntax

```jsx
const condition = 1 + 1 === 2; 
classnames('foo', {'bar': true, 'baz': condition})
```

'foo' will always be printed, 'bar' too,  but 'baz' will be printed if the expression evaluates to true.

## Conclusion 

that’s been it! I hope you enjoyed this post, And hopefully you learned something new, If you know any other life-saving tool, share it in the comments!

Thanks for reading, happy conditional styling.
How to Fix the XAMPP Error “MySQL Shutdown Unexpectedly”
Tags: xampp, mysql, development, localhost
Published: 2022-06-04 10:37:48

---
title: How to Fix the XAMPP Error “MySQL Shutdown Unexpectedly”
published: true
description: XAMPP - Error: MySQL shutdown unexpectedly
tags: xampp, mysql, development, localhost
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0y4nptfngsuha7y53mh.jpg
---
If you use a local development environment, you may run into problems that are similar to those on a live server. In some cases, your website or web application may be unable to connect with its database because MySQL isn’t running or it shut down unexpectedly.

Depending on which local environment you use, the process of troubleshooting your MySQL database might vary a bit. With XAMPP, the process is remarkably straightforward since you get access to a control panel instead of having to rely on the command line only.

#### What the XAMPP Error “MySQL Shutdown Unexpectedly” Is
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxoimyz8bw2iya0i0e9o.png)
**Note**
Caution! Don't delete `ibdata1` file!

1. Rename folder `mysql/data` to `mysql/data_old`
2. Make a copy of `mysql/backup` folder and name it as `mysql/data`
3. Copy all your database folders and mysql folder from `mysql/data_old` into `mysql/data`
5. Copy `mysql/data_old/ibdata1` file into `mysql/data` folder

**Start MySQL from XAMPP Control Panel**

XAMPP Fixed
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eby85nr1zrvlv2zzh88w.png)
Sliding Window Maximum
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 10:30:40

You are given an array of integers `nums`, there is a sliding window of size `k` which is moving from the very left of the array to the very right. You can only see the `k` numbers in the window. Each time the sliding window moves right by one position.

Return _the max sliding window_.

**Example 1:**

**Input:** nums = \[1,3,-1,-3,5,3,6,7\], k = 3
**Output:** \[3,3,5,5,6,7\]
**Explanation:** 
Window position                Max
---------------               -----
\[1  3  -1\] -3  5  3  6  7       **3**
 1 \[3  -1  -3\] 5  3  6  7       **3**
 1  3 \[-1  -3  5\] 3  6  7      ** 5**
 1  3  -1 \[-3  5  3\] 6  7       **5**
 1  3  -1  -3 \[5  3  6\] 7       **6**
 1  3  -1  -3  5 \[3  6  7\]      **7**

**Example 2:**

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

**Constraints:**

*   `1 <= nums.length <= 105`
*   `-104 <= nums[i] <= 104`
*   `1 <= k <= nums.length`

**SOLUTION:**

    import heapq
    
    class Solution:
        def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
            n = len(nums)
            maxes = []
            deleted = {}
            window = [-num for num in nums[:k]]
            heapq.heapify(window)
            maxes.append(-window[0])
            for i in range(0, n - k):
                heapq.heappush(window, -nums[i + k])
                deleted[-nums[i]] = deleted.get(-nums[i], 0) + 1
                curr = window[0]
                while curr in deleted:
                    heapq.heappop(window)
                    deleted[curr] -= 1
                    if deleted[curr] == 0:
                        del deleted[curr]
                    curr = window[0]
                maxes.append(-curr)
            return maxes
Understanding React hooks
Tags: react, hooks, webdev, blog
Published: 2022-06-04 10:27:53

> ###Table of Content:
> - <a href="#what-are-hooks">What are Hooks</a>
> - <a href="#state-as-a-hook">State as a Hook</a>
> - <a href="#effect-as-a-hook">Effect as a Hook</a>

If you want to learn about hooks from the basics then this blog will be helpful to you. So, let's understand what is hooks? and how we can use them in our Projects. 

> <h3 id="what-are-hooks">What are Hooks<h3>

Hooks are functions that let you use React state and other react features without writing a class. Hook does not work inside classes but lets you use React without classes. 
We are going to look at some of the built-in React Hooks such as useState and useEffect.
With Hooks, we can extract stateful logic from a component so it can be tested independently and reused.

---
> <h3 id="state-as-a-hook">State as a Hook<h3>

We have an example counter here. After every click on the button the counter increments the value:
```
import React, { useState } from "react";

export default function App() {
  const [counter, setCounter] = useState(0);
  return (
    <div className="App">
      <h1>You clicked counter {counter} times</h1>
      <button onClick={() => setCounter(counter + 1)}>Click me</button>
    </div>
  );
}
```
The above code gives us the output as follows:
{% embed https://youtu.be/DhHzpdrmnAQ %}
_useState_ is a Hook. We call it inside a function to add some local state to it. React preserve this state between re-renders. _useState_ return a pair of the current state and a function that let us update the state. We can call this function using an event handler or somewhere else. 
_useState_ takes only one argument as its initial state. In this example 0 is our initial state and using this our counter starts at zero. You can change as per your need. The initial state argument is used only at the initial render.
We can also use a state hook more than once in a single component.

---
> <h3 id="effect-as-a-hook">Effect as a Hook<h3>

The _useEffect_ hook, adds the ability to perform side effects from a function component. As we can manually change the DOM from React component because it can't be done during rendering. By default, React runs the _useEffect_ hook after every render including the first render.
For Example, the below example sets the Document title after React updates the DOM:

```
import "./style.css";
import React, { useEffect, useState } from "react";

export default function App() {
  const [counter, setCounter] = useState(0);
  useEffect(() => {
    document.title = `Counter: ${counter} time`;
  });
  return (
    <div className="App">
      <h1>You clicked counter {counter} times</h1>
      <button onClick={() => setCounter(counter + 1)}>Click me</button>
    </div>
  );
}
```
The above code gives us the output as follows:
{% embed https://youtu.be/H6suUTh4Zbg %}

---

I hope you have understood what is Hooks and how to use them. We will learn how to create our custom hooks in the next blog which will be updated soon. If you have any suggestions regarding the blog, please let me know in the comments section.

####Thank you!
Get Maximum in Generated Array
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 09:30:41

You are given an integer `n`. A **0-indexed** integer array `nums` of length `n + 1` is generated in the following way:

*   `nums[0] = 0`
*   `nums[1] = 1`
*   `nums[2 * i] = nums[i]` when `2 <= 2 * i <= n`
*   `nums[2 * i + 1] = nums[i] + nums[i + 1]` when `2 <= 2 * i + 1 <= n`

Return _the **maximum** integer in the array_ `nums`​​​.

**Example 1:**

**Input:** n = 7
**Output:** 3
**Explanation:** According to the given rules:
  nums\[0\] = 0
  nums\[1\] = 1
  nums\[(1 \* 2) = 2\] = nums\[1\] = 1
  nums\[(1 \* 2) + 1 = 3\] = nums\[1\] + nums\[2\] = 1 + 1 = 2
  nums\[(2 \* 2) = 4\] = nums\[2\] = 1
  nums\[(2 \* 2) + 1 = 5\] = nums\[2\] + nums\[3\] = 1 + 2 = 3
  nums\[(3 \* 2) = 6\] = nums\[3\] = 2
  nums\[(3 \* 2) + 1 = 7\] = nums\[3\] + nums\[4\] = 2 + 1 = 3
Hence, nums = \[0,1,1,2,1,3,2,3\], and the maximum is max(0,1,1,2,1,3,2,3) = 3.

**Example 2:**

**Input:** n = 2
**Output:** 1
**Explanation:** According to the given rules, nums = \[0,1,1\]. The maximum is max(0,1,1) = 1.

**Example 3:**

**Input:** n = 3
**Output:** 2
**Explanation:** According to the given rules, nums = \[0,1,1,2\]. The maximum is max(0,1,1,2) = 2.

**Constraints:**

*   `0 <= n <= 100`

**SOLUTION:**

    class Solution:
        def getMaximumGenerated(self, n: int) -> int:
            if n == 0:
                return 0
            arr = [0] * (n + 1)
            arr[1] = 1
            for i in range(n + 1):
                if 2 * i <= n:
                    arr[2 * i] = arr[i]
                if 2 * i + 1 <= n:
                    arr[2 * i + 1] = arr[i] + arr[i + 1]
            return max(arr)
Sum Tree
Tags: dsa, algorithms, trees, gfg
Published: 2022-06-04 10:07:19

This post discusses the solution of the problem - [](https://practice.geeksforgeeks.org/problems/sum-tree/1)

We need to solve this problem using Children Sum Property, which means sum of left and right child should be equal to its root. A tree with single node, is also considered to be following children sum property.A empty tree is also considered to be following Children Sum Property.



Below is the solution of the problem.


```
class Solution
{
    public:
    
    int findSum(Node*root){
        if(!root) return 0;
        return root->data +findSum(root->left)+findSum(root->right);
    }
    bool isSumTree(Node* root)
    {
         // Your code here
         if(!root) return true;
         if(!root->left && !root->right) return true;
         
         if(findSum(root->left)+findSum(root->right) == root->data)
         return (isSumTree(root->left) && isSumTree(root->right));
         else return false;
    }
};
```
MetaMask Login using Golang and VueJS
Tags: golanguage, blockchain, authentication, jwt
Published: 2024-06-19 20:24:46

---
title: MetaMask Login using Golang  and VueJS
published: true
date: 2022-06-04 10:04:47 UTC
tags: GoLanguage,Blockchain,authentication,JWT
canonical_url: https://blog.gkomninos.com/metamask-login-using-golang-and-vuejs
---

A step by step tutorial to build single click login by using MetaMask API. Backend is build using Golang and VueJS for the frontend.
binding.pry by many programming languages
Tags: javascript, python, ruby, php
Published: 2022-06-04 09:13:37

Comparison of process interruption tool

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

## What is binding.pry?
While debugging, the engineers sometimes want to see the variable values at that point. If your language is static and you use IDE, you can set break point  by GUI tools. However, if you use a scripting language with a pure text editor, we cannot take it the same way.

Open REPL and run each line might be possible, but it's a hassle.
On Ruby, inserting binding.pry or binding.irb can launch REPL at a specific point. I share how we can do the same thing for the other languages. 

## Ruby
After `gem install pry` 

```ruby
require 'pry'
a = 1
b = 2
binding.pry # open REPL
puts a+b
```

Since Ruby 2.4, native irb supports similar feature

```ruby
require 'irb'
a = 1
b = 2
binding.irb # open REPL
puts a+b
```

## Python
`pip install ipython`

```python
from IPython import embed
a = 1
b = 2
embed() # open REPL
print(a+b)
```

## Node.js
Style is different. `node inspect test.js`

```javascript
a = 1;
b = 2;
debugger; // breakpoint
console.log(a+b);
```

At launch time, the cursor is on the head of the script. Move to the breakpoint.

```javascript
debug> cont // Continue to breakpoint
debug> repl // Open REPL
```

## PHP
`composer require psy/psysh `

```php
<?php
require 'vendor/autoload.php';

$a = 1;
$b = 2;
eval(\Psy\sh()); // open REPL
echo $a+$b;
echo "\n";
```

## Impression
Node.js's style is unique.
Min Cost Climbing Stairs
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 10:00:47

You are given an integer array `cost` where `cost[i]` is the cost of `ith` step on a staircase. Once you pay the cost, you can either climb one or two steps.

You can either start from the step with index `0`, or the step with index `1`.

Return _the minimum cost to reach the top of the floor_.

**Example 1:**

**Input:** cost = \[10,15,20\]
**Output:** 15
**Explanation:** You will start at index 1.
- Pay 15 and climb two steps to reach the top.
The total cost is 15.

**Example 2:**

**Input:** cost = \[1,100,1,1,1,100,1,1,100,1\]
**Output:** 6
**Explanation:** You will start at index 0.
- Pay 1 and climb two steps to reach index 2.
- Pay 1 and climb two steps to reach index 4.
- Pay 1 and climb two steps to reach index 6.
- Pay 1 and climb one step to reach index 7.
- Pay 1 and climb two steps to reach index 9.
- Pay 1 and climb one step to reach the top.
The total cost is 6.

**Constraints:**

*   `2 <= cost.length <= 1000`
*   `0 <= cost[i] <= 999`

**SOLUTION:**

    class Solution:
        memo = {}
        
        def minCostClimbingStairsRec(self, i, cost):
            if i > len(cost) - 1:
                return 0
            if i == len(cost) - 1:
                return cost[i]
            if i not in self.memo:
                self.memo[i] = cost[i] + min(self.minCostClimbingStairsRec(i + 1, cost), self.minCostClimbingStairsRec(i + 2, cost))
            return self.memo[i]
        
        def minCostClimbingStairs(self, cost: List[int]) -> int:
            self.memo = {}
            return min(self.minCostClimbingStairsRec(0, cost), self.minCostClimbingStairsRec(1, cost))
Construct a Binary Tree from Inorder and Postorder
Published: 2022-06-04 09:50:04


When we are given a root,left and right subtree : 

**Inorder**  :  Left Root Right 
**Preorder** :  Root Left Right

We can get the root from the Preorder traversal, and the first element from the Preorder traversal is Root.If we locate the root, we can find the left and right side of the tree easily. We can follow the similar fashion and construct the whole tree.


Here is the code of the solution 

```
class Solution{
    public:
    int order=0;
    Node* build(int in[],int pre[],int s,int e){
        if(s>e){
            return NULL;
        }
        Node* root=new Node(pre[order++]);
        int index=0;
        for(int i=s;i<=e;i++){
            if(in[i]==root->data){
                index=i;
                break;
            }
        }
        root->left=build(in,pre,s,index-1);
        root->right=build(in,pre,index+1,e);
        return root;
    }
    Node* buildTree(int in[],int pre[], int n)
    {
        return build(in,pre,0,n-1);
        // Code here
    }
};

```
Why Should You Opt For Professional Garage Door Repair?
Published: 2022-06-04 09:01:08

People who enjoy repairing things around the house would jump at the chance to work on a garage door repair project. DIY enthusiasts would be interested in such projects. Even they, however, risk a total disaster if they do not have the proper tools. It is a difficult task, and there is a big difference between saying "I think I can do it" and actually doing it.
Each type of work requires a unique set of abilities, and repair projects do not always go as planned. It is sometimes far more expensive to replace the entire thing, or you may be injured. As a result, in some cases, leaving it to the professionals rather than experimenting is preferable.
Consider the possibility of getting your hands/clothes dirty or even getting hurt. Here are some of the reasons why you should hire a professional garage door repairer:
1.  Time
If you need to repair a garage door, you should spend some time determining what is causing the issue. After identifying the problem, you may need to spend more time experimenting with trial and error methods to see what works best, whereas a professional could do all of this much faster due to his/her experience. 
2. Price
Hiring a professional [longmont garage door companies](http://www.longmontgaragedoorrepairbrothers.com/) is a cost-effective solution because they are more experienced and knowledgeable about the problem than amateurs, and he or they will have access to all necessary tools. You will need to buy or rent tools if you plan to do your own garage door repair. While this raises your costs, it also raises the risk of not completing the project properly. As a result, hiring a professional[ garage door installation Longmont](http://www.longmontgaragedoorrepairbrothers.com/) is the superior choice. 
3. The Risk of Injury
A professional knows how to reduce the chances of an accident occurring. You could end up hurting yourself if you don't know how to use certain tools. 
4. Take Advantage of the Advantages
Many repair services are available 24 hours a day, seven days a week, so if your door breaks early in the morning or late at night, you can rely on these services to fix it right away. 
5. High-quality repair
The majority of professionals provide a guarantee on the quality of their work. They are offering a free service for a limited time. If you contact them, they will repair it for free if it occurs during the warranty period. 
Sixth. Convenience
Hiring a professional [garage door opener repair Longmont](http://www.longmontgaragedoorrepairbrothers.com/) is more convenient because you will not have to lift heavy objects or get your hands dirty. You can complete other important tasks or relax while the professional is working. Door repair professionals can complete the job quickly. You can get help from [Garage door opener Longmont](http://www.longmontgaragedoorrepairbrothers.com/) for better service.
[Garage door repair Longmont co](http://www.longmontgaragedoorrepairbrothers.com/) provides skilled professionals for all types of door repair, ensuring that quality is not compromised.
Number of Ways to Split Array
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 09:00:45

You are given a **0-indexed** integer array `nums` of length `n`.

`nums` contains a **valid split** at index `i` if the following are true:

*   The sum of the first `i + 1` elements is **greater than or equal to** the sum of the last `n - i - 1` elements.
*   There is **at least one** element to the right of `i`. That is, `0 <= i < n - 1`.

Return _the number of **valid splits** in_ `nums`.

**Example 1:**

**Input:** nums = \[10,4,-8,7\]
**Output:** 2
**Explanation:** 
There are three ways of splitting nums into two non-empty parts:
- Split nums at index 0. Then, the first part is \[10\], and its sum is 10. The second part is \[4,-8,7\], and its sum is 3. Since 10 >= 3, i = 0 is a valid split.
- Split nums at index 1. Then, the first part is \[10,4\], and its sum is 14. The second part is \[-8,7\], and its sum is -1. Since 14 >= -1, i = 1 is a valid split.
- Split nums at index 2. Then, the first part is \[10,4,-8\], and its sum is 6. The second part is \[7\], and its sum is 7. Since 6 < 7, i = 2 is not a valid split.
Thus, the number of valid splits in nums is 2.

**Example 2:**

**Input:** nums = \[2,3,1,0\]
**Output:** 2
**Explanation:** 
There are two valid splits in nums:
- Split nums at index 1. Then, the first part is \[2,3\], and its sum is 5. The second part is \[1,0\], and its sum is 1. Since 5 >= 1, i = 1 is a valid split. 
- Split nums at index 2. Then, the first part is \[2,3,1\], and its sum is 6. The second part is \[0\], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.

**Constraints:**

*   `2 <= nums.length <= 105`
*   `-105 <= nums[i] <= 105`

**SOLUTION:**

    class Solution:
        def waysToSplitArray(self, nums: List[int]) -> int:
            n = len(nums)
            p = [0]
            for num in nums:
                p.append(p[-1] + num)
            ctr = 0
            for i in range(n - 1):
                l = p[i + 1]
                r = p[-1] - l
                if l >= r:
                    ctr += 1
            return ctr
Mockery 1 Illuminate Console OutputStyle askQuestion() but no expectations were specified
Published: 2022-06-04 21:13:22

---
title: Mockery 1 Illuminate Console OutputStyle askQuestion() but no expectations were specified
published: true
date: 2022-06-04 08:46:00 UTC
tags: 
canonical_url: https://dcblog.dev/mockery-1-illuminate-console-outputstyle-askquestion-but-no-expectations-were-specified
---

When running a PESTPHP test if you come across this error:

```

Received Mockery_1_Illuminate_Console_OutputStyle::askQuestion(), but no expectations were specified
```

Usually caused by caching, clear your cache by running:

```

php artisan optimize:clear
```
Maximum Number of Words Found in Sentences
Tags: leetcode, dsa, theabbie
Published: 2022-06-04 08:30:41

A **sentence** is a list of **words** that are separated by a single space with no leading or trailing spaces.

You are given an array of strings `sentences`, where each `sentences[i]` represents a single **sentence**.

Return _the **maximum number of words** that appear in a single sentence_.

**Example 1:**

**Input:** sentences = \["alice and bob love leetcode", "i think so too", "this is great thanks very much"\]
**Output:** 6
**Explanation:** 
- The first sentence, "alice and bob love leetcode", has 5 words in total.
- The second sentence, "i think so too", has 4 words in total.
- The third sentence, "this is great thanks very much", has 6 words in total.
Thus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words.

**Example 2:**

**Input:** sentences = \["please wait", "continue to fight", "continue to win"\]
**Output:** 3
**Explanation:** It is possible that multiple sentences contain the same number of words. 
In this example, the second and third sentences (underlined) have the same number of words.

**Constraints:**

*   `1 <= sentences.length <= 100`
*   `1 <= sentences[i].length <= 100`
*   `sentences[i]` consists only of lowercase English letters and `' '` only.
*   `sentences[i]` does not have leading or trailing spaces.
*   All the words in `sentences[i]` are separated by a single space.

**SOLUTION:**

    class Solution:
        def mostWordsFound(self, sentences: List[str]) -> int:
            return max([len(s.split()) for s in sentences])