teleren/devto huggingface dataset:
Number of Connected Components in an Undirected Graph
Tags: dsa, python
Published: 2022-02-21 13:51:57

##Instructions

Count the number of connected components in an undirected graph.

##Approach
We initialize count and iterate through every node in the graph traversing through its neighbors as far as possible. We increment count by 1 when there are no more nodes in the connected component.
We also need to keep track of the visited nodes to avoid a loop and duplicate look up.


###Implementation

```python
def countComponents(graph):
    count = 0
    visited = set()
    for node in graph:
        if traverse(graph,node,visited) == True:
            count+=1
    return count
def traverse(graph,current,visited):
    if current in visited:
        return False
    visited.add(current)
    for neighbor in graph[current]:
        traverse(graph, neighbor,visited)
    return True     
graph = {
    'a': ['c', 'b'],
    'b': ['d'],
    'c': ['e'],
    'd': ['f'],
    'e': [],
    'f': [],
    'g':[]
}
print(countComponents(graph))
```
I failed an easy test
Published: 2022-02-21 13:36:29

This is just me, blame myself and summarize my problem.
[The problem here](https://www.hackerrank.com/challenges/sherlock-and-valid-string)

According to the description, a valid string is a string that has all characters appears a CONST time(i will call it the perfect string), or just one character has more than 1 time appears.

But i misunderstood it, i thought we can remove one character(incase string is not perfect), and then it can possibly valid if we remove one more, and so on. It blows my brain, especially in the context of an interview, i get nervous, and then things go wrong.

The solution is very simple, the only thing we should care about is the frequencies, or in fact how many frequencies of character occurs in the string.

Step 1: create a mapping between character and its frequency
![Step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ad3phb2ijcszutjpmzs7.png)
Step 2: create a mapping between the frequency and number of times it occurs
![Step2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g2xiqet09kwqmrrpmdgx.png)
Step 3:
- Case 1: If there's more than 2 frequencies, it mean the string is not valid, no way to make a one frequency from removing a character
![Case 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yx22mr2u3qr29hhkapa.png)
- Case2: If there's just 1 frequencies, the string is just one character repeat serveral times
![Case 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7277kocr4hho5tg485qx.png) 
- Case 3: Now the last case is 2 frequencies case, let say `a` and `b`. We must delete one charater to make the string valid, but after deleting, `a` and `b`'s value in the frequency map will be changed, to make a string valid, the final frequency map must contains just 1 key(case 2).
First we must check if `a` and `b` occurs 1 time, if both of them occurs more than 1 time, we can't make a string valid even after deleting one character.

Let say we wanna delete the character that has frequency of `a`, after deleting, we have a new frequency that is `a-1`, and the value of a in the frequency mapw will be reduced by 1
so we have a new frequency map `{ b: bOccurrences, a: aOccurences-1, [a-1]: 1 } `
To make string valid, `aOccurrences - 1` must be 0 and [a-1] must be `b` or 0, or in another words: `aOcurrences` == 1 and `(a-1 ==b || a == 1)` (note that obviously `b` cannot be 0)
Same approach with b.
If you feel confused, see the code below
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0m57na02o2tq6yp3y5sx.png)

Here is final solution in python
![Final](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dbtz7df0a5jk0334gtrh.png)
How To Display A SnackBar In Flutter
Tags: flutter, dart, snackbar
Published: 2022-02-21 13:29:27

Hi, It's [Kest](http://afolayanademola.com.ng/) [Again](https://hashnode.com/@kest) And I am about to show *you how to display a snackbar in Flutter*.

***What's a SnackBar anyway?*** 🤔🤔🤔
A SnackBar can be useful to briefly inform your users when certain actions take place. For example, when a user swipes away a message in a list, you might want to inform them that the message has been deleted. You might even want to give them an option to undo the action.

You will be able to display a Snackbar in three easy steps:

- Create a Scaffold.

- Display a SnackBar.

- Provide an optional action.

## **1. Create a Scaffold**
Creating a Scaffold is one of the easiest things to do in Flutter, as a piece of general knowledge, > everything in Flutter is a widget, And Fortunately, it's the same for Scaffold.
The Scaffold widget, from the material library, creates this visual structure and ensures that important widgets don’t overlap.

        return MaterialApp(
          title: 'SnackBar Demo',
          home: Scaffold(
              appBar: AppBar(
              title: const Text('SnackBar Demo'),
              ),
             body: const SnackBarPage(),
            ),
          );

## **2. Display A SnackBar**
With the Scaffold in place, Its time to Display a Snackbar, you can do that with the code snippets below:

        const snackBar = SnackBar(
            content: Text('Yay! A SnackBar!'),
           );

         // Find the ScaffoldMessenger in the widget tree
         // and use it to show a SnackBar.
         ScaffoldMessenger.of(context).showSnackBar(snackBar);

Yay!! that's it. It's as easy as that. However if you would like your snackBar to perform more functions other than displaying messages about users actions. You can add other properties to the widget.

**3. Provide an optional action**
You might want to provide an action to the user when the SnackBar is displayed. For example, if the user accidentally deletes a message, they might use an optional action in the SnackBar to recover the message.

Here’s an example of providing an additional action to the SnackBar widget:

         final snackBar = SnackBar(
             content: const Text('Yay! A SnackBar!'),
             action: SnackBarAction(
             label: 'Undo',
             onPressed: () {
              // Some code to undo the change.
              },
             ),
            );

And that's a wrap. _Shikena_🤗 (that's all). I hope this article has been able to enlighten you and make building awesome, beautiful, and useful apps.

If you would like to discuss this or any related issue[Chat Me](https://wa.me/message/OEGQ4YVXBSFWL1). Follow me on [Twitter](https://twitter.com/Har4lionkest) for More...
Laravel sample of package by feature
Tags: php, laravel
Published: 2022-02-21 13:26:54

---
title: Laravel sample of package by feature
published: true
description: Sample Laravel app of package by feature
tags: php, laravel
//cover_image: https://direct_url_to_image.jpg
---

Hi, I am tyamahori.

Here is a my sample Laravel Application of `package by feature`.


https://github.com/tyamahori/laravel-template/tree/main/src/package/SomeSpecificApplication/CreateApp
Code Smell | Divergent change
Tags: codequality, refactorit
Published: 2022-02-21 13:21:30

Hello, today we are back with the code smells refactoring series and in this case we are going to talk about code smell called ``Divergent Change``, this smell can be detected when we observe that at a specific point in our application we perform too many changes, these points can be a certain class, a ``.js`` or ``.ts`` file that exports certain functions, etc

A small tip to be able to detect it easily is usually when conflicts occur repeatedly in a certain file, it is usually very likely that this file is complying with the code smell of ``Divergent change``, **WARNING: Take with caution not always will comply with this rule, you have to review the code before acting**


## Cause

- The module have many responsibilities
- The context of changes is not clear from day one but new changes are still being implemented in the application


```ts
class Hero {
  stamina: number;
  health: number;
  armorHealth: number;
  armorStatus: number;
  armorRarity: string;

  defense(): void {
   // ...
  }

  attack(): void {
   // ...
  }
}
```
___

## Solution

Split the class using ``Extract Class``:

```ts
class Hero {
  stamina: number;
  health: number;
  armor: Armor;

  attack(): void {
   // ...
  }
  
  defense(): void {
   // ...
  }
}

class Armor {
  health: number;
  status: number;
  rarity: string;
  
  getHealth(): number {
    // ...
  }
}
```

___

## Benefits

- Maintain adherence to the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single-responsibility_principle)
- More reliable and tolerant of changes
- Add semantics to the code

___

Thanks for reading me 😊

![thanks](https://media.giphy.com/media/cNZPX3T2ts2ibMWDeA/giphy.gif)
Limit User Registration to Specific Dates with Auth0 Actions
Tags: programming, webdev, security
Published: 2022-02-21 13:20:36

### With Auth0’s Actions, it’s easy to ensure that users can sign up for an account only between a specific start date and end date.

### <br>

Some applications have a limited lifetime. A website or app for limited-time events such as a conference, convention, or concert will only be useful when the event takes place. Since there’s no point in allowing people to sign up for an account after the event is over, you may want to limit registration to a specific set of dates.

It usually takes a considerable amount of work to limit the dates when new users could register an account. However, if you’re using Auth0 to authenticate your users, this task became a lot easier thanks to Actions!

Actions are a new feature that allows you to extend Auth0 beyond what it can do “out of the box”. They’re Node.js functions that you can add to various flows within Auth0’s processes, including logging in, changing passwords, and signing up for a new account. You write and store these functions in the Auth0 dashboard, where they’re part of your tenant’s settings, and Auth0’s servers execute them.

In this article’s exercise, you’ll learn how to write an Action that limits when users can sign up for an account for a specific application. If a user signs up for an account outside the defined valid registration period, their attempt to sign up will be canceled, and they will see a message explaining why.


## Prerequisites

You’ll need the following for this exercise:

- **Auth0 account:** Actions are an Auth0 feature, which means you need an Auth0 account to use them. <a href="https://auth0.com/signup" data-amp-replace="CLIENT_ID" data-amp-addparams="anonId=CLIENT_ID(cid-scope-cookie-fallback-name)">You can sign up for free,</a> and the process is pretty painless.
- **Any application that uses your Auth0 tenant to provide Universal Login.** Any web-based, mobile, or desktop application will do, just as long as it is one of your tenant’s applications. You’ll need it to log in and see how defining Actions changes how login works. If you don’t have any applications that use Auth0 for authentication, you can download one from the [Auth0 Quickstarts](https://auth0.com/docs/quickstarts/) page.

[Read more...](https://auth0.com/blog/limit-user-registration-to-specific-dates-with-auth0-actions/?utm_source=content_synd&utm_medium=sc&utm_campaign=actions)
PHP Type Hinting
Tags: php, typehinting, backend
Published: 2022-02-21 13:20:28

Type hinting are type declarations to function arguments, return values and class properties. PHP ensures the value is of the same type you declared or throws an TypeError. It isn't required but very useful to catch mistakes and helpful to others reading your code to understand what is up.

## Function arguments

To type hint our function argument message of our method error, we would add string just in front of our argument:

```
<?php

class Logger

{

    private $message;

    

    function alert(string $message)

    {

        return $this->message;

    }

}

$logger = new Logger;

$logger->alert('Wrong password');
```

This makes sure that whatever is passed to our method, `$message` is always a type of string or an error is thrown.

## Return values

This also works for our response. In this case we expect our method would return a string and so we add `: string` after our argument:

```
<?php

class Logger

{

    private $message;

    

    function alert($message): string

    {

        return $this->message;

    }

}

$logger = new Logger;

$logger->alert('Wrong password');

```

Whatever we would pass to our error method as arguments (string, integer, boolean, array etc.), our return should always be a type of string otherwise an error is thrown.

## Class properties

Besides methods we could also type hint our properties. In case of our message we add the annotation `@var string`:

```
class Logger

{

    /**

     * @var string

     */

    private $message;

    

    function alert($message)

    {

        return $this->message;

    }

}

$logger = new Logger;

$logger->alert('Wrong password');
```

This makes sure that whenever we call this property it should be a type of string or an error is thrown.

## All type hints together

If we would save logging  messages in our database and we would like to create getters and setters for our message, we could use all 3 types of type hinting as followed:

```
class Logger

{

    /**

     * @var string

     */

    private $message;

    

    function setMessage(string $message): void

    {

        $this->message = $message;

    }

    

    function getMessage(): string

    {

        return $this->message;

    }

}
```

I have type hinted the property `$message`, the argument as string and added the expected result of a string for the `getMessage()` method. For the `setMessage` method I added the expected result `void`. This means we do not expect anything for this method, this is because the setter would only set our property and doesn't return us anything.

## Type hinting methods

Some would also type hint their methods, similar to our property, but this isn't necessary because we already type hinted our property, argument and response.

Let me know what you think and share your knowledge on Type Hinting!
Tips to Hire Dedicated Kotlin Developer
Published: 2022-02-21 13:17:48

Kotlin is one of the most popular programming languages and most companies want to hire a Kotlin developer right now. Of course, that means that it's hard to find talent in the market. So, in order to hire a good Kotlin developer, your company needs to be prepared for a competitive recruitment process.

**So sharing with you some tips while hiring a dedicated kotlin developer**

- Kotlin has a lot of hidden features, so your developer must be aware of them
- Make sure the developer have experience with languages other than Kotlin like Java
- Look for candidates who also have experience in complete app development
- Analyze the candidates portfolio
- Understand the programming skills and experience with Java
- The developer must possess knowledge of android platform and other frameworks

The tips shared above will help you analyze the candidate better but the main question that arise here is how do you find the suitable and worthy kotlin developers?

**WebClues Infotech** is a web & mobile app development agency that provides services to hire a dedicated kotlin developer.

You just need to share your developer skills or project requirement and you will receive a list of suitable candidates based on your requirement. You can conduct interviews of the candidate you find suitable and select the best one to sign the agreement and start the work.  

I hope the tips help you in hiring a dedicated kotlin developer.
Das LearnPress WordPress-Plugin
Tags: wordpress, lms
Published: 2022-02-21 13:09:21

WordPress LMS (Learning Management System). Der Markt für WordPress LMS ist in den letzten Jahren explodiert. WordPress ist die beliebteste CMS-Plattform der Welt. WordPress LMS' sind extrem leistungsfähig und skalierbar. Aber sie sind auch sehr teuer. Der WordPress LMS-Markt wird von teuren, funktionsreichen Lösungen für Unternehmen dominiert.

WordPress ist so mächtig, dass die Möglichkeiten endlos sind - aber es ist furchtbar zeitaufwändig, herauszufinden, wie man das alles selbst einrichtet. Mit LearnPress kannst du deine WordPress-Website in weniger als fünf Minuten einrichten, und in weniger als fünf Minuten hast du einen voll [funktionsfähigen Online-Kurs](https://kursprofi.com/review/learnpress/).

Lernmanagementsysteme (LMS) wie Blackboard und Moodle sind leistungsstarke Werkzeuge, um dein Team zu informieren und zu motivieren, aber sie sind nicht sehr flexibel. Dein LMS steht oft im Mittelpunkt des Büros, deshalb müssen moderne Designregeln dafür sorgen, dass Lernportale ansprechend und mobilfreundlich sind.
VidToon is here! Drag and drop animation made easy... 
Tags: beginners, tutorial, career
Published: 2022-02-21 13:00:11

Wow! I just glimpsed a brand new animation tool that’s going to 
make your business (and life) a lot easier! 
It’s called VidToon and you can see it here:[Click here](https://tinyurl.com/5n7xea6s) 
With VidToon you can create animated videos easily. 
It’s as simple as: 
1. Drag and place your assets on the screen 
2. Make some simple edits
3. Export your video quickly 
And you’re done! 
That’s it. 
Best of all, it doesn’t matter what industry you’re in. VidToon can help you generate more of what you need such as leads, sales, and profits. 
And VidToon works for anyone. Including, but not limited to: 
● Digital Marketers 
● Affiliates 
● Ecommerce 
● Coaches 
● Social Media 
● YouTube Channels 
● Local Consultants 
● Bloggers 
It’s a proven fact that animated videos can help grow your business, but if we’re honest...they are also a pain in the butt to create. 
But not with VidToon. This software lets you create various animated videos in any niche quickly and easily. 
But don’t take my word for it. 
Head over now and see it in action for yourself on the page here: [Click here](https://tinyurl.com/5n7xea6s)
Quick Prototyping with Tailwind and DaisyUI
Tags: tailwindcss, daisyui, productivity, design
Published: 2022-02-21 12:57:51

For quick prototyping I use Tailwind and DaisyUI CDNs.
**Note:** The order of the CDNs.
```html
<link href="https://cdn.jsdelivr.net/npm/daisyui@1.25.4/dist/full.css" rel="stylesheet" type="text/css" />
<link href="./theme.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2/dist/tailwind.min.css" rel="stylesheet" type="text/css" />
```

---

To customize the default theme of DaisyUI, copy and paste the CSS variables into `theme.css`.
**Note:** The colors are in HSL format.
```css
/* theme.css */

:root {
  --p: 140 52% 55%;
  --pf: 120 100% 25%;
  --pc: 0 0% 100%;
  --s: 314 100% 47.1%;
  --sf: 314 100% 37.1%;
  --sc: 0 0% 100%;
  --a: 174 60% 51%;
  --af: 174 59.8% 41%;
  --ac: 0 0% 100%;
  --n: 219 14.1% 27.8%;
  --nf: 222 13.4% 19%;
  --nc: 0 0% 100%;
  --b1: 0 0% 100%;
  --b2: 210 20% 98%;
  --b3: 216 12.2% 83.9%;
  --bc: 215 27.9% 16.9%;
  --in: 207 89.8% 53.9%;
  --su: 174 100% 29%;
  --wa: 36 100% 50%;
  --er: 14 100% 57.1%;
  --border-color: var(--b3);
  --rounded-box: 1rem;
  --rounded-btn: 0.5rem;
  --rounded-badge: 1.9rem;
  --animation-btn: 0.25s;
  --animation-input: 0.2s;
  --btn-text-case: none;
  --btn-focus-scale: 0.95;
  --navbar-padding: 0.5rem;
  --border-btn: 1px;
  --tab-border: 1px;
  --tab-radius: 0.5rem;
}
```
**For Theming**
daisyUI comes with a number of themes, which you can use with no extra effort. Each theme defines a set of colors which will be used on all daisyUI elements. To use a theme, add data-theme attribute to your tag.
```html
<html data-theme="light"></html>
```
Introduction to Data Structures and Algorithms with Modern JavaScript
Published: 2022-02-21 12:54:07

In this article we will tackle the following:
i.	What are data structures and Types of Data Structures?
ii.	What is an Algorithm?

**Data Structures** 
Data structures allow you to manage data. They help us to store and organize the data primitives, so that they can be efficiently accessed and used in algorithms.
**a.	Arrays**
Arrays are ordered list of sequences of primitive data types, that are a special variable, which can hold more than one value. There are two object-oriented implementations of array-like objects: queue and stacks. In Array data duplicates are allowed, Size is adjusted dynamically, elements are accessed via index and are iterable (therefore, you can use the for loop)
 
**b.	Hashtable / map**
A hash table is a dictionary-like data structure, where keys are paired with values. Maps are great for rapid retrieval and modification of data since they store data for easy access. Maps have become nearly ubiquitous. They are Ordered key value with pairs of data, and one can access data via keys. Maps are iterable and keys can be anything (we can use reference values) 
**c.	Objects**
In objects we group data into one. The keys that are used in objects have to be numbers or strings. Keys are important because they’re unique while values are not .Objects have contracts that can store data .Objects can contain methods and functionalities and are not iterable
 
**d.	Sets**
Sets are unordered list of data, that doesn’t allow duplicates. In sets Insertion order is not stored, We access and extract data via method, iterable is allowed one ( can use the for loop)
 
**e.	Stacks**
A stack is an ordered list which follows LIFO (last in first out) algorithm. You can access the elements of a stack from only a single end.



**Algorithms**
An algorithm is a sequence of steps to solve a well-defined problem. A set of rules that precisely define a sequence of operations. We have different types of algorithms as stated below;
**i.	Binary Search**
This is a divide and conquer algorithm, that divides the array in half every time it checks whether an element of the array is the one, we're looking for.
**ii.	Big O notation**
This is a way of representing the general growth in the computational hardness of a task as you increase the data set. We have 5 types of Big O notation as stated below
•	O(1)
•	O(n)
•	O(n^2)
•	O(log n)
•	O(n!)

**iii.	Imperative code**
 This is when you tell your program every single step to achieve a specific outcome as per your expected output.
**iv.	Recursion**
This is a programming technique using function or algorithm that calls itself one or more times until a specified condition is met at which time the rest of each repetition is processed from the last one called to the first. Recursion involves solving problems by breaking things down into simpler/smaller versions of themselves
**v.	Tail recursion**
This is when, instead of doing an invocation of the recursive function as the return statement, it does a jump and reuses the same context of the prior recursive called.