teleren/devto huggingface dataset:
Top Mistakes To Avoid While Using React Native
Published: 2022-04-20 05:18:40

Not performing unit tests

Another typical error that [Reacts Native developers](https://www.stellardigital.in/react-native-app-development) makes while creating react native apps is failing to complete unit testing. Most developers overlook this step since they are accustomed to working without written unit tests. Moving on in the development process without a unit test in place, on the other hand, might be a hazardous move.

Addressing faults and difficulties at the last minute or after the product has been released can be a difficult undertaking. When a product with flaws is made available to the public, it produces a poor impression of both the product and the brand. The easiest method to avoid it is to test its functioning and guarantee that all components are fully functional before releasing the product. Unit testing is highly useful in this situation.

Unit tests enable developers to test individual units or components of an application to ensure that they are performing as planned. This is done during the development stage (code phase) to assist developers to save time and money in the long run.

Inside the render function, change the state
Data contains all of the information about the component that will be displayed on the state. It retrieves information from the store and shows it on the screen. React offers a method called set state () that accepts the new object state and compares it to the previous state. After that, add the new state to the old state and circulate the data.

This cycle will last a lifetime. When you directly alter the state, the life cycle is disrupted, and all prior states may be corrupted. The appliance may occasionally behave improperly or crash. When this happens, you’ll lose track of all states and may end yourself writing bespoke code instead of React. As a result, these solutions are possible if you directly alter the state. To avoid this disaster, you’ll construct a child component for the function’s content and send it down as a prop. By implementing the render function, we can make the value mutable.

Abstraction Layer Constraints
To provide the finest functionality, you must add an abstraction layer to the React Native framework, which you may do in the local stage. This layer, in and of itself, brings with it several recurring concerns – and you must take precautions to avoid them

Identifying the bugs you face in the abstraction layer. When you have bugs, it might lead to a slew of problems.
Reliance on third-party libraries and services is high.
Reliance on the execution of bespoke designs
React Native App Development Company
You read that heading right. Stellar Digital operates as a [React Native App Development Company](https://www.stellardigital.in/react-native-app-development) with a team of highly qualified developers that are experts in their field. They can guarantee that their React Native development services will provide your company the boost and reach it needs. As a result, stop waiting and start building your React Native application with Stellar’s experts.
Which articles are you missing?
Tags: watercooler
Published: 2022-04-20 05:15:32

I'm writing this article, especially for you.

The loyal reader, the person who is planning to grow by learning.
The person who is a close replica of how I learn and grow.

What kind of articles are you missing?
I'd love to get some insights into what could help you become even better?

## Ideas and suggestions

So far, I have a couple of topics with various audiences.

- CSS fun things (Much like the [CSS logos series](https://daily-dev-tips.com/tags/css-logos/))
- JavaScript functions explaining one specific function
- Projects that we build from start to finish
- Offtopic chats
- Deeper specific topics

You might favor one of these approaches, or something completely different, like "react" articles.

I hope to receive your opinion on which articles and what kind of article type works best for you.

## How to provide this feedback

You can either send me a message on Twitter (public or DM) or respond to my email (info@daily-dev-tips.com).

Let me know what has been the best help/topic/article so far for you in a couple of words.

And let's work together on making you become 10x better than that.

### 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)
Longest Consecutive Sequence
Tags: leetcode, array, blind75
Published: 2022-04-20 04:45:40

---
title: Longest Consecutive Sequence
published: true
description: 
tags: leetcode, array, blind75
//cover_image: https://direct_url_to_image.jpg
---
###
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

You must write an algorithm that runs in O(n) time.


```
Input: nums = [100,4,200,1,3,2]
Output: 4
Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
```
---

```javascript
var longestConsecutive = function (nums) {
    let num_set = new Set(nums);
    let longestStreak = 0;
    for (let num of nums) {
        if (!num_set.has(num - 1)) {
            let currentNum = num;
            let currentStreak = 1;
            while (num_set.has(currentNum + 1)) {
                currentNum += 1;
                currentStreak += 1;
            }
            longestStreak = Math.max(longestStreak, currentStreak);
        }
    }
    return longestStreak;
}
```
*Time Complexity* : O(n)
Memoization decorator in python
Tags: python, programming, beginners
Published: 2022-04-20 04:03:33

In the previous articles on the [Python decorator series](https://sureshdsk.dev/series/python-decorators), we have learnt decorators, how they work and to implement a simple function based decorator and a class based decorator and decorator that supports parameters. In this article, we will create a simple memoization decorator function that caches result.

Memoization is an optimisation technique used to speed up programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.

## Factorial of a number
Let's create a function that calculates factorial of a number in a recursive way. 

```python

def factorial(n):
    if n == 1:
        return n
    else:
        return n * factorial(n - 1)


if __name__ == '__main__':
    print(factorial(20))
    print(factorial(10))
    print(factorial(15))
    print(factorial(5))

```
Output
```
2432902008176640000
3628800
1307674368000
120
```

Since factorial of a given number is always same(idempotent), We can optimize this function by caching results for the given value. Let's create the decorator function,

```python
from functools import wraps


def memoize(func):
    cache = {}

    @wraps(func)
    def wrapper(*args, **kwargs):
        if args not in cache:
            print(f"Calling for {func.__name__}({args})")
            cache[args] = func(*args, **kwargs)
        else:
            print(f"Using cached result for {func.__name__}({args})")
        return cache[args]

    return wrapper


@memoize
def factorial(n):
    if n == 1:
        return n
    else:
        return n * factorial(n - 1)


if __name__ == '__main__':
    print(factorial(20))
    print(factorial(10))
    print(factorial(15))
    print(factorial(5))

```

Output
```
Calling for factorial((20,))
Calling for factorial((19,))
Calling for factorial((18,))
Calling for factorial((17,))
Calling for factorial((16,))
Calling for factorial((15,))
Calling for factorial((14,))
Calling for factorial((13,))
Calling for factorial((12,))
Calling for factorial((11,))
Calling for factorial((10,))
Calling for factorial((9,))
Calling for factorial((8,))
Calling for factorial((7,))
Calling for factorial((6,))
Calling for factorial((5,))
Calling for factorial((4,))
Calling for factorial((3,))
Calling for factorial((2,))
Calling for factorial((1,))
2432902008176640000
Using cached result for factorial((10,))
3628800
Using cached result for factorial((15,))
1307674368000
Using cached result for factorial((5,))
120
```

From the output, we can see that for computing the factorial of 10, 15 and 5, we used cached result. 

In the next article, we will implement various kinds decorator recipes. Stay tuned for upcoming articles. Subscribe to the newsletter and Connect with me on [twitter](https://twitter.com/sureshdsk) to get my future articles.
Is it possible to create a commit with a different date?
Tags: git, webdev, tutorial, github
Published: 2022-04-20 04:02:32

**This a first short tutorial from a Git Tricks series**.

Sometimes, you might run into a situation where you need to create a commit with a different date than the current one. Luckily, you can handle this using following timestamp in git
 

- `GIT_AUTHOR_DATE`
- `GIT_COMMITTER_DATE`

you might be now you're wondering what's actually the difference between `Author` and `Committer`

#### Let's Understanding dates in Git: author date vs. committer date & ‘approxidate
&nbsp;

> The author is the person who originally wrote the work, whereas the committer is the person who last applied the work.

&nbsp;

So if, for instance, you send in a patch to a project, the author date will be when you made the original commit but the committer date will be when the patch was applied. Another common scenario is rebasing: rebasing will alter the commit date, but not the author date.


#### The Command
<code>
GIT_AUTHOR_DATE='Mon May 18 19:32:11 2022 -0400' \
  GIT_COMMITTER_DATE='Mon May 18 19:32:11 2022 -0400'\
  git commit -m 'Commit from the past'
</code>

As shown in the example above, you can set both values to any date you like and your code will be committed on that date.

**Note**
you can also use other formats

#### Date formats
RFC `2822 Mon, 18 May 2022 19:32:11 -0400`
ISO `8601 2022-05-18 19:32:11 -0400`
local `Mon May 18 19:32:11 2022`
short `2022-05-18`
relative `5.seconds.ago`, `2.years.3.months.ago`, `6am yesterday`

Let’s connect on [LinkedIn](https://www.linkedin.com/in/abdlrahmansaber/), [Twitter](https://twitter.com/Abdlrahmansabe4)
Javascript Binary Tree data structure
Tags: javascript, binarytree, datastructure, programming
Published: 2022-04-20 04:01:09

**Binary Tree:**
A binary tree is a data structure consisting of a set of linked nodes that represent a hierarchical tree structure. Each node is linked to others via parent child relationship.
Any given node can have at most two children(left&right).

**Internal structure of binary tree:**

```
class Node {
    constructor(data, left = null, right = null) {
        this.data = data;
        this.left = left;
        this.right = right;
    }
}

class BST {
    constructor() {
        this.root = null;
    }
    add(data) {
        const node = this.root;
        if (node == null) {
            this.root = new Node(data);
        } else {
            const searchTree = function(data) {
                if (data < node.data) {
                    if (node.left == null) {
                        node.left = new Node(data);
                        return;
                    } else if (node.left != null) {
                        return searchTree(node.left)
                    }
                } else if (data > node.data) {
                    if (node.right == null) {
                        node.right = new Node(data)
                        return;
                    } else if (node.right != null) {
                        return searchTree(node.right)
                    }
                } else {
                    return null;
                }
            }
            return searchTree(data)
        }
    }
    findMax() {
        let current = this.root;
        while (current.right != null) {
            current = current.right;
        }
        return current.data;
    }
    findMin() {
        let current = this.root;
        while (current.left != null) {
            current = current.left
        }
        return current.data;
    }
    find(data) {
        let current = this.root;
        while (current.data != null) {
            if (data < current.data) {
                current = current.left;
            } else {
                current = current.right;
            }
            if (current == null) {
                return null;
            }
        }
        return current;
    }
    isPresent(data) {
        let current = this.root;
        while (current) {
            if (data == current.data) {
                return true
            }
            if (data < current.data) {
                current = current.left;
            } else {
                current = current.right;
            }
        }
        return false;
    }
}

const bst = new BST();
bst.add(1);
bst.add(2);
bst.add(3);
console.log(bst.findMin());
console.log(bst.findMax());
console.log(bst.find(1));
console.log(bst.isPresent(1));
```
> _Any comments or suggestions are welcome._
Laravel orderBy, groupBy and limit Example
Tags: laravel, mysql, orderby, groupby
Published: 2022-04-20 03:05:47

In this artical we will see laravel orderBy, groupBy, and limit example, in this laravel orderBy, groupBy and limit example we will see different types of laravel 8 query example.

The orderBy method allows you to sort the results of the query by a given column. The first argument accepted by the orderBy method should be the column you wish to sort by, while the second argument determines the direction of the sort and may be either asc or desc

orderBy()

Laravel Example :

```
​$users = DB::table('users')
         ->orderBy('name', 'desc')
         ->get();
```

SQL Query:

```
select * from `users` order by `name` desc;
```

Output :

All users name will be sort by descending order.

groupBy()

The groupBy and having methods may be used to group the query results. The having method's signature is similar to that of the where method.

```
$users = DB::table('users')
         ->groupBy('account_id')
         ->having('account_id', '>', 100)
         ->get();
```
 
limit()

limit method is used to limit the number of results returned from the query.

```
$users = DB::table('users')
         ->limit(5)
         ->get();
```
 
---

You might also like :

- **_[Read Also: Laravel whereMonth and whereYear Example](https://techsolutionstuff.com/post/laravel-wheremonth-and-whereyear-example)_**

- **_[Read Also: Laravel 8 Google Recaptcha Example](https://techsolutionstuff.com/post/laravel-8-google-recaptcha-example)_**

- **_[Read Also: How To Generate Barcode In Laravel](https://techsolutionstuff.com/post/how-to-generate-barcode-in-laravel)_**
Encode and Decode Strings
Tags: strings, leetcode, blind75
Published: 2022-04-20 02:54:56

---
title: Encode and Decode Strings
published: true
description: 
tags: strings, leetcode, blind75
//cover_image: https://direct_url_to_image.jpg
---

###
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.

---

```javascript
var encode = function (strs) {
    let res = '';
    for (let char of strs) {
        res += (char.length).toString() + `#` + char;
    }
    return res;
}

var decode = function (s) {
    let res = [];
    for (let i = 0; i < s.length; i++) {
        let j = i;
        while (s[j] != '#') {
            j++;
        }
        let wordLength = parseInt(s.substring(i, j));
        res.push(s.substring(j + 1, j + 1 + wordLength));
        i = j + wordLength;
    }
    return res;
}
```
*Time Complexity* : O(n)
A small alternative of fingerprint.js, Broprint.js
Tags: news, npm, javascript, react
Published: 2022-04-20 02:34:37

Greetings developers ☕.

I have published a browser fingerprinting library to NPM. It's written in typescript. A user can uniquely identify a browser by generating the device id with this library.

> Broprint.js is the world's easiest, smallest and powerful visitor identifier for browsers.`(too much to handle 😅)`

This library usages `canvas` and `audio` fingerprint techniques. We are already using it in production for a small userbase and It works great.
Below is the GitHub link of [Broprint.js](https://broprintjs.netlify.app/).

`Repo is broken`

This library really needs contributions of the developer community, myself being a beginner in opensource don't know much about things.

Your contributions are more than welcome to this repo, also what you can do is give star or fork this repo your contributions will be shown at the bottom. `(I just learned this luring strategy few days earlier from dev.to itself 🤪)`

![broprint.js forkers and stargazers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qc7vcty96xnj9s8syfa7.png)
  

Live Demo of this project -  [Broprint.js](https://browserfingerprint.netlify.app/)

Thank you for reading and have a great day ahead ✌.
Equality Array(Data Structure tips in C#)
Published: 2022-04-20 02:33:33


Hello guys, today I want to focus on Array, actually, I hope you know about array and in this article, I try to a bit deeper into it. so let's go…
I start with a sample:

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

define 2 DateTime array
I have defined exactly 2 DateTime arrays like each other, just the names are different.
What do you think? are they equal to each other?

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

As you see, when using the ‘==’ operator for 2 arrays, however, each item is exactly like the other, the result is false!
I hope you remember Value-type and Reference-type.

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

When I define a value-Type like DateTime, each variable is put in memory like the above picture so “mydate!=yourdate”.Now let’s look at how Reference-Types are stored

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

Reference-Type means the variable doesn't actually contain the string ”Shayan” and stores the address of memory where store the variable(xx).
However DataTime is Value-Type,DataType[] is Referencetype because ,Array is Reference-Type

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59ic2wy6czl9o4pwc7mb.jpeg)

Therefore when defining 2 Arrays with the same values, they are located at different addresses, and bankHols1==bankHols2 is false **(why???)**
Because the “==” operator for ReferenceType check Addresses and addresses are different.
this rule is ok for all Reference-Type collections in c#, But be careful about “String”.
The string is reference type but Microsoft overrides the”==” operator for it so when using the “==” operator for 2 string that is the same as each other the result is true.

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

Now the question is: **how can compare just the value of 2 arrays?**
Microsoft introduces the **SequenceEqual()** extension method (in the LinQ)

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

But be careful when using SequenceEqual(), it is too expensive because comparing each pair of elements if it is a bit large could be a lot of operations.
NODE JS Programming
Tags: node, javascript, programming
Published: 2022-04-20 02:11:45

**Introduction**
 
Node JS is a JavaScript runtime built on Chrome's V8 Javascript Engine.

Node JS is an asynchronous event-driven JavaScript runtime, it is used to develop scalable networks and dynamic web applications.

NODE JS consists of a lot of inbuilt and third-party modules which are invoked in the application to be developed. We can also create our modules in NODE JS.

It is an open-source server environment.

It supports various platforms including Windows, Linux, and macOS.

Node.js = Runtime Environment + JavaScript Library

We know that when a user requests something from a server, the server needs to send the response to the client and many programming languages and platforms have different methods of handling the requests and responses in a different manner. Here is how PHP and NODE JS handle the request-response.
 

**Features**
 
Asynchronous and Event-driven Environment:

A NODE JS program or the API runs asynchronously which makes the application boost and it never waits for another program in order to execute the current task.

Dynamic:

Node JS is dynamic and flexible with its wide variety of packages offered with NPM

Speed:

Applications built on NODE JS are very scalable in real-time and are speedy due to NODE JS's non-blocking nature.

To know more about the comparison and useful links visit the below link.

[https://fsh.org.in/blog-details/Programming/NODE+JS/13](https://fsh.org.in/blog-details/Programming/NODE+JS/13)
Dart Operators — Dart Programming — Part 4
Tags: beginners, flutter, dart, mobile
Published: 2022-04-20 02:06:31

Hello guys. From now on i'll move into Medium to write blog but still want to share for another channel. So i'll up-to-date my blog in here. You guys can check my lastest about [Dart Operator](https://hoangnguyen0403.medium.com/dart-operators-dart-programming-part-4-f304d941c541) in Medium
Accessing Route Helpers from Rails Console
Tags: rails
Published: 2022-04-20 02:05:14


![Accessing Routes from Rails Console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/625fbxn86eku4cuqk1x3.png)

In Rails, routes map an incoming URL to a controller action. When you define a route for your application, you also get path and URL helpers to build relative or absolute URLs from the route's name. For example, suppose that you have a `users` resource in your `config/routes.rb`:

```ruby
resources :posts
```

This route creates the method `posts_path` that you can use in the view. For simple routes, you can probably guess the output of the helper, e.g., the `posts_path` helper will return the URL `/posts`. For complex routes, especially nested ones, it can be hard to figure out the URL until you use the helper to render the view. 

This post shows a simple way to check the output of URL and path helpers directly from the Rails console. We will also see how to access these helpers in your models.  

<!--more-->

Here's a typical route file with a single route.  

```ruby
# routes.rb

Rails.application.routes.draw do

  get '/posts/:id/preview', to: 'posts#preview', as: "preview_post"

end
```

This route maps the URL `posts/:id/preview` to `PostsController#preview` action. Additionally, we have named the route `preview_post` using the `as` option. Hence, Rails will automatically generate `preview_post_path` and `preview_post_url` helpers for us. 

To see the routes in your application, you can run the `rails routes` command. 

```bash
> bin/rails routes -g preview

Prefix Verb URI     Pattern                  Controller#Action
preview_post GET  /posts/:id/preview(.:format) posts#preview
```

However, this doesn't tell you what URL the route will generate for you. For that, you can call the helper methods on the `app` object, which represents your application. Rails adds all the helpers to the `app` object when it boots. Hence you can check the output of any named route helper in the console, which is pretty handy during development.  

```ruby
irb(main):018:0> post = Post.first

irb(main):019:0> app.preview_post_path(post)
=> "/posts/5/preview"
```
---

### Accessing Helpers from Models

By default, the helper methods are accessible from your controllers, views, and mailers. If you need to access the auto-generated helper methods from other places (such as a model), then you can do that by including `Rails.application.routes.url_helpers` in your class:

```ruby
class Post < ActiveRecord::Base
  include Rails.application.routes.url_helpers

  def link
    post_path(self)
  end
end

Post.find(1).link # => "/posts/1"
```


I hope that helps.