teleren/devto huggingface dataset:
The Right Way and the Wrong Way to use Switch Statements
Published: 2021-06-14 20:43:56

<img width="100%" style="width:100%" src="https://media.giphy.com/media/MbXKzbvQOgRZ6/giphy.gif">

Once I learned how to write `switch` statement, I never wanted to go back to `if`/`else` statements because switch statements are so much cleaner looking and easier to read. But I have learned that even if a switch statement works correctly, that doesn't mean you've used it correctly. My mistake was using `true` as the expression to be evaluated. Even though it works, this is considered bad practice.

The [Mozilla Developer Network Web Docs states the following:](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch)
> A switch statement first evaluates its expression. It then looks for the first case clause whose expression evaluates to the same value as the result of the input expression...

####The Wrong Way to use a `switch` statement

```javascript
let myVar = "Saturday";

myFunction = () => {
  switch (true) {
    case myVar === "Tuesday":
      console.log("weekday");
    case myVar === "Saturday":
      console.log("weekend");
    default:
      return null;
  }
};

myFunction();
// "weekend"
```

---

####The Right Way to use a `switch` statement

```javascript
 let myVar = "Saturday";

myFunction = () => {
  switch (myVar) {
    case "Tuesday":
      console.log("weekday");
    case "Saturday":
      console.log("weekend");
    default:
      return null;
  }
};

myFunction();
// "weekend"
```
####Controversy

That said, [some people](https://seanbarry.dev/posts/switch-true-pattern) like using the `switch (true)` pattern because it can make code blocks easier to read compared to long, complex `if`/`else` statements. This whole issue is [quite controversial](https://news.ycombinator.com/item?id=26777090). My advice is to only use the `switch (true)` pattern under the following circumstances:
1. The readability of the code is significantly improved when using `switch (true)`
2. Your team is ok with using this pattern

####Another Wrong Usage of a Switch statement: Comparing Values

While we're on the subject, you can't use the `switch` statement if you are comparing values. As said above, `switch` is for evaluating the input expression and then testing to find the first case expression whose evaluation matches the input expression. For example, this won't work:

####The Wrong Way to compare values

```javascript
let myVar = 5;

myFunction = () => {
  switch (myVar) {
    case myVar > 10:
      console.log(`greater than ten`);
    case myVar < 10:
      console.log(`less than ten`);
    default:
      return null;
  }
};

myFunction();
```

####The Right Way to compare values

```javascript
let myVar = 5;

myFunction = () => {
  if (myVar > 10) {
    console.log(`greater than ten`);
  } else if (myVar < 10) {
    console.log(`less than ten`);
  }
};

myFunction();
// less than ten
```

The moral of the story is:
- Use a `switch` statement if you want to *test* the value of a variable
- Use an `if`/`else` statement if you want to *compare* the value of a variable
New Demo POsts
Tags: ddddd, eeeee, fffff, ggggg
Published: 2021-06-03 04:55:58

Writing a Great Post Title

    Think of your post title as a super short (but compelling!) description — like an overview of the actual post in one short sentence.
    Use keywords where appropriate to help ensure people can find your post by search.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kic911513ojrnelpdouh.jpg)
Stand-up
Published: 2021-06-04 19:05:42

 For June, the monthly Virtual Coffee, a developer community, challenge is to build in public. As part of this we are using Stand-up to keep each other informed on our progress. I wrote a brief introduction to stand-up for the group. I thought I could expand it in to a post here. SEO branding tip, reuse the content you create.

![dc's harley quinn telling a joke. "2 variables walked into a foobar. the second should have ducked."](https://christopherleejarvis.com/JarvisScript/wp-content/uploads/2021/06/harley.jpg)<figcaption>Not that kind of  stand-up</figcaption>
## What is Stand-up?

 A series of daily meeting with set questions to give a quick update on your current progress. Usually held a start of the day so all team members can get a quick update on where everyone is. sThere is a set time limit, around 15 minutes, and only one person talks at a time. This is often controlled by having a focus object like a book. Only the person holding the object is allowed to speak when they are done they pass the object around. Our Bootcamp TAs recommended the item be heavy or unwieldy so no one will want to hold it too long. We used a broken chair arm.

 The questions are.

 - What did you do yesterday?
 - What are you doing today?
 - Do you have any blockers?

 **What did you do yesterday?**

![captain Marvel holding Thor's hammer](https://christopherleejarvis.com/JarvisScript/wp-content/uploads/2021/06/cap_marvel_hammer.jpg)

 - What did you accomplish yesterday or since the last update? Did you meet your goal? What did you learn?

 **What are you doing today?**
 - What do you plan to do today. Any particular goals you want to met before the end of day.

 **Do you have any blockers?**
 - A blocker is something keeping you from your goal. A problem you need some help to resolve. Anything team mates can help with. Team members can give you some quick tips. For more involved answers you can set up a one on one discussion outside of the stand-up. By using a phrase like "Let's talk about this more after the meeting."

Everyone should get a chance to announce where they stand and if they need help. Over all these should be quick focused meetings to keep the group informed of any progress. In larger companies departments may do their own stand-up and then send a representative to a larger company or division stand-up. 

![a man with a clock for a head](https://christopherleejarvis.com/JarvisScript/wp-content/uploads/2021/06/time.jpg)

Stand-ups are a good tool to reduce meetings and get people back to creating. Too many meetings can kill productivity and concentration.

##Let's talk about this more after the meeting.

Does your company have stand-up traditions? Do you have a certain object you pass around? 

```
-$JarvisScript git push
```
My journey to Software Engineering
Published: 2021-06-04 03:38:16

I graduated high school from a very small town in Northern California. There were three stop lights and the closest mall was more than 30 minutes away in Oregon. The only thing to fight my boredom was looking forward to college. Math was my favorite subject in high school so naturally it became my declared major in college. One of the lower division requirements for a math major was C+ programming, which was my first experience with coding.  

Several years later and after several major changes, I eventually graduated with a degree in accounting and finance. After my undergrad studies I contemplated the different paths I could pursue. I could take the CPA exam or apply to grad school or even law school, but I didn't have the motivation.

It wasn't until the unprecedented year of 2020 that started my journey into software engineering. I began to contemplate life again. The one thing I did know for sure was I love working Microsoft Excel (and still love today) so I decided to pursue a certificate in computer programming at my local community college. One of the requirements for the certificate was an intro to computer science class so I enrolled last summer and this was when I fell in love with coding!

I found my motivation!  I respectfully made arrangements to leave my job last fall, started my journey and haven't looked back.  After months and months of research I finally chose to pursue my software engineering certificate with Flatiron school.  I will complete my program in October 2021 and I'm looking forward to it!
Tuning Neural Networks
Published: 2021-06-08 23:47:27

When modeling a neural network, you most likely won’t run into satisfactory results immediately. Whether it’s underfitting or overfitting, there are always small, tuning changes that can be made to improve upon the initial model. For the most part, for overfit models, these are the main techniques you can use: normalization, regularization, optimization 

### Dealing with Overfitting
Here is an example of what an overfit model would look like:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xqel864mo44hlw0h87j0.png)

Here we can see that as the training accuracy increases, at a certain point, the validation accuracy stagnates. This means that the model is getting too good at recognizing purely the training data that it fails to recognize general patterns.

**Regularization**
Regularization is often used when the initial model is overfit. In general, you have three types to choose from: l1, l2, and dropout.

L1 and l2 regularization basically penalizes weight matrices that are too large and in the back propagation phase. An example of it being used:
```python
model.add(Dense(128, activation='relu', 
kernel_regularizer=regularizers.l2(0.005)))
```

Dropout, on the other hand, sets random nodes in the network to 0 on a given rate. This is also an effective counter measure to overfitting. The number within the dropout function represents the rate at which dropout will occur. An example:
```python
model.add(Dropout(.2)) 
```

**Normalization**
Another countermeasure to overfitting a model is to normalize the input data. The easiest thing to do is to normalize to scale the data to be between 0 and 1. What this does is potentially cut down training time and stablize convergence. You could also normalize within layers such as the random normal:
```python
model.add(Dense(64, activation='relu', 
kernel_initializer=initializers.RandomNormal())
```

**Optimization**
Lastly, you could try different optimization functions. The three most used are probably Adam, SGD, and RMSprop. 
Adam (“Adaptive Moment Estimation”) is one of the most popular and works very well. 

### Dealing with Underfitting
Underfit models would look like the opposite of the above graph, where training accuracy/loss fails to improve. There are a few ways to deal with this.

**Add Complexity**
A likely reason that a model is underfit is that it is not complex enough. That is, it isn't able to identify abstract patterns. A way to fix this is to add complexity to the model by: 1) adding more layers or 2) increasing the number of neurons

**Training Time**
Another reason that a model may be underfit is the training time. By giving a model more time and iterations to train, you give it more chances to converge to a more ideal solution. 

### Summary 
To summarize, overfit models require regularization, normalization, and optimization while underfit models require more complexity and training time. Neural networks are all about making small, incremental changes until you reach a good balance. These tips will ensure that you are moving in the correct direction when you inevitably find the need to tune a model.
Orphaned CloudFormation Stacks — HouseKeeping
Tags: aws, cloudformation, housekeeping, cost
Published: 2021-06-11 15:57:21

**Scenario**

* There could be some stacks missed out during teardown process due to some issues and this might leave those stacks orphaned. 
* Also when App teams create a new stack without deleting their previous stack, this will leave the previous stack orphaned.

**Solution**

* List out all the stacks based on the state in the corresponding account using below python script. Filter the suspecting orphaned stacks from the list.
```
# Function: EvaluateOrphanedStacks
# Purpose: List out stacks based on the state and accounts
import boto3
import json
from datetime import datetime
from datetime import date
cfn_client=boto3.client('cloudformation')
def list_stacks():
paginator = cfn_client.get_paginator('list_stacks')
response_iterator = paginator.paginate(
StackStatusFilter=[
'CREATE_IN_PROGRESS',
'CREATE_FAILED',
'CREATE_COMPLETE',
'ROLLBACK_IN_PROGRESS',
'ROLLBACK_FAILED',
'ROLLBACK_COMPLETE',
'DELETE_IN_PROGRESS',
'DELETE_FAILED',
'UPDATE_IN_PROGRESS',
'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS',
'UPDATE_COMPLETE',
'UPDATE_ROLLBACK_IN_PROGRESS',
'UPDATE_ROLLBACK_FAILED',
'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS',
'UPDATE_ROLLBACK_COMPLETE',
'REVIEW_IN_PROGRESS',
'IMPORT_IN_PROGRESS',
'IMPORT_COMPLETE',
'IMPORT_ROLLBACK_IN_PROGRESS',
'IMPORT_ROLLBACK_FAILED',
'IMPORT_ROLLBACK_COMPLETE'
]
)
for page in response_iterator:
for stack in page['StackSummaries']:
print(stack['StackName'])
if __name__ == '__main__':
list_stacks()
```

Note:
Its ALWAYS recommended and good practice to reduce the orphaned stacks and unwanted resources !
Top 8 Skills Required to Become a Front End Developer 2021?
Tags: beginners, webdev, programming
Published: 2021-06-15 10:58:56

A front end engineer is somebody who carries out website architectures through programming dialects like HTML, CSS, and JavaScript. The front end engineers work with the plan and standpoint of the site. While, the back end engineers program what goes on in the background like information bases.Also check the main difference betweem them on <a href="https://en.wikipedia.org/wiki/Front_end_and_back_end">wikipedia</a>. In the event that you head to any site, you can see crafted by a front end designer in the route, formats, and furthermore the manner in which a site appears to be unique from your mobile device.

If you’re looking for a career as a front end developer, you will face many burning questions. How long will it take to learn all the essential skills? What is the average front end developer salary ? What does a typical day of a front end developer look like?

Top 8 Technical skills that a front end developer must possess:

1. HTML/CSS
2. JavaScript/jQuery
3. Responsive Design
4. Frameworks
5. Testing/Debugging
6. Version Control/Git
7. Browser Developer Tools
8. CSS Preprocessing

I hope this post on “8 skills you need to be a good front end developer” was helpful and relevant to you.
Does Sanity CMS Work in China?
Tags: sanity, netlify, javascript, node
Published: 2021-06-17 03:32:39

---
canonical_url: https://www.21cloudbox.com/solutions/does-sanity-cms-work-in-china.html
---

## What is Sanity CMS?
Sanity is one of many headless CMS (content management systems) for structured content. Headless CMS helps content editors, marketers, and developers work together to deliver a better content experience to their users.

<p>&nbsp;</p>
## Does Sanity CMS work in China?

The short answer is No. 

Why? Sanity is built and hosted on top of the Google Cloud Platform which is blocked completely in China. 

<p>&nbsp;</p>
Here is the long answer:

We reached out to the Sanity team to see if their service works in China, and here is what we got:

<p>&nbsp;</p>
![Sanity's response to their service working in China](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3pqnyhlbr6yarm5x6f73.png)
<p>&nbsp;</p>

So simply put, if the Sanity team doesn't have experience with China, you are unlikely to get good support from them. If you are just testing Sanity out, and don't need your site to be highly available in China. It doesn't hurt to try.

Since the Sanity CMS is based on GCP (Google Cloud Platform), if GCP has good support in China, we probably can still use it in production, but what we found was this: 

> " **Google does not offer and has not offered cloud platform services inside China** and Google Cloud is not weighing options to offer the Google Cloud Platform (GCP) in China."
> – [Google's Media Statement](https://techcrunch.com/2020/07/08/google-reportedly-cancelled-a-cloud-project-meant-for-countries-including-china/)

So this looks like Sanity CMS doesn't work in China by "words" and it is also not in the coverage area of the Sanity and GCP. The next thing we want to know is: if a website is published with Sanity CMS, whether the site can be loaded in China or not. More specifically, how fast the site loads in China. Here are the speed test results:

...


To read the full content of this post, go to: [https://launch-in-china.21cloudbox.com/solutions/does-sanity-cms-work-in-china.html](https://launch-in-china.21cloudbox.com/solutions/does-sanity-cms-work-in-china.html)

<p>&nbsp;</p>
<p>&nbsp;</p>
When should you pick up the phone?
Tags: team, remotework, practices, communication
Published: 2021-06-18 10:19:28

---
title: When should you pick up the phone?
published: true
date: 2021-06-17 00:00:00 UTC
tags: team,remotework,practices,communication
canonical_url: https://jhall.io/archive/2021/06/17/when-should-you-pick-up-the-phone/
---

I’m a big advocate of distributed teams, and work-from-home policies for those who want it. But this always raises the question: How do we handle meetings and other forms of communication?

I’ve talked about my take on this [in a video](https://www.youtube.com/watch?v=OcUZxA4IICs&t=994s). But I was recently involved in a conversation on a specific aspect of this:

**How do you decide when to take a conversation off of Google Docs or Jira and move it to a more real-time channel?**

My basic rule for something like this is to use something like Google Docs/Jira/GitHub/whatever as a system of record. Make sure all important decisions are stored there.

If the discussion ever becomes emotional, repetitive, or otherwise unproductive, that’s a great time to take it to a more (virtually) face-to-face medium. Just make sure that any conclusions from that meeting are then recorded back into the system of record. And if possible, even record the face-to-face call for future reference.

A simple heursistic you might use is what I’ve heard called the **upshift reply threshold**. The idea is to make an agreement with your team about how many replies are needed before a more real-time communication medium is triggered. For example, with an upshift reply threshold of three, a third reply on GitHub might trigger a Slack conversation. A third reply on Slack might trigger a Zoom call. Choose a threshold that works for your team and situation.

* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._
Will `.at()` be something useful?
Tags: javascript, discuss
Published: 2021-06-17 13:28:03

I recently read a post [here](https://dev.to/laurieontech/at-coming-soon-to-ecmascript-1k91) on dev about the consideration of `.at()` implementation in JS.

If you don't want to read the original post (you should) here's a little recap.

## .at()
As far as I get this new function can be used as a replacemente for the classic `[]` if used with a positive index but can also access elements in reverse order if used with negative index.

Eg.
```JavaScript
const arr = [ 'a', 'b', 'c', 'd'];
arr.at(0);  // 'a'
arr.at(3);  // 'd'
arr.at(4);  // undefined
arr.at(-1); // 'd'
arr.at(-4); // 'a'
arr.at(-5); // undefined
```
Just looking at this (pun intended) show to me that `.at(-1)` is a sugar syntax to get the last element of an array without using `.length` nor `.slice()`.

## Doubts
I still have to dig deeper but I already have a couple of doubts.
### How oftend do we need it?
`.at(-1)` can be useful (and a lot of languages has something to get the last item) but how often do you need to get the second or third last item? I image as often as you need the second or the third so not so much.
### Loop in reverse order
You (or at least someone) could think that it can be handy for looping in a reverse order. An out of bound index return `undefined` so it should be easy, right? Well, no because array can have undefined element even in the middle
```JavaScript
const arr = ['a', undefined, 'c'];
```
so we still have to rely on the old way with
```Javascript
for (let i = 1; i <= arr.length; i++) {
   const item = arr.at(-i);
}
```
very much like
```JavaScript
for (let i = arr.length - 1 ; i >= 0; i--) {
   const item = arr[i];
}
```
or in a simpler way
```Javascript
for (const item of arr.slice().reverse()) {
```
The examples are from the comments written by [Henry Ing-Simmons](https://dev.to/hisuwh) on the original post.
### Negative index
I know, I know. Javascript allow only non negative index in arrays but we all knows that sometimes it allows some crazy shit like
```JavaScript
const arr=[];
arr[-1]="a";
arr[0] ="b";
arr[1] ="c";

console.log(arr);     // ["b", "c"]
console.log(arr[-1]); // "a"
```
Obviosuly it's not black magic but it's just creating a property `-1` for the object `arr`
```JavaScript
// do you remember that
const arr=[];
console.log(typeof(arr)); // object
```
Ok, this one was just to screwing around and keep you from falling asleep while reading my post.
## Recap
IMHO `.at()` will be used just to get the last item of an array.

If you think I'm missing something I urge you to point me in the right direction because I'm struggling on my own in finding a real purpouse for `.at()`
Automatic image slider in Html Css | Awesome CSS Slideshow
Tags: html, css, beginners, webdev
Published: 2021-06-17 16:01:28

***Hello guys, today I am going to show you how to create an automatic image slide in Html css, in this video you will learn how do you create an awesome CSS slideshow with fade animation.***

{% youtube BAnuWHgwZU8 %}
The Arguments Object in Javascript
Tags: javascript, array, arguments, webdev
Published: 2021-06-19 10:32:24

In javaScript we are free to pass as many argument as we want and javaScript won't show us error. For example:
```
function multiply(x) {
    var result = x * 10;
    console.log(result);
}
multiply(5,7,8,9);  //50
```
This code won't show error becuase javaScript avoids these extra arguments. But if we want,we can access them via an Object which is called arguments object.

Those parameters which are present in funciton definition can only be accessed by the parameter name.Other additional parameter will have to access  throguh arguments object.
Let'see and example:
```
function wage(salary, month) {
    const total = salary * month;
    const invoice = total + arguments[0];
    console.log(invoice); 
}
wage(1000, 5, 1000);
```
The output of the above funciton is 6000. IF you add more arguments , we also can access them throgh argument object.

Remember that It's not an Array , It's an arry like object which doesn't have any array like properties except length. You can calculate legth of the argument with **arguments.length**. For example:
```
function wage(salary, month) {
   console.log(arguments.length)
}
wage(1,2,3,4,5,6,7,8,9,10);  //10
```
Althoguh arguments object don't have array properties and methods but we can convert them to array and use all the Array properties
#4 ways to convert Argument Object to Array
**First Method:**
```
function wage(x,y) {
    return Array.prototype.slice.call(arguments);
}
wage(1, 2, 3); //[1,2,3]
```
**Second Method:**
function wage(salary) {
    return  [].slice.call(arguments);
}
wage(1, 2, 3); //[1,2,3]
**Third Method:**
```
function wage(salary) {
    return Array.from(arguments);
}
wage(1, 2, 3); //[1.2.3]
```
**Fourth Method:**
function wage(salary) {
    return  [...arguments];
}
wage(1, 2, 3); //[1.2.3]

I hope you now have a clear idea of converting this array like object to an actual array. You can also check type of arguments passed in the funciton. FOr example
```
function wage() {
    console.log(typeof arguments[0]); //Number
    console.log(typeof arguments[1]); //String
    console.log(typeof arguments[2]); //Object
    console.log(typeof arguments[3]); //Object 
}
wage(1, "John", ["A","B"],{age: 25,gender: "Male"});;
```
Thanks for reading my article.