teleren/devto huggingface dataset:
JavaScript check if array contains a value
Tags: javascript, beginners
Published: 2022-01-27 09:16:32

Let's sketch the use case. We have some roles that can access a particular page.
So only people with that specific role should be able to continue.

These valid roles are defined in an array.

```js
const roles = ['moderator', 'administrator', 'superman'];
```

How can we check to see if a user's role is part of this list?

For the sake of this article, we'll assume the user's role is a simple string like so:

```js
const role = 'user';
```

There are a couple of options for us here. Let's take a look at each of them.

## JavaScript includes

This might be my personal most used option. It's quick and straightforward and has no weird overhead.

This [`includes` method](https://daily-dev-tips.com/posts/vanilla-javascript-string-includes/) will return true or false if it can find the string you are looking for.

```js
roles.includes('user');
// false

roles.includes('moderator');
// true
```

## JavaScript indexOf

We can also use indexOf, which will return `-1` if it can't find the item or the actual index if it does.

```js
roles.indexOf('user');
// -1

roles.indexOf('superman');
// 2
```

This could be super helpful if you need the item's index anyway, but I think `includes` should work better for you if you don't.

## JavaScript some

Another way of doing this is using the [`some` method](https://daily-dev-tips.com/posts/javascript-some-method/), this will return a boolean like the `includes` method.

It will return if some of the items in the array match the search query.

```js
roles.some((role) => role === 'user');
// false

roles.some((role) => role === 'moderator');
// true
```

Again, depending on the use-case, this could be the better solution, mainly good if you would have to check for multiple things to match.

## JavaScript find

The [`find` method](https://daily-dev-tips.com/posts/javascript-find-function/) is a new way of searching an array, and it will return undefined or the item.

```js
roles.find((role) => role === 'user');
// undefined

roles.find((role) => role === 'moderator');
// 'moderator'
```

This method is perfect if you need the entire object to do something with.
Imagine the roles being an object, and we want to use another property of this object.

And there you go, multiple ways of checking if an array contains a value.

You can try all of these out in the following CodePen (Note: Open your terminal)

{% codepen https://codepen.io/rebelchris/pen/ExwJjgr %}

### 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)
How to hire the right iOS app developer
Published: 2022-01-27 09:16:12

If you plan to gain significant revenue satisfying wealthier smartphone users, opt for iOS and look for appropriate app developers for hire.

**Steps to [hire a dedicated iOS app developer](https://www.webcluesinfotech.com/hire-ios-app-developer/)**
1. Decide on the project requirements 
2. Share the requirements with the agency that offers dedicated iOS developers for hire 
3. Get a call & communicate the final developer's skills requirements with the representative 
4. Get a shortlisted developers list suitable as per your requirement 
5. Conduct an interview of the candidates 
6. Finalize the developer based on the interview performance or ask for more candidate resumes if you are not satisfied with the developer 
7. Sign the contract mentioning cost structure, approx time duration of the project, working hours, and other necessary terms & conditions. 

**WebClues Infotech** is a mobile app development company. One can hire their dedicated iOS developers for their technical requirements. While hiring iOS developers, you can choose the hiring model at your discretion. This helps to maximize productivity and achieve greater results quickly. Their developers assist customers throughout the lifecycle of the product development.  

Just drop them your details and their team will get back to you within business hours. Contact them now to discuss further.
Best Python Projects That You Can Finish In A Min!
Tags: python, beginners, simple
Published: 2022-01-27 09:16:11

1. _Take A Break Reminder App_
   **Codes**:
```
import time
   from plyer import notificationif __name__ ==    "__main__":
   while True:
        notification.notify(
            title = "ALERT!!!",
            message = "Take a break! It has been an hour!\nCode By @rohithaditya ",
            timeout = 10
        )
        time.sleep(3600)
```
2. Quadratic Equation Solver:
```
import math
print('Welcome!...)

a = input("Enter the first number a: ")
b = input("Enter the second number b: ")
c = input("Enter the third number c: ")
y = int(b) * int(b) - 4 *int(a)*int(c)
if y == 0:
    e = - int(b)/2*int(a)
    print()
    print("The result: ",e)
elif y >= 0:
    rt = (-int(b) - math.sqrt(D))/2*int(a)
    rt2= (-int(b) + math.sqrt(D))/2*int(a)
    print("The first result: ", rt)
    print("The second result: ", rt2)
else:
    print("The equation has no solution!")
print("I'm glad my help touched")
print("This Program Done By @rohithaditya ")
```

3. Hello World Program
```
print('Hello World\nAnd Bye!')
```
No need for web fonts - give the browser a break!
Tags: nextjs, react, javascript, performance
Published: 2022-01-27 09:15:51

Are you using a snippet provided by Google Fonts to load fonts for your web application?

What if I told you that the cool kid on the block ([Vercel](https://vercel.com/)) has some performance gains for you?

- Quicker page load
- Reduced network requests
- Version locked fonts
- Offline support 

You can take advantage of these gains by using a library they've provided called [Fontsource](https://fontsource.org).

It's a monorepo full of open source fonts which are version locked (unlike google Fonts, who can update a font at any given time), allowing you to manage your fonts like any other project dependency.

By using Fontsource you're also giving the browser a break and skipping a render-blocking request as your fonts will be hosted right there in your production code. No need to go and get the css file and then download the fonts. Check out some of the performance benchmarks [here](https://github.com/HTTPArchive/almanac.httparchive.org/pull/607) 🔥

Google also performs some tracking on their fonts, so sticking with a Google web font ties you into being tracked without warning.

Fontsource doesn't just support Google Fonts either, they have an evolving set of open source fonts too!

Using Fontsource also allows your fonts to work offline which is great for PWAs and also working locally, as your fonts are available without the need for fetching.

Here's an example of how to get started in a NextJS project using the Google Font, Inter.

```
yarn add @fontsource/inter
```

Then all we need to do is import it wherever we want to use it. In this example I want it available globally in my app, so I'm importing it in my `_app.tsx`.

```javascript
import "@fontsource/inter";
```

Fontsource also allows you to select weights and even styles, allowing you to trim the payload!

```javascript
import "@fontsource/inter/700.css";
import "@fontsource/inter/700-italic.css"
```

The font can then be referenced anywhere in your application using a CSS stylesheet, CSS Module, or CSS-in-JS.

```css
body {
  font-family: "Inter", sans-serif;
}
```

Give Fontsource a go, it makes life so much easier when dealing with fonts!
Eating The Frog
Tags: discuss, personal, improvement, growth
Published: 2022-01-27 09:13:23

---
title: Eating The Frog
published: true
description: If you eat the frog in the morning, probably nothing worse will happen for the remainder of the day.
tags: discuss, personal, improvement, growth
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8n83gh4ayy93a24ogqd.jpg
---

_Originally published on [my blog](https://www.nikola-breznjak.com/blog/daily-thoughts/eating-the-frog/)._

> Brian Tracy popularized the term "Eat that Frog". What that means is that if you want to truly move the needle day in day out, you should start your day by tackling the hardest thing on your to-do list (and, I hope you do have [to-do lists](https://www.nikola-breznjak.com/blog/daily-thoughts/to-do-lists/) in the first place).

---

This is [why I write](https://www.nikola-breznjak.com/blog/daily-thoughts/why-do-i-write-these-daily-thoughts-posts/) these 'daily thoughts' posts.
React 18 setTransition
Tags: react, javascript
Published: 2022-01-27 09:06:47

## startTransition

[React 18](https://reactjs.org/blog/2021/12/17/react-conf-2021-recap.html) introduces a new concurrent feature called [startTransition](https://github.com/reactwg/react-18/discussions/41) which aims to solve problems we tried to solve using [debounce and throttle](https://css-tricks.com/debouncing-throttling-explained-examples/), and much more.

This [thread](https://github.com/reactwg/react-18/discussions/65) gives a deep dive example of how it solves the problem of UI responsiveness when there is expensive computation taking place.

Before React 18, we tend to use debounce (or throttle depending on the situation) to schedule this compute intensive task at a given time *T* so that the UI feels more responsive to other events. But every time the task will start after *T* has elapsed, even if it takes less time than *T*. And the task will still occur as a whole chunk, blocking the thread during this time. 

This is where startTransition API brings a new approach to deal with these problems.
It can:
- split tasks into small chunks and be smart enough to let the browser process incoming events (mouse events for example) -> **yielding**
- manage an urgent update in priority skipping pending ones -> **interrupting**
- update using new state by disposing of unfinished task with stale state -> **skipping old results**

Check my [personal blog](https://nextjs-blog-pfongkye.vercel.app/) for more articles.
Day 19 of 100 - Java: the good parts book read
Published: 2022-01-27 09:02:36

Read Java: The Good Parts

## The type system

A pragmatic combination of features that provide an excellent tool.

1. Interface is a way of building units of meaning that can be shared, extended, and explained
2. An object is actually an instance of many types
3. Every object in a Java program is an instance of a class.
4. Only classes can be directly instantiated
5. Interfaces play into the far more important use of the type system, which is to allow compile time checking of the arguments and return values passed to and returned from methods.

Single inheritance example,

```diff
public interface GraphicsObject{
 Point getOrigin();
 void setOrigin(Point newOrigin);
+ boolean draw(Point drawOrigin);
 ...
 }

public interface Cowboy {
 boolean ride(Horse toRide);
 boolean rope(Cow toRope);
+ boolean draw(Point toShoot);
 ...
}


public class GraphicalCowboy implements GraphicsObject, Cowboy {
...
}
```

Since both the interfaces have `draw()` signature we cannot have two difference implementations for the `draw()` method.
How to Create a Custom Error Class in Javascript
Tags: beginners, javascript, node
Published: 2022-01-27 09:00:09

---
title: How to Create a Custom Error Class in Javascript
published: true
date: 2022-01-27 09:00:09 UTC
tags: [ beginners, javascript, node ]
canonical_url: https://thomasstep.com/blog/how-to-create-a-custom-error-class-in-javascript
---

This is going to be short and sweet.

```javascript
class MyError extends Error {
  constructor(message) {
    super(message);

    this.name = 'MyError';
  }
}

module.exports = {
  MyError,
};
```

You can throw the error like so.

```javascript
const { MyError } = require('./errors');

try {
  throw new MyError('This is my error that threw.');
} catch (err) {
  if (err instanceof MyError) {
    console.error('Instance of MyError found.');
  }

  console.error(err);
}
```
About Of Shortcode Technologies
Tags: shortcodetechnologies, webdesign, mobileapp
Published: 2022-01-27 08:47:42

[Shortcode Technologies](https://shortcode.tech/), primarily based in the US and having offices in Canada & India is an Innovative Software solutions company that caters to businesses of varied sizes. We have built products for our clients using Angular, NodeJs, Salesforce, Java, and AWS. These applications are currently being used by users across the US. Shortcode Tech provides Web & Mobile Apps, Websites, DevOps, Digital Marketing – USA | CANADA | INDIA. If you are looking for the best [web development company in Canada](https://shortcode.tech/), you can visit the site to contact them.

We build custom web applications, mobile apps, and develop conversion focussed websites for businesses to build a strong online presence. We help companies and well-established businesses elevate their brand value & their digital marketing strategies with our shrewd yet economical solutions. We worked with clients from major countries like the USA, Canada, Australia, and India.
VSCode: Awesome Multi-cursors/selection Tricks
Tags: vscode, tutorial
Published: 2022-01-27 08:40:05

Hey **fellow creators**

Learn some *multi-cursors* and selection tricks that you can use in VSCode!
 
If you prefer to watch the video **version**, it's right here :

{%youtube MlsMVaItPKA%}

&nbsp;
##1. [ctrl + alt + arrow down|up].

It will simply create some multi-cursors below or above your line.

If you want to exit the multi-cursor, press escape.

&nbsp;
##2. [pushed mouse wheel + go down|up].

It will create some multi-cursors too, it's a bit faster than the one above.

&nbsp;
##3. [ctrl + d].
*[ctrl + d]* will help you find some occurrences. For example, if you want to change several divs into paragraphs, pressing *[ctrl + d]* after highliting one will allow you to do that faster!

&nbsp;
##4. [ctrl + shift + l].
You can also find all occurrences at once after highliting something with *[ctrl + shift + l]*. For example, this will select all the divs!

&nbsp;
##5. [alt + click].
Finally, you can use *[alt + click]* to place a new cursor wherever you want.

&nbsp;
Come and take a look at my **Youtube channel**: https://www.youtube.com/c/TheWebSchool

*See you soon!*

Enzo.
Front-end developers: Do you use manual testing tools as part of your coding process?
Tags: testing, frontend, browserstack, qa
Published: 2022-01-27 08:38:31

---
title: Front-end developers: Do you use manual testing tools as part of your coding process?
published: true
description: Do you perform a manual test before finishing a feature or leave it to tests / QA?
tags: testing, frontend, browserstack, qa
cover_image: https://images.unsplash.com/photo-1541506618330-7c369fc759b5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=765&q=80
---

I recently moved companies, from a startup to a larger, more corporate organisation with a separate QA department.

I was questioned when I requested a Browserstack license: "What would you do with that? Browserstack licenses are for QA." I've always included a manual testing step in my coding process, am I unusual?
#26 - Pillars CodeWars Kata (8 kyu)
Tags: javascript, webdev, tutorial, 100daysofcode
Published: 2022-01-27 08:38:06

##Instructions

There are pillars near the road. The distance between the pillars is the same and the width of the pillars is the same. Your function accepts three arguments:

number of pillars (≥ 1);
distance between pillars (10 - 30 meters);
width of the pillar (10 - 50 centimeters).
Calculate the distance between the first and the last pillar in centimeters (without the width of the first and last pillar).

---

##My solution:

```javascript
function pillars(num_pill, dist, width) {
  return num_pill == 1  ? 0 : ((num_pill-2)*width) + ((100*dist)*(num_pill-1)) 
}
```
---

##Explanation
I just used a ternary conditional that checked if the number of pilars is 1, it'll return 0, else, It'll multiply the number of pilars minus 2, by the width, so I can get the length of all the pilars except for the first and the last one, and then I'll sum the distance by 100 so I can get it in centimeters and the result of this by the number of pilars minus one, because to get the sum of the lengths between two pillars I have to rest one, beacuse they are ordered like this:

> | -- | -- | -- |

So if there are 4 pillars, there are only 3 empty spaces that contain a length


---

**What do you think about this solution? 👇🤔**

[My Github](https://github.com/Cesardlr)
[My twitter](https://twitter.com/cesar__dlr)
[Solve this Kata](https://www.codewars.com/kata/5bb0c58f484fcd170700063d)
Annual webMethods customer survey 2021
Tags: webmethods, newsletter
Published: 2022-02-02 12:40:30

---
title: Annual webMethods customer survey 2021
published: true
date: 2022-01-27 08:31:36 UTC
tags:  webmethods, newsletter
canonical_url: https://tech.forums.softwareag.com/t/annual-webmethods-customer-survey-2021/254759
---


**We completed our tenth annual webMethods Customer Survey in May 2021, collecting very useful information from customers across the globe. We truly appreciate all of you who took the time to respond to us. [Read the original article](https://tech.forums.softwareag.com/t/annual-webmethods-customer-survey-2021/254759) in the Software AG Tech Community to learn about how we use this valuable information to better meet your needs.**


* * *

> This article is part of the TECHniques newsletter blog - technical tips and tricks for the Software AG community. [Subscribe](https://info.softwareag.com/TechCommunity-Subscription-Page.html) to receive our quarterly updates or read the [latest issue](https://tech.forums.softwareag.com/techniques-latest).
Effective Risk Management with Alfabet – Part 3
Tags: alfabet, newsletter
Published: 2022-02-01 10:40:28

---
title: Effective Risk Management with Alfabet – Part 3
published: true
date: 2022-01-27 08:30:31 UTC
tags: Alfabet, newsletter
canonical_url: https://tech.forums.softwareag.com/t/effective-risk-management-with-alfabet-part-3/254758
---



**This is part 3 of our 5-part series on application-based risk management. In [part 1](https://tech.forums.softwareag.com/t/alfabet-effective-risk-management-part-1/242390), we learned how to prepare a detailed listing of all applications as preparation for setting the scope of the risk assessment. [Part 2](https://tech.forums.softwareag.com/t/effective-risk-management-with-alfabet-part-2/244915) covered prioritizing applications for risk protection and mitigation. Here we will discuss the next step, which is assessing the risks to applications to be able to suggest and evaluate possible mitigations.**

Read [Part 3](https://tech.forums.softwareag.com/t/effective-risk-management-with-alfabet-part-3/254758)  in the original article in the Software AG Tech Community. 


> This article is part of the TECHniques newsletter blog - technical tips and tricks for the Software AG community. [Subscribe](https://info.softwareag.com/TechCommunity-Subscription-Page.html) to receive our quarterly updates or read the [latest issue](https://tech.forums.softwareag.com/techniques-latest)
NVIDIA CUDA setup on Colab
Published: 2022-01-27 08:19:17

The faster way to CUDA programming. Just open it right now [here ↗](https://colab.research.google.com/github/j143/notebooks/blob/main/cuda_on_colab.ipynb)

or

visit [colab.research.google.com](https://colab.research.google.com) for Google Colab for online jupyter notebooks. Make sure to set `GPU` accelerator in the `Runtime` -> `Change runtime type`.

![set runtime type to GPU](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wynv3rsnp22hb87pe2yl.png)


## 1. Remove existing CUDA installation

This remove all the `nvidia` and `libnvidia` named packages and libraries in the system.

```py
!apt-get --purge remove cuda nvidia* libnvidia-*
!dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 dpkg --purge
!apt-get remove cuda-*
!apt autoremove
!apt-get update
```

## 2. Download and install latest CUDA

Visit https://developer.nvidia.com/cuda-downloads 

![Installer configuration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvdv4fcbhn0bse89c58s.png)

Latest example,

```py
!wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
!sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
!wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb
!sudo dpkg -i cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb
!sudo apt-key add /var/cuda-repo-ubuntu2004-11-6-local/7fa2af80.pub
!sudo apt-get update
!sudo apt-get -y install cuda
```
 
## 3. Check the installation

```py
!nvcc --version
```

and create simple `.cu` file

```py
%%writefile /content/main.cu

#include <iostream>

int main() {
    std::cout << "This is from CUDA\n";
    return 0;
}
```
and compile it.

```py
!nvcc main.cu -o main
```

---

Resources
1. https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html
Get Instant Business Line of Credit
Published: 2022-01-27 08:10:55

Gconnectpro is a financial service provider for global businesses, startups, personal & much more. We have 100+ lenders you can choose from. Our funding system is secure and easy to connect you with your needs. We take pride in offering a wide range of business loans based on what you desire and what you deserve.
What does Gconnect have for you?

Get Instant Business Line of Credit

It is a revolving loan that gives business owners access to a fixed amount of money. You can use this money in your everyday operations according to your cash requirements. Gconnectpro can help you quickly open a line of credit at the reasonable
[business line of credit rates](https://gconnectpro.com/service/business-line-of-credit/).  
They are specifically designed to help businesses finance inventory or repair equipment, make payroll, and finance marketing campaigns.
SBA loan
US SBA programs range from short-term working capital to long-term financing for your small business. You can even fill out an SBA loan application to refinance debt and get small loans. Let GConnectPro help you get the SBA financing that your business needs.
Our SBA loan offers an opportunity to leverage 
[small loans for business](https://gconnectpro.com/service/sba-loans/) as part of the SBA program while removing obstacles in traditional financing methods. You can get SBA financing at terms that are right for you, with GConnectPro.
Today's Daily Humor For Devs - Daily Developer Jokes
Tags: jokes, dailydeveloperjokes
Published: 2022-01-27 08:00:04

---
title: "Today's Daily Humor For Devs - Daily Developer Jokes"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258922d1b9.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
I’ve been hearing news about this big boolean.

Huge if true.
 -->
DOM for beginners #4
Tags: javascript, html
Published: 2022-01-27 07:58:33

## CSS styling in Js

We can also style element of html from css.

```
<body>
    <h1 id="h1id1">This is first heading</h1>
    <h1 id="h1id2">This is second heading</h1>

    <!--             script               -->

    <script>
        document.getElementById('h1id1').style.color='red';//for single line styling

        document.getElementById('h1id2').setAttribute("style", 'color:red; background: green; text-align:center; border-radius: 2rem; border: 1rem solid black');

    </script>
</body>

```