teleren/devto huggingface dataset:
Nov. 24, 2019: What did you learn this week?
Tags: weeklylearn, discuss, weeklyretro
Published: 2019-11-23 14:58:39

This is not a new concept for a post or Tweet. David Walsh usually posts one every week.

{%twitter 1197918614776635398 %}

Having said that, I thought it’d be fun to start a weekly series on DEV where people just comment with something they learnt this week. It could be programming tips, career advice etc.

![Neo in the matrix having just learnt kungfu](https://media.giphy.com/media/3o7btNhMBytxAM6YBa/giphy.gif)

And if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

{% link https://dev.to/devteam/what-was-your-win-this-week-bic %}

![Obama drops the mic](https://media.giphy.com/media/3o7qDEq2bMbcbPRQ2c/giphy.gif)

Let’s see how this goes. 😸
Laravel adding custom validation errors
Tags: laravel, validation
Published: 2019-11-23 14:41:34

---
title: Laravel adding custom validation errors
published: true
description: Have a situation where you need to add custom errors to the error array after validation?
tags: [Laravel, Validation]
cover_image: https://thepracticaldev.s3.amazonaws.com/i/85au2waejkj2upzickg3.png
canonical_url: https://dcbblog.dev/laravel-adding-custom-validation-errors
---

Validating in Laravel can be really simple for instance take this example:

```php
request()->validate([
    'due_date' => 'required',
    'template' => 'required'
]);
```

This will validate that data in the request object and passes an array of rules which will validate both due_date and template exist and are set in the request object. If the validation fails then a redirect is automatically executed to the previous page passing both the user input and an array of errors.

For simple validation, this is amazing! simple and effective but in cases when you need to add a custom error message to the error object this cannot be used instead use the Validator class and pass in the request object and an array of rules.

```php
$validator = Validator::make(request()->all(), [
    'due_date' => 'required',
    'template' => 'required'
]);
```

To add a custom error with this approach an errors->add() method can be called:

```php
if (request('event') == null) {
    $validator->errors()->add('event', 'Please select an event');
}
```

The add method accepts two params the custom name and its value.

Now at this point, nothing would happen as the validation has not been run to complete this you would normally write:

```php
if ($validator->fails()) {
    return redirect('post/create')
                ->withErrors($validator)
                ->withInput();
}
```

Calling ->fails() executes the validation and will redirect with input and errors upon failure.

This can be simplified further by instead writing:

```php
$validator->validate();
```

Which does the same thing but automatically.

Putting it all together:

```php
//setup Validator and passing request data and rules
$validator = \Validator::make(request()->all(), [
    'due_date' => 'required',
    'template' => 'required'
]);

//hook to add additional rules by calling the ->after method
$validator->after(function ($validator) {
	
    if (request('event') == null) {
    	//add custom error to the Validator
        $validator->errors()->add('event', 'Please select an event');
    }

});

//run validation which will redirect on failure
$validator->validate();
```

Now for cases where custom errors are required to be added this allows this without too much extra work.
I created a React & Redux Boilerplate
Tags: redux, react, javascript, opensource
Published: 2019-11-23 14:16:55

It's always awful to start an app from scratch. Specially with React, you always need to delete some files in boilerplate created with `create-react-app`. And adding *Redux* is also another big problem and it takes much of time. 
To make your task easy, I've created a boilerplate for React and Redux. It includes setup for
1: React
2: Redux
3: styled-components
4: react-animations
One important thing, people always worry about creating a PWA with React. I've also added all the features of PWA. The app has working service workers and is installable.
Here's the repo: 
[react-pwa-boilerplate](https://github.com/MuhammadWasif/react-pwa-boilerplate)
If you're an open-source lover, don't forget to add more features used mostly by creating a *pull request*.
And **don't forget to start the repo**, if you like the boilerplate.
Day 12 of⚡️ #30DaysOfWebPerf ⚡️: Image loading for the lazy
Tags: webperf, performance, images, webdev
Published: 2019-11-23 14:09:29

{% twitter 1198240350629965824 %}
{% twitter 1198240352144175104 %}
{% twitter 1198240353071116289 %}
{% twitter 1198240372150943744 %}
Tool to release self-made package to Github at high speed
Tags: showdev, rust, cli
Published: 2019-11-23 14:06:13

https://github.com/k-nasa/rgh

Using [rgh](https://github.com/k-nasa/rgh), You can release self-made package easily and fastly to github.

## Demo

https://raw.githubusercontent.com/k-nasa/rgh/master/assets/demo.gif

In the demo, a release is created with the v0.1.0 tag, and three files under `/dist` are uploaded in parallel

## Usage

The repository is obtained from the local `.git` directory, and GitHub token reads the environment variable `GITHUB_TOKEN`.
It is also possible to pass it as an option instead of an environment variable.

```
OPTIONS:
        --commit <target-commitish>    Specifies the commitish value that determines where the Git tag is created from.
                                       Can be any branch or commit SHA. Unused if the Git tag already exists. Default:
                                       the repository's default branch (usually master).
    -t, --token <token>                Set Github API Token (By default reads the GITHUB_TOKEN environment variable)
        --title <name>                 The title of the release
    -b, --body <body>                  Text describing the contents of the tag.
        --draft <draft>                 [possible values: true, false]
        --prerelease <prerelease>       [possible values: true, false]

ARGS:
    <tag>         tag
    <packages>    upload packages dir or file
```

## Installation

### Pre-compiled executables

Get them [here](https://github.com/k-nasa/rgh/releases)

### using homebrew

```
brew install k-nasa/tap/rgh
```

### using cargo

Currently it cannot be built with the stable version.

```
cargo +beta install rgh
```


I plan to add options while maintaining a simple interface.

I would be happy if you commented on the features I wanted.
💡 LightBulb v2 released!
Tags: showdev, productivity, opensource, dotnet
Published: 2019-11-23 13:40:46

After over a year since last release and long months full of work, I'm happy to release LightBulb v2 to the world!

For those who don't know, LightBulb is a Windows background application that controls the gamma of your display(s), gradually reducing blue light as it gets late. It's similar to the Windows built-in NightLight feature and apps like f.lux, but offers much wider customization options, more features, better performance, an elegant UI, and it's completely open-source!

⭐ **You can download it [here](https://github.com/Tyrrrz/LightBulb/releases/latest) but please note that you also need to have [.NET Core 3 runtime for desktop apps](https://dotnet.microsoft.com/download/dotnet-core/3.0/runtime) installed.**

The main new feature of v2 is the completely reworked UI and the addition of the dashboard screen which shows up-to-date relevant information. Here you can see the sundial which indicates where you are in the 24-hour cycle separated by phases of day-time, night-time, and transitions.

Also, I've added the brightness configuration to go with color temperature. This will let you personalize LightBulb even further and your eyes will be thankful. 👀

![dashboard](https://raw.githubusercontent.com/Tyrrrz/LightBulb/453f0cb2e414741f93dcf8e6c54eb8a31f71ce42/.screenshots/dashboard.png)

Settings have also seen a few enhancements, namely the ability to manually fine-tune every configuration value, including your location. Previous versions of LightBulb required you to have active internet connection in order to accurately calculate sunrise & sunset times, but not anymore -- you can set it manually or use the text box to search for any valid address.

![settings](https://raw.githubusercontent.com/Tyrrrz/LightBulb/453f0cb2e414741f93dcf8e6c54eb8a31f71ce42/.screenshots/settings.png)

For the full list of changes (there are over 30 of them), check out the [changelog](https://github.com/Tyrrrz/LightBulb/releases/tag/2.0)! ❤️
Hey, WordPress devs. Try Python
Tags: discuss, wordpress, python, restapi
Published: 2019-12-04 17:10:55

---
title: Hey, WordPress devs. Try Python
published: true
date: 2019-11-23 13:00:09 UTC
tags: discuss,wordpress,python,rest-api
canonical_url: https://medium.com/@keramotul.islam/hey-wordpress-devs-try-python-bf04cea3b635
---

![WordPress plus Python](https://cdn-images-1.medium.com/max/1024/1*wNcIHeTjDl2E7D5gi-82RQ.jpeg)

The strongest side of WordPress is The Rest-API. We can fetch WordPress data with any programming language and print it wherever we want.   
Calling Rest-API with JavaScript is kind of okay. But Calling Rest-API with Python can be the starting point of the next big thing.

Here are two things about Python:  
**1)** Python is the present trend.   
**2)** Python is a sustainable future.

> If you want to make money from product,  
> you have to go through the trend;   
> towards the future.

Now let’s see how Python works with WordPress Rest-API…

``` python
import requests
from urllib.request import urlopen

endpoint = "https://abmsourav.com/wp-json/wp/v2/posts/"
rqst = requests.get(endpoint)

if rqst.status\_code == 200:
    with urlopen(endpoint) as url:
    data = url.read()

print(data)
```

You can make a deep analyzation of your e-commerce, blog, business website data with python. Then you can print the output on a web app, website, google sheet… wherever you want.

The world of data analyzation, deep learning are just in front of the door.   
Are we ready for it?
What questions should the interviewee ask the interviewer?
Tags: discuss, career, hiring
Published: 2019-11-23 12:52:33

There are countless articles that advice every interviewee to ask questions when they go to an interview. Be it something technical, personal or growth related. 

However, besides all these guides, there are a couple of things each and every one of us (_should_) care about. No matter if it's related to _relocation_, _conferences_ or just _remote_/_vacation_ days.

So, what are some of the questions you always ask the interviewer when taking a new job into consideration?
Need for a mentor
Tags: html, webdev, beginners
Published: 2019-11-23 12:44:52

I'm currently learning HTML, CSS & eventually JS. 

HTML seems fairly easy but CSS has been the kicker. Positioning especially. 

Anywho, I'm currently looking for a mentor to guide me through or someone to "ginger" me when I'm down.

*I'm currently taking Colt Steele's course on Udemy.
* "Ginger" in this context is a Nigerian slang meaning motivate.

Thanks, Dev community
Announcing: Advent of Swift
Tags: ios, swift
Published: 2019-11-23 12:27:09

December has always been a month of sharing for me. Sharing food and experiences with family, celebrating the end of what has (hopefully) been a wonderful year, reflecting and setting goals for the new year. And this year, I have decided to share something really special with the iOS community.

In December I will publish a new blog post *every day* until Christmas eve. That's 24 blog posts in total. And since I want this whole endeavor to be about the community itself, [I need your input](https://twitter.com/DonnyWals/status/1194868995209478145). Send me messages on [Twitter](https://twitter.com/donnywals) to let me know what you want to learn and I will do my best to cover your topic in December during Advent of Swift.

Of course, I won't be able to cover every question you send me. But rest assured, I won't ignore any of your suggestions. If your post doesn't make the cut for Advent of Swift, I'm definitely keeping it around on my list of ideas for future blog posts and will do my best to cover your suggestion in 2020. 

Let's make Advent of Swift 2019 a great success together!
Is PHP or Java the better choice
Tags: discuss
Published: 2019-11-23 11:55:06

---
title: Is PHP or Java the better choice
published: true
description: 
tags: discuss
---

I'm an experienced java for web developer who has probably forgotten all I knew about PHP, however with the more strings-to-the-bow mentality I wondered what people's thoughts were on creating a new web project in Java or learning PHP and coding in that.
The project I'm thinking is a front end (which I'll probably use as an excuse to hone my flailing Angular skills) and back end with some persistence for data such as a MySQL database.
Which option is cheaper hosting wise, which option makes more sense for a fairly trivial project like this?
All input truly appreciated.
gen_tcp:listen/2 のポート指定について
Published: 2019-11-23 11:38:05

gen_tcp:listen(0, []) とやるとエフェメラルポートが利用されます。
では gen_tcp:listen(0, [{port, 5000}]) とやるとどうなるでしょうか？

```erlang
> {ok, Socket} = gen_tcp:listen(0, []).
{ok,#Port<0.6>}
> inet:sockname(Socket).
{ok,{{0,0,0,0},52766}}
> f().
ok
> {ok, Socket} = gen_tcp:listen(0, [{port, 5000}]).
{ok,#Port<0.7>}
> inet:sockname(Socket).
{ok,{{0,0,0,0},5000}}
```

port が優先されます。
Alfred, Devhints.io, Stack Overflow, and Dash for quick reference on my programming
Tags: alfred, devhintsio, dash, stackoverflow
Published: 2019-11-23 11:08:06

---
title: Alfred, Devhints.io, Stack Overflow, and Dash for quick reference on my programming
published: true
description: A short story on what I added to my dotfiles this week
tags: alfred, devhints.io, dash, stackoverflow
---

Okay, so I wanted to write something short today and I thought, "why not write about the new features on your dotfiles that you added this week?" So that's what I wanted to talk about. Here goes. Do take note that I haven't written anything in, like, a few months so please go easy on me.

### [Alfred](https://www.alfredapp.com/), [Devhints.io](https://devhints.io/) and [Stack Overflow](https://stackoverflow.com/)

First, Alfred. Well, this honestly has been on my machine for quite some time now. It's a spotlight alternative for OSX but it doesn't stop there. You can customize it more especially when you have powerpack in it. Although, in this article, I'm not going to talk about that because I myself do not have powerpack. It's paid, sorry. What I wanted to mention regarding Alfred are the custom web searches. I configured my Alfred web searches to search through stack overflow whenever my query on it starts with `>` and then if the query, however, starts with `;` it will then search on [Devhints.io](https://devhints.io/). Take a look.

![alfred](https://imgur.com/ZsdFbvu.gif)

Pretty neat if you ask me. It has been quite helpful after I added it so I probably will use it for a long time.

### [Dash](https://kapeli.com/dash)

Dash, on the other hand, is an API Documentation Browser and Code Snippet Manager. It's an app where I can reference methods whenever I need them. Let's say I didn't know what `private` on Ruby is, I can just search it on Dash. It also works offline which is a plus. What's more? You can add it directly to your Vim which is insane! I've set it up so that if my cursor block is on top of the word `private` and I hit `;d` on normal mode, it will automatically search `private` on Dash. Which is super awesome! Take a look!

![dash](https://imgur.com/CR4Yh6p.gif)

Cool stuff, am I right? I'm really pumped up with these additions to my workflow and I think this is, by far, the best addition in my workflow to date.
Why I Want To Stop Using Google Adsense
Tags: googleadsense, adsense, analytics
Published: 2019-11-23 10:51:48

---
title: Why I Want To Stop Using Google Adsense
published: true
description: It's because I am not earning enough money with it. But there is more to that.
tags: google AdSense, Adsense, Analytics
---

Initial Article ==> [Why I Want To Stop Using Google Adsense](https://phpocean.com/blog/article/why-i-want-to-stop-using-google-adsense/104)

# Adsense's policies dictate what content you should publish and how your website should look like.

I see this to be very limiting. It kills the freedom of expression of the publishers. People write for various reasons and on various topics. It doesn't encourage original content and it dilutes messages. Words and figures of speech have different meanings in various regions in the world. It's a mistake to judge content based on a single standard. In several articles, I have been restricted to use terms like "longevity of software", "when do you spend client's money or funds, etc.", Images with AI illustrations, etc. The list goes on. Besides, they impose to you where you should place the ads on your websites implicitly shaping your website's design and content. I have a sever concern with this. I am pretty sure that ads won't show in this article because of those terms I am bringing in and the fact that I am criticizing Adsense.


# Ads should earn as far as one shows up on my website

Adsense displays ads even if it doesn't pay the publisher, and whatever happens, Adsense takes funds from advertisers. It's a cheat. It hurts to see that you had some hundreds of genuine visits but at the end of the day your income is just $0.0X These ads just got displayed to my visitors for nothing. Nothing.


# Geolocalization injustice

Revenues from most countries, except the USA, Canada, Australia, and their liking, are dangerously too low. This happens especially to Africans and Indians. If Adsense decided to underrate our countries, then there is no need for me to use it. It seriously pains me to see that a whole day, hardly my content can earn $0.5 after all these ads displayed on my website because they judged that our content is not good enough for them. But, was it not good for us, we, in these countries you qualify for unworthy? If we must write for those rich countries' standards before our content gets to be seen as good, that is unfair and reduces diversity and creativity to one thing. So, Adsense shouldn't have reached here in the first place....

Full Article here [Why I Want To Stop Using Google Adsense](https://phpocean.com/blog/article/why-i-want-to-stop-using-google-adsense/104)
Creating a Gauge Chart with Machine Learning (ML5, Teachable Machine) – Using React (Hooks) with D3
Tags: react, machinelearning
Published: 2019-11-23 10:39:47

{% youtube HLpw0JFY4-E %}

Hi, this is part 7 of my "Using React (Hooks) with D3" series, and in this one, I am adding Machine Learning (ML5, Teachable Machine) to the mix.

I use Teachable Machine to create a Machine Learning Model, I use this Model to predict if I am present, and visualize the prediction in a Gauge Chart.

Hope you like it!
What is your automation testing stack? 
Tags: devops, testing, productivity, selenium
Published: 2019-11-23 10:16:21

I am planning to put together the testing tools and frameworks into a spreadsheet with the help of the community members. 

Please let us know what’s the tech stack of your automation testing across all layers like UI, API, Contract Testing, Unit Testing, Security Testing, Performance/load testing, Usability Testing, CI/CD, Containerization, Test Reporting, Monitoring of APIs etc., in the comments below. 

Feel free to add if you have any other different testing done.
is there anyway to submit analogus array values into sub-array?
Tags: javascript, react, node, array
Published: 2019-11-23 07:09:12


This is the array that i tried working with :

let array = [
"getX",
"getY",
"getZ",
"getRotationX",
"getRotationY",
"getRotationZ",
"getRotation"];

I tried different ways , but coudn't acheieve so , I want to arrange analogus valuegetx, gety, getz into one subarray, same goes for rotation and scale. Does anyone have idea on how to proceed ?

output: const array  = [['getY','getX','getZ'], ['getPositionX'....],...];
Redux, who would have Thunk?
Tags: redux, react, javascript
Published: 2019-11-23 05:24:21

In my program I recently learned about Thunk. Thunk is middleware for Redux that allows you to return a function from your action creator instead of an action. This allows you to dispatch multiple actions to your reducer which comes in handy when working with asynchronous requests, which as we know can take various amounts of time. A dispatch can be made when the initial event triggers it and another can be made when the data from the request becomes available. 

Here is an example:

```
const fetchAstronauts= () => {
  return (dispatch) => {
    dispatch({ type: 'LOADING_ASTRONAUTS' });
    fetch('http://api.open-notify.org/astros.json')
      .then(response => response.json())
      .then(json => dispatch({ type: 'ADD_ASTRONAUTS', astronauts: json.people }));
  };
} 
```

Here, the fetchAstronauts function is an action creator that returns a function with dispatch being passed as a parameter. When dispatch is mapped to props, you can add the function as a prop to be called by dispatch like so:

```
const mapDispatchToProps = dispatch => {
  return {
    fetchAstronauts: () => dispatch(fetchAstronauts())
  }
}
```

Then, when your component mounts, you can call componentDidMount to make the asynchronous request to the API and update your redux store like so:

```
componentDidMount() {
    this.props.fetchAstronauts();
}
```

To go over the previous code, when the component mounts, the prop fetchAstronauts will be called, triggering a call to dispatch with our action creator being called as the argument. Our action creator will first dispatch an action with type: 'LOADING_ASTRONAUTS' to our reducer, and then once our astronaut data becomes available, another action will be dispatched to the reducer with the payload of astronaut data. This data can be used to update your state however you would like within your reducer. 

Additionally, Thunk can be used to conditionally dispatch an action. Here is an example from the [documentation](https://github.com/reduxjs/redux-thunk):

```
function incrementIfOdd() {
  return (dispatch, getState) => {
    const { counter } = getState();

    if (counter % 2 === 0) {
      return;
    }

    dispatch(increment());
  };
}
```

Here, the function is only dispatching an action to the reducer if the counter property in state is odd. Very useful!

To wrap it up, I think Thunk is pretty great, in that it makes it simple to change how we dispatch actions to our reducer. All in all, this is achieved by wrapping our action creator in a function that has access to dispatch.

Let me know if you have any other good uses for Thunk or any other middleware I should read up on. Thanks for reading! 

![Thinking Astronaut](https://media.giphy.com/media/IedrY2VP5IO5ivDQAD/giphy.gif)