teleren/devto huggingface dataset:
Mongoose auto timestamp
Tags: mongodb, database, javascript, architecture
Published: 2021-02-02 06:21:55

## Let mongoose schema handle timestamps for you

It's a little difficult to manage createdAt and updatedAt on each Create and Update operation.

We can have it handled by mongoose built-in features.There are three ways to add timestamps in mongoose schema 

## 1. createdAt and updatedAt in timestamp format.

```javascript
const mySchema = new mongoose.Schema(
    {
        name: String,
    }, 
    {
        timestamps: true,
    }
);
```

#### output: 
`createdAt: 2021-02-02T06:12:26.668Z`,
`updatedAt: 2021-02-02T06:12:48.930Z` 

## 2. Timestamp with a custom field name

By default, the names of the fields are createdAt and updatedAt. Customize the field names by setting `timestamps.createdAt` and `timestamps.updatedAt`.

```javascript
const mySchema = new mongoose.Schema(
    {
        name: String,
    }, 
    {
        timestamps: { createdAt: 'addedAt', updatedAt: 'modifiedAt' },
    }
);  
```

#### output: 
`addedAt: 2021-02-02T06:12:26.668Z`,
`modifiedAt: 2021-02-02T06:12:48.930Z` 

## 3. Timestamp with number format (double)

By default, Mongoose uses `new Date()` to get the current time. If you want to overwrite the function Mongoose uses to get the current time, you can set the timestamps.currentTime option. Mongoose will call the `timestamps.currentTime` function whenever it needs to get the current time.

```javascript
const mySchema = new mongoose.Schema(
    {
        name: String,
        createdAt: Number,
        updatedAt: Number,
    }, 
    {
        timestamps: { currentTime: ()=> Date.now() },
    }
);  
```

#### output: 
`createdAt: 1612246845043`,
`updatedAt: 1612246853068`
Adding Transition 🧐
Tags: html, css, codenewbie, codepen
Published: 2021-02-02 06:02:50

This post is a part of our "20 Days of CSS animation post"

{% link https://dev.to/atulcodex/20-days-of-css-animation-post-3g8d %}

In this post, I'll explain to you how to add transition on hover. 👇👇👇👇 here you can see our HTML file in that we have our heading tag "Hover over me". And in our CSS file, you can see we are targeting heading and heading:hover. We can add a transition in CSS in two ways.

{% codepen https://codepen.io/atulcodex/pen/ExNaNXL %}

![Manual Transition](https://dev-to-uploads.s3.amazonaws.com/i/395h4ltrt5cx78l84vzh.png)

In the first way, we are adding transition effect to each and every tag manually

But in a second way, we can add the transition to all tags at once like this 👇

![Smart transition property](https://dev-to-uploads.s3.amazonaws.com/i/t6tu006azk38cs41w6ac.png)

That's all for this post And if you are interested to learn CSS you can join [Eduonix E-Learning platform](https://www.eduonix.com/UHJvZHVjdC0xMzE1MDIw).
Error: listen EADDRINUSE: address already in use :::1006 on mac
Tags: eaddrinuse, address, errors, mac
Published: 2021-02-02 05:44:20

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dy92b9gop23pcxhbvqz3.png)

To resolve this issue on mac there are 3 steps

1. First need to find `PID` using below command line
   `sudo lsof -i :portNumber` // put your using portNumber here
2. Now it will ask you password. After enter password you will get `PID`.
3. Then run below command
   `kill -9 PID`  // put the PID you get above

Thanks
How I Learned The Intuition Behind Recursion
Tags: computerscience
Published: 2021-02-02 05:39:44

When I was studying data structures and algorithms, I did some exercise implementing BST(binary search tree) and its operations.

I was able to implement `insert` and `search` using iteration because it's more intuitive for me compared to using recursion, until I have to work on the `delete` operation, specifically on the case where the node I need to delete has 2 children. For context, in order to this, I had to identify the left most node of the right subtree and use its value to replace the value of the node I intend delete.

Using iteration looks easy for BST with a height of 2 or 3 even. However, as I was trying to test it on cases wherein the height of tree is 4 or greater, the code got complicated. So I reset my thoughts, then looked at the problem in a different perspective, then it hit me! A node of a BST is a BST itself! And this applies to linked-lists and array as well, a node of a linked-list is a linked-list, an index of an array is an array.

Then I suddenly remember what Prof.Skiena said, from a reader of his book, on one of his lectures about building a mental model for recursion. 

> If you take a bite out of a salad, you get a smaller salad. But if you took a bite from a hamburger, you don't get a smaller hamburger. 

Here's the output of my work:

{%gist https://gist.github.com/jeromecaisip/a24b779b5a11f2efc1b834e065e189ae %}
TIL Shader Keywords
Tags: todayilearned, godot, unity3d, gamedev
Published: 2021-02-02 05:35:04

2021-02-01
*A short month begins*

So a few months ago, I basically verified for myself that the Godot Engine works on Chromebooks via Linux. There's also a fascinating tool called Material Maker which is built off of Godot and (you guessed it!) it too works on Chromebooks via Linux.
![Chromebook Linux Terminal and Material Maker with a shader node graph](https://dev-to-uploads.s3.amazonaws.com/i/ni46tgufa4no8s6921ii.png)
With this tool, it's possible to export Unity Materials. I took a peek at the exported files and the only thing that stood out was the .mat file. I opened it and it's a YAML file that describes the material and its properties.
```
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
  serializedVersion: 6
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_Name: test
  m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
  m_ShaderKeywords: _METALLICGLOSSMAP _NORMALMAP _PARALLAXMAP
  m_LightmapFlags: 4
```
The Shader Keywords caught my eye. 
Uber Shaders are a shading method I've seen on prior projects; this is where your project has one shader to rule them all but this shader has many "variants" that are generated based on the Shader Keywords. In Unity, the idea is that you can have many materials that use just one shader asset but can look different because of the shader variants.
Paul Evans’ Writing a Core Perl Feature
Tags: programming, c, perl
Published: 2021-02-08 02:46:53

---
title: Paul Evans’ Writing a Core Perl Feature
published: true
date: 2021-02-02 05:07:22 UTC
tags: Programming,C,Perl
canonical_url: https://phoenixtrap.com/2021/02/01/paul-evans-writing-a-core-perl-feature/
---

[This upcoming blog series](http://leonerds-code.blogspot.com/2021/02/writing-perl-core-feature.html) by Perl core contributor Paul Evans promises to be very interesting, as it details what goes into developing and committing a new feature into Perl itself. Evans recently added the [isa operator to Perl 5.32](https://perldoc.pl/perl5320delta#The-isa-Operator), and will be describing how to add a similar (but fictional) feature across 10 or more articles. I’m looking forward to following along.
Change default Next.js app Port
Tags: nextjs
Published: 2021-02-02 05:05:23

Wanting to change the default port for your Next.js app is a very common problem. If any other app or process is running on port `3000`, you will get this error in your terminal

```bash
Port 3000 is already in use.
error Command failed with exit code 1.
```

## Solution

There are 2 ways to go about solving this.

1. First is to give it a temporary port number. This is useful when you want to run your Next.js app on another port for a single time.

```bash
npm run dev -p 3040
```

or

```bash
yarn dev -p 3040
```

This will run your app on port `3040` for this particular session. Once you close the process you will have to write this again if you want it on port `3040`.

2. The Second method is to set it inside your `package.json`'s script section.

```json
"scripts": {
    "dev": "next -p 3040", // This will change it for dev environment
    "build": "next build",
    "start": "next start -p 3040" // This will change it for the production
}
```

Now just run

```bash
npm run dev
```

or

```bash
yarn dev
```

Happy to be of help. :)
Linux Commands (CLI) To Get You Started
Tags: linux, ubuntu, programming
Published: 2021-02-02 05:01:56

This article deals exclusively with the Command Line Interface(CLI), rather than a Graphical User Interface(GUI) you may be familiar with. A basic understanding of the terminal is essential to diagnosing and fixing most Linux based systems.  

What is a command? A command is a software program that when executed on the CLI performs an action on the computer. When you type in a command, a process is run by the operating system that can read input, manipulate data and produce output. It runs a process on the operating system, which then causes the computer to perform a job.  

## List of Commands   
### The 'ls' Commands  
 
Most commands follow a simple pattern of syntax:  

```
command [options…] [arguments…]
``` 


#### - to display a listing of information about files you will use  
``` Linux
ls
```   
> Note: Every part of the command is normally case-sensitive, so LS is incorrect and will fail, but ls is correct and will execute.   

#### - results in a "long display" output, meaning the output gives more information about each of the files listed:  
```
ls -l
```   
#### - To print results in reverse order alphabetical order use:  
```
ls -r
```  
#### - To sort files by timestamp: 
```
ls -lt
``` 
#### - To sort files by size use:  
```
ls -l -S
``` 
### Switch Between Directories Commands  

#### - To print the current working directory use:  
```
pwd
```   
#### - To change from one directory/folder to another use:  
```
cd [directory name here]
```   
#### - To move to previous directory use:  
```
cd /
``` 
#### - To move to home/first directory use:  
```
cd ~
```  

Find the rest of the article at my blog [HERE](https://larymak.hashnode.dev/)  

Connect With me at [Twitter](https://twitter.com/larymak1) | [Insta](https://www.instagram.com/nextgencoders/) | [YouTube](https://www.youtube.com/channel/UCrT1ARRZfLOuf6nc_97eXEg) | [LinkedIn](https://www.linkedin.com/in/hillary-nyakundi-3a64b11ab/)  | [GitHub](https://github.com/larymak)
Python - NLTK toolkit error
Tags: python
Published: 2021-02-02 04:49:04

Hi, i was developing chatbot using NLTK toolkit, all the packages was installed, but still getting the attached errors. Whats wrong with environments?

Looking for your support

Traceback (most recent call last):
  File "E:/RD/Python/jChatBot/main.py", line 1, in <module>
    from nltk import *
  File "E:\RD\Python\jChatBot\venv\lib\site-packages\nltk\__init__.py", line 128, in <module>
    from nltk.collocations import *
  File "E:\RD\Python\jChatBot\venv\lib\site-packages\nltk\collocations.py", line 39, in <module>
    from nltk.metrics import (
  File "E:\RD\Python\jChatBot\venv\lib\site-packages\nltk\metrics\__init__.py", line 16, in <module>
    from nltk.metrics.scores import (
  File "E:\RD\Python\jChatBot\venv\lib\site-packages\nltk\metrics\scores.py", line 15, in <module>
    from scipy.stats.stats import betai
  File "E:\RD\Python\jChatBot\venv\lib\site-packages\scipy\__init__.py", line 130, in <module>
    from . import _distributor_init
  File "E:\RD\Python\jChatBot\venv\lib\site-packages\scipy\_distributor_init.py", line 61, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
Makerwork 002
Tags: minecraft, python, hosting, makerwork
Published: 2021-02-05 12:48:40

---
title: Makerwork 002
published: true
date: 2021-02-02 04:00:06 UTC
tags: #minecraft, #python, #hosting, #makerwork
canonical_url: https://makerwork.netlify.app/posts/makerwork002/
series: Makerwork
---

Hey Makers! 👋 

Welcome to the **Digest 002** of the Makerwork newsletter. Tad, our featured maker, is a software engineer at heart. 🏆 

Our Product section 📦 includes a several open-source repositories and a featured product, namely **Minecraft Playdates**.⭐️

We have a new section for Education 📚 & Resources.🧩

Also, take a look at what we've been reading 📖, and read the interview with our featured maker Tad. ⚡

Thank you.

[READ HERE](https://makerwork.substack.com)

*The Makerwork newsletter includes interviews with makers featured in the email sharing their insights about open-source, their blog and work.*
Money Making Apps
Tags: moneymakingapps, androidapps, mobileapps, moneyearningapps
Published: 2021-02-02 03:55:55

We'll show you a simple way to make money through what you're already doing. Yes, making money apps using your Smartphone is one of the easiest ways to earn money.

Everyone holds a prestigious mobile on their hand. But they are using their costly smartphone just for talking to others or sending images to someone.

We'll show you how to make money when you use your smartphone. Below is the list money making apps to earn money when you use your cellphone.

Learn How to Earn from <a href="https://moneytells.com/36-best-money-making-apps/">Money Making Apps</a>
Three Reasons Why You Need To Learn Svelte/Sapper
Tags: javascript, svelte, webdev
Published: 2021-02-02 03:48:13

Svelte is a compiler that is used to make lightweight SPA (single page applications), much like the ones you create with react, vue or angular. However svelte is quite different from them, and comes with some awesome features that makes working with svelte worthwhile. Sapper is a an application development framework that builds on top of svelte components, it is quite similar to Next.js for react and Next.js is actually one of the inspiration for the sapper framework. Svelete and Sapper are new to the scene so they are not too popular among developers, although this should not deter you, let's discuss three reasons why you should be using svelte and sapper for your work.

1. Svelte is a compiler and not a framework, unlike your regular frontend framework like angular, react, vue, svelte is a compiler, this implies that svelte will compile your code down into a JavaScript implementation without shipping the svelte library along with it! This makes for faster and more graceful apps, generally the other frameworks ships your code along with the core-library of the framework deployed with it and this adds to our final build size and makes our file quite big, slowing down load times. However svelte negates this by compiling our code into JavaScript that the browser can understand. svelte components are also smaller in code length compared to vue/react.
2. Svelte is also easy to learn, much easier than react, or vue. The syntax is clean and easy to use/ remember. It also allows us to use async/await in template rendering and i think that is so cool, you should try it out. Sapper is also easy to learn and use as much as svelte, in little to no time you should have a basic idea of how to build a simple sapper app, and with a few days of lessons and practice, you could be making high performant apps with svelte and sapper.
3. Sapper is flexible and you can use it with either express or polka for your server while you can clone the webpack template repo or the rollup template, depending on which you are comfortable working with. Sapper apps are also easy to deploy too. It took me a few clicks to deploy a dummy website i built with sapper and svelte and it was done, hosted without a stress. Sapper allows us to export static websites to platforms like a mentioned above simply and easily with just one command. We can preload the data a page uses before it's loaded. Routing is gracefully handled and you can easily implement some of the route gaurds that angular provides without having to write as much code too, just simple logic.

I hope this three reasons will definitely help make you decide to start learning the above technology, on my next post i will do an introduction on how to use sapper, so stay tuned for that.
Make Professional Components with Pub/Sub and Custom Events
Tags: pubsub, javascript, webcomponents
Published: 2021-02-02 03:42:44

---
title: Make Professional Components with Pub/Sub and Custom Events
published: true
description: How to use broadcasters and listeners for dependency-free code
tags: pubsub, javascript, webcomponents
cover_image: https://miro.medium.com/max/700/1*QSZ9aoyQeWb_upp65CgcRQ.png
---
Publish/subscribe is a classic software design pattern that allows pieces of an application to be decoupled. It uses messages instead of functions, closures, or callbacks. It promotes an architectural style that has flexibility through independence.

I recently applied the pub/sub pattern to the state management of a DOM component. Its implementation was at times confusing, but the final result was a satisfying UI/UX. The extra effort was worth it.

The full story is on Medium at https://medium.com/javascript-fanboi/2021-033-pub-sub-and-custom-events-a9ff6f93152

Bottom line: The pub/sub pattern helps remove dependencies between the source of truth and the user interface.

Unfortunately pub/sub can become a tangled mess — because the code for publishing and subscribing are almost always in separate modules. The key to success is staying organized.
My Flutter Learning
Tags: flutter, webdev
Published: 2021-02-02 03:35:54

Dear Friends,
   Wish you a very Happy New Year 2021. Wish you health and happiness.
Do you have a dream of developing awesome Mobile App or Web App?
Trust me Flutter is a suitable cross platform technology to fulfill your dream.
As the start of the month of February 2021, I have embarked my Flutter Learning journey with Google 30 Days Flutter program. 

Here is the link for [Google 30 Days Flutter program](https://developers.googleblog.com/2021/01/join-us-for-30daysofflutter.html)

Flutter is Google’s open source UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. It’s one of the fastest growing, most in-demand cross platform frameworks to learn and is used by freelance developers and large organizations around the world. Flutter uses the Dart language, so it will feel natural to many of you familiar with object-oriented languages. (Ref. Google 30  Days Flutter)

I am pretty excited to learn Flutter and do my ultimate activity i.e. to develop.

I will keep posting about my experience while learning.

Let's Join.
How to Teleport in Vue 3
Tags: vue, javascript, webdev
Published: 2021-02-02 03:34:14

A few days ago I decided it was time for me to update myself to the new version of Vuejs, Vue 3. And today I wanted to share with you the first thing I learn that version two didn't have, the `teleport` component.

It's well known that modern web applications fit in a div.

{% twitter 1346423883285499904%}

Ok, React uses `#root` and Vue uses `#app` but they just do the same, which is inject the JavaScript code into that div. So here it comes the question:

## What if I have an element I want to display as a sibling of the `#app` element in the html?

Sometimes we have a loader or a modal (aka popup) component that is not part of the app, but anyway, it will be injected inside the `#app` element. Thus, the html will look like this:

```html
<html>
  <body>
    <div id="app">
      <!-- Other injected HTML here -->
      <div class="loader">
        <!-- HTML for the loader goes here -->
      </div>
    </div>
  </body>
</html>
```

### Let's teleport!

![Goku Teleport](https://media.giphy.com/media/cW55zyF7dJAf6/giphy.gif)

To use the teleport component in your app, you need to first, add a sibling to the `#app` element in the html.

```html
<html>
  <body>
    <div id="app"></div>
      <!-- built files will be auto injected -->
    <div class="loader"></div>
      <!-- loader component will be injected here -->
  </body>
</html>
```

Once you've done that, go to your `.vue` file and use the teleport component:

```html
<template>
  <teleport to=".loader" v-if="showLoader">
    <Loader />
  </teleport>
  <!-- The logic of your component goes below -->
</template>
```

And that's it. Now, when the showLoader condition is met, the loader will show in the specified html element. Notice that I used a CSS selector so if the element was an id, I could have done it like this: `<teleport to="#loader" v-if="showLoader">`

> If you found it useful, please like, subscribe, and share the knowledge.

> You might like what I share on [my Twitter][Twitter profile] too.

[Twitter profile]: https://twitter.com/eligarlo
MERNG PROJECT... I NEED HELP!! IM SICK OF THE ERRORS!!!!
Tags: graphql, react, help, webdev
Published: 2021-02-02 03:32:50

I’m getting “module not found” for Apollo-server, also for gql and then I’m getting “some”, is undefined????? 
I started out with the wrong way of learning MERNG, it was all backend server side.... nothing at the client, but it did work a little.... BUT, I want to do it the right way.
There’s all these random “depreciated, update” trash, WHY CANT THEY JUST MAKE IT WORK!!!! 

I’m getting undefined when it’s imported,
Then there’s “import” or there’s “const Items
= require(‘something’);

I’m trying to make a simple MERNG app, and it’s turning to trash!!! 

I’ve done it before, but the wrong way of everything on the server.