teleren/devto huggingface dataset:
Day 4 - API w/MongoDB: Wine App Part II
Tags: codenewbie
Published: 2020-09-17 19:58:20

This was a long time coming! I have wanted to build a Nodejs server with MongoDB and decided to learn it today to build out the web server for the bigger wine application project.

![postman](https://media.giphy.com/media/d3KAVJVJdSnAadYhLQ/giphy.gif)
<figcaption>Postman Preview</figcaption>

My training is in full-stack engineering and my marketing background involved working with SQL. So I'm just as interested in NoSQL databases and finding out how they work. It was also today that I learned NoSQL stands for "Not Only SQL" and not "No SQL".

![learning](https://media.giphy.com/media/83QtfwKWdmSEo/giphy.gif)


## What I Learned

I worked on setting up MongoDB, making connections, building a simple schema and routes today. From my experience in building this server, I know I will enjoy using MongoDB because of it's advantages such as cloud hosting and flexible schemas. For sandboxing, I am not ashamed to use GUIs and it's awesome that Mongo has related products in one place. 

## How This Will Help Me

In terms of skillset, I know I just expanded on my database knowledge. But I think the bigger question is how can I effectively figure out which database to use in order to handle optimized requests? I will definitely be doing a lot of reading (or Googling) in the next coming days. I am taking the time to enjoy the feeling of being Dr. Frankenstein on pulling this off in a few hours.

![it's alive](https://media.giphy.com/media/4EIOCwkztiPhS/giphy.gif)

Also, I am looking forward to connecting the frontend version of this wine app to the server!

Onto the next challenge!
What are your favorite subscriptions?
Tags: watercooler, discuss
Published: 2020-09-17 21:08:57

---
title: What are your favorite subscriptions?
published: true
description: I'm looking for monthy-ish subscription recommendations!
tags: watercooler, discuss
//cover_image: https://direct_url_to_image.jpg
---

What are the monthly-ish subscriptions (boxes, shipments, or online services) that bring you joy?
Good Idea or Bad Idea
Tags: discuss, question, feedback
Published: 2020-09-17 21:04:30

Had an idea I needed to get out of my head. This was the result. I can't tell if this is a good idea or not worth my time. 

Is it useful to anyone? Is it useful to me? I can't tell at this point. Thought I would ask for some feedback and maybe more ideas. 

Basically, it's just an executable I have running on a timer (Windows Task Scheduler). 

* The Greeting on the left changes throughout the day
* The Date in the middle obviously changes only once a day
* The weather data can be loaded from one of two sources at the moment ([OpenWeather](https://openweathermap.org/api) and [WeatherBit](https://www.weatherbit.io/api))
* The Priority items is pointed at a specific Trello list and pulls in the cards and description from that list
* The primary background is just a simple background image
* The background, colors and fonts _can be_ configurable

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fuxkcwkkqjhbxmybfatt.jpg)

I thought maybe...
* There could be three columns in the lighter gray area but not sure what the other two columns would be (calendar might be nice)
* I have plenty of room below the focus area to use up, but this is calculated based on the user's screen size
* Might be cool if it could take multi-monitor setups into account

Your thoughts?
How to extend and use an extended Request type in Typescript / Express?
Tags: help
Published: 2020-09-17 20:47:51

---
title: How to extend and use an extended Request type in Typescript / Express?
published: true
tags: help
---

How to extend and use an extended Request type in Typescript / Express?

I'm adding a BUNCH of middleware libraries that extend the Request Object. I.E. One added user to req. Another add cookie() to req. Another add csrfToken() to req. etc..

When I add a request handler function, how do I tell that function to use the req with all the bells and whistles added by middleware?

Do I hunt down every DefinitelyTyped package corresponding to the middleware? If so, then will the Request type be magically 'decorated` with these properties?

To make it even harder, I've written my own middleware that adds properties to Request

`req.myCustomFunction()`

In this case, will I need to declare, and extend the Request myself with myCustomFunction?

In addition, will that Request which I am extending 'include' the types given by DefinitelyTyped?

```
declare namespace Express {
  export interface Request {
    myCustomFunction: () => void
  }
}
```

Will this now include ALL the properties included via DefinitelyTyped AND my myCustomFunction?

How do I reference this interface when using?

Will it be Express.Request? Or just Request?

If I reference it as Request, how does Typescript know to use "my" Request and not the one exported by Express's DefinitelyTyped library?


```
declare namespace Express {
  export interface Request {
    import_destination?: string;
    isZipImport?: boolean;
    method: string;
    originalname: string;
    unzippedPath?: string;
    url: string;
    user?: TUser;
  }

```

DOES NOT WORK

```
declare module global {
  interface Request {
    file?: FileObj;
    files?: FileObj[];
    user?: TUser;
    isZipImport?: boolean;
    unzippedPath?: string;
  }
}
````
DOES NOT WORK

```
declare global {
  declare module 'express' {
    export interface Request {
      file?: FileObj;
      files?: FileObj[];
      user?: TUser;
      isZipImport?: boolean;
      unzippedPath?: string;
    }
  }
}
```

DOES NOT WORK

```
declare namespace Express {
  export interface Request {
    user?: TUser;
    isZipImport?: boolean;
    unzippedPath?: string;
  }
}

````

DOES NOT WORK


I'm seriously pulling my hair out trying to get this work. 
WHY WHY WHY.. is this so complicated to make work????
Day 63: Fetching Icons from Open weather
Tags: 100daysofcode
Published: 2020-09-17 20:46:16

I worked on fetching icons from open weather to autoupdate my app. 
```html
<div class="left">
      <img id="weatherIcon" src="" alt="">
 </div>
```
```javascript
let icon = data.weather[0].icon
const img = document.querySelector('#weatherIcon');
img.setAttribute('src', `http://openweathermap.org/img/wn/${icon}@2x.png`)
```
I also fetched the icons and data for the next seven days.
```javascript
	await axios(`https://api.openweathermap.org/data/2.5/onecall?lat=33.441792&lon=-94.037689&exclude=hourly,minutely,current&appid=`,{
			"method": "GET"
		})
		.then(response=> {
			let data = response.data
			console.log(data)

			
			data.daily.forEach(day => {
				let icon = day.weather[0].icon

				const section = document.querySelector('.section3');
				const card = document.createElement('div')
				card.setAttribute('class','card')
				section.appendChild(card);

				const p = document.createElement('p')
				p.textContent = 'nextDay'
				card.appendChild(p)

				const innerCard = document.createElement('div')
				innerCard.setAttribute('class','innerCard')
				card.appendChild(innerCard)

				// const innerCard = document.querySelector('.innerCard')
				const img = document.createElement('img')
				img.setAttribute('src', `http://openweathermap.org/img/wn/${icon}.png`)
				innerCard.appendChild(img)

				const temp = document.createElement('p')
				temp.textContent = `${Math.round(day.temp.day - 273.15)}°`;
				innerCard.appendChild(temp)

				const weather = document.createElement('p')
				weather.textContent = day.weather[0].main
				innerCard.appendChild(weather)

			});

		})
```
_Day 63_
What is the JavaScript version of sleep()?
Tags: sleep, async, await, javascript
Published: 2020-09-17 20:39:58

There is no `sleep` `function` in JavaScript, but with `async`/`await` syntax it is very easy to implement.

If we need to mimic behavior like this written in `c` code.

```c
#include<stdio.h>
 
main() {
   printf("Sleeping for 1 second.\n");
   sleep(1);
   return 0;
}
```

Using `async`/`await` syntax it is very simple.

```javascript
const sleep = (timeout = 1) => new Promise((resolve) => {
  setTimeout(resolve, timeout * 1e3);
});

console.log('before sleep');
await sleep(1);
console.log('after 1 second!');
```

You can also use milliseconds version.

```javascript
const sleepMs = (timeout = 1e3) => new Promise((resolve) => {
  setTimeout(resolve, timeout);
});

console.log('before sleep');
await sleep(1000);
console.log('after 1000 milliseconds!');
```
Using github Workflow to Recognize Community Contributions 
Tags: actionshackathon
Published: 2020-09-17 20:38:42

### My Workflow
Leader-board for Community Contributions
Actions Used:
- checkout
- setup-python
- peter-evans/close-issue
- peter-evans/create-or-update-comment

### Submission Category: 
 Wacky Wildcards


### Yaml File or Link to Code
 `{% github https://github.com/devcpune/Awesome-DevC-Contributors/blob/master/.github/workflows/main.yml %}` 

### Additional Resources / Info

 Workflow is currently in use by [Awesome-DevC-Contributors](https://github.com/devcpune/Awesome-DevC-Contributors)
[Journey of the Leaderboard workflow](https://dev.to/shriaas2898/how-i-used-github-workflow-to-recognize-community-contributions-30oc)
How I used github workflow to recognize community contributions(Part-1)
Tags: actionshackathon, github, workflows, leaderboardworkflow
Published: 2020-09-17 20:36:14

Recently Developer Circles Facebook has concluded its Open Source Immersion Program, and we at DevC Pune thought to make a repository to recognize all the PRs made by the community during this program and decided to make a repository which has leader-board for the same, but collecting all the data was difficult and there comes GitHub workflows to the rescue which made ease the process of collecting data about PR and publishing on the repository. Enough with the stories! Let's talk about what we actually did.

Before starting let's understand what is a **workflow** and  how it works.

## What is a GitHub Workflow?

A **GitHub Workflow** is a mechanism used for automating your projects life cycle, remember event handling in other languages like Java, JavaScript etc? Yep this is the same just with **GitHub events**. 
- Instead of `onClick`, `onHover` etc we have events like: `PR opened`, `Issue opened`, `Issue edited` etc.
- When an event occurs, the workflow has a list of `jobs` to be executed, in a job we can do some processing, and use some `actions`, which are just like functions in our regular programming language.

## How does a GitHub Workflow works?

Every workflow needs to have a `.yml` which contains various sections of identifying the event and list of jobs reacting based upon the event. The yml file can even call another script to do some processing. When a job is executed it creates an instance of you repo on cloud, like a docker image, and now this is instance is just like a copy of your repo on a local machine, once you are done with processing you have to push the changes back to GitHub to see the changes. So you can use this instance to to perform anything which you do on your terminal.


### Creating a yml file
- In the first line we have to specify the name of the workflow:
```yml
name: add-project
# This workflow gets executed when someone opens an issue for adding a project
```
You can also add some comment to describe what that workflow is doing.
- We can define an event on which a workflow will be triggered like this:
```yml
on:
  issues:
      types: [opened,edited]
```
Now comes the list of `jobs`, we can define a `job` as:
```yml
jobs:
  add_project_job:
    if: startsWith(github.event.issue.title, 'add|')
    name: add-project
    runs-on: ubuntu-latest
    steps:
```
Here `add_project_job` is the name of job. We can also specify condition which decides if certain job will be executed or not.
The `runs-on` parameter specify the environment which will be created to run the job. Next we have to define steps which will be executed inside a job.


And that is the basic structure of a GitHub workflow. We'll discuss the whole workflow in detail in the next part! Till then keep automating!

### References:
[Official Documentation](https://docs.github.com/en/actions/learn-github-actions)
[Link to Full Code](https://github.com/devcpune/Awesome-DevC-Contributors/blob/master/.github/workflows/main.yml#L29)
Github CLI 1.0 released 🎉 
Tags: github, opensource, news
Published: 2020-09-17 19:58:52

Github has recently released Github CLI which will help us to easily create workflows from the terminal with the aim of less context switching.

It provides the following benefits which will help you in several ways
* Run the entire workflow, from issues through releases.

* Call Github API to script any action, and set custom alias for any command.

* Connect to enterprise server in addition to Github.com

## Installation

It can be installed on **Windows**, **macOS**, and **Linux**

On macOS, it can be easily installed using **Homebrew** or **MacPorts** using the following commands.

#### Homebrew
```bash
brew install gh
brew upgrade gh
``` 

#### MacPorts
```bash
sudo port install gh
sudo port selfupdate && sudo port upgrade gh
``` 

For Linux, you can follow the [installation process here](https://github.com/cli/cli/blob/trunk/docs/install_linux.md).

Windows installation can be done using **scoop**, **Chocolatey**, and as [downloadable MSI](https://github.com/cli/cli/releases/tag/v1.0.0).

## Commands (the interesting part 🤔 )

After a successful installation, you need to authenticate your Github account.

To authenticate your account use the following command. Series of steps will be followed to complete your authentication process.

```bash
gh auth login
```
After authentication, you can use the GitHub CLI 🥳 

With the help of commands that come with Github CLI, you can easily achieve the tasks required to be done using the browser.

I found the following things pretty useful to done using CLI 😉
 
* Creating and forking your repo

* Create, delete upload, download and manage your release.

* Create, review and check the status of your PR.

* Open, review, tag, create and check the status of all the issues or the ones specifically assigned to you.

* Create gist using a specific file or multiple files.

* Make a request to Github API and print the response.

* Generate shell scripts for Github CLI commands.

* Set up aliases for most used GitHub commands.

You can find more details about the commands and setup process here.

{% github cli/cli %}

I am excited to explore more about Github CLI as this will make my work a bit easy with less context switching and I'll be able to concentrate better without switching desktops 😜
IBM Data Science Capstone: Car Accident Severity Report
Published: 2020-09-17 20:20:23

**Introduction:**
To reduce the frequency of car collisions in a community, an algorithm must be developed to predict the severity of an accident given the current weather, road, and visibility conditions. When conditions are bad, this model will alert drivers to remind them to be more careful.

**Business problem:**
The purpose of this project is to analyze the collision dataset for the city Seattle and find patterns, also determine key factors such as weather, light and road conditions, drug or alcohol influence, to provide the best traffic accident severity prediction. 

**Data Understanding:**
We will use SEVERITYCODE as our dependent variable Y, and try different combinations of independent variables X to get the result.

**Methodology:**
The data is now ready to be modeled. 

**K-Nearest Neighbor (KNN)**
KNN will help us predict the severity code of an outcome by finding the most similar to data point within k distance.

**Decision Tree**
A decision tree model gives us a layout of all possible outcomes so we can fully analyze the consequences of a decision. Its context, the decision tree observes all possible outcomes of different weather conditions.

**Logistic Regression**
Because our dataset only provides us with two severity code outcomes, our model will only predict one of those two classes. This makes our data binary, which is perfect to use with logistic regression.

Initialization: 
![Screen Shot 2020-09-17 at 9.58.19 PM](https://dev-to-uploads.s3.amazonaws.com/i/igg8rmgjkd039fn3t8l2.png)

Normalizing the data: 
![Screen Shot 2020-09-17 at 10.00.21 PM](https://dev-to-uploads.s3.amazonaws.com/i/f70j422wk5vqsmd8e5wr.png)

Train/Test Split:
![Screen Shot 2020-09-17 at 10.01.26 PM](https://dev-to-uploads.s3.amazonaws.com/i/sxtmz8v8ju9xus0rohb4.png)

Then we modeled the data using 3 different machine learning algorithms: KNN, Decision tree, and Logistic regression.


Results & Evaluation: 
Then we checked the accuracy and found out that the Decision tree is the most accurate model. 

**Discussion:**
Most crashes happened in clear, dry, and bright conditions. Most days are clear, dry, and bright, so it’s no surprise that most car crashes occur under these conditions. I also found out that crashes with a distracted driver or an impaired driver are statistically more likely to result in injury, which is also not a surprise. The results of the data indicate to city officials that they should ask drivers to be more alert in ideal conditions.

**Conclusion:**
Based on historical data from weather conditions pointing to certain classes, we can conclude that particular weather conditions have a somewhat impact on whether or not travel could result in property damage (class 1) or injury (class 2).
What Netlify got wrong
Tags: javascript, devops
Published: 2020-09-17 20:14:18

I love Netlify. Netlify have helped me save thousands of minutes during my career. Previously I'd been using huge virtual machines and then complicated AWS S3 to host my frontend sites. But when I met Netlify it was intense love. We saw each other every day and every minute. Netlify's only focus was my prosperity.

But then came a day. She was coming home with a big bloat of stuff; AWS Lambda, Forms, Identity, plugins, etc. A bunch of features that I didn't need at all. And then I started to run into different bugs/problems in the build environment. I took a few steps back and saw that Netlify never was the perfect one.

With a bit perspective it seems clear that Netlify's main purpose isn't frontend hosting, but instead to be a service minded problem solver for website builders. As a software company you can choose to either do one thing well or everything okay, and I think Netlify is the latter. And that's fine, many people want it that way, just look at AWS.

But my requirements are quite different, I want it simple and easy:

* Be able to run jobs before and after deployment.
* Build environment should only be configured once.
* Possibility to easy rollback the release if the e2e test failed.
* The whole CD process should be monitored from the CI environment.

And to find that I have to search further. Thanks for everything, Netlify.
A GitHub Action to Build Modular Android Projects
Tags: actionshackathon, github, opensource
Published: 2020-09-17 20:01:36

---
title: A GitHub Action to Build Modular Android Projects
published: true
description: My submission to the GitHub Actions x DEV Hackathon!
tags: actionshackathon, github, opensource
---

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon, please fill out all sections.)


### My Workflow

As most Android Developers know, an [Android Project](https://developer.android.com/studio/projects) may have many
 different modules.
 
If you change one single module and submit a Pull Request, most CI workflows will try to build/test all the existing modules, which might take a lot of time, when in reality you only need to build the module you changed.
 
This GitHub Action aims to solve that problem. When you submit a Pull Request, it will only build the module you changed,or no module at all if you left them untouched (in case of documentation or configuration changes).

#### Real Project Showcase

Take a look at this project I forked: [quickstart-android](https://github.com/rosariopfernandes/quickstart-android). It contains many different modules (admob, analytics, database, etc).

I made a change to the database module and sent a Pull Request:

{% github https://github.com/rosariopfernandes/quickstart-android/pull/11 %}

GitHub Actions built the `database` module only and finished in 4m 40s, as seen in the [log](https://github.com/rosariopfernandes/quickstart-android/runs/1130510216?check_suite_focus=true).

Building the whole project generally takes around 17min, as seen in this [log](https://github.com/rosariopfernandes/quickstart-android/pull/11/checks?check_run_id=1130502965).

### Submission Category: 
Phone Friendly


### Yaml File or Link to Code
{% github https://github.com/rosariopfernandes/modular-android-action/ %}

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)


### Additional Resources / Info

- Inspired by the blog post ["Selectively running Android modularized unit tests on your CI server"](https://overflow.buffer.com/2019/12/20/selectively-running-android-modularized-unit-tests-on-your-ci-server/) by [Joe Birch](https://twitter.com/hitherejoe).
- I've previously written a [blog post](https://dev.to/rosariopfernandes/run-android-modularized-builds-selectively-on-github-actions-4jp1/) describing how I adapted Joe's code for GitHub Actions.
- The Projects bellow are already using this workflow:
    - [firebase/quickstart-android](https://github.com/firebase/quickstart-android/)
    - [firebase/snippets-android](https://github.com/firebase/snippets-android/)

[Note]: # (Be sure to include the DEV usernames of your collaborators, if any. )

[Reminder]: # (Submissions are due on September 12th (11:59 PM PDT) and winners will be announced on September 23!)
Using GitHub CLI v1.0
Tags: github
Published: 2020-09-17 19:59:41

Github CLI v1.0 has been released and is available for download on Linux, MacOS, Windows machines

#### With Github CLI v1.0, you are able to:
- run entire github workflow from the terminal
- set a custom alias for any command
- connect to github enterprise server 2.20+

#### Installation/Setup
##### MacoS
```bash
brew install gh
```

##### Linux

```bash
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh
```
##### Windows
- via scoop
```bash
scoop bucket add github-gh https://github.com/cli/scoop-gh.git
scoop install gh
```
- via chocolatey
```bash
choco install gh	
```
#### Managing Github repository using github cli
- Initialize private repository
```bash
gh repo create <name>
```
- Initialize a public repository
```bash
gh repo create <name> --public
```
- Clone remote repository
```bash
gh repo clone <repository-url>
```
- Fork repository
```bash
gh repo fork
```

#### Managing Pull requests using github cli
- Create pull request
```bash
gh pr create
```
- Checkout pull request
```bash
gh pr checkout {<pull request number> | <url> | <branch>} [flags]
```
- View the Diff
```bash 
gh pr diff
```
- Check all tests are passing
```bash
gh pr checks
```
- Merge pull request
```bash
gh pr merge
```

#### Manage Aliases with github cli
- Create aliases
```bash
gh alias set
```
- Share your aliases with a gist
```bash
gh alias list | gh gist create
```

#### Manage Issues with github cli
- Create a new issue
```bash
gh issue create
```
- List issue
```bash
gh issue list
gh issue list --state closed
```
- View status of issue
```bash
gh issue status
```
### Resources
- [GitHub CLI 1.0 is now available](https://github.blog/2020-09-17-github-cli-1-0-is-now-available/)