teleren/devto huggingface dataset:
How to use Async/Await in JavaScript
Tags: javascript, webdev, programming, react
Published: 2022-01-26 12:48:36

Promises have been a great escape from callbacks, ever since they were introduced. Instead of callbacks hell, promises provide **.then()** API to chain multiple promises. However, in-case there are multiple dependencies, using **.then** becomes dreadful too and seems no much different than callbacks hell:  

```javascript
function getUser(userId){
    return fetchUser(userId)
        .then(user=>fetchUser(...))
        .then(image=>fetchImage(...))
        .catch(err=>console.error(err))
}

function displayPublicUser(userId){
    getUser(userId)
    .then(user=>{
        if(user.isPublic){
            displayUser(...)
        }
    })
}
```

## Introducing Async/Await
**Async** and **Await** keywords were introduced in ECMAScript 2017. Though they work as a synthetical sugar for Promises only, However, the asynchronous behavior of promises looks much like synchronous now and the code becomes much easier to handle. Comparing the above code using Async/Await will be like:

```javascript
async function getUser(userId){
    const user = await fetchUser(...);
    const image = await fetchImage(...);
    return user;     
}

async function displayPublicUser(userId){
    let user = await getUser(userId);
    if(user.isPublic){
        displayUser(...);
    }
}
```

**Await must be inside Async function**
In order to use **await**, make sure the parent function has async keyword attached to it. In case the function is not Async, then using Promises would work fine. Or there is an alternative to use IIFE wrapper to introduce **Async** keyword:

```javascript
function getUser(userId){
    return fetch(`https://some-api/user/${userId}`);
}

//WRONG
const user = await getUser(5);

//CORRECT 
getUser(5)
.then(user=>{...})
.catch(err=>{...})

//OR

//CORRECT
(async ()=>{
    const user = await getUser(5);
})()
```

## Error Handling
It's recommended to handle errors prior to their appearance. I have got two of the most used approaches below:

```javascript
async function displayUser(userId){
    const user = await fetchUser(userId).catch(err=>{
        console.log(err);
        return null;
    });
    return user;
}
```
The one I like and used most is:
```javascript
async function displayUser(userId){
    try{
        const user = await fetchUser(userId)
        return user;
    }
    catch(err){
        console.error(err);
        return null
    }
}
```

That's it for now, your comments are highly appreciated. See ya! 👋.
Our Digital Marketing Services//Allied Technology NY USA
Tags: digitalmarketing, appdevelopment
Published: 2022-01-26 12:43:23

[We are a strategy-driven agency that is guaranteed to provide results and deliver success. We have an extensive history of building cutting-edge professional responsive websites, custom mobile applications & digital marketing solutions designed to help businesses achieve their goals. Whether you are a local business, a national business, or an international business, our tailored services will ensure to deliver incredible solutions. We excel at delivering design, consultations, and developing businesses to their maximum potential growth. Allied Technologies, with its years of experience, has built an impressive portfolio that has only been possible because of our hard-working and very knowledgeable team. We believe in quality results and provide our clients with nothing short of perfection. Our testimonials speak for themselves. Here, at Allied Technologies, our team stands united and excited to be a part of your business journey.](https://alliedtechnologies.io/#)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4pgmaigugephpyucbka.png)
Pull logs from a remote server
Tags: apachenifi, beginners, ubuntu, datascience
Published: 2022-01-26 12:30:15

I am a beginner in NIFI. And i would like to read live logs from a remote server to a Nifi flow on another system. I have no access to install Nifi on that remote server, please what is the best method to implement the above scenario.
Thanking you so much for your reply.
Best Photo & video Editing Software's for Android?
Tags: video, editor, videoediting, photoediting
Published: 2022-01-26 12:27:08


Hi there.

- It's been a long time since I spent hours drawing sprite sheets and icons, I've been rendering UI elements in blender for a while, but I'm finding myself needing to make up a bunch of sprites once again.

- I used to have a couple of icon editors which were limited in terms of automated effects, but were really easy to use. These don't run very well on W10, they ancient so it's not surprising.

- I have Gimp, a bunch of Corel stuff including Painter and a few other things I've downloaded over the last year or so, all good at what they do but none are any good at pixel based editing.

- Just wondering what editing software you folks are using, especially you guys and gals doing the superb 2d animation work.
- I have already used Picsart photo & video Editor and Inshot pro video editor for editing my YouTube videos.

Many thanks.
Asked Question In MERN Interview
Tags: express, reactnative, redux, node
Published: 2022-01-26 12:21:32

## Official Definition :

- Node.js is an open-source cross-platform server-side runtime environment built on Chrome’s V8 JavaScript engine, which executes JavaScript code outside of a web browser.



## What is node js?

- When we write the JavaScript code and run it in browser it runs perfectly but what if you want to run it on server(your computer) and not in some browser.
- then Nodejs come into the picture.
- And Nodejs give a runtime environment for your JavaScript 
- Actually Nodejs used the same engine as that of chrome browser.

>  It is a JavaScript runtime built on Google Chrome V8 Javascript engine.

## What is Javascript runtime?

- Javascript runtime is a place where we can execute our javascript code
- it is like a container or enviroment where we can execute there code
- simply we write javascript code and run into the browser then browser internally using the V8 javascript engine and give the run time environment and this engine is nothing but a program that execute your javascript code
- but if see that browser is the place where we cana run our javascript code in the browser, but we know that internally browser using the javascript V8 engine
- then we talk about that what is this.

## What is javascript engine?

- Javascript engine is program that execute the js code .It is like a container or environment where js code executed.
- chrome : used the V8 javascript engine
- Mozilla Firefox : used the Spidermonkey
- Internet Explorer : Chakra to execute the code
- When we talk about the run javascript to other than browser then nodejs come into the picture.
- So we let's we talk about the
- So nodejs is place where we can execute our javascript code it is like a container or environment where we can run our js code.
- It is used the V8 engine to execute the js code and this engine is also use by the Google chrome browser.
- Node js Allow to execute the javascript code outside the browser.
- it help to build strong, scalable, secure web application  .
- It is most popular platform which used to build the backend of webapplication.it can also help to build the RESTFULL API.
- The best thing about the Nodejs is that it is open source platform so if you face any problem solution is already given to the Stackover flow

## When we used this nodejs?

- When we have large data set then we used the nodejs for example video streaming apps,chat application and real-time application.


- we also know that nodejs is also called as asynchronous event-driven javaScript runtime then we can  not understand some time what is ,means that
- asynchronous means that not a particular sequence for executing the tasks when ever the I/O is free it will execute the task accordingly
 



- Happy coding
Introducing tailwind-bicolor: auto handle reverse dark color
Tags: tailwindcss, css
Published: 2022-01-26 12:20:16

Tailwind includes a `dark` variant that lets you style your site differently when [dark mode](https://tailwindcss.com/docs/dark-mode) is enabled.

For example:
```html
<html>
<body>
  <div class="bg-white dark:bg-black">
    <!-- ... -->
  </div>
</body>
</html>
```
The background color of page will be `white` in light mode while being `black` in dark mode.

Let's show another example from the official:
```html
<p class="text-slate-500 dark:text-slate-400 mt-2 text-sm">
  The Zero Gravity Pen can be used to write in any orientation, including upside-down. It even works in outer space.
</p>
```
The text color will be `slate-500` in light mode while being `slate-400` in dark mode.

But you will find it's what a boring work soon:
* `white` vs `black`
* `slate-500` vs `slate-400`
* ...

uh-huh? The color is **opposite**? interesting.

Let's take a look at tailwind's [color palette](https://tailwindcss.com/docs/customizing-colors):

![color palette](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3azd5yzv1qza38bl9vgd.png)

Have you found how to find the reverse color? It's obviously:
* `50` to `900`
* `100` to `800`
* `200` to `700`
* ... and vise versa

Why not create a variant to auto handle this for us?
This is why [tailwind-bicolor](https://github.com/tmkx/tailwind-bicolor), and it's super easy to integrate to your project.

```javascript
// tailwind.config.js
const { bicolor } = require('tailwind-bicolor');

module.exports = {
  // ...
  plugins: [bicolor()],
};
```

```html
<div class="bg-white dark:bg-black"></div>
<!-- Replace with below ↓↓↓ -->
<div class="bi:bg-white"></div>
```

and that's it! Go to [Online Demo](https://bicolor.fancier.dev/).

```html
<div class="bi:bg-green-400"></div>
```
will generate:
```css
.bi\:bg-green-400 {
  --tw-bg-opacity: 1;
  /* green-400 */
  background-color: rgb(74 222 128 / var(--tw-bg-opacity));
}
.dark .bi\:bg-green-400 {
  /* green-500 */
  background-color: rgb(34 197 94 / var(--tw-bg-opacity));
}
```

It will auto handle reverse color by default, but it's also customizable even if you want to use green in light while using blue in dark.

{% github tmkx/tailwind-bicolor no-readme %}
Note: How to downgrade/skip a Ubuntu Package with aptitude
Tags: linux, ubuntu, tutorial
Published: 2022-01-26 12:11:22

## Downgrade a Ubuntu Package with aptitude

List all the available versions:

```
aptitude versions example
```

Downgrade to an old version:

```
aptitude install example=1.2.3
```

## Skip upgrading a Ubuntu Package with aptitude

Say, the version `1.2.4` had an issue so that you want to skip installing the version next time you run `aptitude full-upgrade` etc:

```
aptitude forbid-version example=1.2.4
```

## References

- [How to Exclude Specific Package from apt-get Upgrade](https://linoxide.com/exclude-specific-package-apt-get-upgrade/)

- `man aptitude`
Learning C# Booleans in Public
Tags: csharp, dotnet, programming, webdev
Published: 2022-01-26 11:57:35

Boolean data type has two values: true or false.  Booleans are typically used to check conditions.
![Code snippet on using booleans in C#](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5ycciu3cvdhsfpv5ovb.png)
Today I have attempted 5 java programming exercises  😊.
Tags: java, beginners, programming
Published: 2022-01-26 11:47:19

1.Java program to print 'Hello' on screen and then print my name on a separate line.

2.Java program to print the sum of two numbers. 

3.Java program to divide two numbers and print on the screen.

4.Java program to print the result of the following operations.
Test Data:
a. -5 + 8 * 6
b. (55+9) % 9
c. 20 + -3*5 / 8
d. 5 + 15 / 3 * 2 - 8 % 3

5.Java program that takes two numbers as input and display the product of two numbers.



---

**> Exercise from w3resourse**
What defines a good workplace/job? Here's what I think
Tags: discuss
Published: 2022-01-26 11:25:19


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

Here is what I think a good workplace is,

1. Teammates are supportive, transparent, give the credits you deserve and don't steal them
2. You are given opportunity to explore and learn
3. You are not blamed time and again for the mistakes you made
4. You are allowed to take part, however small or huge in any project of your team
5. Your time & health are valued
6. A good compensation 
7. Your opinions are valued if it deserves them

**What do you think makes a good workplace?**

- Tharun

{% user developertharun %}
tsParticles - Click Event with Confetti explosion
Tags: codepen, javascript, typescript, showdev
Published: 2022-01-26 11:16:00

<p>tsParticles - Click Event with Confetti explosion</p>

<p>Read more on GitHub: <a href="https://github.com/matteobruni/tsparticles" target="_blank">https://github.com/matteobruni/tsparticles</a></p>

<p>Website: <a href="https://particles.js.org" target="_blank">https://particles.js.org</a></p>

{% codepen https://codepen.io/matteobruni/pen/wvPvOVg %}

{% github matteobruni/tsparticles %}

{% link https://dev.to/matteobruni/tsparticles-1390-released-2111 %}
Mitglieder und Produkte mit Thrive Apprentice erstellen
Tags: membership, wordpress
Published: 2022-01-26 11:05:58

Die [WordPress-Mitgliedschafts-Plugins](https://medium.com/inhalt/mitglieder-und-produkte-mit-thrive-apprentice-erstellen-91855cf94087) sind eine sehr gute Möglichkeit, deine WordPress-Seite attraktiver zu machen, denn sie können fast alles. Mit diesen Plugins kannst du deine WordPress-Seite attraktiver gestalten. Es gibt viele Plugins, die in WordPress verwendet werden können, aber einige von ihnen müssen auf jeder WordPress-Seite installiert werden. Die Mitgliedschafts-Plugins sind eine sehr gute Möglichkeit, deine WordPress-Seite attraktiver zu machen, da sie fast alles können.

WordPress-Mitgliedschafts-Plugins sind Plugins, die deinem WordPress-Blog Funktionen hinzufügen. Sie können eine Vielzahl von Funktionen bieten, wie z. B. das Hinzufügen eines Kommentarbereichs, das Einrichten eines sticky comments-Bereichs, das Posten in deinen sozialen Netzwerken von deiner Website aus oder sogar das Hinzufügen eines Warenkorbs zu deiner Website. [Mitgliedschafts-Plugins](https://kursprofi.com/thrive-apprentice-mitglieder/) können dazu verwendet werden, die Funktionalität deines Blogs zu erweitern oder um eine bestimmte Funktion zu ergänzen, die du vielleicht implementieren möchtest.
How to X paper
Tags: machinelearning, ai, research
Published: 2022-01-26 11:05:07

- [How to read a paper](https://web.stanford.edu/class/ee384m/Handouts/HowtoReadPaper.pdf)
- [How to do good research, get it published](http://www.cs.ucr.edu/~eamonn/public/SDM_How_to_do_Research_Keogh.pdf)
- [How to read more papers](https://www.louisbouchard.ai/research-papers/)
1305. All Elements in Two Binary Search Trees
Tags: 100daysofcode, algorithms, programming, java
Published: 2022-01-26 10:57:42

# Description

Given two binary search trees `root1` and `root2`, return *a list containing all the integers from both trees sorted in **ascending** order*.

## Example 1:



```
Input: root1 = [2,1,4], root2 = [1,0,3]
Output: [0,1,1,2,3,4]
```

## Example 2:



```
Input: root1 = [1,null,8], root2 = [8,1]
Output: [1,1,8,8]
```

## Constraints:

- The number of nodes in each tree is in the range `[0, 5000]`.
- `105 <= Node.val <= 105`

---

# Solutions

## Solution 1

### Intuition

1. inOrder travel each tree, and put their values into a list
2. sort this list

### Code

```java
List < Integer > res = new ArrayList < > ();
public List < Integer > getAllElements(TreeNode root1, TreeNode root2) {
		
    inOrder(root1);
    inOrder(root2);
    Collections.sort(res);
    return res;
}

private void inOrder(TreeNode root) {
    if (root == null) {
        return;
    }
    inOrder(root.left);
    res.add(root.val);
    inOrder(root.right);
}
```

### Complexity

- Time: O(nlogn)
- Space: O(n)

---

## Solution 2

### Intuition

1. use two stacks to travel trees inorder
2. pop smaller node firstly

### Code

```java
public List < Integer > getAllElements(TreeNode root1, TreeNode root2) {
    List < Integer > res = new ArrayList < > ();
    Stack < TreeNode > stack1 = new Stack < > (), stack2 = new Stack < > ();

    while (root1 != null || !stack1.isEmpty() || root2 != null || !stack2.isEmpty()) {
        while (root1 != null) {
            stack1.push(root1);
            root1 = root1.left;
        }
        while (root2 != null) {
            stack2.push(root2);
            root2 = root2.left;
        }
        if (stack2.isEmpty() || (!stack1.isEmpty() && stack1.peek().val < stack2.peek().val)) {
            root1 = stack1.pop();
            res.add(root1.val);
            root1 = root1.right;
        } else {
            root2 = stack2.pop();
            res.add(root2.val);
            root2 = root2.right;
        }
    }

    return res;
}
```

### Complexity

- Time: O(n)
- Space: O(n)

---

## Solution 3

### Intuition

1. inorder travel each trees, and store there values in different lists
2. merge sort these two lists

### Code

```java
public List < Integer > getAllElements(TreeNode root1, TreeNode root2) {
  ArrayList < Integer > res = new ArrayList < > (), list1 = new ArrayList < > (), list2 = new ArrayList < > ();
  inOrder(root1, list1);
  inOrder(root2, list2);

  int i = 0, j = 0;
  while (i < list1.size() && j < list2.size()) {
    if (list1.get(i) < list2.get(j)) {
      res.add(list1.get(i++));
    } else {
      res.add(list2.get(j++));
    }
  }

  while (i < list1.size()) {
    res.add(list1.get(i++));
  }
  while (j < list2.size()) {
    res.add(list2.get(j++));
  }

  return res;
}

private void inOrder(TreeNode root, ArrayList < Integer > list) {
  if (root == null) {
    return;
  }
  inOrder(root.left, list);
  list.add(root.val);
  inOrder(root.right, list);
}
```

### Complexity

- time: O(n)
- size: O(n)

# Similar Questions
How to find the N most present element in a list in Python 💻 🐍
Tags: python
Published: 2022-01-26 10:53:11

If you have a list in Python 🐍 and you need to find for example the 3 elements that are the must present in the list. 

You can do it like this :

Create a list
```
mylist = [1,2,3,4,4,4,4,5,5,6,7,8,8,8,9]
```
Create two variables, maxcount is the number N of elements that we are searching.

```
count = 1
maxcount = 3

```

Use a while loop to find what we are looking for :

```
while count <= maxcount:
    num = max(set(mylist), key=mylist.count)
    print(num)
    count+=1
    while num in mylist:
        mylist.remove(num) #Here we remove the element that was the max
```

Now the full code:

```
mylist = [1,2,3,4,4,4,4,5,5,6,7,8,8,8,9]

count = 1
maxcount = 3

while count <= maxcount:
    num = max(set(mylist), key=mylist.count)
    print(num)
    count+=1
    while num in mylist:
        mylist.remove(num)

```

Now the result is :

```
4
8
5
```
You can even add them to a new list...



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tlxjxrq036qhd4nte4o2.jpg)
A simple yet powerful virtual office for slack
Published: 2022-01-26 10:49:46

Hey there, my name is Tiago and I am working on a platform that allows to create a virtual office in seconds...

[Indie Offices](https://indieoffices.com) is a platform that allows any slack based team or community to create a virtual office in seconds.

**How does it works?**

The concept is very simple, when you tap on *Open The Door* it asks you to login with slack and creates 2 virtual rooms that are always open and anyone can join at any time. **You don't need to actively create a room every time you want to meet someone.** 

The idea is to motivate a more spontaneous vibe just like in an office where you work and chill together.

**How others know I joined?**

[Indie Offices](https://indieoffices.com) have a great integration with slack. Whenever you join a virtual room your slack status will be updated. For example , if I join the work room, a little lap top  be appended to my slack username.

Besides you can send a message to the virtual-office channel (created by the tool) letting the others know that you have joined.

**Why is it better than other solutions?**

The reason why I built it like this is because is simple and easy to setup. Many other solutions coffee also an avatar that you can use to walk around, but in reality is not very practical.

**Next steps**

I am reaching out to remote companies to convince them to try it out and my goal is to help everyone to be more connected.

If you have a slack channel you can try it for free in [Indie Offices](https://indieoffices.com)

Let me know what you think
My First Backend Development Internship!
Tags: beginners, career, python, devjournal
Published: 2022-01-26 10:34:45

Hello fellow Devs!

I hope you are doing well. This blog post is just me summarising the journey I've had in the past few months, so this is more for me than anyone else. But you are absolutely welcome to read it.

So a few days back, I finally concluded my **first** **Backend Developer Internship** that started in September 2021. These **4 months** were filled with excitement and memorable learning experiences. Since a small blog entry would be an injustice to it, I will divide it into a couple or more posts. So let's start at the beginning...

#Moments Before Applying
I was in my **second year** of B.Tech during March 2021 and it was about to be over. So like some other friends of mine, I wanted to do an internship in summer break _(May, June, July)_. I had prepared my resume for the same with whatever much I had done and learnt till then. 
_(4-5 okayish projects, created a shop management desktop app for a nearby shop, wrote a few articles as technical content writer for geeksforgeeks.)_

Now in retrospect this sounds good enough to apply for internships. But at the time, I felt **there was something lacking**. And I wanted to fix it. So I worked more and more. Changed complete format of resume thrice, along with infinite edits in each. 

In late April, I prepared everything and went on internshala and angel.co to apply for internships. But something funny kept happening. Every time, I would fill the form and answer the "Why should we hire you?" etc questions, but when it came to finally clicking on submit, I **just couldn't do it**.

Instead I would just close the tab, and _go back to learning something more_. Making something new. Using another API. Just anything but submit.
I learnt a few more things during these iterations. _(docker, docker-compose, node, sqlite etc.)_ And before I realised, the **summer was over**.

Finally, at the end of August, a friend of mine pushed me to apply and see what happens. So August 28th, I finally pushed the submit button on 4 applications (after the first one, it became easier).

And surprise surprise! I _got a call back_ from **2** of the **4** internships, the next day itself. One of them scheduled an interview for 30th which I cleared rather smoothly _(that's debatable though. It was my first interview so I was quite nervous.)_.

And this is how I, **the anxious developer**, started my internship in a side branch of Proffus, **Ztocks Pvt. Ltd.**, as a Backend Developer, assigned to **create the backend of a production level application** from scratch.
.
.
.
.

In the next post, I will tell you about the first month of my internship and how I handled (or rather mishandled) it.
Thanks for reading. :)