teleren/devto huggingface dataset:
JavaScript check if property exists in Object
Tags: javascript, beginners, webdev
Published: 2022-07-05 06:29:27

You might need to determine if an object holds a particular property.

Let's say we have a user object. Optionally the email property can be set. If not, we want to show a form so the user can fill out their email.

How can we determine if this field exists?

```js
const userOne = {
  name: 'Chris Bongers',
  email: 'info@daily-dev-tips.com',
};

const userTwo = {
  name: 'John Do',
};
```

And to answer that, there are several ways of doing that. Let's take a look at the three most common ones.

## Using hasOwnProperty to see if an object has a property

By using `hasOwnProperty` we can evaluate if an object has `Own` property.

Let's see how it would work on our example data.

```js
console.log(userOne.hasOwnProperty('email'));
// Returns: true

console.log(userTwo.hasOwnProperty('email'));
// Returns: false
```

That is perfect. But there is a catch to using this method. It only works for `Own` properties, not extended object properties.

As you may know, objects come with the `toString` method, and if we try to check if that exists, it will return false. (While this does exist)

```js
console.log(userOne.toString());
// Returns: [object Object]

console.log(userOne.hasOwnProperty('toString'));
// Returns false
```

## Using in to see if an object has a property

Another more explicit way of checking if an object has a property is using `in`.

This one can check in own and inherited properties.

```js
console.log('email' in userOne);
// Returns: true

console.log('email' in userTwo);
// Returns: false

console.log('toString' in userOne);
// Returns: true
```

## Using undefined to see if an object has a property

The last method is to use an undefined check. This method will work for omitted properties but can cause you headaches if the property exists but has an undefined value.

```js
console.log(userOne.email !== undefined);
// Returns: true

console.log(userTwo.email !== undefined);
// Returns: false

console.log(userOne.toString !== undefined);
// Returns: true
```

Now let's see what happens in the following example:

```js
const userThree = {
  name: 'Steve Stevenson',
  email: undefined,
};

console.log(userThree.email !== undefined);
// Returns: false
```

The check is acceptable, but it's not what we might be looking for.

## Conclusion

When trying to find out if an object holds a particular property, we need to consider how safe we want to be.

I would generally not recommend using the `undefined` check.

If you only evaluate `Own` properties, the `hasOwnProperty` is a solid solution.

But you might want to be on the safe side and use the `in` check to determine if an object has a property.

### 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)
I created an entire dynamic website with NextJs on android!
Published: 2022-07-05 06:26:26

## Context

So before beginning let me give you some context.
I'm develop websites on android! You'll ask why, simply because I don't have pc :(
In my learning period I have found many ways to code a perfect website on android, from generating an NextJs or ReactJs project to creating a responsive design to a perfect code editor. I have found a way for all of this!

---

### Topic

Moving on to discussion, I recently finished working on a dynamic website for an eSports organization that is build using NextJs!

Many of you still won't belive it but ya this site is 100% responsive.

I'm looking forward to upload a blog on this topic, named "This is how I created a dynamic website on android"

---

### Your Feedback

I want to know your opinions. Will you like to know about my development process? Will you like to know ky secret to make websites responsive and test responsiveness on android? **Let me know in comments!**

---
College Degree System
Tags: career, college, programming, productivity
Published: 2022-07-05 06:12:42

When we consider about the college computer science degree system 90% of this study system is failed to teach about a specific technology, semester to semester the syllabus gets changed and we have to learn that before we completely understand about the previous technology. Understanding one thing to the core is more important than getting the basic of many things. So how can a student focus on one thing, even if we tried most of student will miss the other educational works .So how can we clear this situation...some of my thoughts are here.

1.Learning about a technology that matters.
   In my college semesters the C++ language was a important thing, it used in many semesters for practical lab exams. So early learning about this programing language can help you a lot in future semesters and it is also a very popular and power full language.
2.Picking up a good language to Master.
   It is so important to choose a technology and work on it consistently at least one hour in a day. It can improve your language familiarity and you can make a sense that how it all works. Python is a most picked language in college students who tries to enter this field.
3.Making connections with senior students who has experience in our field.
  Trying to connect with other students that have more knowledge than us can help with many situations and they can clear our doubts. And networking with the people have same mindset like us is always a good thing.
4.Connecting our future semester study's to the previous language that we choosed to master.
   It means that when we are studying about a new language in the next semester try to connect that language concepts to our previously choosed language. Doing like this can help us to understand the present concept faster and make a sense about this concept application in our main language. Most of the time main concepts are same in different languages.
5.Proving others that we know this language.
  When we understand about the language, then we have to show it to others that I can do things in with this programing language. Making some projects with that and helping others can make a overall mindset that he is good at this.

  I think all this can be done with self study with consistency, College can only provide some base knowledge about things(sometimes not).
What You Need To Know About Disaster Recovery Planning
Tags: cybersecurity
Published: 2022-07-05 05:58:46

[Natural disasters](https://www.uscybersecurity.net/disaster-recovery-planning/) have a way of wreaking havoc on Earth. However, is that the only disaster you need to remain cautious of? We have to deal with man-made disasters more regularly than the natural ones. The best way to damage someone’s business is with a well-planned cyber-attack. We all know that prevention is better than reaction, but sometimes these disasters catch us off-guard and ruin organizations overnight. To avoid feeling helpless after being struck by an unplanned, unfortunate, and devastating occurrence, it is essential to think ahead with Disaster Recovery Planning (DRP).

There should not be any limitation on security and disaster recovery solutions. After all, no one can risk thinking that they are too safe. However, the planning needs to be on a financially realistic level so that it helps keep the business afloat in the case of a disaster. There are a few things that you need to keep in mind to formulate successful disaster recovery solution. Any successful DPR must carry out a thorough Business Impact Analysis (BIA), along with a Risk Analysis (RA). These will help in determining which areas of the business need more protection. Additionally, they will help you establish an estimated Recovery Time Objective (RTO).
Find My IP Address
Tags: findipaddress, ipaddress
Published: 2022-07-05 05:51:50


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

[WPRefers](https://wprefers.com/) developed a tool that helps you to know about the current IP address of the device or internet you are using right now.
424. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-05 05:32:35

```
class Solution {
 public:
  int characterReplacement(string s, int k) {
    int ans = 0;
    int maxCount = 0;
    vector<int> count(128);

    for (int l = 0, r = 0; r < s.length(); ++r) {
      maxCount = max(maxCount, ++count[s[r]]);
      while (maxCount + k < r - l + 1)
        --count[s[l++]];
      ans = max(ans, r - l + 1);
    }

    return ans;
  }
};

```
438. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-05 05:31:35

```
class Solution {
 public:
  vector<int> findAnagrams(string s, string p) {
    vector<int> ans;
    vector<int> count(128);
    int required = p.length();

    for (const char c : p)
      ++count[c];

    for (int l = 0, r = 0; r < s.length(); ++r) {
      if (--count[s[r]] >= 0)
        --required;
      while (required == 0) {
        if (r - l + 1 == p.length())
          ans.push_back(l);
        if (++count[s[l++]] > 0)
          ++required;
      }
    }

    return ans;
  }
};

```
I wrote a gRPC GUI client with go
Tags: go, grpc, programming, github
Published: 2022-07-05 05:30:17

I would like to introduce you to a gRPC client tool([pgt](https://github.com/crossoverjie/ptg)) for your own use, it is used similarly to postman/[bloomrpc](https://github.com/bloomrpc/bloomrpc).


 
![introduce](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gkazfxvntuonjc7gj805.gif)

![introduce](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22gt5hvny4sw4o3fbow6.gif)
---

Not only that, it also supports http/gRPC cli benchmark testing.


![introduce](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktwpl6pfc4e00ag6pn48.gif)

For more functions usage and introduction. please refer to the project home page:
[https://github.com/crossoverjie/ptg](https://github.com/crossoverjie/ptg)


## Why create it?

There are several similar gRPC client like this:

- https://github.com/bloomrpc/bloomrpc: it is beautiful and powerful.
- https://github.com/fullstorydev/grpcui: it providers similar functionality based on browser and also has cli tools.


But they each have something I am not comfortable with:

- bloomrpc: it has the fatal disadvantage of not supporting int64, which can lead to loss of accuracy.
- grpcui: there is no downside to it, the main problem is that I am used to using the browser tab at work, which makes it less convenient to use it in the browser.

![bloomprc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymrxlyed4m74szuz0at2.png)

> So i wanted to make my own int64 compatible client tool to make my work more comfortable.



If you have a similar problem, I hope this can help you.
128. Leetcode Solution in JavaScript
Tags: javascript
Published: 2022-07-05 05:30:02

```
var longestConsecutive = function(nums) {
    // Handle base case of empty array
    if (!nums.length) return 0;

    // Give ability to look up nums by value
    const set = new Set(nums);
    let max = 0;

    for (const num of set) {
        // Make sure we are starting at the beginning of the sequenece
        if (set.has(num - 1)) continue;

        let currNum = num;
        let currMax = 1;

        // Look numbers that make a consecutive sequence
        while (set.has(currNum + 1)) {
          currNum++;
          currMax++;
        }
        // Update max
        max = Math.max(max, currMax);
    }

    return max;
};
```
Basic Understanding Of React Features
Tags: beginners, react, tutorial, webdev
Published: 2022-07-05 05:25:08

in this part we will see some react features, ReactJS is gaining quick popularity as the most popular JavaScript framework for web developers. It plays a crucial part in the front-end ecosystem. The most important characteristics that are available in ReactJS are as follows.

JSX
Components
One way data-binding
Virtual DOM
Simplicity
Performance
[read more](https://reactjsguru.com/basic-understanding-of-react-features/)
Apply Formatting to a Cell Range in the React Spreadsheet
Tags: react, webdev
Published: 2022-07-05 05:09:39

Learn how easy it is to apply formats to a cell range in the Syncfusion [React Spreadsheet](https://www.syncfusion.com/react-ui-components/react-spreadsheet) component. You will learn how to format numbers in a cell range and apply cell formatting options like font sizes. This video demonstrates the use of conditional formats with preset colors, data bars, color scales, and icons scales. 

**Product overview**: https://www.syncfusion.com/react-ui-components/react-spreadsheet

**Download an example from GitHub**: https://github.com/SyncfusionExamples/how-to-apply-formatting-to-a-cell-range-in-the-react-spreadsheet

{% youtube AyHLgzNq6_w %}
#3. Creating api endpoints and routes for different functionalities ☀
Tags: react, node, javascript, webdev
Published: 2022-07-05 05:02:12

## Today we see how to create api endpoints and add them to the router.

We try to keep everything structured and clean. It's a good practice to keep everything readable.

Now we have below 2 steps for today.

- Create api end points in the server file (server.js),

- Create route for the different api endpoints.

## Creating API endpoints
In the below code we created api endpoints  and add required file to it. Now it is important to know that `app.use()` is use to access any functionality or file written in any other folder.

```
const express = require('express')
const connectDB = require('./config/db');
const app = express();
connectDB();

const PORT = process.env.PORT || 5000;

//API endpoints
app.use('/api/auth', require('./routes/api/auth'));
app.use('/api/posts', require('./routes/api/posts'));
app.use('/api/profile', require('./routes/api/profile'));
app.use('/api/users', require('./routes/api/users'));


app.get('/', (req, res) => res.send('API Test'))
app.listen(PORT, () => {
    console.log(`Server is running at ${PORT}`)
})

```


## Creating route for api endpoints
Routes are nothing but different page of application having different component in it to work individually upon calling to their respective api.

Now create a folder name route within this folder create another folder name api  and then create all the files accordingly.
As you can see below I have files as [auth, users, profile and posts]. 

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

You can just copy paste the below code in all the files

```
const express = require('express')
const route = express.Router();

//@route GET api/users
//@desc  Test users
//@access public

route.get('/', (req, res) => res.send('Users route'));

module.exports = route;

```

You can check if APIs working or not on browser or use postman.
I am using postman and using port 5000.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qocoqjqg80pz0o5uz7id.png)
Using the new INumber type to generify math functions in .NET 7
Tags: dotnet, csharp, tutorial, programming
Published: 2022-07-05 04:58:12

.NET 7 is just around the corner and is already bringing a lot

Among those improvements, a small specific one is really elegant and may help you in writing methods that are dealing with numbers in a better way: the new `INumber<T>` interface.

## Setup 🧰

This feature is still in preview so, to try and run the following code you will need to create a new project using .NET 7 and enable the preview features.

The `.csproj` for my console app looks like this:

```xml
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <LangVersion>preview</LangVersion>
  </PropertyGroup>

</Project>
```

## Use case 🔎

Let's image that we are building a shopping app and we want to check out a cart. For now all prices TTC are round numbers so we wrote the following method to sum it all:

```csharp
int CartValue(int[] numbers)
{
    var result = 0;
    foreach (var i in numbers) result += i;
    return result;
}
```

We later use it in our logic to compute the value of our cart:

```csharp
var prices = new[] { 1, 2, 3 };
var sum = CartValue(prices);
```
And it works great !

## Until ...

It *worked* great but now we also have the shipment and other taxes that we must sum along with the price and our method no longer works:

```csharp
var pricesWithTaxes = new[] { 1, 2, 3, 1.5 };
var sumWithTaxes = CartValue(pricesWithTaxes);
// ^ This is not an int[] and won't compile
```

We may be tempted to rewrite the `CartValue` method to accept `double[]` instead of `int[]` and then cast all numbers to `double` to fix this issue, but we also noticed that .NET 7 is available and there is a brand new feature for this

## Introducing `INumber`

From now on, numbers are implementing the `INumber<T>` interface which exposes underlying math concepts such as the notion of zero, addition, one, etc. for numbers, regardless the type of `T`

In our case, it means that both `int` and `double` are `INumber` exposing the same concepts (although not the same values for those)

Let's rewrite our method to accept an array of any number:

```csharp
T CartValue<T>(T[] numbers)
    where T : INumber<T>  // <-- Don't forget the constraint!
{
    var result = T.Zero;
    foreach (var i in numbers) result += i;
    return result;
}
```

And just by using a generic to specify that the provided array is a number, our method is working great again and the previous code should now compile!

There are a lot more than just this interface in .NET 7 and I recommend you to check out the .NET 7 Preview blog that Microsoft has been writing about the next version of the framework

I hope that you learned something valuable, have a great day!
Data Structures 101: Introduction to Data Structures and Algorithms.
Published: 2022-07-05 04:56:38

## Definitions:
A **Data Structure** refers to a way of organizing so as to use it effectively.
The 'use' of this data is during processes such as when storing, retrieving or modifying it in a computer's memory.
The ideal requirement from a programmer during the design of any of these processes would be to use minimum space in memory while still maintaining minimum running time.
Therefore, the need for Data Structure can be summarized as follows:
- To allow for efficient management of huge amount of data
- To allow for fast sorting and searching data

## Types of Data Structure:
1. Primitive Data Structure
2. Adaptive Data Structure

The figure below shows the different classifications of data structures:

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


## 1. Primitive Data Structure
These refer to data structures such as integer, char, float and Boolean etc. that come built-in to programs.

## 2. Non-Primitive (Adaptive) Data Structure
These refer to more complex data structures that are built upon from primitive data structures.
Their formation is as a set of data elements that are either of the same data type (homogenous) or of different data type (heterogeneous).

These are further divided into:
 - **Linear Data Structure:** These emphasize on data that has been arranged in one dimension (i.e. sequentially) such as arrays, linked lists, stacks, queues.
 - **Non-Linear Data Structure:** These emphasize on data that has been arranged in multiple dimensions (i.e. hierarchically) such as trees, graphs, tables.

## Algorithms

An **Algorithm** refers to a set of instructions which are executed in order so as to perform a certain task.
Some of the various algorithms that are mainly performed on Data Structures include:-
	- **Traversing:** this refers to accessing a data element for processing
	- **Searching:** this refers to finding the location of one or more data items
	- **Inserting:** this refers to adding a new data element to a pre-existing collection of data elements
	- **Deleting:** this refers to removing a data element from a pre-existing collection of data elements
	- **Sorting:** this refers to arranging data elements in a certain order
	- **Merging:** this refers to combining two separate collection of data elements that have been sorted into one list of sorted data elements
Vue Js 3 - Single-File Component
Tags: vue, javascript, beginners
Published: 2022-07-05 04:18:59

Vue Single-File Components is a special file format that allows us to encapsulate the template, logic, and styling of a Vue component in a single file. 

Here's an example Single-File Component:

```
<script>
export default {
  data() {
    return {
      greeting: 'Hello World!'
    }
  }
}
</script>

<template>
  <p class="greeting">{{ greeting }}</p>
</template>

<style>
.greeting {
  color: red;
  font-weight: bold;
}
</style>
```

#Why Single-File Component

- Build modular components using familiar HTML, CSS and JavaScript syntax
- Collocation of intrinsically related problems
- Compiled templates
- CSS with component scope
- More ergonomic syntax when working with the Composition API
- Further optimization at compile time via cross parsing of templates and scripts
- IDE support with autocompletion and type checking for template expressions
- Ready to use Heat Module Replacement (HMR) support.

#How It Works
Vue SFC is a framework-specific file format and must be pre-compiled into standard JavaScript and CSS by @vue/compiler-Single-File Component. The compiled Single-File Component is a standard JavaScript (ES) module - meaning that with the proper build settings, you can import Single-File Component as a module:

```
import MyComponent from './MyComponent.vue'

export default {
  components: {
    MyComponent
  }
}
```

---

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

###Connect with us priteshbhoi18@gmail.com