teleren/devto huggingface dataset:
Practical Functional Programming in JavaScript - Why it's worth it
Published: 2020-06-15 00:16:04

Welcome to my series on Practical Functional Programming in JavaScript. In this installment, I talk about why it's worth it for you to go through all the trouble of learning functional programming in the first place. For the best reading experience, you should have programming fundamentals and familiarity with ES6+ JavaScript.

The biggest reason why you should learn functional programming is
**you will become a much better programmer**. Your programs will start to look as if they were written in plain English, and you will gain expressive power beyond your wildest dreams.

![power-colorful-explosion.gif](https://github.com/a-synchronous/assets/blob/master/gifs/power-colorful-explosion.gif?raw=true)

This is because functional programming is a natural way for humans to think about programs. Functional programming is **declarative**, meaning you declare what you want from the computer. In this way, you bend the computer to your will.

I'll show you what I mean with two functions, `doubleArrayWithLoop` and `doubleArrayWithMap`. Both functions take an array and return an array with every element multiplied by 2.

```javascript
const doubleArrayWithLoop = arr => {
  const doubled = []
  for (let i = 0; i < arr.length; i++) {
    doubled.push(arr[i] * 2)
  }
  return doubled
}

const doubleArrayWithMap = arr => arr.map(number => number * 2)

doubleArrayWithLoop([1, 2, 3]) // > [2, 4, 6]
doubleArrayWithMap([1, 2, 3]) // > [2, 4, 6]
```

Right off the bat, `doubleArrayWithLoop` may appear more natural if you're more accustomed to loops. Here is a rough translation of what is going on.

> In `doubleArrayWithLoop`, take an array `arr`, create a new array `doubled`, then start a for loop with `i` initialized to 0. Every iteration of the loop, push onto `doubled` the value of `arr` at index `i` multiplied by 2. After iteration is complete, return `doubled`.

It's just a tad bit wordy. Notice how `doubleArrayWithMap` reads a bit more like plain English.

> In `doubleArrayWithMap`, take an array `arr` and return an array with each number of `arr` multiplied by 2.

It reads as if I copy and pasted from the two functions' description from above. Indeed, `doubleArrayWithMap` is the more functional of the two approaches because we are able to declare at a high level what we want. With `doubleArrayWithLoop`, we have to hold the computer's hand, telling it step by step how to give us what we want. This is the difference in **expressive power** between a program adhering to functional programming principles and a program that does not. This is also in part why there's so much hype over functions like `map`, which you'll run into over and over again in your functional programming journey.

You can find the rest of the series on rubico's [awesome resources](https://github.com/a-synchronous/rubico#awesome-resources)
Dot vs Bracket object notation in Javascript
Tags: javascript
Published: 2020-06-15 00:00:00

---
  title: Dot vs Bracket object notation in Javascript
  published: true
  tags: JavaScript
  date: Mon Jun 15 2020 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/dot-vs-bracket-notaion-objects-javascript
  cover_image: https://melvingeorge.me/_next/static/images/main-93e65de648f8b1b54e3668674b12a2c2.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/dot-vs-bracket-notaion-objects-javascript)
  
Consider this object,

```javascript
const Person = {
  name: "John",
  age: 23,
  email: "john@example.com",
};
```

We can access this object's properties using the dot notation and bracket notation.

## Dot Notation - `.`

Let's access the `name` property on the `Person` object.

```javascript
const Person = {
  name: "John",
  age: 23,
  email: "john@example.com",
};

// using dot notation
const personName = Person.name; // Result: John
```

- Properties can be accessed using the `.` after the object's name followed by the property name you need to access.
- It most common way of retrieving property from an object.

## Bracket Notation - `[]`

We can use our old object `Person`.

```javascript
const Person = {
  name: "John",
  age: 23,
  email: "john@example.com",
};

// using bracket notation
const personName = Person["name"]; // Result: John
```

- Properties can be accessed using `[]` after the object's name followed by the property name inside the bracket.

### Why do we need bracket notation if we have dot notation?

- Bracket notation helps in getting computed value.

Consider this object,

```javascript
// defining new variable with value age
const propertyName = "age";

const Person = {
  name: "John",
  age: 23,
  email: "john@example.com",
};

// access object property by passing variable value
Person[propertyName]; // Result: 23
```

Here the `Person` Object is given variable `propertyName` inside the bracket. JavaScript checks the value of the variable and puts that value into the bracket and then returns the property value from the object.

Bracket notation is useful when working with dynamic data.

### Feel free to share if you found this useful 😃.

---
Twitter authentication with Go Language and Goth
Tags: go, sociallogin, oauth
Published: 2020-09-10 05:44:59

---
title: Twitter authentication with Go Language and Goth
published: true
date: 2020-06-15 00:00:00 UTC
tags: Go,SocialLogin,OAuth
canonical_url: https://www.loginradius.com/engineering/blog/twitter-authentication-with-golang-and-goth/
---

In this blog, we’ll be implementing authentication via Twitter in a Golang web application. For this, we’ll be using Goth, a social authentication middleware for Golang. Pre-requisites: Basic knowledge of HTML/Golang Golang should be installed in your system Firstly, We need to…

   
[Read On](https://www.loginradius.com/engineering/blog/twitter-authentication-with-golang-and-goth/)
Understanding types of Errors and how to handle them! 
Tags: javascript, codenewbie, tutorial, codequality
Published: 2020-06-14 23:29:07

As Programmers, we all want to that works. And no one really enjoys getting errors, or the anxiety that comes from dealing with them. The best way around this would be to set up error detection and figure out the best way to handle them. My goal with this brief blog is to show you how to properly handle JavaScript and avoid shipping code that's messy and full of bugs. 

First, we must understand that errors have different types.  
1) **Syntax errors**: when your code is compiling. 
2) **Runtime errors**: that are caused when executing/running your code.
3) **Logic errors**: that are caused by you as a programmer during your coding and writing functional logic. 

Example of **Syntax Error**: 

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

This code: will cause a syntax error because it is missing a closing parenthesis, even though the code below it might run if it doesn't depend on it all. 



Example of **Runtime Error**:

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

This code: will cause a runtime error because openObject is not a method in javascript nor does it even exist.


Example of **Logic Error**:


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9f0nh252w7afmw5mv7a5.png)

if the inputs were (5, 2.5) this code will also cause a error,  because it can’t handle fractional exponents, even though mathematically we can raise a number to the halfth power but in javascript this can be done with Math.pow()..


So how can one avoid these errors and what are the best methods for error handling?

These are two of the many ways:

**Try & Catch:**
try statements are statements that will execute. 
If an exception occurs, the exception is placed in e and the catch clause is executed otherwise, the catch clause is skipped. The last clause executes after the try statement is finished, 
it executes regardless of whether or not an exception was thrown or caught.

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


**The onError():**

This error handling was the first event handler to facilitate and handle errors in JavaScript, it can be used in many different ways, below is example of how to use to to make sure pictures load properly! 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1mzmi8i4t8695rfd1xx2.png)


As Programmers, we all knew there many rooms to improve and master our skillsets and coding functionality, there’s no harm in trying, and no shame in admitting failure. There will always be mistakes, it’s what we do about them that matters in the end. I hope that you learned from this blog as much i did reviewing and writing up this content! Happy coding!
Monolith/Microservices to Family/Company analogy
Tags: microservices
Published: 2020-06-14 23:21:38

Today I was reading Chris Richardson's book Microservices Architecture and it struck me that the Monolith to Microservices relation is analogous to that of a Family and Company.

Firstly, from a very high level view, both Monolith diagrams and Microservices diagrams have a bunch of boxes with various connections between them. What is the fundamental difference between them? The main difference is how the boxes are related. The boxes in the Microservices talk to each other only via Interprocess connection. Every other difference between the two architectures stems from this basic difference. There is no such restriction in the Monolith. 

If you consider a family business run by a close-knit family. They generally tend work very efficiently as a group and accomplish a lot more than a group of strangers. There are many reasons for this, but the primary reason is that they have a very strong informal communication amongst themselves. 

This works really well up to a point. If the business grows beyond the capacity of the family,  they need to get outsiders to help them, Then things change. Their existing communication patterns won't work. They'll have to develop some formal ways of interacting with the outsiders. Once these formal ways are developed, then they can bring in a lot many outsiders and accomplish a lot more. People can be easily replaced as well.  They can become a much bigger company. 

Similarly, the communication between the boxes in a monolith are easy and don't require too much formality. However when the communication is constrained between boxes as in Microservices where it is forced to happen via Interprocess communication, it needs to become a lot more formal. The communication has to be via formal contracts. So the boxes become independent. They can be replaced with other boxes. More boxes can be brought in. 

So, although communication between any two entities is constrained and formal and therefore poorer, it paves the way for the system to grow larger.
What are Optionals in Swift Anyway?
Tags: swift, beginners
Published: 2020-06-14 22:44:50

I have taken it upon myself to learn Swift, the programming language created by Apple for use on their devices. As if learning JavaScript, React, Python, Flask and Django isn't enough! I'll admit, I didn't know much about the language before I started it. I've seen sample code or screenshots posted online and they look so... confusing. It turns out, they are confusing *but* many of the code is autogenerated for you when you drag-and-drop an element into your file. Yep, I didn't know it was partly a visual language where you get to point and click on a simulated device to interact with it. Amazing!
 
I'm only a few hours into my course but I've already learned so much. Some things I like, somethings I don't like. One of those things I don't like is that you aren't able to reassign a variable to a different data type. What do I mean by this? If I were to create a variable called `myName` and set it to a some string, I can't reassign `myName`'s value to, let's say, an integer. Or a float, double, array, etc. It can forever only be assigned to a string type. I hate it!
 
To top it off, you can't assign a variable the value of `nil` and reassign it to a primitive data type later. Lame! I know! This is problematic for me because I'm used to doing this all the time. In React, before any fetching occurs, I set my states to `null`. They can then easily be reassign to a string, array, object, etc. This isn't possible in Swift.

So what are the different methods to best combat optionals? There's `if let`, force unwrapping and optional chaining; but, what is recommended by many Swift developers is the `guard let` statement. This is the one I want to talk about. First, let's consider this single line of code:

```swift
var optionalNumber: Int?
```

What it's saying is to create a variable called `optionalNumber` and assign it the `Int?` property. This means that it will either be an integer or a nil value. Obviously, it will never be both, but as I said previously, if it's one data type, it can never be the other.

`Guard let` statements are great because it provides an early `return` in a function should an optional be equal to `nil`.

```swift
func doubleNumber(num: Int?) {

  guard let num = num else { return }

  print("The doubled number is \(num * 2)")

}
```

So what we're doing in this function is returning double the number that we pass in as an argument. If it's `nil`, however, it will exit the function early and not reach the print statement.

The second line of code is our `guard let` statement that catches an `nil` values. It does that by creating a temporary variable with the same name as `number`. If `number` is not `nil` it gets skipped. If it is, it will run the code within its curly brackets. Remember, the brackets are on one line but you can use it in a multiline to add more lines of code before the `return` statement.

And that's all there is to `guard let` and optionals! If you're interested in learning more about optionals, I suggest you take a look at the other ways you can use them which I provided above.
Error handling in javascript
Tags: javascript, beginners
Published: 2020-06-14 22:28:19

Errors in your code are inevitable. Controlling the flow and error handling are important parts of debugging and making your program run smoothly. 

In this post, we'll cover **throw**, **try/catch**, and **finally**. 

##Throw

The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be executed), and control will be passed to the first catch block in the call stack. If no catch block exists among caller functions, the program will terminate. 

If you know what your value shouldn't be, you can add a throw statement to your function and catch unapproved values before they continue. 

```js
let num = 12

if(num === 12){
  throw "I don't like this value"
}

//expected output: Uncaught I don't like this value
```
You may throw any expression, not just expressions of a specific type. The following code throws several exceptions of varying type: strings, numbers, booleans and objects.

##Try...Catch

The try...catch statement marks a block of statements to try, and specifies one or more responses should an exception be thrown. If an exception is thrown, the try...catch statement catches it.

The try...catch statement consists of a try block, which contains one or more statements, and a catch block, containing statements that specify what to do if an exception is thrown in the try block. 

```js
let json = '{ "age": 30 }';
 
try {
 
  let user = JSON.parse(json); 
  if (!user.name) {
    throw new SyntaxError("Incomplete data: no name");
  }
 
  console.log( user.name );
 
} catch(e) {
  console.log( "JSON Error: " + e ); 
}
```
When we obtain our JSON object, we find there is no name property. Now we throw our new Syntax error, which means that our catch block will run and log the error in the console. If there was a name in the JSON, it would log the name. 

##Finally

The finally block contains statements to be executed after the try and catch blocks execute. Additionally, the finally block executes before the code that follows the try…catch…finally statement.

It is also important to note that the finally block will execute whether or not an exception is thrown. If an exception is thrown, however, the statements in the finally block execute even if no catch block handles the exception that was thrown.

```js
try {
 
  let user = JSON.parse(json); 
  if (!user.name) {
    throw new SyntaxError("Incomplete data: no name");
  }
 
  console.log( user.name );
 
} catch(e) {
  console.log( "JSON Error: " + e ); 
} finally {
  console.log("This will always run, even when there's no exception")
}
```
How to Install MySQL 8 on Windows 10
Tags: mysql8, windows10
Published: 2020-06-14 22:26:40

---
title: How to Install MySQL 8 on Windows 10
published: true
description: Simple step by step instruction on installing MySQL 8 win chocolately on Windows 10, creating password and creating database with mysql
tags: mysql8, windows10
//cover_image: https://direct_url_to_image.jpg
---


We are going to install chocolatey (a package installer for Windows ) that will let us install mysql 8 with one command on the fly, that will save us time and on behalf of us it will go ahead and configure them as well.

## Install Chocolatey 

Launch your powershell with admin rights and run the following command
`Set-ExecutionPolicy AllSigned
`
Followed By 

`Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
`

Now relaunch the powershell and check chocolatey version and install MySQL

`choco --version
`
## Install MySQL 8 With Chocolatey

`choco install mysql -y
`
This command will install latest version of MySQL and set it to system's path. 

 
## {Video} Install MySQL with Chocolatey

{% youtube CS6o_0j1QdE %}

### Related Post..
[MySQL is not recognized on Windows OS](https://tubemint.com/mysql-is-not-recognized-as-an-internal-or-external-command/)
How to convert .py file to .exe 2 methods
Tags: python, beginners, tutorial, codenewbie
Published: 2020-06-14 21:10:04

hello , today i will show you how to convert python file(.py) to an executable file(.exe) .
##**first method:**
first , open your terminal or command line , write this command to install **auto-py-to-exe**
<pre>
pip install auto-py-to-exe
</pre>
second, after installing **auto-py-to-exe** write this command to open  
**auto-py-to-exe**
<pre>
auto-py-to-exe
</pre>
after writing this command this window will open :
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n4j1nyg6jkuegtx0ytsy.png)
set the script location then convert.
##**second method:**
we will use py installer
in the command line write:
<pre>
pip install PyInstaller
</pre>
After installing **pyinstaller** write the path of the file.
**example**
<pre>
cd Desktop
</pre>
after going to the path of the file:
<pre>
pyinstaller name_of_the_file.py
example
pyinstaller pass.py
</pre> 
after the build complete select file called dist:
 ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8pg286zi3kukjt3nsugg.png)
then select name of the file.exe:
 ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qx9bx8bxogbkfzc2lndf.png)
###**Note: auto-py-to-exe uses pyinstaller**:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/iat7qoeocczqgxoe0eup.png)
Don't forget to follow me .
you can support me on buy me a coffee:
<a href="https://www.buymeacoffee.com/Oxyoxide" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>
Twitter : https://twitter.com/Oxy_oxide
buy me a coffee : https://www.buymeacoffee.com/Oxyoxide
thanks for reading .
Beggining my #100DaysOfGADS2020 journey
Published: 2020-06-14 21:03:21

Day 1 of #100DAYSOFGADS2020 : 
I got accepted into the program and I so happy. I mostly used this day to get acquinted to the slack workspace and make new friends. Hope this improves me greatly.


Day 2 of #100DAYSOFGADS2020 : 
Didn't really do much today. Went through the courses given to us and kind of revised basic programming functions. Most of what I watched are things I already know but I guess it doesn't hurt to learn it again.

Day 3, 4 & 5 of #100DAYSOFGADS2020 : 
I managed to go through some courses which contain things I already know but turns out I really do not know much. I Learnt more about Android Studio. THings like Refactor, debug (using break point) etc are tools that I have never really used well in Android Studio but I am learning to now. I now prefer debug instead of run (which i use every single time). Also I learnt the different methods of the Logcat and how it can be used (and that you can right-click to clear the Logcat). Also learnt more about the Gradle files and how I can 
manipulate it to get what I want. Guess it's not bad to "start afresh"
The React useState Hook
Tags: react, hooks, state
Published: 2020-06-14 20:49:52

The React useState hook (function) allows users to update the state of a function component. Historically, only class components had state capabilities, and these only applied to objects. However, the function component useState hook can be used with booleans, objects, arrays, strings, numbers, etc.

When we build React components with state, we allow components to render dynamically based on user input.  To get started, we import useState and create a function component:

```jsx
import React, { useState } from 'react';

export default function Demo() {
  return (
    <div>
      
    </div>
  )
}
```

The useState hook is called directly inside the function component, like so:

```jsx
import React, { useState } from 'react';

export default function Demo() {

const [user, setUser] = useState('');

  return (
    <div>
      
    </div>
  )
}
```

Let's break down how this hook is constructed. It's declared as a const variable and has two values, a state component and the name of a function you will call to change the state. Additionally, the setState function is passed the initial value as its argument.

1.) A state variable: user
-The state variable preserves value in between function calls, so this is what you will call to display the current state of user.

2.) A function that updates state: setUser
-This creates the name of a function that you will call to change the state. React has already built in the functionality, so your only requirement here is giving this function a name and calling it where you need it.

3.) The initial state: ('')
-This value us what your component will render until the state is updated.


Now let's take a look at how these values are used inside of the function component:

```jsx
import React, { useState } from 'react';

export default function Demo() {

const [user, setUser] = useState('');

  return (
    <div>
      <p>
        Welcome {user}
      </p>

      <form>
        <label>
          Name:
        </label>
        <input type="text"
          value={user}
          onChange={event => setUser(event.target.value)}
        />
      </form>
    </div>
  )
}
```

When the user types their name into the form input element, the setUser function is called because it is invoked by the onChange function. This updates the user state variable and will then display this updated state where it is called in the paragraph element.