teleren/devto huggingface dataset:
Rest Parameters
Tags: javascript, es6
Published: 2020-03-19 18:56:09

Rest parameters are a feature introduced in ES6. They allow us to represent any indefinite number of arguments in a function as an Array. 

To use this new syntax, you can simply prefix the parameter with `...` and this will create an array with all the user supplied arguments. In the `restDemo` function below I simply return the parameters:
```javascript
const restDemo = (...parameters) => {
  return parameters;
};

console.log(restDemo(2, 3));
// expected output: [2,3]

console.log(restDemo(1, 2, 3, 4, 5));
// expected output: [1,2,3,4,5]

console.log(restDemo('hi'));
// expected output: ['hi']
// Rest parameters will put even a single element into an array

console.log(restDemo());
// expected output: []
// If no elements are passed it is defined as an empty array
```

Now, lets consider a simple use case for rest parameters. The `add` function below takes any number or arguments as input and returns their sum. I am using ES6 array method `reduce` here to add the values.
```javascript
const add = (...numbers) => {
  return numbers.reduce((n, sum) => (sum += n), 0);
};

console.log(add(2, 3));
// expected output: 5

console.log(add(1, 2, 3, 4, 5));
// expected output: 15
```

Also, an important thing to note is that rest parameters can only be applied to the very last argument of a function. Consider some functions as below, the `firstFunction` passes the second parameter `b` as a rest parameter. This will throw an error. 
```javascript
const firstFunction=(a,...b,c)=>{
  // some code
  // this will throw an error
}
```

While the `secondFunction` passes the third(and last) parameter `c` as a rest parameter. This will put all the parameters after the first two into an array. 
If only two parameters are passed `c` will be defined as an empty array.
```javascript
const secondFunction=(a,b,...c)=>{
  // some code
}

// Examples
secondFunction(1,2) // a=1, b=2 ,c=[]

secondFunction(1,2,3,4) // a=1, b=2 ,c=[3,4]
```
Can I Use replace() method to autoreplace all the chosen strings within a user input box of text type in js?
Tags: help, javascript, html
Published: 2020-03-19 18:49:20

Let's say there is a long-*ss paragraph, and some words in it are issues to copyright, so custom replacements are needed to all strings in p or span tags. By the way, it can be also a user-inputted text that is to be changed to fit the rules. Now, can i create a function with replace() method, and, is it possible to change the strings automatically by ".onclick"-ing on <input type = "button">? Pls provide a fully functional code of both <!DOCTYPE html> '/html' and 'script' '/script'.
Trailing URL Slashes in Django
Tags: django, python, tutorial, beginners
Published: 2020-03-19 18:44:28

Among Django's many built-in features is [APPEND_SLASH](https://docs.djangoproject.com/en/dev/ref/settings/#append-slash), which by default is set to `True` and automatically appends a slash `/` to URLs that would otherwise [404](https://en.wikipedia.org/wiki/HTTP_404).

**Note**: The Chrome web browser automatically appends a trailing slash `/` to URLs so you'll need to use something like Safari to see this in action.

For example, within the Admin of any Django project, if you wanted to see "Users" the full route is `http://127.0.0.1:8000/admin/auth/user/` but if you instead typed into your web browser `127.0.0.1:8000/admin/auth/user` (notice no `/` at the end there!), it automatically redirects to `http://127.0.0.1:8000/admin/auth/user/`.

And if you look at the logs in your command line, you'll see something like the following which shows a [301 redirect](https://en.wikipedia.org/wiki/HTTP_301) was perfored my Django to append the slash.

```
[19/Mar/2020 15:49:44] "GET /admin/auth/user HTTP/1.1" 301 0
[19/Mar/2020 15:49:44] "GET /admin/auth/user/ HTTP/1.1" 200 6596
```

Now let's turn off the default setting to confirm that Django is performing this action for us. Within your `settings.py` file, add the following line at the bottom:

```python
# settings.py
APPEND_SLASH = False
```

The local Django webserver will automatically restart to reflect the changes. Try again to refresh the web page for the User section of the admin without the trailing slash: `127.0.0.1:8000/admin/auth/user`.

The result? A 404 page! Because we've turned `APPEND_SLASH` off. 

![404 Page](https://dev-to-uploads.s3.amazonaws.com/i/8mo9mir2fo3vwmsiy1rm.png)

You can see this in the logs as well.

```
[19/Mar/2020 15:53:41] "GET /admin/auth/user HTTP/1.1" 404 3869
```

Therefore as a practical matter make sure that you include a `/` at the end of your Django URLs. You don't _have_ to but absent this nice built-in feature--or Chrome--you'll receive unexpected errors.

Special thanks to [Carlton Gibson](https://twitter.com/carltongibson) for help on this topic and suggesting the Admin example.
Announcing You Got This 2020: From Home
Tags: event, conference, online
Published: 2020-03-19 18:42:02

---
title: Announcing You Got This 2020: From Home
published: true
description: Today we're announcing a free, online version of our popular core skills conference.
tags: event, conference, online
---

We hope you, your family and friends are keeping safe. While health comes first and always will, it sucks that many events have needed to postpone or cancel in light of recent events. The organizers of the UK and New York You Got This events have decided that we can at least try and provide some useful content to fill the void.

![](https://dev-to-uploads.s3.amazonaws.com/i/l0kngscqfnv02d5pedh3.png)

Enter [You Got This 2020: From Home](https://home.yougotthis.io). It’s a free, one-day and fully-online version of You Got This that we’ve just announced to be happening on June 6 2020.

8 great speakers on a range of topics around core skills (to be announced), live captioning, and we’re mailing out stickers to folks who register.

So please do sign up and encourage your friends and colleagues to register.

Finally, we’re looking for a few sponsors. If you work at a company that might be interested - please get in touch and let us know.
Java 8 - Lambda Expression 101
Tags: java, lambdaexpression, functional
Published: 2020-03-19 17:57:11

One of the biggest changes in Java 8 was lambda expression. The main reason to bring lambda expression to Java is to bring the benefit of functional programming into Java. 

##What is Lambda Expression?

It is a <strong>concise</strong> representation of <strong>anonymous functions</strong> that can be <strong>passed around</strong>. Unlike methods, it is nameless and is not associated with the particular class. It can be passed as an argument to a method or stored in a variable. Lambda expression is said to be a concise representation since there is no need to write boilerplate code as we do for anonymous classes.


##Convert method into Lambda Expression

It is really very easy to convert a method into a lambda expression. Following are some rules:
* **Remove the name**
* **Remove the return type**
* **Remove the modifier**
* **Add the arrow symbol(->)**

####Example 1:

Let’s take the following method,

```java
public void sayHello() {
    System.out.println(“Hello”);
}
```
After removing the name, the return type and the modifier from the above method, 

```java
() {
	System.out.println(“Hello”);
}
```
But to make it a valid lambda expression, we need to add a special symbol, 
 ->. Hence the above method becomes:
```java
() -> { System.out.println(“Hello”); }
```
The above is the valid lambda expression. But we can concise the above lambda expression even more. If we have only one statement in the body of lambda expression, curly brackets are optional.
```java
() -> System.out.println(“Hello”);
```
**_Note: If multiple statements are in the body of the lambda expression then the curly bracket is mandatory._**

___
IPFS:🦠Pandemic resilient infrastructure
Tags: ipfs, decentralized, covid19
Published: 2020-03-19 18:30:47

---
title: IPFS:🦠Pandemic resilient infrastructure
published: true
description: The importance of distributed filesystems during CoVid-19 Pandemic 
tags: ipfs, decentralized, covid19
---
This is a unique moment for Humanity, that will touch everyone. "Shoulder to shoulder" (social distanced) we will support each other.

Remote working is now mandatory for many nations and #StayAtHome 🏠 is the most important strategy against [SARS-CoV-2](https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public), flattening the curve of CoViD-19 cases, but this move will stress the Internet infrastructure.

![IPFS Logo](https://dev-to-uploads.s3.amazonaws.com/i/b0jgha09e5nkf71m4j02.jpg)

One thing we can do about this is to use [IPFS](https://ipfs.io/) (The InterPlanetary File System) and other distributed filesystems to store and safeguard relevant public health literature, e.g. situation reports, guidelines, scientific papers. In the case of network intermittence, we will all have this data available.

Here are some examples:

*World Health Organization CoViD-19 Situation Reports*
[QmPaidwPiMKfqgdz9f39hKdM4rcgJBymRYTHtxgKG1tR2A](https://ipfs.io/ipfs/QmPaidwPiMKfqgdz9f39hKdM4rcgJBymRYTHtxgKG1tR2A)

*WHO Coping with stress during the 2019-nCoV outbreak*
[QmTWsDwfRvmLbG1vs2c3UncZXCGFBNTv1jcPvTNaZaNxZ5](https://ipfs.io/ipfs/QmTWsDwfRvmLbG1vs2c3UncZXCGFBNTv1jcPvTNaZaNxZ5)

*Portugal CoViD-19 Situation Reports*
[QmYCoAKArCKLQAwzYQ2VdYnL4dP9tCrhD97JQuqUQCBqAb](https://ipfs.io/ipfs/QmYCoAKArCKLQAwzYQ2VdYnL4dP9tCrhD97JQuqUQCBqAb)

It doesn't stop here, your creativity will find more use cases.

Set up your node, [get started today](https://ipfs.io/#get-started).
Building 3rd party JARs in Spring (Maven project)
Tags: java, ttodayilearned
Published: 2020-03-19 18:21:33

I had an external `.jar` that cannot be imported from public repositories using pom.xml, it's `XPTO.jar`.

I was able to run the project locally from my IDE and everything worked perfectly. Refer to the library after downloading it as follows:
```xml
<dependency>
    <groupId>com.xpto.lib</groupId>
    <artifactId>XPTO</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/XPTO.jar</systemPath>
</dependency>
```
#### When I run mvn clean package to create my `.jar` file and try to run the created `.jar`, an error will pop up.

![](https://media2.giphy.com/media/jN86rcdOyrpyo/giphy.gif?cid=790b7611c4135decda7cebc5c00a6de2af0736c98637ddae&rid=giphy.gif)

I was facing this error and  about getting crazy before finding this solution.

# Miracle Solution  🙆‍♂️🙆‍♀️
![](https://creepyfunnyxd.tumblr.com/post/45791598475)

In your `pom.xml` just add this `<includeSystemScope>true</includeSystemScope>` like this
```xml 
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <classifier>exec</classifier>
            <includeSystemScope>true</includeSystemScope>
        </configuration>
    </plugin>
</plugins>
``` 
#### The IDE can easily see the scope of the system by default, however when generating our build we have to force the maven to see this same scope.
wal-e Postgres Backups - Building SaaS #32
Tags: python, django, saas, postgres
Published: 2020-03-19 18:04:08

{% youtube bValji0iK6s %} In this episode, we worked on Postgres database backups and modified the backup tool, wal-e, to use the Shiv app format.

[wal-e](https://github.com/wal-e/wal-e) is Postgres database backup tool that works by managing the Write-Ahead Log (WAL) that a Postgres database produces.  The WAL is the log of recent changes that happened in the database.  If you have access to a full WAL, then you can conceivably reproduce a Postgres database's data.

When I switched the deployment to use a Shiv app, we now have to remove every use of the existing virtual environment in the system.  The `wal-e` executable is installed in the `bin` directory of the virtual environment so we need another way to access it.

The way that the Shiv app can execute other binaries is with the `[SHIV_ENTRY_POINT](https://shiv.readthedocs.io/en/latest/#shiv-entry-point)` environment variable.  Using the setuptools-style link of `wal_e.cmd:main`, we can run the wal-e executable that is available to the Shiv app.  Because I already use the `envdir` command, we only had to make two changes:

1. Replace `{{ venv_path }}/bin/wal-e` with `/srv/apps/conductor.pyz`.
2. Add a `SHIV_ENTRY_POINT` file to `/etc/wal-e/env` with the appropriate setuptools-style value.

Once we made the changes, I deployed things to the staging site with Ansible.  From there, we verified that the cron entry was changes with:

```bash
$ sudo su -  # change to root
$ su - postgres  # change to postgres account
$ crontab -l  # list cron entries
```

With the wal-e updates in place, nothing used the Python virtual environment so we could finally delete it!

In the next stream, we're going to begin the process of removing the Git clone to complete the process of simplifying deployment.

This article first appeared on [mattlayman.com](https://www.mattlayman.com/building-saas/wal-e-postgres-backups/).
Java 8 - Lambda Expression Rule
Tags: java, lambda, functional
Published: 2020-03-19 17:57:49

There are some rules to make lambda expression more concise.

####Example 1:
Let's take an example:
```java
public void displaySum(int a, int b) {
    System.out.println(a + b);
}
```
The valid Lambda expression of above method is:
```java
(int a, int b) -> System.out.println(a + b);
```
It can be made more concise by taking out the parameter's datatypes.
```java
(a, b) -> System.out.println(a + b);
```
**_Note: The type of the parameters can be declared explicitly, or it can be inferred from the context._**

____

####Example 2: 
Let's take another example:
```java
public int square(int a) {
    return a * a;
}
```
Its equivalent lambda expression is:
```java 
n->n*n;
```
**_Note:_**
**_1. If there are no curly brackets, then the return keyword is not needed._**
**_2. If there is only one parameter in the function, then () is also not needed._**

____


#####Q1. Write an lambda expression that returns length of string.
```Give answer on the comment below :)```
___

####How to execute the Lambda expression?

To execute the lambda expression, we use one of the other features of java 8: **Functional Interface**. We will discuss it in the next post of this series.
___
Friday Night Deploys: #15 Developer Pitfalls Or (How Not To Die Miserably In The Hole You've Dug)
Tags: podcast, webdev, jokes, beginners
Published: 2020-03-19 17:45:48

## Intro
Last week the DevPlebs talk about: The burden of daylight savings time! Becoming a conspiracy podcast! Death threats! Wimpy web developers! Meeting our quota for talking about web development on the podcast! Our collective bad memories! Keith's lazy dogs! Canadian winter! Phil's Gatsby talk and his average sized deck! The ever-declining quality of this podcast! Only listening to audio in .FLAC format! Dropping spoilers for the movie Saw! The market for erotic podcasts! Using bitwise operators to look smart and write unmaintainable code! Holding yourself accountable! Keith's weird promise of fan fiction at 1000 streams! Bidets and Thai butt guns! Weak and lazy metaphors! Professor Jaret Wright! People trying to sell us services even though we're broke! How to be a better developer!

## Listen to The Full Episode!
{% spotify spotify:episode:3KJ9kxzV5MBrA3kekPcXIF%}

_or [listen directly on spotify](https://open.spotify.com/episode/3KJ9kxzV5MBrA3kekPcXIF)_

**We're also on...**
**Apple Podcasts:** https://podcasts.apple.com/us/podcast/15-developer-pitfalls-or-how-not-to-die-miserably-in/id1485252900?i=1000468378208

**Google Music Podcasts:** https://play.google.com/music/m/Dk5474xryh6szykb64fg7j463ke?t=15_Developer_Pitfalls_Or_How_Not_To_Die_Miserably_In_The_Hole_Youve_Dug-Friday_Night_Deploys

**Our Website:** https://www.devplebs.tech/friday-night-deploys/14-developer-pitfalls-or-how-not-to-die-miserably-in-the-hole-youve-dug/

## Get In Touch With Us!
Have you fallen into any of these pitfalls? Do you have any additional pitfalls? If you would like to share for us to read out in the next episode you can reach us at the following...

**Twitter:** [@DevPlebs](https://twitter.com/DevPlebs).
**Email:** deadbeats@devplebs.tech

## Follow Our Twitters... If You Want!
[DevPlebs](https://twitter.com/DevPlebs).
[Keith Brewster](https://twitter.com/brewsterbhg).
[Phil Tietjen](https://twitter.com/phizzard).

You can also ask questions or give us some feedback about the show!
I made a React UI Library with a focus on a minimalist design

Tags: react, javascript, ux, ui
Published: 2020-03-19 17:45:16

# [![Uniui](https://github.com/ericm/uniui/raw/master/img/uniui.svg?sanitize=true)](http://uniui.moynihan.io)
![npm](https://img.shields.io/npm/v/react-uniui?style=flat-square)
![Build](https://github.com/ericm/uniui/workflows/Build/badge.svg?branch=master)

https://github.com/ericm/uniui

[Uniui](http://uniui.moynihan.io) is a React Typescript UI library currently in beta.

## Installation

To install Uniui, simply run the following in the root directory of your react project:

```
    $ npm i react-uniui
```

## Usage

You can import the entire library via:

```ts
    import Uniui from "react-uniui";
```


Or individually:

```ts
    import { Button, Selection } from "react-uniui";
```

## Components Preview
### Buttons
![button](https://github.com/ericm/uniui/raw/master/img/button.png)
```tsx
<Button>Button</Button>
<Button type="flat">Button</Button>
<Button type="borderless">Button</Button>
```
[See more in the docs](http://uniui.moynihan.io/components/button)

### Radio Menu
![button](https://github.com/ericm/uniui/raw/master/img/radio.png)
```tsx
<SelectionGroup>
  <Selection type="radio" label="Radio button 1" />
  <Selection type="radio" label="Radio button 2" />
  <Selection type="radio" label="Radio button 3" />
</SelectionGroup>
```
### Checkboxes
![button](https://github.com/ericm/uniui/raw/master/img/checkbox.png)
```tsx
<SelectionGroup>
  <Selection type="checkbox" label="Checkbox 1" />
  <Selection type="checkbox" label="Checkbox 2" />
  <Selection type="checkbox" label="Checkbox 3" />
</SelectionGroup>
```

### Switches
![button](https://github.com/ericm/uniui/raw/master/img/switch.png)
```tsx
<SelectionGroup>
  <Selection type="switch" label="Switch 1" />
  <Selection type="switch" label="Switch 2" />
  <Selection type="switch" label="Switch 3" />
</SelectionGroup>
```

[See more in the docs](http://uniui.moynihan.io/components/selection)

### TextField
![button](https://github.com/ericm/uniui/raw/master/img/text.png)
```tsx
<TextField value="Text" subtitle="TextField" />
```
[See more in the docs](http://uniui.moynihan.io/components/textfield)

See the [Component API docs](http://uniui.moynihan.io) for further reference
What was the last thing you mastered, that made you a faster & cleaner programmer/coder?
Tags: html, javascript, tricks, discuss
Published: 2020-03-19 17:32:37

The helping hands for me were the shortcuts. I had to do a lot of typing, so not only did I need to copypaste quickly, but also think of a way that would come in handy with custom coding and editing too. 
It might sound weird, but an extra help for me was to use speech-to-text extensions. Of course, the syntax,like the parenthesis and dot-commas, comment dashes and dollar signs, opening and closing quotes I had to put manually.
Quarantine Assistant - part 2 - first view in React Native
Tags: showdev, hackathon, react, reactnative
Published: 2020-03-19 17:30:33

It's about half of the remaining time. I had configured a project, my mate prepared UI design and this night before the job I made the first view. 

To remind, the project is about a mobile application for local authorities to better control and contact with people in quarantine.  

![](https://i.imgur.com/NQgQHgg.jpg])
Created a website which shows the latest COVID-19 stats in India
Tags: github, opensource, webdev, covid19
Published: 2020-03-19 17:25:51

I have created a website that shows the latest COVID-19 (CoronaVirus) statistics in India!!

Website URL: http://gocoronago.ml
Github Repo: http://github.com/iamrohitsuthar/gocoronago

If anyone wants to contribute to the project then check out my Github Repository.
React Router V6
Tags: javascript, react
Published: 2020-03-19 17:24:20

Here's a sneak peek at V6 of React Router.

Functions have been unified and customised through parameterized configuration.

Bundle size is 50% smaller.

Read the post https://alligator.io/react/react-router-v6/#switch-is-becoming-routes.

GitHub repo
https://github.com/ReactTraining/react-router/releases

Credits
Ferenc Almasi - Thanks to @flowforfrank for making this photo available freely on @unsplash 🎁 https://unsplash.com/photos/L8KQIPCODV8
Searching for Projekt Helpers in Germany
Tags: charity, laravel, react, help
Published: 2020-03-19 17:18:52

Hey Guys, we are working on a project to help people to connect about Covid-19. We are looking for a few people which want to help out on a charity base:

Backend: Laravel
Frontend: Vue or React
If you are from Germany and wanna help us out or even just wanna help out and do speak german please message me or just comment here. I´ll be happy to share more information with u!

Mfg
Common tasks of managing HTML DOM with vanilla JavaScript
Tags: javascript, showdev, html, webdev
Published: 2020-03-19 17:03:37

## Story

Web development goes very fast. I still remember the moments when starting to use [jQuery](https://jquery.com), [Prototype](http://prototypejs.org),[script.aculo.us](https://script.aculo.us), [Zepto](https://zeptojs.com) and many more.

Nowadays, even if our application is powered by mordern tools such as Angular, Vue, React, Svelte, .etc, we have to deal with DOM.
The frameworks encapsulate and hide the DOM management directly, but still give us a door to work with DOM via _ref_, _event handlers_.

If you develop or use a web component in any framework, you have to work with DOM at a certain level.

Knowing the browser DOM APIs and how to use them play an important role in web development.
A website introducing the APIs, well-known problems, most popular questions could be very useful. 

## Introducing htmldom.dev

![htmldom.dev](https://dev-to-uploads.s3.amazonaws.com/i/qht2h3z39n14fzvcwh5i.png)

* No external library. Only native browsers' APIs
* Small and easy to understand examples
* Live demos with source made in vanilla Javascript:

![Live demo](https://dev-to-uploads.s3.amazonaws.com/i/aued590b5b13vpoe10hc.png)

* Many tips and good practices included, such as

![Good to know](https://dev-to-uploads.s3.amazonaws.com/i/oenirbg6vggzap8hb1bl.png)

* Many real use cases
* Work with the modern browsers. _Try to support IE 11_

Here it is
* The official website: https://htmldom.dev
* Github: https://github.com/phuoc-ng/html-dom

## Help me spread it

If you find it helpful, please 
* Give [the Github repos](https://github.com/phuoc-ng/html-dom) a star
* Share it or this post on Twitter (you can [tag me](https://twitter.com/nghuuphuoc))

Don't forget to hit the [Subscribe button](https://htmldom.dev) to get the latest news on htmldom.dev and my upcoming tools.
In case you miss, [CSS Layout](https://csslayout.io) is another useful resource as well.

See you in the next journey! And **stay safe**, my friends.