teleren/devto huggingface dataset:
MongoDB Query: Remove duplicate records from the collection except one
Tags: mongodb
Published: 2020-03-21 10:30:09

<a href="https://www.codefari.com/2020/03/mongodb-query-remove-duplicate-records.html">Codefari.com</a>
var duplicatesIds = [];
db.Employee.aggregate([
        {
            $group: {
                _id: {
                    EmpId: "$EmpId"
                },
                dups: {
                    "$addToSet": "$_id"
                },
                count: {
                    "$sum": 1
                }
            }
        }, {
            $match: {
                count: {
                    "$gt": 1
                }
            }
        }
    ], {
    allowDiskUse: true
}).forEach(function (doc) {
    doc.dups.shift();
    doc.dups.forEach(function (dupId) {
        duplicatesIds.push(dupId);
    })
});
printjson(duplicatesIds); 

db.Employee.remove({_id:{$in:duplicatesIds}}) 
db.Employee.find();


Now we will do an analysis of the above-written query.
1- var duplicatesIds = []: This is an array declaration where this query will push the duplicate IDs.

2-{$group:{_id:{EmpId:"$EmpId"},dups:{"$addToSet":"$_id"} ,count:{"$sum":1}}}: Here we are grouping the records on behalf of EmpId, and using $addToSet command, we can create an array "dups", and count:{"$sum":1} is counting the duplicate records.

3- {$match:{count:{"$gt":1}}}: Here we are filtering the records that have a count greater than 1. As the above group pipeline, we are counting the duplicate records on behalf of EmpId.

4- ForEach: we are iterating records one by one here which are grouped EmpId, here we will find the array of duplicate records, for example 
"dups" : [
        ObjectId("5e5f5d20cad2677f9f839327"),
        ObjectId("5e5f5d27cad2677f9f839328"),
        ObjectId("5e5f5cf8cad2677f9f839323")
    ].

5- doc.dups.shift():Here we are removing one record which will not be deleted, and It means we will delete the duplicates except one document.

6- doc.dups.forEach(function (dupId): here again, we are iterating the array to push (duplicatesIds.push(dupId)) it records (duplicatesIds)on the above-declared array.

7- db.Employee.find(): to fetch the records.
Now finally execute the above MongoDB query, and you will find the following records.

For more details follow the <a href="https://www.codefari.com/2020/03/mongodb-query-remove-duplicate-records.html">codefari.com</a>
Sort Order of Posts in a Series?
Tags: meta, series
Published: 2020-03-21 10:37:28

I'm a bit surprised about the (in a timeline) 2nd post [Blogging About My Repositories to Guide Interest](https://dev.to/jhermann/blogging-about-my-repositories-to-guide-interest-gm7) being the first in the generated list of posts. Any hints to fix this?

Maybe related to the *original* date of posts at the source? If that, it might be a worthwhile feature to allow explicit ordering (`series: #«PRIO» «TITLE»`, with prio defaulting to the UNIX timestamp used currently), or else sort by order of publishing on `dev.to` instead of any sources.
Folding furniture for home office
Tags: discuss, productivity
Published: 2020-03-21 10:31:33

My home-office set up consists of a single standing desk and occupies 2.25m2. I don't always work from home, but the desk just stands there getting in the way.

I recently got a new desk that can be packed away in just one minute.

{% youtube HdWBJu45pjg %}

![Wirecutter style testing](https://dev-to-uploads.s3.amazonaws.com/i/j15qwdogj00px2u9qz62.png)

I wonder if anyone else uses folding furniture?
Am I the only one with the lack of space problem? :)
Compile Podcast Ep 9: Workout and Productivity
Tags: developer, podcast, productivity
Published: 2020-03-21 09:45:47

---
title: Compile Podcast Ep 9: Workout and Productivity
published: true
description: "This week my friend Yuekun and I talk about working out and how it impacts your productivity!"
---

*This is reposted from [my personal site](https://nickwu007.github.io/).*

This week my friend Yuekun and I talk about working out and how it impacts your productivity!

{% youtube UvwWEHGzDww %}

### Breakpoints

 - 00:00 A little foreword
 - 01:00 Podcast Intro
 - 02:25 What happens when you don't work out
    - 02:54 Prone to chronical injuries
    - 04:03 Mental stress from getting stuck at work
	- 05:16 Lack of discipline and confidence
 - 07:25 "Does working out make you more tired actually?"
 - 09:19 Benefits to productivity from working out
    - 09:53 It is important to spend some time away from work
    - 10:08 Science of health benefits
    - 11:37 Nick's personal journey of working out
    - 13:29 Benefits to developers
    - 18:32 Discovering hidden points
    - 21:35 Cultivate a healthy respect to time management and building habits
 - 27:54 What time of day would be the best for workout if you have live a 9-5 life?
 - 37:56 Wrapping up

### Reach out to us!

Subscribe and stay tuned! Also send in any comment or request for new topics and we will try our best to make them happen!

My Twitter: https://twitter.com/WujunaoNick

This Podcast is also on:
 - [Google Play Music](https://play.google.com/music/listen#/ps/Ifd5mlxhgc5cmlsytadsglqfd4y)
 - [iTunes](https://podcasts.apple.com/gb/podcast/the-compile-podcast/id1436437367)
 - [Spotify](https://open.spotify.com/show/2UH9hK7VlS7ytjYdM8Vd78)
Make a password manager with python
Tags: python
Published: 2020-03-21 09:42:55

If you are like me, you probably have logged in many websites so far. But rarely remember any password of them. And sometimes, the websites won't let you sign up until you add a 'super-strong password.' But as a matter of sorrow, you forgot that password the next day.

There is a simple solution to this gigantic problem. Use a password manager. But nowadays, maintaining privacy in this vast online world is quite impossible unless you don't use the internet at all. But you aren't going to that, are you?

You even may find your password in the dark web selling for a couple of dollars. So, using a third-party password manager doesn't sound safe to me. You should also be concerned about this. (I am not demotivating you guys not to use a third-party password manager.)

So, what is the solution? Luckily we are developers and we have mighty weapons in our hand. Programming!!! Yes, my friend, you guessed it right. We are gonna make a password manager on our own. Sounds exciting? Because this really is exciting.

I am thinking to make a series where I will break the project probably in three parts and upload them every 2 days. I have already started coding and made significant progress. But I needed to stop because of the other projects I am currently working on. 

In the next post, we will get our environment set. 🌲

So, what are you waiting for? Just hop right in and get your own password manager up and running.
ignoreit: vscode extension to automatically ignore files and folders
Tags: vscode, gitignore, git, ignoreit
Published: 2020-03-21 09:42:25

I published a VSCODE extension with the name `ignoreit`. It automatically helps you to add files and folders to .gitignore and creates a symlink between ".env" and ".env.example" files. So, you’re sure your secrets are never pushed to github or other source controls.
[https://marketplace.visualstudio.com/items?itemName=marcdomain.ignoreit](https://marketplace.visualstudio.com/items?itemName=marcdomain.ignoreit)

# USAGE

* Install and navigate to `vscode settings.json` and ensure you have "ignoreit.array": [".env", "node_modules", "coverage"] as one of the key-value pairs. The array is a list of files and folders you wish to always ignore. Feel free to modify it.
* If any of the files or folders specified in the array exists in your project directory, ignoreit extension will add it to the .gitignore file.
* If .gitigore file does not exist in your project directory, ignoreit extension will create a .gitignore file and fill in the files you're to ignore.
* The .gitignore content will be the files in your project directory that corresponds to the ignoreit.array
* You can manually add other files to the .gitignore file. New files are always appended to the existing ones.
* If .env file is part of the files in your directory, ignoreit extension will create a .env.example file and fill it with the the contents of your .env file. Only variables are filled in, values are left behind. The .env and .env.example files will always be in sync.

# REQUIREMENTS
This extension works when you're working in a git repository on VSCODE.
This extension requires that ignoreit.array key be added to your VSCODE settings.json file and value should be an array of files you wish to automatically add to .gitignore file in all your project (if the files or folders exist in your project). See example below

`"ignoreit.array": [".env", "node_modules", "coverage"]`

[https://marketplace.visualstudio.com/items?itemName=marcdomain.ignoreit](https://marketplace.visualstudio.com/items?itemName=marcdomain.ignoreit)
MDI icons search web app for productive front end devs 
Tags: showdev
Published: 2020-03-21 09:22:23

[Material Design Icons](https://materialdesignicons.com)'s icon library is awesome, and gaining a lot of traction lately as [Vuetify](https://vuetifyjs.com) defaults to it with v2.

But the official website totally sucks, and looking for the right icon is a pain 🤮.

As a front end dev, I use icons a LOT and finding the right one is usually not a breeze.

So I have built a small web app to search MDI's icon. I have used Algolia to power the search and thanks to the open sourced collaborative list of meta tags for each MDI icons, the search will returns you **related icons** (eg : search for 'house' will return you 'home' icons as well).

**Try it out :** [mdisearch.com](https://mdisearch.com)

PS - It is open sourced, built with Vue and Vuetify.
Array.sort gotcha: Case of the missing key
Tags: javascript, beginners, webdev, codenewbie
Published: 2020-03-21 08:49:12

When you are working as a web developer, you will have to sort an array in ascending or descending order at some point in time.

To sort arrays based on some value, we can use the built-in Array.prototype.sort() function which works as follows:

```
// sort in ascending order
array.sort(function (a, b) {
  if (a < b) {
     return -1;
  }

  if (a > b) {
     return 1;
  }
  
  if (a === b) {
     return 0;
  }
});

// sort in descending order
array.sort(function (a, b) {
  if (a < b) {
     return 1;
  }

  if (a > b) {
     return -1;
  }
  
  if (a === b) {
     return 0;
  }
});
```

Since the `array.prototype.sort()` function depends on `positive`, `negative` and `zero` values to determine the order of elements, we can simplify the above logic if we are working with numbers:

```
// sort in ascending order
array.sort(function (a, b) {
  return a - b;
});

// sort in descending order
array.sort(function (a, b) {
  return b - a;
})
```

So if we are sorting an array of object, in ascending order, our code will look like this:
```
let array = [{ id: 1, value: 10 }, { id: 2, value: 2 }, { id: 3, value: 5 }];

// sort in ascending order:
array.sort(function(a, b) {
  return a.value - b.value;
});

// Output => [{ id: 2, value:  3 }, { id: 3, value: 5 }, { id: 1, value: 10 }];
```

But imagine I introduce a new element into the mix, which doesn't have the key `value`:

```
// New element { id: 4 } which doesn't have the key `value`
let array = [{ id: 1, value: 10 }, { id: 4 }, { id: 2, value: 2 }, { id: 3, value: 5 }]; 

// sort in ascending order:
array.sort(function(a, b) {
  return a.value - b.value;
});

// Output => [{ id: 1, value: 10 }, { id: 4 }, { id: 2, value: 2 }, { id: 3, value: 5 }];
``` 

Because our new element doesn't have the key `value`, accessing it will return `undefined`. Now, trying to subtract a number with `undefined` will result in `NaN` and cause our sort function to not work as intended.

I recently got stung by this gotcha and worked around it by assigning `0` to the missing values:
```
// New element { id: 4 } which doesn't have the key `value`
let array = [{ id: 1, value: 10 }, { id: 4 }, { id: 2, value: 2 }, { id: 3, value: 5 }]; 

// sort in ascending order:
array.sort(function(a, b) {
  const valueA = a.value || 0;
  const valueB = b.value || 0;

  return valueA - valueB;
});

// Output => [{ id: 4 }, { id: 2, value: 2 }, { id: 3, value: 5 }, { id: 1, value: 10 }];
```

As I was ordering array of objects in descending order by `likes`, this worked perfectly for my use case.
Best resources and learnings on running online events
Tags: devrel, community, help
Published: 2020-03-21 08:44:30

Thank you for all the feedback and love from the last 2 articles! As evident from them, a lot of my learnings come from others who have graciously shared their knowledge. 

This post will be a live document where I will continue to update with new helpful articles I come across. 

Here are a couple of resources I've found to be helpful:
* Detailed how-do on setting up online events: [Video Recording and Live Streaming for RK
](https://aworkinprogress.dev/video-recording-and-live-streaming-for-rk/)
* Timeline to organizing an online conference: [End-to-end guide to a livestream conference in 3 weeks](https://dev.to/truckerfling/end-to-end-guide-to-a-livestream-conference-in-3-weeks-5dgc)
* Very detailed guide on Zoom: [A Guide to Hosting Virtual Events with Zoom](https://docs.google.com/document/d/1KLRrnm6g5YvD8QRSPwwNWq6NPk9FYvMpZPy_XEyOmMM/edit?fbclid=IwAR3LPyCZjbvnL_wpL26rmXD6PwQ03B_xgnDtr-fDssZEfifI7qlhdgovMTw)
* Guide to hosting podcasts: [How to launch a local podcast](https://drive.google.com/file/d/16Jebn-EUkjIz2Ze33R8-Vkbmplgu1oBm/view?fbclid=IwAR2wWDVwy6QDJuuRhz7TldfUNrTEhokYkGRyciWzXEvVy13xj-g83UATCsc)
* Timeline to organize an online meetup: [Some advice on running online meetups](https://dev.to/maxkatz/some-advice-on-running-online-meetups-138f)
* Learnings from Hack the Crisis: [How to set up an online hackathon within 6 hours](https://docs.google.com/document/d/1MzjbHEWJOHB8G5cSitIS0mqCN8F9f01wDBVmdaR31yA/edit)
* Good overview of how to get started on online events: [Get started with running an Online Event with Peatix](https://docs.google.com/presentation/d/1ADwjXcL4UArewnI1vejmohpMvT3f31FVTAxsWgZFJJI/edit?fbclid=IwAR3kjd1Np4Uf2xA_PO9z8dK9y9WlVS83TUb_2ysFiz2H9Eq6AwgwAjArOLg)

## Watch out for Zoom-bombing!
> *"A troll entered the call and screenshared Two Girls, One Cup and other horrifying sexual videos. Attempts to block the attack were thwarted as the perpetrator simply re-entered the call under a new name and screenshared more gross-out clips.” - [TechCrunch](https://techcrunch.com/2020/03/17/zoombombing/)*

I didn't know that this could be a thing! 🤦🏻‍♀️

Here are a couple of articles I've found helpful in addressing this topic. 
* [How to set-up a Zoom meeting to reduce risk from trolls and opponents disrupting your meeting](https://powerlabs.io/how-to-setup-a-zoom-meeting-to-reduce-risk-from-trolls-and-opponents-disrupting-your-meeting)
* [How to Keep the Party Crashers from Crashing Your Zoom Event](https://blog.zoom.us/wordpress/2020/03/20/keep-the-party-crashers-from-crashing-your-zoom-event/)

# Your turn: what did you learned or resources you have found on running online events for developers?
Please share them in the discussions below!

&nbsp;

>Like articles like this? I write about DevRel career advice, building communities, and designing developer programs. You can receive all my articles and more in your inbox when you sign up for my newsletter here: [https://bit.ly/updatesfromsha](https://bit.ly/updatesfromsha)
Magento Logs: A Better Way To Understand Your Application And Take Better Decisions
Tags: magento, logs, errors
Published: 2020-03-21 08:30:16


Developing an ecommerce store is not easy and you need a lot of technical expertise to develop and manage the store. To deal with the challenges, many developers prefer to use CMS platforms.
Each platform has its own set of features and advantages. However, if you are in the market for a robust ecommerce platform that fulfills every need of an ecommerce store then your choice should be Magento. 
Errors are pretty common during the development process. Before resolution, the errors have to be identified and categorized. To help developers during the process, Magento offers a <a href="https://www.cloudways.com/blog/magento-logs/">Magento log</a> feature to maintain the errors and exceptions logs for your ecommerce store.
To read the full article visit Cloudways blog.
What is the strong UI framework to make fantastic UI in React?
Tags: react
Published: 2020-03-21 07:13:47

Hi, friends. If I use some UI frameworks like material ui or primereact, it will save my time but it's really hard to customize. And also, there is limitation to customize. In other words, if I use frameworks, I can't build whatever I want. But If I don't use frameworks at all, it will be hard work and it's not effective. So if someone can suggest an underlying framework, it will be help for me. The framework should be qualified by next things. 1. fully custom. This means it never be conflicted with other css. 2. strong function. This means.. Even though it will take more time, I should make whatever I want through that framework. I just thought about reactstrap, react-bootstrap or just tailwind css but I'm not sure.
Guide to Learn full-stack web developer or software developer
Tags: codenewbie, discussionthreads, career
Published: 2020-03-21 07:04:42

---
title: Guide to Learn full-stack web developer or software developer
published: true
description: I got a finance degree and doing work as a finance executive for 7 years. Now I need to change, something new... Passion in developing...    

tags: #CodeNewbie #Discussion Threads #career 
 
---
There are 9 falsy values in JavaScript inside of a browser. Can you name them all?
Tags: javascript
Published: 2020-03-21 06:33:27

Sometimes when programming in JavaScript, it is easy to get an uncertain feeling of, what in JavaScript are falsy?

It is slightly different if it is pure JavaScript versus in a browser.

When it was ES5, there were 8 falsy values.  Can you name them all?

Scroll down to read what they are...
　
　
　
　
　
　
and scroll some more...
　
　
　
　
　
　
and more...
　
　
　
　
　
　
The answer is, there were 5 primitive types in JavaScript ES5.  Each primitive type contributes 1 falsy value, except Number, which contributes 3:

The way I remember them is:

NNBUS

Null, Number, Boolean, Undefined, String

And the corresponding falsy values are:
```js
null
0
-0
NaN
false
undefined
''
```

So this is "falsy 7".  There is one more, at the end of this post.

`0` can be viewed as the same as `-0` sometimes, depending on how you look at it.  If you have `n` dollars, and `n` is `0` or `-0`, it really doesn't matter that much.  But let's say, if you calculate something, and it is `1 / 0` or `1 / -0`, then they give very different results:

```js
1 / 0    // Infinity
1 / -0   // -Infinity
```

The operator `===` would compare `0` and `-0` to be the same, but `Object.is()` would compare them as different:

```js
0 === -0           // true
Object.is(0, -0)   // false
```
The other different behavior of `Object.is()` is that it returns `true` for `Object.is(NaN, NaN)`, while `NaN === NaN` returns false.  So in a way, you can think of `Object.is()` as the twin brother of `===` that is more precise.

You can also think of `0` not being equal to `-0`: when it is `+0`, a tiny bit of matter, it can cost you nothing, such as a grain of sand.  But if it is `-0`, which is a tiny bit of antimatter, it would cost you a lot of money, as the current price of 1 gram of antimatter is $62.5 trillion dollars.

In ES6, there are two more new primitive types: Symbol and BigInt.  Symbol is the only primitive type that doesn't have a falsy value, and BigInt also contributes one falsy value: `0n`.

Now, almost all objects in JavaScript are truthy values, except one. Do you know what it is?  Together, they make up the 9 values in JavaScript that are falsy, and the object is `document.all`, and is falsy coming from the usage when the code checks `if (document.all)` and `document.all` is falsy to tell the program: don't use `document.all`.

```js
document.all     // HTMLAllCollection(3) [html, head, body]

!!document.all   // false
```

So the falsy values in JavaScript in a browser, 9 of them, are:

```js
null
0
-0
NaN
false
undefined
''
0n
document.all
```
Predict the Output
Tags: c, challenge, beginners
Published: 2020-03-21 06:33:06

Predict the output of the following code and tell me why this works:

```c
#include <stdio.h>
int main()
{
    int x = 10;
    while (x --> 0) 
    {
        printf("%d ", x);
    }
   return 0;
}
```

The one who answers well will get a follow back!
Mockito: Passing in any() and a literal to the same method
Tags: java, mockito, testing, groovy
Published: 2020-03-21 05:41:45

Mockito has a restriction where when using `Mockito.when(someMethod(...))` you can't pass in a combination of `any()` and literal values to `someMethod()`.It complains that we have to pick one. So, the following is illegal:

*Solution 1 (preferred and as shown by Stephen):*

Mockito.when(context.configFileProvider(eq("file1"), any())).thenReturn("file1_contents")


*Solution 2 (works but ugly and the original post here):*

```
Mockito.when(context.configFileProvider("file1", any())).thenReturn("file1_contents")
```

There is a way around it which I stumbled upon when trying to test nested closures while writing Groovy scripts for Jenkins (don't ask me). Here it is:


        Mockito.when(context.configFileProvider(Mockito.any(), Mockito.any())).thenAnswer(
            new Answer<String>(){
                @Override
                String answer(InvocationOnMock invocation){
                    List arg1 = invocation.getArgument(0)
                    switch (arg1.get(0)) {
                        case "file1": return "file1_contents"
                    }
                }
            }
        );

This is logically equivalent to the previous statement.