teleren/devto huggingface dataset:
Error Boundary for wrong props or how I hacked prop-types package
Tags: react, javascript, proptypes
Published: 2020-02-02 10:40:14

Hi everyone! Not so long time ago my tech-lead at work gave me a task to create an Error Boundary for wrong prop-types. As we know, prop-types package throws usual console warnings if some components receive wrong props. But we needed it to throw an Error.
There was no information about handling prop-types errors on the internet, so I decided to look into the source code of the [prop-types package](https://github.com/facebook/prop-types).
And my attention was riveted by one interesting constant in the [ReactPropTypesSecret.js](https://github.com/facebook/prop-types/blob/master/lib/ReactPropTypesSecret.js) file. That's it:
![SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED](https://dev-to-uploads.s3.amazonaws.com/i/tddeenw9o873qnktlj3s.png)
Looks funny, yeah? :smile:
So after laughing, I tried to figure out what's the sense of this constant. And I succeed.
In the file [factoryWithTypeCheckers.js](https://github.com/facebook/prop-types/blob/master/factoryWithTypeCheckers.js) I found function, that checks single prop-type (you give the reference to this function each time when you write propTypes for your component. For example, PropTypes.number calls this function for the number prop-type).
That's how it looks:
![factoryWithTypeCheckers.js](https://dev-to-uploads.s3.amazonaws.com/i/kbi3q0br5oleh873n2ou.png) 
And we have to pay attention to the last argument of this function - secret. And if we pass the constant that we found in the previous step there - we will get access to hidden features of prop-types! In this case, our function will return the object of prop-types error (if there is no error it returns null).
So with the usage of this knowledge, I created my own high-ordered component, that takes a component as an argument (and this component has to have *errorBoundary* prop. This is a component, that our HOC will render if props are not valid). That's how it looks:
```
import React from 'react';
import SECRET from 'prop-types/lib/ReactPropTypesSecret';

const propTypesChecker = (Component) => (props) => {
  const analysis = Object.keys(Component.propTypes).map((key) => {
    const validator = Component.propTypes[key];
    return validator(props, key, Component.name, '', null, SECRET);
  });

  const errors = analysis.filter((error) => error !== null).map((error) => error.message);
  const arePropsValid = errors.length === 0;
  const ErrorBoundary = props.errorBoundary;

  return (
    arePropsValid
      ? <Component {...props} />
      : <ErrorBoundary errors={errors} />
  );
};

export default propTypesChecker;
```

The main function here is the *analysis* function. Here we use ReactPropTypesSecret in order to get access to error objects. And this function just returns all the error messages after checking PropTypes.

And I created NPM-package, so you don`t need to write this on your own :)

My package on NPM: [Click!](https://www.npmjs.com/package/react-props-validator)
Source code: [Click!](https://github.com/kirillgenets/react-props-validator)
Unpublished Video ~ 3d1p
Tags: javascript, docker, tutorial, html
Published: 2020-02-02 10:07:06

Javascript/XMLHttpRequest/SVG Internet Speed test.

For High Speed connections we need constant stream of Data. 

For download we can send request to huge files and close the connection when needed. 

When we test Upload speed from browser, we have are limited 
by the technology. 

We have no Standard way to know Available Memory!


Recently several people reported our new version have issue while testing upload speed from iPhone 6/6s

While testing via Xcode simulator everything fine.

but a real device will return "Failed to load resource: WebKit encountered an internal error"

I thought server configuration may have some issue. After some time i found this was due to limited memory allocation by webkit! 

I reduced the memory consumption for upload data! Now it is working fine. 

but we need larger amount of data for HIGH SPEED connections. Currently only Google chrome and Firefox Allow us to know the Available memory.

looking for a workaround that works everywhere!
Top 3 programming languages to learn in 2020 based on meta analysis
Tags: beginners, webdev, javascript, career
Published: 2020-02-02 09:59:06

We did a ***meta analysis of the rankings of several articles, statistics, surveys and search indices*** to list the best programming languages to learn in 2020. They are based on criteria like job opportunity, community and difficulty to learn.

In the below video I also explain ***WHY these programming languages are so popular*** and which one to learn ***based on your career plans or interests***.
For example, which one should you use when you want to become a web developer? Which programming language is the best for data science or artificial intelligence?

What career plans do you have and which programming language did you choose to learn? 🤓

{% youtube 9e6sUNhAB4M %}

-----------------

You can connect with me on [Twitter](https://twitter.com/Njuchi_) and [YouTube](https://www.youtube.com/channel/UCdngmbVKX1Tgre699-XLlUA?sub_confirmation=1).
Dynamically modify page in WKWebView in iOS
Tags: ios, swift
Published: 2020-02-02 09:13:38

If you have page in `WKWebView` in your app, you can modify it pretty freely. This can be useful for example when you are embedding your own page and want to provide different look/functionality when loaded in a web view.

`WKWebView` has method `evaluateJavaScript` which does exactly what it says. It will run any JavaScript code you provide on the loaded page.
This can be also very useful for getting information back about the page. For example you can ask for the total height and modify your app user interface accordingly.

Method looks like this:

```swift
func evaluateJavaScript(_ javaScriptString: String, 
      completionHandler: ((Any?, Error?) -> Void)? = nil)
```

`completionHandler` is not required but you can check for errors to verify everything works or use the `Any?` to get result from JS code.

```swift
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { (height, error) in
         if let height = height as? CGFloat {
  		} 
})
```

Yet another use case can be filling forms on pages with saved data so users have better experience and don’t have to do it manually. Since you can run *any JavaScript* the possibilities are pretty endless. If you are sure there is jQuery loaded on the page, you can use it to simplify some common tasks.

I would highly recommend writing your JavaScript in editor that supports it so you don’t miss `;` or something like that when running the code in `WKWebView`. Also it is a good idea to test the code on the page in browser by opening the developer console and pasting it here. It is much faster to debug than running your app and doing it via `evaluateJavaScript` method.

_Is anything not clear? Do you want more information? Ask in the comments and I will do my best to help you. Thanks for reading!_
Laravel 6 | Create API Authentication using Laravel Passport
Tags: laravel, api, authentication, passport
Published: 2020-02-02 09:07:39

Hello Artisan

In this tutorial we are going to learn about laravel passport. In this tutorial i will show you step by step that how to create api authentication using laravel passport.

In this laravel 6 passport tutorial i will show you login registration and logged in user details. So lets start our laravel api authentication token tutorial.

If you don't know how to create api authentication, then you are a right place. In this example i will show you how to create very simple api and authentication.

https://www.codechief.org/article/laravel-6-create-api-authentication-using-laravel-passport
What is your lunch break routine?
Tags: watercooler
Published: 2020-02-02 09:05:06

I actually break my lunch time into two breaks. As I get hungry early, I eat my sandwiches quickly around 12:15 in the office kitchen. Then I do some more work and have another longer break at 1:15 pm. Usually I go for a walk during the second break and listen to a light podcast. If I could, I'd love to take a nap, but since I can't I do that, just getting some exercise and time away from the screen is also helpful. What do you do? 
PS: my company allows for one hour lunch break.
Javascript reduce() Array Method
Tags: javascript
Published: 2020-02-01 17:43:09

The `reduce` array method is used to reduce all values in an array to a single value. It is passed an argument which is a function that is executed on every value in the array.

## Syntax

```js
array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
```

### Explanation of identifiers

* `function`: executed on all elements.
* `total`: This is the previously returned value of the function. That is, the return value from the previous function execution. It is also used as the initial value for the first iteration of the reduce method if the `initialValue` is not stated.
* `currentValue`: The value of the current element.
* `currentIndex`: The index of the current element. This is optional. It starts from 0 if `initialValue` was provided, otherwise, 1.
* `arr`: The array the method was called upon. This is optional.
* `initialValue`: The value which would be passed to the function as an initial value. That is, the value which the iteration would start with before incrementing. It is optional. The default initial value is the value of `total`.

### In other words,

If `initialValue` is provided, the execution starts from the first element, otherwise, the second element of which the first element would be the `initialValue`.

## Return Value

The return value of the `reduce` method is `total`. This would be passed to the next iteration (if there exists another element) or be returned as the final result from the method.

Examples

### 1. Add all elements of an array

```javascript
let addFunction = (a, b) => a + b;
let arr = [2,3,4,5];
let result = arr.reduce(addFunction);
console.log(result);
// Expected output
// 14
```

The output is **14** How?

Using arrow function, `addFunction` has only two arguments - `total` and `currentValue`. `initialValue` is not stated, hence, `total` will be the initial which as seen above is **2**. Since, **2** is the initial value, the iteration passes onto the next value, **3**.

The initial value is then added to the current value (3) which increments `total` (2+3 = 5). **5** is passed to the next value (4) as a total and also incremented until the last element, **5**. After addition, there is no other element for `total` to be passed to, hence, the method returns `total`.

### 2. Maximum Number in Array

```javascript
let maxNum = (a, b) => a > b ? a : b;
let arr = [34, 56, 12];
let maximumNumber = arr.reduce(maxNum, 40);
console.log(maximumNumber);
// Expected Output
// 56
```

Here, we have an `initialValue` - **40**. This becomes `a` and **34** becomes `b`. **34** is less than **40**, so **40** is returned an passed to the next value, **56**. **56** is greater, hence, returned and passed to **12**. **56** remains greater and it is returned as the final result.

-----

I hope with this, you can see how the `reduce` array method works. Like I stated before, it reduces all values in an array to a single value.

Thanks for reading! 🙂
A free personal file host on your command line
Tags: linux
Published: 2020-02-02 08:43:44

I'm a big fan of file sharing, but not through cloud storage solutions like Google Drive and Dropbox. There's so much bloat on their UIs that sways from the intent of just sharing a file to someone. I thought of managing my own FTP server but paying something monthly for the few occasions I'm going to share a file doesn't sound like a good idea.

Then came IBM cloud and their free offerings. The coolest thing about IBM cloud is they don't ask your credit card details to avail the free stuff. Plus their free tier is actually generous. Check Cloud Object Storage as an example:

![Alt Text](https://files.bensarmiento.com/ben-files/Screenshot%202020-02-02%20at%204.15.32%20PM.png)

That's 5GB of public outbound traffic. If I go only with sharing screenshots, that's a lot of screenshots I'll be able to share. And IBM COS is what I actually use as my file host. If you check the URL of the image above, it uses my domain `files.bensarmiento.com` which is just a CNAME a configured to point to my COS bucket. (OK, so apparently it isn't as everything goes through dev.to's image CDN which is Cloudinary)

Now to do the file host you need the following: IBM COS bucket, service credentials (you can setup this one when creating the bucket), and `rclone` installed on your local machine. [rclone](https://rclone.org/) is a nifty tool for anything cloud storage, I suggest checking it out.

After setting up the bucket, if you want a subdomain to not expose the ugly IBM COS domain on the URL you can do that by adding a `CNAME` record with value `s3.<region code>.cloud-object-storage.appdomain.cloud`.

Next step is to configure rclone to upload to it. Easiest way to is to edit `rclone.conf` found in `$HOME/.config/rclone/`.

This should be what's inside (replace everything `<that looks like this>`):

```
[ibm]
type = s3
provider = IBMCOS
env_auth = false
access_key_id = <access key>
secret_access_key = <secret key>
region = <region code>
endpoint = s3.<region code>.cloud-object-storage.appdomain.cloud
acl = public-read
```

After that, the command `rclone copy local.file ibm:<bucket-name>` should work. Then in your `.bashrc` or `.zshrc`:

```
function upload {
    rclone copy $1 ibm:<bucket-name>
    a=`basename $1`
    b=`echo $a | urlenc enc`
    echo "https://<your configured url>/<bucket-name>/$b"
}
```

So now, you should be able to do `upload local.file` which will output you something like `https://files.bensarmiento.com/ben-files/Screenshot%202020-02-02%20at%204.15.32%20PM.png`.

**Bonus:** you can setup something like a URL shortener of some sort with this setup (if your bucket URL is short).

```
function redirect {
    a=`mktemp /tmp/goto.XXXXXXXX`
    b=`echo "$a.html"`
    echo "<meta http-equiv='Refresh' content='1; url=$1'>Redirecting to $1..." > $b
    upload $b
}
```

Hope other providers can offer more generous free tiers.
New Bushido-strap React Style Library Update!
Tags: react, webdev, uiweekly, npm
Published: 2020-02-02 07:57:50

I'm happy to announce that bushido-strap has just received a pretty big update! [Check out the doc's for an in-depth guide on each component!](https://www.npmjs.com/package/bushido-strap) 

I would love to go over some of the most exciting changes here on my blog with y'all! :heart:

## New style Maps!

So, just like before, you can use `justify="space-between"` on a bushido-strap component. But now you can also do `jc_between` for the same effect! Adding `stretch` to a component will make it's width 100% and it doesn't stop there! You can turn Card box-shadows off with the `noshadow` prop and add a box-shadow to Box, Col, and Row with the `shade` prop. And, of course, you can still set a custom box-shadow by giving a value to the `shadow` props.

## New Style Props And Prop Names!

There is now a `sqr` prop and all components that have a width and height prop. When you give a value to the `sqr` prop it adds that value to width AND the height at the same time. So `<Box sqr="5rem" bg="crimson" />` will be a box that is 5rem heigh, 5rem wide and a background color of crimson.

Margin and padding can be quickly added now with some easy style maps.
xsm = margin: 1rem;   | xsp = padding: 1rem; 
sm = margin: 2rem;    | xsp = padding: 2rem; 
mm = margin: 3rem;    | mp = padding: 3rem;  
lm = margin: 4 rem;   | lp = padding: 4 rem; 
xlm = margin: 5rem;   | xlp = padding: 5rem; 

A lot of prop names have been shorted. 
- width is now w
- height is now h
- padding is now p
- margin is now m
- background is now bg

### Example:

```react
export default MyComponent() {
  return (
    <Card w="40rem" noshadow jc_center>
      <Col jc_around stretch>
        <Row xsp xsm stretch jc_center shade bg="crimson">
          Text 1
        </Row>
        <Row xsp xsm stretch jc_center shade bg="royalblue">
          Text 2
        </Row>
      </Col>
    </Card>
  )
}
```

**Would look something like:**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/t964epw8s1qmhyywkazr.png)

**Here's a picture of some basic components:**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/55wq7paa5mv4knnw5qot.png)

**And here's a pic of the portfolio I'm working on now using my library.**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0d5dv6lu9813mlnk9okx.png)

## Thanks for reading!

For a deep dive into what this library has to offer, [check out my docs!](https://www.npmjs.com/package/bushido-strap)

For an easy way to bootstrap a React project with this library, already integrated, set up, and ready to go: `create-react-app app-name --template bushido-lite`. You can find the [docs for my template here.](https://www.npmjs.com/package/cra-template-bushido-lite)
Midbrain Activation
Tags: midbrainactivation
Published: 2020-02-02 07:55:58

Midbrain Activation Basic Level Course:(Sensory/cognitive System)
Midbrain Activation basic level course and franchise - If you are looking for the midbrain basic level course and franchise for the respective course then we can help you. We have experts in our team that shape your child towards the brighter side of the future. We have designed our courses after considering the need for each & every child. As our brain is one big neural network. Neural networks are wired through a process of structuring, re-building, and re-directing brain connections. We regularly monitor the growth & progress of a child.

How can we help you to learn mid brain basic level courses?
Understudies begin to distinguish the hues and letters without customary tactile information. By utilizing the left mind's five detects. Dr. Paul Dianes says that certain activities like eye exercises & brain gyms will help to balance both left & brain development. We have 5 levels in this course. Brain Gym fitness classes can be assigned according to each individual's needs.

Feedback is continuously generated so we can monitor progress.

Affects of midbrain basic level course on midbrain
Inspiration is discriminating as it discharges cerebrum chemicals. Mind chemicals, or neurotransmitters, for example, dopamine and acetylcholine are discharged when an individual persuaded and supported. These mind chemicals assume a discriminating part in the development of more grounded and stronger cerebrum associations. Furthermore, that is basic to assemble more grounded mind associations. The cerebrum is then changed into a more proficient and compelling neural system for execution. Tactile engine improvement activities upgrade cerebrum proficiency in directing complex developments, prompting better consideration and core interest. Specifically designed exercises that train fine-motor, gross-motor, visual processing and integrates all these skills.

What Is Midbrain Activation?
Midbrain as the name already describes it is the brain between the left and right side of the overall brain. If midbrain is continuously at training then it can easily balance the left and right side of the brain. With the right training, you can learn to improve your learning efficiencies and much more.


Contact Information
Below mentioned are the contact details of the Rajmin academy for the best midbrain basic level course and franchise.

Name - Rajmin Academy

Address - RAJMIN ACADEMY, NEAR HDFC BANK, MULLANPUR-RAIKOT ROAD, LUDHIANA (pb)

Phone Number - 09256893044, 08194991633

Visit our Website: <a href="https://www.midbrainacademy.in/midbrain-activation.html">Midbrain activation</a> , <a href="https://www.midbrainacademy.in/Photographic-Memory-Programme.html">Photographic memory programme</a> , <a href="https://www.midbrainacademy.in/Abacus.html">abacus</a> , <a href="https://www.midbrainacademy.in/Quantum-Speed-Reading.html">Quantam speed reading</a>
Being A Better Blogger
Tags: webpack
Published: 2020-02-02 07:22:01

So you would like to blog on the web. Before you begin you need to consider why you would like to be a blogger and how to start blog or want to buy web hosting. This article gives you an essential web Blogging advice to consider before you commence your web blogging adventure. You're definitely not alone. There are 12 million blogs on the web from the United States alone and every day over 120, 000 new blogs are created. There are 1.4 million new website posts every day and over 57 million Americans read blogs.22 of the 100 most popular web sites on the web today are blogs. The motivation behind why web journals are so mainstream is on the grounds that sites are intelligent sites.

Blogs offer the capability to give and receive instant feedback and blog readers can voice their opinion and add to the discussion. Blogs also provide free info which is latest and changes quickly and after all, why do people surf the internet? For info, of course. The web blogging platform is an extremely easy to use interface where bloggers can upload new info to the web as frequently as they like. A blogger needs only the most elementary of computer skills to start blogging. If you know how you can turn your computer on and connect to the web, you too can be a blogger. 

The WordPress platform is a free piece of software that's by far, the best tool to use for your blog. To answer this question first we have to make a short trip down memory lane and look at the history of blogging. At the beginning, when blogs actually started, they were on-line diaries. The term blog is gotten from web log.. People used a weblog as an on-line journal and talked about themselves, what they were doing, their activities and the events taking place in their lives just as they'd in a written personal diary or journal. Even today there are a lot of blogs which are on-line diaries. 

These types of blogs are of benefit both to the blogger and hisher readers. It is great to connect with like minded people and share your opinions and views of the world. Another group of individuals that like to blog are the ones which have special interests, maybe a cause that they support, a charity that they support, or a specific hobby that they enjoy. They blog to promote their message, and also to interact with others who share the same interests. They want their blog to function as a type of hub of info for their readers or target audience. These bloggers collect info from numerous different sources and present it to their readers in a central place. These bloggers create a dialogue or conversation about their special area of interest and invite others to participate via their blog. If you want to know best web hosting for start a blog then you should must google it once or you may visit -- https://waystomakemoneyonlineguide.com/a2-hosting-review/