teleren/devto huggingface dataset:
Introduction To Recursion & The Call Stack
Tags: beginners, javascript, career, todayilearned
Published: 2019-11-13 15:41:13

## What is Recursion?

Recursion is when a function calls itself.

## Syntax:

```javascript
function func(){
   if(/*base case*/){
      return something  
   } else { // recusive case
      func()
   }
}
```

## Example
Let's write a function that returns the factorial of a number passed in as argument.

The factorial of a number is that number multiplied by every number from itself down to one.  

4! = 4 * 3 * 2 * 1 = 24
3! = 3 * 2 * 1 = 6

```javascript
function factorial(num){
   if (num === 1) { // The factorial of 1 is 1 so our base case is set
      return num;
   } else {
      return num * factorial(num -1) // Recursive case 
   }
}
```

The best way to understand this is by going through the function step by step. To visualize, we will use a <b>Call stack</b>. Please <a href="https://developer.mozilla.org/en-US/docs/Glossary/Call_stack">click here</a> if you don't know what a call stack is before proceeding.

<b>TL;DR</b>
Call Stack represents what order the functions are being called in and what variables they are being called with.

Order:
1. factorial(4) => 4 
2. factorial(3) => 3 
3. factorial(2) => 2 
4. factorial(1) => 1 * (1-1) = 1 = base case

4 * 3 * 2 * 1 = 24

Okay, I know for those who are not acquainted with recursion may find this cumbersome. I urge you to read more about it. 

But the baseline is, a recursive function will continue to call itself until the base case is fulfilled!

See you in the next one!
Least Confusing Way To Check Lots of Conditions
Published: 2019-11-13 15:29:23

---
title: Least Confusing Way To Check Lots of Conditions
published: true
description: 
tags: 
---

What is most clear and easy to read:

```
const myCondition = (a && b) || (a && c) || d || e;
```

-- or --

```
const myCondition = [a && b, a && c, d, e].some((cond) => !!cond);
```

Comment and tell me what you think! I tend to find lots of boolean logic difficult to read just because there are so many gotchas and I'm looking for better ways to write this kind of code.
DVD Player
Tags: csharp, dotnet, dvd, help
Published: 2019-11-13 15:20:39

Can someone please tell my how to play dvd files with c# code I can detect the dvd and the title of the disc playing avi and mp4 files works just not if there on a dvd drive. 

        //Button to play dvd
        private void TStripBtnPlay_Click(object sender, EventArgs e)
        {
            //axWinMP.URL = "f:\\\\VTS_01_1.VOB";  //VIDEO_TS.IFO";
            //axWinMP.URL = "D:/videos/video.480p.mkv";
            
            axWinMP.URL = "f:/VIDEO_TS/VIDEO_TS.IFO";
            //axWinMP.m
            axWinMP.Ctlcontrols.play();
            //axWinMP.dvd.domain;
        }
Day 9 of⚡️ #30DaysOfWebPerf ⚡️: Image Resolution
Tags: webperf, images, performance, webdev
Published: 2019-11-13 15:14:50

{% twitter 1194631798405251072 %}
{% twitter 1194631801395789826 %}
{% twitter 1194631854625701888 %}
{% twitter 1194632057076379649 %}
{% twitter 1194632084473565185 %}
{% twitter 1194632087409549313 %}
Daily Challenge #116 - Shortest Knight Path
Tags: challenge
Published: 2019-11-13 15:12:01

---
title: Daily Challenge #116 - Shortest Knight Path
published: true
series: Daily Challenge
description: Given two different positions on a chessboard, find the least number of moves it would take a knight to get from one to the other
tags: challenge
---

Given two different positions on a chessboard, find the least number of moves it would take a knight to get from one to the other. The positions will be passed as two arguments in algebraic notation. For example, `knight("a3", "b5")` should return 1.

The knight is not allowed to move off the board. The board is 8x8.

For information on knight moves, see https://en.wikipedia.org/wiki/Knight_%28chess%29

For information on algebraic notation, see https://en.wikipedia.org/wiki/Algebraic_notation_%28chess%29

***

_This challenge comes from ElDynamite on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Welcome Thread - v48
Tags: welcome
Published: 2019-11-13 15:10:17

---
title: Welcome Thread - v48
published: true
description: Welcome to DEV! A thread of hellos and intros.
tags: welcome
---

![rainbow high five](https://media.giphy.com/media/129P2fIHBVzby0/giphy.gif)

### Welcome to DEV!

1. Leave a comment below to introduce yourself! You can talk about what brought you here, what you're learning, or just a fun fact about yourself.

2. Reply to someone's comment, either with a question or just a hello. 👋 

**Great to have you in the community!**
Java Deep Learning cookbook free copies
Tags: java, machinelearning, books, github
Published: 2019-11-13 15:04:14

Hello All,

I'm the author of the book "Java deep Learning cookbook" -> https://www.amazon.com/Java-Deep-Learning-Cookbook-Deeplearning4j-ebook/dp/B07YLYH2KY

Are you a Java developer who want to explore deep learning? Do you have basic understanding on deep learning? Then this book is for you! 

I have some limited amount of free review copies available! If interested, feel free to comment here.
JavaScript Begginer Loop+Conditional question
Tags: javascript, beginners
Published: 2019-11-13 14:52:34

Hi there, 

I've just started to study javascript and I'm reading the Eloquent Javascript book, recommended by several friends and websites I've read. 
I just finished the 3 chapter where I had to write one particular piece of code to answer to one of the challenges on the book. I couldn't do it at first and them I looked at the answer provided by the book, and I still can't figure it out why it was done like that.

Could somebody try to explain me in a better way as to why this code is written like this? Thank you so much for all replies.

var  size = 8;
for (var i = 1; i <= size; i++) {

  var line = (i % 2)?'':' ';

  for (var j = 1; j < size; j++) { 
      line += (j % 2)?'#':' ';
  }

  console.log(line);

}

The task was to write a code that would produce a table chess with spaces and # simbols with a size of 8x8.

What I can't quite understand is: 

1- Why we use (i % 2) in this case?
2-What does the ? symbol represents on this statement?
Product Makers - Why Are You Not Making Enough Sales?
Published: 2019-11-13 14:47:39

As a solo dev without doing freelancing, I need to make products and sell. Some products don't perform well and this is a map I create to clear the fog:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/70b34r51biya1u6tao1h.png)

As I made the map, I realized one very important thing:
=> I think money is more valuable than my time (spending on ads is bad and spending time on writing, making videos is good). 

This could be a fault in my thinking.

So, what is your approach to marketing your products?
Why do I like JavaScript?
Tags: javascript
Published: 2019-11-13 14:42:33

I have worked with Python, Java, but the language that I most love and admire is JavaScript, much to the freedom (sometimes used too much) that it gives to us developers, and to its high productivity rate.
In the following, I explain a bit more about what do I like in JavaScript.

**Prototypal Inheritance**

For those who are not familiar with these terms, in Javascript objects inherit directly from other objects, unlike traditional OO languages, where objects inherit from other classes.
This paradigm makes the code more flexible, you will not have to create a new class to create a specific method to do something very specific, you can just add to the prototype of the object. One thing that makes this very easy to understand is when you take the toString() functions as an example, every object in Javascript has the toString() function, because it is already implemented in its prototype.

**Community**

Due to its high usage, the Javascript community is getting bigger and bigger. If you are like me and are used to google errors like “_funName_ is not a function”, you’ll know that many people can help you on StackOverflow, or somebody has already developed a beautiful library that does exactly what you need (and has made available on npm or on Github).

**Node.js**

Popularly, JavaScript is known for its ability to run in the client-side, but in 2009 the Node.js project was released, which allows developers to write command-line tools and server-side scripting using JavaScript.
Since its release, Node.js has been an alternative to server-side development with its event-driven architecture and with awesome frameworks like Express.js that helps developers create RESTful APIs.

**Frameworks**

Despite the framework war that many developers have created, I found fantastic the number of frameworks and libraries created in JavaScript, they all have its pros and cons, and one will be more suitable to your solution than others.

I have been lucky to work with the three most popular frameworks (library in the case of React) in the market, Angular, React, Vue, and I have learned much working with them, and if we analyze a framework such as Vue, we can see that the frameworks are envolving and helping our lives.

Finally, the popularity of JavaScript with frameworks and libraries, I’d say JavaScript will get bigger and bigger, and I strongly recommend if you are a developer and don’t work with JS, I’d say give it a try, because this language is here to stay, at least for now.
Day2:Tuple,Array - 100DayOfRust
Tags: rust
Published: 2019-11-13 14:35:33

## Tuple, Array and Slice

```rust
use std::mem;

fn calculate(a: i32, b:i32) -> (i32, i32) {
    (a + b, a - b)
}

fn stat_slice(slice: &[i32]) {
    println!("Slice has length: {}", slice.len());
}

fn main() {
    // unpacking to assign
    let (a, b) = (5, 3);
    // get the returned tuple
    let (a, b) = calculate(a, b);
    println!("a is {}, b is {}", a, b);
    
    // array
    let a:[i32; 5] = [1, 2, 3, 4, 5];
    for num in a.iter() {
        println!("num is {}", num);
    }
    println!("First num is {}", a[0]);
    println!("Size of A is {} bytes", mem::size_of_val(&a));
    
    // slice
    stat_slice(&a);
    stat_slice(&a[2..4]);
}
```

Result:
```
a is 8, b is 2
num is 1
num is 2
num is 3
num is 4
num is 5
First num is 1
Size of A is 20 bytes
Slice has length: 5
Slice has length: 2
```
Functional programming is great, but not for the reasons everyone keeps telling you
Tags: functional, algorithms, beginners
Published: 2019-11-13 14:31:48

There is no necessarily fundamental reason why functional programming is better than a procedural or object oriented approach. Yes, pure functions, clean code, readability etc. *may* make your programmes safer and easier to reason about.

But that isn't why I like functional programming.

I simply prefer the way it allows me to think about problem solving. Maybe the world is inherently split into programmers who think functionally and those who think procedurally - someone should fund a psychology research project!

As an example, say I have some data structure and would like to transform it. My thought process is to start writing down a list of actions that I think will be needed. This is an iterative process, as the consequences of each action becomes clearer and extra steps are added. I might also realise that a particular action is really a special case of something that already exists - so I just co-opt that action (or function). In doing so, I may have to change it to make it more generic - but that's fine because it's a pure function and therefore safe.

After a while, I might write some pseudo code which simply sets out the logical action sequence - often the initial list of actions *is* the pseudo code. And this pseudo code often ends up being the actual function I want. Then there is a detail which is the additional implementation needed to flesh-out some of the functions implied by specific actions in the pseudo code.

If there is iteration needed, that's a single recursive function which can be defined in pseudo code by name at this stage. It is sufficient to know that an iteration is needed and what form the output will take.

If there is a sequence of actions needed, that's a composition which the pseudo code represents with a sequence of functions.

If the logic determines that data needs transforming (e.g. filtering) then that's fine, just state it as an action. The result will be used further down the pseudo code and no need to worry about side-effects because there are none.

So the logical steps to get from initial data to result are quickly clear and little additional infrastructure is needed to just make it happen. This to me is how many people already solve problems and therefore functional programming doesn't necessarily need any change of mindset.

However, the wrinkle is that the incremental state of the data is not immediately obvious - the functional approach almost wants you to not care. And therefore your real mindset switch is to one of imagining data structure transformations as the chain of functions progresses.
[Go] simple comparison between GoLand, VScode-Go, Vim-Go 
Tags: go, goland, vscode, vim
Published: 2019-11-13 14:21:07


These are 3 tables I used to introduce "Refactoring in GoLand" in a meetup event.

They are features I used in daily programming frequently.I think they are also good cheat sheet for gophers would like to switch between different editor/IDE, so I share here and hope helpful to someone. 

Tables are sorted in 3 categories:
- Navigation: like search, go to code block/file etc.
- Generate: features that IDE/editor helps you write less code
- Refactor: features to save your time and do refactoring safety


PS: I don't use vim-go, just study the document, if any mistake , please inform me to correct it.  Any feedback is welcome.



### Navigation
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/rpey3mjqmv61unt8s2j5.png)
### Generate
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/5z2h9p2s9iy50a3m42e2.png)
### Refactor
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/u9nj6ml1avg4xdwyqxik.png)
Fetching data from an external API in React
Tags: react, javascript
Published: 2019-11-13 14:17:38

---
title: Fetching data from an external API in React
published: true
description: 
tags: reactjs, javascript
cover_image: https://ferrariwebdevelopment.s3.us-east-2.amazonaws.com/assets/20191001-fetch-from-api.jpeg
---

## Using the Fetch API to retrieve data

When we don't pass `props` to a React class component we can omit the class constructor. We can just set the state as a variable on the class in this way:

```js
class Dogs extends React.Component {
  state = {
    dogs: []
  }
}
```

Typically, the `state` object is initialized to an empty value.
In the example above we set the dogs attribute of the `state` object to an empty array.
This is because we expect to receive the `state` data from an external `API` as an array.

We call the external `API` in `componentDidMount()`, like we saw in a previous article.
When we receive the data, we update the state with the array we receive.

In the example below, we fetch an array of dog images from the `dog.ceo` `API`. We use the Fetch `API` that is included in Javascript. The Fetch `API` provides an interface for retrieving resources on the internet. It's similar to `XMLHttpRequest` but with additional features.

```js
componentDidMount() {
  fetch('https://dog.ceo/api/breed/husky/images')
    .then(response => res.json())
    .then(dogs => this.setState({dogs: dogs.message}))
    .catch(error => console.log('Error:', error));
}
```

`fetch()` returns a Javascript *Promise* that calls the `then()` method if it resolves correctly, or the `catch()` method if it encounters an error.

We will talk about Promises in future articles. For now let's just say that `fetch()` works asynchronously and retrieves data from an external `API`.
After we get the data successfully, `fetch` calls the first `then()` method above where we convert the response to `JSON` format with the call to `response.json(`).

The result of this method call is then sent to the next `then()` method.
In it we use `setState()` to update the initial component state (an empty array) with the array of dog images returned by the `API`.

At this point we have achieved our goal of updating the component state with data from an external `API`.

The `catch()` method handles any errors that may occur during the `API` call, like a page not found or a dropped connection and will not be called if the operation is successful.

There are other ways to fetch external data in React. One popular method is to use the Axios library, that is similar to the Fetch `API`.
We will learn how to use Axios to fetch data in a future article.
Apples announces new 16-inch Macbook Pro
Tags: news, apple, discuss
Published: 2019-11-13 14:13:38

---
title: Apples announces new 16-inch Macbook Pro
published: true
description: Discussion thread for the new Macbook Pro thread
tags: news, apple, discuss
cover_image: https://thepracticaldev.s3.amazonaws.com/i/rh76drwo4kolf4kt1olw.png
---

Apple [announced](https://www.apple.com/newsroom/2019/11/apple-introduces-16-inch-macbook-pro-the-worlds-best-pro-notebook/) the new 16-inch Macbook Pro.

Per usual, their [main landing page](https://www.apple.com/macbook-pro-16/) goes over the key features.  The major highlights:

- 16-inch Retina display
- Up to 8-core processor
- Up to 8TB SSD storage
- Up to 64GB of memory
- AMD Radeon Pro 5000M series graphics
- Six-speaker sound system and studio-quality mics
- Up to 11 hours of battery life
- Dedicated escape key
- Dedicated arrow buttons

What does everyone think?
About Garrett Hofer
Published: 2019-11-13 14:09:18

As a junior in high school, Garrett Hofer helped his father get back on track for his life goals after losing his long-term job in his early 50s. This inspired Garrett Hofer Colorado in his career choice of helping families with their finance after he learned there are many brilliant people who don’t have a plan for the unexpected events in life.

Garrett Hofer graduated with honors from the University of Wyoming with a B.S. in Finance. While Garret Hofer attended the University of Wyoming, he played Club Rugby and was the President of the Financial Management Association. 

Garrett Hofer Colorado attained the certification as a CFP® Professional at the early age of 24. Garrett Hofer enjoys the comprehensive process of helping people understand and achieve their financial aspirations.

Garrett Hofer Colorado dedicates time to the ACP Veterans Mentor Program. This is Garrett Hofer’s 3rd year of engagement working with a military Veteran to ensure a successful transition from military life to private enterprise.  

In Garrett Hofer’s free time, he focuses on finding ways to create an active and healthy lifestyle for himself and his family.  Garrett Hofer Colorado enjoys spending quality time outside and enjoying a wide range of activities such as hiking, fishing, horseback riding, basketball, rugby, football, soccer, swimming, playing at the beach, and climbing rock walls.
Weekly Picks #101 — Development Posts
Tags: javascript, webdev, flutter
Published: 2019-11-13 13:38:59

* [Launching Postwoman v1.0 ? - free, fast & beautiful alternative to Postman ?](https://app.dailynow.co/r/c3fce357a1281d0c62165747f60d9611)
* [Top 7 Dark-Themed Admin Templates](https://app.dailynow.co/r/4410b4f17ef93af6a5832c6e4061d323)
* [What is super() in JavaScript?](https://app.dailynow.co/r/3d0d841d826865639d034f84e03d6445)
* [What Every Developers & Programmers Need to Read in November](https://app.dailynow.co/r/04411c84df7b24100ae4c2995f3426ad)
* [Greedy Algorithms](https://app.dailynow.co/r/39ef95d76c72cd6a67d165eb8dbd76e0)
* [Seven Essential JavaScript Functions](https://app.dailynow.co/r/4d6e907e17a7be81f168c3e5e884801d)
* [The Path of the Self-Taught Programmer: Avoiding Common Problems](https://app.dailynow.co/r/4ca933bca72b147f1335787108418e8e)
* [Introduction to GitHub Desktop: A GUI Enhancement to a CLI Approach](https://app.dailynow.co/r/8a6472e9c47f75ad1b38988ab1cb8dd9)
* [A new JavaScript library for building user interfaces, Easy, Fast, And readable Syntax, Mix With React + Flutter Style](https://app.dailynow.co/r/f635a500d96c67fb4318288b2e6ba61b)
* [Build and Deploy a Flutter Web App](https://app.dailynow.co/r/cea4dc7fca9b63379d75dbaaa3d459a6)

* * *

[_Thanks to Daily_](https://www.dailynow.co/) _developers can focus on code instead of searching for news. Get immediate access to all these posts and much more just by opening a new tab._

[![Daily promotion cover](https://cdn-images-1.medium.com/max/1024/1*7bwIhcH467BKX5Ni8XWpQg.jpeg)](https://www.dailynow.co/)
Killing a process in Linux
Tags: linux, beginners, tutorial
Published: 2019-11-13 13:51:23

---
title: Killing a process in Linux
published: true
description: 
tags: #linux #beginners #tutorial
---

1 List running processes
2 Kill a process by PID
3 Default signal sent by the kill command
3.1 Force killing
4 How to kill all processes by name?
5 How to kill all processes by a user?
6 How to kill a nohup process?
7 How to run a process in the background?
7.1 Using screen command
8 How to kill a background process?
9 How to kill stopped processes?
10 Kill operation not permitted


https://likegeeks.com/killing-a-process-in-linux/
Binary Search - Intro
Tags: beginners, javascript
Published: 2019-11-13 13:46:14

Binary search is a widely known and most implemented algorithm in different forms in Computer Science. It is a relatively essential algorithm to know because it's widely used, its popularity in interview questions and its performance.

A binary search algorithm: :
- Allows a user to search for a given value inside of a list.
- It runs in O(log n) time complexity - !Important.
- Can be written as a recursive function

<b>Scenario</b>

If you have a dictionary: A B C D E F G H  I J K L M N O P Q R S T U V W X Y Z and you want to find a single word in the dictionary, you would find it by doing binary search probably by not even realizing it. 

Let's say you want to find the word <i>House</i> in the dictionary, you would open up the dictionary to the middle, and you'd notice that you are in the "M" section. You know that "House" is before the "M" section, so you would totally forget about the second half of the book.

So you've just cut through the input size, the number of elements into half remaining with A B C D E F G H I J K L. Again you would go into the middle of this section and notice that we are now in the F section. H is after F so you would ignore the first half and remain with G H I J K L. We again cut our input size into half and land on section I, we throw away everything after I because H is before I. We go to the middle of what is left G H I and we are now in the H section and we have successfully found the word House. 

By this, you can find that it's efficient because we have only performed 4 operations in an input that has 26 elements. As our input size grows, the number of operations that we will perform will not grow <b>proportionally<b/> but it'll grow <b>logarithimically</b>.

If we had an input size of about 4000 elements it will only take us about 12 operations to find the element that we are looking for.

We will be coding out our binary search in a recursive form. Recursion is an incredibly important concept to understand and be able to implement it in programming. 

In the next post, I'll share out about recursion before we begin coding our binary search algorithm.

See you!
Ruby on Rails 6 with React and Webpacker Part II
Tags: rails6, react, webpacker, railsreactwebpack
Published: 2019-11-13 13:44:56

---
title: Ruby on Rails 6 with React and Webpacker Part II
published: true
description: 
tags: #rails6 #react #webpacker #railsreactwebpack
---
In this part we will Integrate both the React and Rails.

{% youtube MfRGdRCLQIY %}