teleren/devto huggingface dataset:
Intro to the Switch Statement
Tags: javascript
Published: 2020-07-02 12:29:37

There are various ways to write if statements, and the switch statement is a convenient one in many cases. It can replace the need to write multiple if statements. The switch statement checks multiple cases and compares it to a given value. Then it executes the code in each corresponding case block. The switch statement can also have an optional default.

The switch statement will save quite a few keystrokes, and in some scenarios, can be easier to read than multiple if, if else statements.

It starts off with the switch keyword and takes in the argument of the variable whose value we'll be checking the cases against.

```
let fruit = "orange";

switch(fruit) {
 case "apple":
  console.log(`I have an ${fruit}.`);
  break;
 case "orange":
  console.log(`I'd like a glass of ${fruit} juice.`)";
  break;
 case "mango":
  console.log(`I'll try some ${fruit} slices today.`);
  break;
 case "pear":
  console.log(`I enjoy ${fruit}s more than I do apples.`);
  break;
default:
  "I'll take any fruit.";
}
```

```
function checkFruit(fruit) {
  if (fruit === "apple") {
    console.log(`I have an ${fruit}.`);
  }
  else if (fruit === "orange") {
    console.log(`I'd like a glass of ${fruit} juice.`);
  }
  else if (fruit === "mango") {
    console.log(`I'll try some ${fruit} slices today.)`;
  } 
  else if (fruit === "pear") {
    console.log(`I enjoy ${fruit}s more than I do apples.`);
  }
  else {
    console.log(`I'll take any fruit.`);
  }
}
```


The last default case in the switch statement acts as the else statement in the if/else if statement. If none of the cases match the value being provided, then the switch statement will console log "I'll take any fruit.".

The switch statement also uses colons `:`, not semi-colons `;` to create different cases, please be mindful of that syntax. 

The `break` keyword is necessary in the switch statement to ensure the code stops running once the case matches the value. Otherwise, the switch statement will run every case. 

The switch statement can prove useful in a variety of scenarios. You're likely to make fewer errors using a switch statement than multiple if/if else statements. It's important to be comfortable with if/if else statements before using the switch statement. The switch statement is not a replacement for the if/if else statement syntax, but rather an additional way to write if statements when you have multiple cases.
Rewriting to Haskell–Automatic Formatting
Tags: functional, haskell, servant
Published: 2020-03-19 16:48:13

You can keep reading here or [jump to my blog](https://odone.io/posts/2020-03-19-rewriting-haskell-formatting.html) to get the full experience, including the wonderful pink, blue and white palette.

---

This is part of a series:

- [Rewriting to Haskell–Intro](https://odone.io/posts/2020-02-26-rewriting-haskell-intro.html)
- [Rewriting to Haskell–Project Setup](https://odone.io/posts/2020-03-03-rewriting-haskell-setup.html)
- [Rewriting to Haskell–Deployment](https://odone.io/posts/2020-03-14-rewriting-haskell-server.html)

---

One comment in a pull request about code formatting was enough to convince us we needed a tool to solve the problem once for all!

We decided to go with [Ormolu](https://github.com/tweag/ormolu#editor-integration) because it's really similar to how [Elm Format](https://github.com/avh4/elm-format) behaves. In particular, from the readme, among other things:

> Implementing one "true" formatting style which admits no configuration.

and

> Let some whitespace be programmable. The layout of the input influences the layout choices in the output. This means that the choices between single-line/multi-line layouts in each particular situation are made by the user, not by an algorithm. This makes the implementation simpler and leaves some control to the user while still guaranteeing that the formatted code is stylistically consistent.

To install Ormolu it's enough to run the following:

```bash
stack install ormolu
```

Then formatting can be checked in CI with:

```bash
ormolu -m check **/*.hs
```

Or formatted with:

```bash
ormolu -m inplace **/*.hs
```

Also, [plugins](https://github.com/tweag/ormolu#editor-integration) are available to automate formatting whenever a Haskell file is saved! In VIM it works really well:

![Gif showing Ormolu formatting a Haskell file in a VIM buffer](https://odone.io/images/ormolu.gif)

---

Get the latest content via email from me personally. Reply with your thoughts. Let's learn from each other. Subscribe to my [PinkLetter](https://odone.io#newsletter)!
How to Effectively use a Single Monitor
Tags: productivity, wfh
Published: 2020-03-27 18:49:52

---
title: "How to Effectively use a Single Monitor"
published: true
description: "Working from home and missing your multi-monitor setup? I wrote up some tips on how to get more efficient with a single monitor."
tags: [productivity, wfh]
---

Original post: https://nabeel.dev/2020/03/27/single-monitor/

Many people I know love working with multiple monitors. Personally, I'm not a huge fan. The only times I find myself using a second monitor are
when I'm on a video conference (or watching a video) and want to keep working while I listen. Other than that, I'm generally a single-monitor user.

I feel like using a single monitor helps keep me focused. Instead of moving my head left and right between monitors, I use keyboard shortcuts to quickly switch windows on my screen. With many people working from home these days, I imagine many don't have the space for two monitors anyways.

Here are some tricks I use to make the most of my single monitor:

## Virtual Desktops

I use virtual desktops the way many people use multiple monitors. In Windows, you can press `win+tab` to view all your windows, and at the top you'll see a list of virtual desktops. Press the `+` sign to create as many as you need.

Switching between virtual desktops is fast and easy: hold the `ctrl` and `win` keys down, and press left or right to move between desktops. If you're not already comfortable with the `alt+tab` keyboard shortcut, then I highly recommend mastering it to quickly switch between windows.

## Split the Screen

The most common justification I hear for two monitors is: "I need to see two documents side-by-side." For most cases there's a simple alternative: Split Screen. In fact, I would argue that split screen is better than two monitors,
since the two documents can be placed closer together (or even overlapping!)
to make side-by-side comparisons even easier.

In Windows I use `win+left` and `win+right` all the time for this purpose. That keyboard shortcut will automatically size a window to occupy
the left or right half of your screen respectively.

## Invest in a Good Monitor

In my home office, I use a 27" Dell LED monitor. Not all 27" monitors are created equal. Consider getting a high-quality monitor and not the cheapest one possible. And definitely consider getting one high-quality monitor over two low-quality monitors.

## Your Laptop is your Second Monitor

My laptop is my primary work machine. I have docking stations at work and at home, so I just plug in and start working wherever I am. Usually my laptop's screen is turned off while I'm plugged into the docking station. For the few situations where I want a second monitor, I simply turn that screen on.

## End
Kunth-Morris-Pratt(KMP) Algorithm For Pattern Searching
Tags: typescript, javascript, codenewbie, dotnet
Published: 2020-03-19 17:35:27

**Introduction**

Pattern searching is an important problem in computer science. When we do search for a string in notepad/word file or browser or database, pattern searching algorithms are used to show the search results. Here is the list of available algorithms available to for this Job

Read the whole article here

{% medium https://medium.com/@avishekp86/kunth-morris-pratt-kmp-algorithm-for-pattern-searching-552661788e6b %}

If you've liked this article then please follow me on [twitter](https://www.twitter.com/avishekp86) to encourage me to write more article like this.
Returning Observable objects from combineLatest()
Tags: angular, rxjs, reactive
Published: 2020-03-19 18:07:49

---
title: Returning Observable objects from combineLatest()
published: true
date: 2020-03-19 17:56:59 UTC
cover_image: https://www.gilcreque.blog/uploads/2020/0b7e9a8c7c.png
tags: angular, rxjs, reactive
canonical_url: https://www.gilcreque.blog/2020/03/19/returning-observable-objects.html
---

In trying to use more Reactive patterns in Angular I have been using the `combineLatest()` RxJs method to combine several Observables into one Observable and using the `async` pipe to use the data in the template. This ensures that all of the data is available in the template by using `*ngIf`. One thing I did not like about using `combineLatest()` is that it returns an array of results back based on the array of Observables you handed to it. This made accessing this data in the template look messy and made it harder to understand what data you were accessing.

```typescript
cousePageData$: Observable<[User, Course]>;
const user$ = getCurrentUser(); // get the current user
const course$ = getCourse(courseId); // get course by course id
this.cousePageData$ = combineLatest([user$, course$]);
```

In the template this would result in array(`[user, course]`) as a result of using the `async` pipe (`<div *ngIf="cousePageData$ | async as cousePageData>`) and you would have to access `user` and `course` using the index on the array (`cousePageData[0]` and `cousePageData[1]`). As you can see, this obfuscates what data is actually being accessed at this indexes.

So I set out this morning to get this cleaned up in our repository and found a pretty easy solution in RxJs, using `pipe` and `map` to return the results of `combineLatest()` as an object.

```typescript
cousePageData$: Observable<{user: User; course: Course;}>;
const user$ = getCurrentUser(); // get the current user
const course$ = getCourse(courseId); // get course by course id
const cousePageData$ = combineLatest([user$, course$])
                       .pipe(map(([user, course]) => ({ user, course })));
```

In the template this would result in object(`{user: userData, course: courseData }`) as a result of using the same async pipe and you can now access `user` and `course` using the property name on the object (`cousePageData.user` and `cousePageData.course`).

Yay for less obsfucation! Let me know if you have any other ideas regarding this!
Watch collecting, it's addictive
Tags: watercooler
Published: 2020-03-19 20:12:09

It's crucial for your mental health to make room for a hobby, I'm serious, I used to say programming is my hobby, but put me in a group of strangers, I could not talk about anything... Not a thing in common, that's when I realized I was not really living my life.

I have a new hobby, it's a wierd one but I enjoy it. I intend to collect watches. The picture above shows my first and only mechanical watch so far, I kind of dig it. Mechanical stuff is so appealing, I wonder if it will make me a better programmer? 😂
Algorithm 202: Where I Belong in 3 Ways
Tags: algorithms, javascript, array, beginners
Published: 2020-03-19 22:07:52

If you are to queue according to your height, you will need to stand between someone that only you is taller than and someone that only you is shorter than - ``that is where you belong``.

This also applies when finding the position of an element in array where it is to be inserted.

```javascript

whereIBelong([1, 2, 3, 4], 3.5); // 3

whereIBelong([13, 23, 33, 45], 55); // 4

```

In how many ways can you determine the position of a given element?

Let me dish out to you 3 ways and I will give you a hint to one more in the [conclusion](#1)

### Prerequisite
This article assumes that you have basic understanding of javascript's array methods. 

### Let's do this using:

* push(), sort(), indexOf()

```javascript
      function whereIBelong(array, value) {
        let newArray = array.push(value);

        let sortedArray = array.sort((a, b) => a - b);

        return array.indexOf(value);
      }
```

* for...in...loop, break

```javascript
      function whereIBelong(array, value) {
        let newArray = array.sort((a, b) => a - b);
        let position = "";

        for (char in newArray) {
          if (newArray[char] > value) {
            position = char;
            break;
          } else {
            position = newArray.length;
          }
        }

        return position;
      }
```

* filter(), for...of...loop, indexOf()

```javascript
      function whereIBelong(array, value) {
        let newArray = array.sort((a, b) => a - b);
        let maxValue = 0;

        // collect all array values less than the given value
        let smallerValues = newArray.filter(char => value > char);

        if (smallerValues === []) {
          return 0;
        }

        for (char of smallerValues) {
          char > maxValue ? (maxValue = char) : maxValue;
        }

        return newArray.indexOf(maxValue) + 1;
      }
```

<a name="1"></a>
### Conclusion

There are many ways to solve problems programmatically. You can also achieve this using the ``while...loop`` construct - increment it's ``counter`` for every element of the array that the given value is greater than. I will love to know other ways you solved yours in the comment section.

If you have questions, comments or suggestions, please drop them in the comment section.

> Up Next: [Algorithm 101: 3 Ways to Reverse an Integer](https://dev.to/ebereplenty/algorithm-101-3-ways-to-reverse-an-integer-24gn)

You can also follow and message me on social media platforms. 

**[Twitter](https://twitter.com/eberetwit) | [LinkedIn](https://www.linkedin.com/in/samson-ebere-njoku-profile/) | [Github](https://github.com/EBEREGIT)**

Thank You For Your Time.
Culture of Collaboration
Tags: softwaredevelopment, collaboration, learninpublic
Published: 2020-03-19 22:49:17

There is a lot of really great, hard-won advice about remote work from [Justin Searls](https://twitter.com/searls) in his latest blog post, ["Remote, but not alone."](https://blog.testdouble.com/posts/2020-03-19-remote-but-not-alone/) He breaks it up into three sections: advice for remote-working humans in general, advice for remote employees, and finally advice for remote managers/employers. There is one part that really struck a chord for me.

> "If someone is stuck on a problem in isolation, the more time passes, the more shame they’ll feel about asking for help." 

There are two sides to this problem of avoiding asking for help, at least from my experience, so I'll speak to that.

First, as I work on something that I don't understand, I sometimes convince myself that I need to have put in some base level of time and effort. Until I've reached that arbitrary and imagined threshold, I avoid asking for help. What is under the surface there is that I haven't _earned_ asking for help yet. I've deeply internalized that nothing is unearned in this world and that tends to extend to something as small as asking for help.

This time that I spend trying to figure it out on my own may eventually collide with the other side of avoid helping. After a while, I start to feel like I should have already figured out a solution and so I'm ashamed to ask for help. This problem tends to spiral because the more shame I feel, the harder it is to find a solution. And it keeps spiraling as I feel more and more like I missed a reasonable opportunity to ask for help.

> "I could have ask for help at the beginning of the day, but now I've been stuck on this same thing for 4 hours. I can't ask now, they'll know [insert terrible thing I believe about myself here]."

Of course none of this is true. There is no threshold of time and effort that you need to reach to ask for help. Having missed a reasonable time window to have asked for help, that's not a thing either. I know this and yet I still struggle with it.

I think that is where the next bit of Justin's advice comes in to play.

> "On a remote team, it’s everyone’s responsibility to ask for the help they need and routinely offer what help they can give one another."

These feelings of isolation and shame lead us to avoid asking for help and hold us back from learning, growing, and doing our best work. We can combat this with community, with a culture of collaboration that normalizes asking for help and offering help. And though this post is about remote teams, it absolutely applies to all teams.

Give it a try. The next time you feel a hint of getting stuck, don't wait, reach out for help immediately. Each time we do this, we lay part of the foundation of a culture of collaboration.
Basics of Git , Explained .
Tags: git, versioncontrol, beginners
Published: 2020-03-20 05:41:41

I am going to be talking about the basics of version control using git in this blog. Version control allows you to store the different versions of a project when it is under development. For example - You add a new feature to your project but it does not work out. Git allows you to restore the previous version of the project which was working properly.

It is especially helpful when working on large projects and it has advanced tools to help teams collaborate.

Installing git is a very simple task in Linux

__$ sudo apt install git-all__

You will need to configure git once its installed.

*__Initialising a repository__*

Create a simple python file which prints __Hello World__ and store it into an empty directory called __practice__

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

Enter the directory in the terminal and initialise a repository using the command

 __$ git init__

 ![Initialising the repository](https://dev-to-uploads.s3.amazonaws.com/i/i3z4nz0gre7k8mtvfrj8.png)

_**Checking Status**_

Before we do anything further we shall look at the project's status using the command

__$ git status__

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

Master is the main branch of the project.

_**Adding files to the repo**_

In the next step we shall add the python file and check the projects status again using the commands

__$ git add .__
__$ git status__

![Adding the file](https://dev-to-uploads.s3.amazonaws.com/i/sdwtzvdgax8vo6lqbyvx.png)

__*Making a commit*__

Lastly but most importantly , we will commit the python file to our repo using the command 

__$ git commit__

When we enter this command ,  git will ask us to write a message for the commit stating whats its function. We will write *First commit* as our message

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

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

After committing the changes we will look at the status of our project again using

__$ git status__

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

__*Reversing a commit*__

We shall add another line _print("abc")_ to our original file

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

Now we shall check status of project

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

We shall now follow all the commands given above on how to make a commit

__$ git add .__
__$ git commit__
__$ git status__

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

Now say we want to revert the changes and have the previous state of the file. We will use the checkout command to revert the project back to its previous stage.

__$ git revert (commit hash)__


These were the basics to getting started with version control , i will be making more detailed blogs in future posts.


Hey there !
I am Arnav , an engineering student hailing from Mumbai.
Delphi (Win32) to web - Pros and cons of each of the big JS frameworks?
Tags: javascript
Published: 2020-03-20 12:07:43

Hello everyone,,,
A couple of months ago I ported an old Delphi application to the web. It was the standard, classic, Windows desktop application, with windows to enter data, datatables, reports and so. It works, but I think that it's a bit clunky, as it's all server side renderer with Symfony 4 (PHP).
https://speedtest.vet/ https://vidmate.bid/
As an enhancement, I wanna port the frontend of this application to Javascript. I'm an experienced developer (more than 20 years programming), but I'm a novice with modern Javascript (I'm sorry, currently I only use jQuery... :P).

I've been doing some Angular and React tutorials, but these tutorials are very simple and easy, so I still don't know which of these frameworks is the more recommended for the kind of application I want to write. Can you help me to choose which framework to use?

Thank you! :)
JetBrains coupon for 20% discount for companies
Tags: jetbrains, discount, coupon, code
Published: 2020-03-20 14:29:30

Hello, I am sharing this coupon code for a 20% discount on up to 10 commercial licenses for any JetBrains Toolbox products. 

Here is the coupon: **JPVZU-BMSL4-67RSH-NW7LB-P9CAN**

1. An organization can use the Promo Code to redeem a 20% discount on the purchase of up to 10 new annual commercial subscriptions for any JetBrains Toolbox products.
2. The Promo Code should be used in the JetBrains store at https://www.jetbrains.com/.
3. The Promo Code can be applied only to a single purchase of up to 10 commercial Toolbox subscriptions. If you would like to purchase more subscriptions or ones that are not covered by the Promo Code, please create a separate order, but keep in mind the coupon will not apply to it.
The Promo Code is unique and single-use.

Thank you and have a great day!
Algorithm 202: 3 Ways to Sum a Range of Values
Tags: algorithms, javascript, integer, beginners
Published: 2020-03-20 21:10:33

Given an array of two element as minimum and maximum values (``[min, max]``), how can you sum up all the values between the min and max values?

```javascript

rangeSum([1, 9]) // 45

rangeSum([5, 12]) // 68

```

We are about to dive into 3 ways to achieve this!

### Prerequisite
To flow with this article, it is expected that you have basic understanding of javascript's array methods.

### Let's Sum a Range of values using:

* while...loop

```javascript
      function rangeSum(array) {
        let result = 0;
        let i = 0;

        while (i < array[1]) {
          result = result + (i + array[0]);
          i++;
        }

        return result;
      }
```

* for...loop

```javascript
      function rangeSum(array) {
        let result = 0;

        for (let i = array[0]; i <= array[1]; i++) {
          result = result + i;
        }

        return result;
      }
```

* for...loop, push(), reduce()

```javascript
      function rangeSum(array) {
        let rangeArray = [];

        for (let i = array[0]; i <= array[1]; i++) {
          rangeArray.push(i);
        }

        let result = rangeArray.reduce((acc, char) => acc + char);

        return result;
      }
```

### Conclusion
There are many ways to solve problems programmatically. You are only limited by your imagination. Feel free to let me know other ways you solved yours in the comment section.

If you have questions, comments or suggestions, please drop them in the comment section.

> Up Next: [Algorithm 202 (My Interview Question): Grouping Anagrams in 3 Ways](https://dev.to/ebereplenty/algorithm-202-my-interview-question-grouping-anagrams-in-3-ways-49i4)

You can also follow and message me on social media platforms. 

**[Twitter](https://twitter.com/eberetwit) | [LinkedIn](https://www.linkedin.com/in/samson-ebere-njoku-profile/) | [Github](https://github.com/EBEREGIT)**

Thank You For Your Time.