teleren/devto huggingface dataset:
📅📅 How to compare Dates in JS (getting the difference in days)
Tags: javascript, webdev, beginners
Published: 2020-01-09 23:57:32

Let's say we start with a date String and we want to calculate the difference in days to the current date.

* First we need to convert the String to a Date
* then we get today's date
* and compare the two

So how do we convert a String to a Date? The constructor of Date does this for you. Just pass along the String like this:

```js
const pastDate = new Date("2017-04-15")
```

Today's Date you can get with the empty constructor:

```js
const today = new Date()
```

Now let's compare the two dates. For this, we will use the UNIX time. The UNIX time is the time passed in milliseconds since January 1st 1970 00:00:00.


```js
const pastDate = new Date("2017-04-15")
const today = new Date()

const differenceInMs = today.getTime() - pastDate.getTime()
```

This gives us the difference in milliseconds. Let's convert it now to days. By dividing it through 1000 we'll get the difference in seconds. Dividing this by 60 gives us minutes. By another 60 gives us hours. And by another 24 gives us days.


```js
const pastDate = new Date("2017-04-15")
const today = new Date()

const differenceInMs = today.getTime() - pastDate.getTime()
const differenceInDays = differenceInMs / 1000 / 60 / 60 / 24;
```
Coming back to Blogging
Tags: devjournal, beginners, career
Published: 2020-01-09 23:56:45

## Getting My S**t Together

Hey there DEV following, it's been a while...which I said in my last article I wrote in October 2019. A lot has went on since then in my personal life, although my learning has sort of stalled. This is very much the opposite of what I want and need to be doing which leads me into the next topic of this post...

## 2020 Plans

I could of course make extravagant plans and resolutions, but instead, I want to work on developing habits that will help me work toward my goals, both personally and professionally. 

A fantastic book that I am re-reading to help me on this journey is "Atomic Habits" by James Clear. If you've not read it yet I highly encourage you all to do so. 

![Atomic Habits book by James Clear](https://thepracticaldev.s3.amazonaws.com/i/lrpd72gh6debhw58268i.png)

### New Habits

- Wake up by 6:30am during the work week (Monday - Friday)
- Meditate daily for at least 10 minutes
- Read 2x per week for at least 1-hour per session
- Code 5x per week for at least 1-hour per session
- Go to gym 2x per week
- Go on 3 walks per week for at least 15 minutes each

These are the most important habits to me that I build, and you'll notice that they are all rooted in personal development. 

---

## New Coding Mentality

This is something I'd like to expand on in a future post, however, I am looking at web design and project development in a different light lately. Long story short, I am trying to keep things simpler, not get caught up in the fine details as I'm building something new, and force myself to try new things.

Like I said, I'll expand on this in a future post, but so far it seems to be working pretty well and I am enjoying the lack of stress I was putting on myself.

---

## The Curse of Being Too Curious

I am extremely curious with wanting to know what is the best way to do something. This has been crippling me occasionally while coding - let me explain.

![Illustration of person typing on a laptop](https://thepracticaldev.s3.amazonaws.com/i/d3xx2gmz5737wk3v45e3.png)

I often do too much research before starting something new. There is so much information readily available online these days that it's easy to rabbit-hole yourself into reading and reading and watching and watching before taking the first step...in my case that's simply writing code!

It's an annoying habit of mine, one I'd like to break. I would imagine I'm not alone in this, so I was wondering if any of you could suggest how to overcome or work through this paralyzation?
The Most Popular Front-End Developer Guide For ALL Skill Levels
Tags: books, career, beginners
Published: 2020-01-09 23:46:07

As a front-end developer, I often find challenge in overcoming a plateau or **knowing what to do next in 2020.**

In this mindset, I stumbled across the *Front-end Developer Handbook 2019*, which is mind-blowing in its breadth (more about this soon). The guide was last updated in April 2019 according to GitHub. It is still relevant and acutely insightful, with no 2020 edition yet.

I am going to detail everything you need to know about the *Front-end Developer Handbook 2019:* what it is, key learnings, and a helpful breakdown of the book by its audience, depth of learning material, and even how fun the manual is to read --- since after all, reading technical manuals ought to be fun.

If you like the content in this article, you can also find my other content at my blog, _[Books on Code](http://booksoncode.com)_.

## Overview

*Front-end Developer Handbook 2019* is a complete getting-started guide for anyone who wants to become a self-taught front-end web developer in present year. It is a free book, which is accessible online or downloadable in pdf or epub formats. It talks about everything from all the various tools developers might encounter in 2019 to practical career advice like salary expectations.

When you get deeper, the guide presents tons of links to resources on any front-end topic you want to know. There's also a great concluding chapter for resources about developer communities, podcasters, newsletters, and even more reading. From that list, I recommend the [Front-End Focus](https://frontendfoc.us/) newsletter, which introduced me to the *Front-end Developer Handbook 2019* in the first place. 😉

To find this guide and enjoy its glory (before coming back to read my review of it, of course), see [Front-end Developer Handbook 2019](https://frontendmasters.com/books/front-end-handbook/2019/).

##3 Takeaways

In the following sections, I describe my key takeaways from *Front-end Developer Handbook 2019*. Reading books, even technical books, is a personal experience. By sharing what resonated with me, I hope to share the energy and spirit the book conveys.

[Read More](http://booksoncode.com/articles/front-end-developer-handbook-2019)
Bootcamps, tech reviews, interviews, Anything else I'm forgetting?
Published: 2020-01-09 23:37:21

Hello! 

Long time fan, first time blogger. I figured it was time I start putting some thoughts down for all to read. 

I recently wrapped up my time at Flatiron. I was part of the software engineering focus. It was time for me to get some structured focus learning, as all my learning has been from online video tutorials and many other locations. I also was released from my job in January, 2019, and I figured why not start fresh with something I've always thought was super appealing. So this is where we are today. 

After my time with Flatiron, I was presented with a chance to pair up with a professional programmer and do a technical interview. When this came to my knowledge a million lightbulbs went off in my head. I say this because while at Flatiron, technical interviews on my projects were my most dreaded section. I would freeze up. I would stumble over my words. I would not know what the heck I was talking about. But I built the application, why can't I talk about it? That's a mystery I wanted to solve.

So when this was a requirement, I knew I had to buck up and work this out. I decided to take it head on. I knew it was going to be part of my work life, so why not master it now. Boy was I happy I took this approach. For the first time since doing a review I felt comfortable, confident and just about everything in between! 

I was paired up with a guy named Neil. He was patient and understanding when I didn't quite understand what was asked. He liked the way I answered his cultural interview questions. When it comes to personal experience and talking about things outside of code, I sometimes can't shut up, especially if it's about something I'm passionate about.

When it came time to code, I was nervous, but knew I had to do it. I was asked to change the state (React) and make it do something from the object. I knew how to do it, I just couldn't get my fingers typing to make it happen. But that is okay! I wanted to keep talking and explaining my thoughts, no matter how crazy or out there they were. I wanted to bounce thoughts off him and see if I was going in the right direction. 

The second technical question was on algorithms and solving something a palindrome question. This is where I was stumped. I had never solved something like this before. But that was going to stop me. I continued to talk and explain my process, even if I wasn't typing anything. Towards the end, I was right...sort of. I had the ideas and the thought process, but I just couldn't get the code and logic written correctly. 

Now, did I think I bombed it? NO! I was happy with the way I went through the challenges and thought I was way more confident than I initially thought. I think I got the success out of it, and that's what I wanted. Of course the review came back and said "Not passed" But to me, I did pass. I did find that confidence to keep growing and designing. It only comes with practice and repetition that things will get better and I will become more and more successful at this!
npm@6.13.6
Tags: npm, node, javascript, cli
Published: 2020-01-09 23:35:41

---
title: npm@6.13.6
published: true
description: Regular npm release with some patches
tags: npm, node, javascript, cli
cover_image: https://thepracticaldev.s3.amazonaws.com/i/oq83fs011p0oq9290xpr.jpg
---

We just shipped a new **npm** version :rocket:

Go ahead and get it in the usual ways:

```
npm install -g npm@latest
```

This release contain some bug fixes, including an important one that fixes issues using npm within **docker** containers to install new packages.

You can see the full changelog in the **npm** blog: https://blog.npmjs.org/post/190165702645/release-6136
Test composer packages locally
Published: 2020-05-07 23:57:41

---
title: Test composer packages locally
published: true
date: 2020-01-09 23:33:14 UTC
tags: 
canonical_url: https://dcblog.dev/test-composer-packages-locally
---

 ![Test composer packages locally](https://dcblog.dev/assets/images/blog/tutorials/composer/test-composer-packages-locally.png) 

When developing a new composer package you will want to test it locally before uploading it to Packagist.

First, create a composer.json file for your package, here's an example the important part is the autoload psr-4 which sets the namespace path and secondly the relative source path.

```php
{
    "name": "name of the package",
    "description": "short description",
    "autoload": {
        "psr-4": {
            "Daveismyname\\PdoWrapper\\": "/src"
        }
    },
    "minimum-stability": "dev"
}

```

The above example will autoload from a src folder, for this example, I have a Database class stored in a namespace of Daveismyname\PdoWrapper this matches the path in composer.json

```php
<?php
namespace Daveismyname\PdoWrapper;

use PDO;

class Database extends PDO
{

}
```

Now to use this the namespace would be imported and then the class can be called.

```php
require('vendor/autoload.php');

use Daveismyname\PdoWrapper\Database;

$db = new Database();
```

So far this is the starting process for building a package but to actually test it another project is required.

Create a folder to run this from ideally in the parent folder so both the project folder and the package folder are on the same level.

Next create a composer.json file, add the vendor/package name to require and autoload it, to make it work add a repositories array and pass in the local path to the package. This lets composer load the package from the local file system instead of from Packagist.

```php
{
    "name": "dc/demo",
    "description": "",
    "require": {
        "daveismyname/pdo-wrapper": "@dev"
    },
      "autoload": {
        "psr-4": {
          "Daveismyname\\PdoWrapper\\": "src/"
        }
    },
    "repositories": [
        {
          "type": "path",
          "url": "../pdo-wrapper-master"
        }
    ]
}

```

Run composer install

Now the class can be used like any other for example:

```php
require('vendor/autoload.php');

use Daveismyname\PdoWrapper\Database;

$db = Database();
```
Firebase 101: Realtime Database
Tags: softwareengineering, firebase, javascript, programming
Published: 2020-01-15 00:00:30

---
title: Firebase 101: Realtime Database
published: true
date: 2020-01-09 23:28:53 UTC
tags: software-engineering,firebase,javascript,programming
canonical_url: https://medium.com/swlh/firebase-101-realtime-database-58f975033e01
---

[![](https://cdn-images-1.medium.com/max/1600/1*3SgixYfUyTIMfj0qclSwNQ.jpeg)](https://medium.com/swlh/firebase-101-realtime-database-58f975033e01?source=rss-5676ca6163ee------2)

If you missed my previous post, Firebase 101: Authentication, I recommend starting there for a thorough explanation of what exactly…

[Continue reading on The Startup »](https://medium.com/swlh/firebase-101-realtime-database-58f975033e01?source=rss-5676ca6163ee------2)
Gatsby e o desafio de 100 dias
Tags: gatsby, javascript, tutorial, challenge
Published: 2020-01-09 23:23:10

Iniciei a "brincadeira" dos #100DaysOfGatsby e estou bem feliz com o novo "guri" da lista de milhares de frameworks/bibliotecas do mundo javascript.

No primeiro dia, fiz o [tutorial de iniciante deles](https://www.gatsbyjs.org/tutorial/), eles falam que demora até uma semana nessa brincadeira, mas em um dia sem serviço e louça pra lavar já dá pra ser feliz.

Tranquilo de instalar e de configurar, tutorial e documentação bem trabalhado, só tenho a elogiar, ainda mais que usei como desculpa para aprender GraphQL, este que já é "guri" grande e de grande reconhecimento de mercado, faz parte do "arsenal" usado pelo amigo Gatsby.

### Isto pode te economizar uma meia hora:
Tive um problema com os package manager da vida, ele meio que "se perde" quando se tem o npm e o yarn na máquina, para eu não ter problemas, usei apenas o yarn em tudo e em duas situações foi necessário excluir o `package.json`, a pasta `node_modules` e rodar `yarn install`, no mais trocando `npm install --save` por `yarn add` e `npm start` por `yarn start` deu conta do recado.
Why you should put in the time to automate your process.
Tags: devops, deployment, productivity, javascript
Published: 2020-01-09 22:37:19

CI/CD doesn't just save you time (and lots of it). there are a ton of other benefits:

1. stress: how many times have you been worried pushing the deploy button making sure you checked everything twice? 

2. cognitive load: why waste the space in your brain on all these repeat tasks? everything is the same every time!

3. forces better technical decisions: If you are building a feature that will effect production, or could be done in a way that would require manual intervention, CI/CD forces you to think about how to solve this problem in a way that is backwards compatible, can be automated, and wont break production if merged. this leads to more stable code

4. when all these are applied it causes your developer experience to be automated and gives devs the ability to merge often and liberally.
Coding with ADHD: How do You do it?
Tags: productivity, discuss, help, mentalhealth
Published: 2020-01-09 22:35:39

Time to get _vulnerable!_

![Awkward happy dance](https://media.giphy.com/media/Y8bL4lil6jive/giphy.gif)

I was recently diagnosed with ADHD. There. I said it. And it's been such a huge relief to know. I've struggled a long time trying to figure out exactly why I couldn't just _do_ things that I wanted to do. It's affected me as a student in college barely passing my classes and now as an adult internally fighting to sit down and do my work. I can now finally validate and put a name to that struggle.

I've still managed to get to the point where I am now: excited (and intimidated!) as I search for my first big role as a software engineer. But getting to this point took a lot of managing my ADHD symptoms.

Since I couldn't really find anything as well organized as a basic listicle on how other ADHDers managed their work in tech, I wanted to share the ways that I learned to manage my own, both in front of and away from my keyboard.

_But first_ I wanted to first ask the wider Dev community the big question and get some different advice and perspectives. So:

- **How do you do it? How do you manage your ADHD as a developer, engineer, or programmer?** 

But also...

- How do you plan out your work to ensure you're focused on the right tasks and not getting distracted?
- How do you manage your time to make sure you're spending the right amount of time on tasks?
- How do you get past the don't-wanna-work-on-it mental blocker?
- How do you prevent yourself from getting hyper-focused on that one little feature and then spending too many hours on it before realizing you've neglected other, more important, things?

Asking for a friend.
extract_credentials_provider': Cannot load `Rails.config.active_storage.service`: (Aws::Sigv4::Errors::MissingCredentialsError)

Published: 2020-01-09 22:30:22



Check followings

### seting to use credential.yml.enc with master.key in production
`config/environments/production.rb`
```ruby
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
config.require_master_key = true
```

### setting the credential.yml.enc
```sh
EDITOR="vim" rails credentials:edit
```

#### (you may need to install vim)
Dockerfile
```sh
## install vim
RUN apt-get update && apt-get install apt-file -y && apt-file update && apt-get install vim -y
```

### active_storage setting
`config/environments/production.rb`
```ruby
config.active_storage.service = :amazon
```

`config/storage.yml`
```ruby
amazon:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
  region: xxxxxxxxxxxxxxxxxx
  bucket: xxxxxxxxxxxxxxxxxx
```

Make it sure works on Rails console(local
```ruby
[1] pry(main)> Rails.application.credentials.dig(:aws, :access_key_id)
"xxxxxxxxxxxxxx"
```

### switch the setting of the strage strategy on Development
to make sure S3 setting is right.

If it works completely, the problem must be in Heroku.
```ruby
  # Store uploaded files on the local file system (see config/storage.yml for options).
  # config.active_storage.service = :local
  config.active_storage.service = :amazon
```

### put the value of master.key into Heroku config
```sh
heroku config:set RAILS_MASTER_KEY=`cat config/master.key`
```
Javascript(Beginner's first language)
Tags: javascript, python, beginners, webdev
Published: 2020-01-09 22:25:38

What would be a very good first language for a programming beginner to learn and I know most times people say it depends, but I would really love to get others' perspectives 

I tend to lean more on the javascript side of the fence since that was my first language, maybe I am biased. 

I feel it gives enough of a programming structure and flexibility that you could easily get things done and when you want to try other languages it wouldn't be that much of a problem?
TIL: In CSS, DarkGray is lighter than Gray
Tags: todayilearned, css, webdev
Published: 2020-01-09 21:47:54

*When building prototypes or examples, I often use named CSS colors.*


After playing around and working with CSS for some years, today I learnt:

**DarkGray is lighter than Gray 🤔**

It got me so confused, I had to check it three times.

The easy solution:
If you want a "dark gray", choose `DimGray`.☝️
What would you like to know about CSS?
Tags: question, css, webdev, learning
Published: 2020-01-09 21:32:19

Hey, my front-end-friends!

There are many css tutorials and code-snippets out there, but maybe *you* got a topic that is not covered or just didn't find the right solution?

**Tell me in the comments, what you would like to know about CSS.**

Hopefully I later can explain it in a short posting or other nice web-devs will give you some hints/links/examples.

**Let's share our knowledge! 🙌**
Tips to implement Gradle Plugin
Tags: groovy, gradle
Published: 2020-01-09 20:59:13

---
title: Tips to implement Gradle Plugin
published: true
description: Tips to implement Gradle Plugin
tags: Groovy, Gradle
---

Now I'm implementing [a new Gradle Plugin](https://github.com/KengoTODA/spotbugs-gradle-plugin-v2). [The official document](https://gradle.org/guides/?q=Plugin%20Development) is really nice, and I wish my experience will help you to code yours.

## Use groovy for extension and task

The extension is a major way to configure your plugin. It's a class that uses [Property and Provider](https://docs.gradle.org/current/userguide/lazy_configuration.html) as its fields, then users can set values like below:

```groovy
extension {
  intProp = 10
  fileProp = file('config.yml')
  listProp = [ 'bar', 'baz' ] 
}
```

Groovy helps you to generate necessary accessors, so what you need is simply private final fields:

```groovy
class MyExtension {
    @NonNull
    final Property<Boolean> boolProp;

    @Inject
    MyExtension(ObjectFactory objects) {
        boolProp = objects.property(Boolean).convention(false)
    }
}

class MyTask extends DefaultTask {
    @Input
    @NonNull
    final Property<Boolean> boolProp;

    @Inject
    MyTask(ObjectFactory objects) {
        extension = project.exntensions.getByType(MyExtension)
        boolProp = objects.property(Boolean).convention(extension.boolProp)
    }
}
```

## Always prefer lazy-approach

For better performance, we need to learn about [build lifecycle](https://docs.gradle.org/current/userguide/build_lifecycle.html), or face performance problem like [this](https://github.com/spotbugs/spotbugs-gradle-plugin/issues/165).

Prefer the lazy-approach. Pick APIs that lets you specify a `configurationAction` as its parameter like [TaskContainer#register(...)](https://docs.gradle.org/6.0.1/javadoc/org/gradle/api/tasks/TaskContainer.html#register-java.lang.String-java.lang.Class-org.gradle.api.Action-).

Refer [the official document](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html) for detail.

## Understand the difference between getXxx() and findXxx()

In Groovy modules, methods named `getXxx()` throw an exception if you found nothing. On the other hand, methods named `findXxx()` return `null` (not `Optional`!).

So when you expect that you always find the value (e.g. get the extension created by your plugin), use `getXxx()`. Otherwise, prefer `findXxx()` and check the nullness of returned value.


# Worker API

To run heavy computations like static analysis, it is better to use [the Gradle Worker API](https://guides.gradle.org/using-the-worker-api/).

In my case, I need to launch a JVM process to kick [SpotBugs](https://spotbugs.github.io/), and it makes build especially in multi-module projects. Here is the result of [my benchmark](https://github.com/KengoTODA/spotbugs-gradle-plugin-v2/issues/15#issuecomment-572515786):

![Benchmark Result](https://thepracticaldev.s3.amazonaws.com/i/rdqfwnnzaz7qek0cv8po.png)

It requires Gradle 5.6+ but is actually valuable. You may have a try :)