teleren/devto huggingface dataset:
31 : Why is JavaScript considered as a dynamic programming language?
Tags: javascript
Published: 2020-04-29 03:02:06


Dynamic - because of what you see on paper when you analyze the code, is most likely not what you’re going to get when the program runs.

JavaScript allows you to declare (for example) variables whose value (and kind) will only be known at run-time based on conditions “on the ground”.

In contrast, static languages will not compile into runnable code unless all values (or value types) are known upfront.

--- 

Here’s a quick JavaScript example of what makes it a dynamic language:

```var thisIsAString = 'I am a string';
thisIsAString = 1; // assign an integer to thisIsAString
console.log(thisIsAString); // logs 1 to the console```


The variable ‘thisIsAString’ began its life as a string, 
but then I switched it to an integer. 

If you pull up the console on your browser 
(hitting F12 should do it in most browers), 
you’ll notice that the code runs just fine 
even though I changed the variable’s type during program execution.

Being able to change the underlying type of a variable while the program is running without causing an error is what makes JavaScript a dynamic language.

This behavior comes with both benefits and drawbacks, so I would encourage you to keep learning more about programming languages in order to understand the differences!
How to create a private route in React (Route Guard) - example: for authenticated users only
Tags: typescript, react, reactrouterdom, reactrouterguard
Published: 2020-04-29 02:52:37

Hello there!
It always happen when you're building a react app and configuring your routes, you find out that you don't want your routes to be all public all the time. Perhaps you want to make some routes accessible only for authenticated/authorized users, or make them available at a condition that makes sense to your business logic.

I have some good news for you, you don't need some fancy third-party library to achieve that, or even be an expert in routing techniques in single-page-applications.
I will demonstrate a simple solution that you can easily configure into your application logic.

## Prerequisites:
*	A working React application with your routes configured and ready to use.
*	A good cup of coffee (only if you're a coffee fan).

## Problem
I have my routes here all setup and working fine.
```
<Route  path="/page/home"  component={Home}  exact  />
<Route  path="/page/news"  component={News}  exact  />
<Route  path="/page/login"  component={Login}  exact  />
<Route  path="/page/profile"  component={Profile}  exact  />
<Redirect  from="/"  to="/page/home"  exact  />
```
The only problem with these routes is that any one can access the URL `/page/profile` and I only want that route to be available when the user is authenticated, otherwise I want him to be redirected to the login page `/page/login` first.

## Solution
I will create a simple `jsx` or `tsx` component (works for React JS or Typescript) that wraps around the `Route` component from the `react-router-dom` library. It will check for my given condition first, if that's true, it will render that component like it's supposed to do, otherwise it will redirect me to the login page.

Now let's take a look at my component:
```
import  React from  "react";
import { Route, Redirect } from  "react-router-dom";

const  PrivateRoute: React.FC<{
		component: React.FC;
		path: string;
		exact: boolean;
	}> = (props) => {
	
	const condition = performValidationHere();

	return  condition ? (<Route  path={props.path}  exact={props.exact} component={props.component} />) : 
		(<Redirect  to="/page/login"  />);
};
export  default  PrivateRoute;
```
## Code walk-through
The functional component expects three(3) props:
*	The component to render in case of a valid condition `Profile Page for example`
*	The path to that component `/page/profile for example`
*	Any additional parameters like the `exact` attribute

## Final Result
```
<Route  path="/page/home"  component={Home}  exact  />
<Route  path="/page/news"  component={News}  exact  />
<Route  path="/page/login"  component={Login}  exact  />
<PrivateRoute  path="/page/profile"  component={Profile}  exact  />
<Redirect  from="/"  to="/page/home"  exact  />
```

That's it! you've done it, you now have your routes protected.
Binding a resource controller in Laravel
Tags: laravel, beginners, excerpts
Published: 2020-04-29 02:33:53

**What is resource controller?**
Laravel has some conventions/rules for all of the routes of a traditional REST/CRUD controller called resource controller. Laravel also comes with a generator out of the box and a convenient route definition that allows binding an entire resource controller at once.
Simply put, resource controller is used when all **CRUD** operations are performed. Meanwhile, if performed manually, then plain controllers are used.

To generate recource controller:
`php artisan make:controller MySampleResourceController --resource`

**Resource Controller Binding**
`// routes/web.php
Route::resource('tasks','TasksController');
`

To list all the route:
`php artisan route:list`
TOP 10 reasons why Azure DevOps is just BETTER
Tags: devops, azure, top10, reason
Published: 2020-04-29 02:30:10


Still confused about DevOps and ALM tools?

I personally think every tool is good, but Azure DevOps is just better!

What makes Azure DevOps so good for Startups, SMBs and Enterprises?

It's things like Azure Pipelines, Security, Pricing, Extensions, and many more.

These are the __top 10 reasons why Azure DevOps is just better__!

_(Note: the reasons are not in any specific order)_

### Reasons

1. It's modular, but fully integrated
2. Azure Pipelines
3. Enterprise features (_Audit, Security, ..._)
4. Geographic presence (_it's the most distributed DevOps tool ever!_)
5. Azure Boards
6. Pricing (_Boy if it is cheap!_)
7. Dashboards
8. Fully Customizable
9. Best for Azure, perfect for everything else too
10. Integrations and Extensions

### Video

Here you have the video with the full list and discussion:

{% youtube qQphYb1r0wU %}

And you? What do you think? What is your favorite tool?
FunFacts Bling, my first experience with Twilio Voice
Tags: twiliohackathon
Published: 2020-04-29 02:19:07

## What I built
FunFacts Bling, voice bot that delivers fun facts to users

## Link to Code
https://github.com/truongjessica/FunFacts-Bling

## How I built it (what's the stack? did I run into issues or discover something new along the way?)
Followed example code from Twilio's YouTube tutorial; I messed up a few times and discovered how to change the voice (which was pretty neat)

## Future Plans, Final Words
Hope to add more facts APIs and to create more voice bots; I was rushed with time for this project so I didn't really get to personalize it as much as I wanted to
terminal pager ov
Tags: terminal, pager
Published: 2020-04-29 02:02:39

---
title: terminal pager ov
published: true
description: Feature rich terminal pager
tags: terminal, pager
---

ov is a terminal pager, like less and more.
It's modern and feature-rich.

{% github noborus/ov %}

You can download it from [github](https://github.com/noborus/ov). Various packages are also available.

ov operates as a simple pager.
It has the following features.
* Direct viewing of various compressed files
* Supports UTF-8 emoji and combining characters.
* Passes through an escape sequence of colors.

ov is already available in place of `less` in many cases (except for man pager).

And the following functions can be enabled by option or keystroke
* Headers fixed
* Switch between wrapping and not wrapping lines.
* Alternate background colors for the lines.
* Highlight the string between delimiters.

This is useful for displaying tabular data.
And with this feature, you can also conveniently use it as a pager called from `psql` or `mysql`.

![column mode](https://raw.githubusercontent.com/noborus/ov/master/docs/ov-column.gif)
The Facepalming Dev 🤦‍♂️ #3
Tags: humor, fail, wordpress
Published: 2020-04-29 01:11:10

---
title: The Facepalming Dev 🤦‍♂️ #3
published: true
description: How to know it's time to end your work day...
tags: humor, fail, wordpress
cover_image: https://thepracticaldev.s3.amazonaws.com/i/2h4v73fsnjlnbravi1g2.jpg
---

## Preface

I'm primarily a WordPress user at my day job; I'm not sure whether this does or doesn't help my case since being WordPress-Primary means living in the Land of Plugins, but here goes....

## The setup

As with all WordPress sites I work on, most tasks are centered around content and there's a page builder involved. But unlike most WP projects, this one does have at least a handful of actions and filters that I've added to the theme.

On this project, there's a login page. Anyone can use it, but it's meant for users of a specific kind of role. This doesn't prevent it working if your user _doesn't_ have this role, but it's important.

Once this type of user logs in, they then have access to a page full of resources that only this type of user is allowed access to (along with Editors and Admins, who do need to be able to edit content).

## Today's Episode

The task I happened to be focused on was redirecting this particular kind of user if they were trying to access the login page while logged in. Sounds simple enough, right?

So I went on a journey that involved searching through hooks, looking for similar solutions, dumping the `WP` instance for crying out loud... This whole thing lasted about 2.5 hours.

After much work, finally deciding to give up, and beginning to log my (lack of) progress in this area, something dawned on me...

You see, I had created this login page the week before. And in the process of creating this login page, I had 1) installed a powerful redirect-building plugin that 2) included adding URL- and role-specific conditions and 3) had actually _created/tested_ this particular redirect... I ended up deactivating it for a reason that'll require too much explanation for this article...

But yes, *the working solution already existed and I was the one who implemented it*.

I also had the equivalent of 6.5 cups of coffee today and that apparently didn't help me (or maybe it made things worse—who knows).

## Wrap-up

So... That's my facepalm-inducing story this time around. Anyone care to share their own stories below?

## Bonus facepalms

1. I was rushing to publish this towards the end of writing and forgot to set `published: true`. 🤦‍♂️
2. The previous title of this one was "The Facepalming Dev 🤦‍♂️ #2", but I already posted #2 last year... So this is now #3. 🤦‍♂️

I hope I'm finally adding bonus facepalms to this. I think I need to go to bed soon.
Why use TypeScript for web development?
Tags: typescript, javascript, webdev
Published: 2020-04-29 00:57:40

# Why use TypeScript for web development?

In the recent years there is a debate between if JavaScript needs or not the typing being a standard in the code. If we see the [State of JS (JavaScript Flavors)](https://2019.stateofjs.com/javascript-flavors/), TypeScript has gained a lot of popularity in the recent years giving at least 50+% of devs users being happy and determinated to use this superset of JavaScript in the future.

## What is TypeScript?

Typescript borns from Microsoft as an extension of JavaScript which main objective is adding the type support to JavaScript.
Let's be clear, TypeScript isn't another new language you need to learn, is still JavaScript but with superpower following the EcmaScript standard, so don't need to be worried if your code won't work or not in a old broswer.

Let's think in the next example

## Some basic TypeScript

```js
let foo = true

// some code later

foo = 3.1416

if (foo === true) {
  // more code needed but it wont get in and your app is broken now
}
```

As you see we have a `foo` const with a **boolean** value but for some ready you change it into a **number**, after that your app is broken because a condition needed it won't work after that change and can be unnoticed (every one of us suffered for this), so, what is TypeScript adding to avoid this issue? Let's find out:

```ts
// We add the value type by adding : after the var name, in this case is <varName>: <type>
let foo: boolean = true

// some code later

foo = 3.1416
// here TypeScript will alert you saying that you can't assign a number type value into a boolean type, of course we need to remove this line to successfully continue developing

if (foo === true) {
  // your code will be executed safely!
}
```

### So, what TypeScript offers?

Of course is not only about typing but we can say is one of the biggest features, TS has a lot of features that makes your project modular and easy to maintain, and I can say with all certain no neccesity of adding too much documentation into the code because is almost self explained.

TypeScript offers:

- Basic Types (number, boolean, string, array, etc)
- Interfaces
- OOP Classes
- Generics (this one is super powerful that we are going to check in a future post)
- Enums
- and many more

If you wants to learn TypeScript you can check the [documentation](https://www.typescriptlang.org/docs/home.html) and there are some many platforms teaching you how to TypeScript like [PluralSight](https://www.pluralsight.com/) and [Platzi (for spanish speakers)](https://www.platzi.com)
#WebDev on web.dev - Add archived newsletters to /newsletter #2725
Tags: webdev, javascript, opensource, frontend
Published: 2020-04-29 00:56:04

{% youtube Dtoq-vECFDI %}

Hey y'all, my name is Michael and I'm one of the engineers who works on Google's [web.dev](https://web.dev/) site.

On April 29 at 12 PM PST I'll be doing some coding of the site live on YouTube and would love for you to join in.

On web.dev you're able to subscribe to a monthly newsletter from some pages. The newsletter isn't available anywhere else though! So if you missed an email there is no way to see it. Well, we can fix that. In this stream we'll look at hosting these newsletter emails as pages on web.dev.

[(Join the chat here)](https://youtu.be/Dtoq-vECFDI)
Learn Docker Storage
Tags: docker, container
Published: 2020-04-29 00:55:10

Here we gonna see the different ways that the docker storage files.

## Unification filesystem - AUFS

AUFS is one of the most common among Docker installations, it is based in layers, and when a layer creates a new file it will exists only in this layer or derivate  (upper) containers.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xfdorinlfr0hgwh9dy49.jpg)
Whenever you wanna modify a file that besides in bottom layers the Docker uses a technique called CoW (Copy-on-write), where the file of the lowers layers still unmodified (the files in bottom layers are read only to preserve its state), then Docker handler with this simple creating a new copy of this file in the new layer with the modified part attached, do you saw the problem here? Even if a small part of the file is modified, all the file must be copied.
![Alt Docker AUFS Whiteout](https://dev-to-uploads.s3.amazonaws.com/i/pwhtd9uzdowgv2okfsj9.jpg)
This is a technique named whiteout, and the new files are marked as whiteout file.

## Volume mapping
This is the simplest known way and maybe most used by developers to put the application code inside a container, you just need to give Docker a link between a folder in your host and your container, to do so you need to run your container with a -v param, like in this example:

__*$ docker container run -v /var/lib/container1:/var ubuntu*__

With the -v param we are telling the docker to make a link between the /var/lib/container1 folder located in the host with the folder /var located in the container.

This method had a problem that is not being portable, so the host that will execute must have the necessary files.

## Mapping through data container

This model creates a container and inside of it is given a volume to be used by other containers. To create this container just do:

__*$ docker create -v /dbdata --name dbdata postgres /bin/true*__

To consume the data in other containers just run with:

__*$ docker container run -d --volumes-from dbdata --name db2 postgres*__

Now the container db2 gonna have a folder named /dbdata that is the same as in the container dbdata, making the process fully portable. The counterpart of this method is because you gonna need to keep a container just for it.

## Mapping volumes

Since Docker 1.9 we can create volumes in an isolate mode, just use this commando:

__*$ docker volume create --name dbdata*__

The above command the docker creates a volume that can be used by any container. To use this volume, you just need to use this command when creating a new container:

__*$ docker container run -d -v dbdata:/var/lib/data postgres*__

At this point the folder /var/lib/data within the container will point to dbdata volume.

This last model is recommended since the release because it's not easily lost when the container is deleted and still easy to manage it.

This post is part of a series about docker, to see more please follow the tag series: docker-by-tiagomac, keep learning and practicing.
Weird Programming Stuff
Tags: watercooler, discuss, weird, ytho
Published: 2020-04-29 00:50:35

Ok, I somehow came across this today:

{% wikipedia https://en.wikipedia.org/wiki/Whitespace_(programming_language) %}

Which led me to this:
- http://nik.works/project/bodyfuck/ *(an implementation of brainfuck that uses a camera as input)* **don't worry, it's SFW and actually well done**

That reminded of this good ol' classic:

{% github https://github.com/lhartikk/ArnoldC %}

Really tho, I could go on forever but now I'm curious to what sort of weird programming-related stuff you guys have seen throughout the years, add your findings below in the comments 👇 (oh gosh, here we go 😅)

And while we're at it, let's end this post with a video because why not

{% youtube lyZQPjUT5B4 %}

🎠
Use adaptive cards with mention in Microsoft Teams 
Tags: msteams, adaptivecard
Published: 2020-04-29 00:35:53

---
title: Use adaptive cards with mention in Microsoft Teams 
published: true
description: Use adaptive cards with mention in Microsoft Teams
tags: msteams,adaptivecard
---

[Adaptive Card](https://adaptivecards.io/) is very flexible way to create rich card which I can send to many platform. One of the platform is Microsoft Teams.

What's more interesting is that Power Automate can send Adaptive Card now.

[Use adaptive cards in Microsoft Teams](https://docs.microsoft.com/en-us/power-automate/create-adaptive-cards-teams)

One thing I couldn't figure out was how to "mention" people. There is a document [Mention support within Adaptive cards](https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#mention-support-within-adaptive-cards) and it says 

>The mention object inside of an msteams property in the card content, which includes the Teams user id of the user being mentioned

```json
{
  "contentType": "application/vnd.microsoft.card.adaptive",
  "content": {
    "type": "AdaptiveCard",
    "body": [
      {
        "type": "TextBlock",
        "text": "Hi <at>John Doe</at>"
      }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0",
    "msteams": {
      "entities": [
        {
          "type": "mention",
          "text": "<at>John Doe</at>",
          "mentioned": {
            "id": "29:123124124124",
            "name": "John Doe"
          }
        }
      ]
    }
  }
}
```

The question was how to get the **Teams user id**.

I found an thread discussing this at [Ms Teams @ Mentions in adaptive cards](https://powerusers.microsoft.com/t5/Building-Flows/Ms-Teams-Mentions-in-adaptive-cards/m-p/522622#M66891) and at the end, it seems like I just need to use **8:orgid:{org-ID-of-the-user}** format like below.

```json
"entities": [
  {
    "type": "mention",
    "text": "<at>Kenichiro Nakamura</at>",
    "mentioned": {
        "id": "8:orgid:{org-ID-of-the-user}",
        "name": "Kenichiro Nakamura"
     }
  }
]
```

Now I can simply use any way to get the user id, such as [Graph Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer).

If the user id is **f9e0c5cb-f4ee-43d4-91e2-63524d1bacd9**, then the message I send in Power Automate looks like:


```json
{
   "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", 
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
      {
        "type": "TextBlock",
        "text": "Hi <at>Kenichiro Nakamura</at>"
      }
    ],
    "msteams": {
      "entities": [
        {
          "type": "mention",
          "text": "<at>Kenichiro Nakamura</at>",
          "mentioned": {
            "id": "8:orgid:f9e0c5cb-f4ee-43d4-91e2-63524d1bacd9",
            "name": "Kenichiro Nakamura"
          }
        }
      ]
    }
}
```

The result is:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xqew0eqy7bd4prglv3hm.jpg)

Cool :)
How to get filepath recursively in Go
Tags: go, filepath, dfs
Published: 2020-04-29 00:35:18

---
title: "How to get filepath recursively in Go"
published: true
description: How to get filepath recursively
tags: Go,Filepath,DFS
---
## Introduction

You sometimes want to get a list of the filepath in directory. One of the ways to achieve shell find-like behavior in Go is to use [ioutil.ReadDir](https://golang.org/pkg/io/ioutil/#ReadDir). Another way is to use [filepath.Walk](https://golang.org/pkg/path/filepath/#Walk).

This is a common way to use ioutil.ReadDir, but I often see implementations that use panic or log.Fatal for error handling. In Go, the correct error handling is to return the error to the caller and output the error at an entry point such as main.go.

Therefore, this article introduces an example implementation of correct error handling using ioutil.ReadDir.

## Implementation

As an example, we want to scan a directory with three files, as follow.

```
mypkg
├── dir_b
│   └── file_b
├── dir_c
│   └── file_c
└── file_a
```

- dir.go

The point is to call Dirwalk recursively in the case of a directory and search until you reach a leaf (file) in the directory tree. It then merges the paths that reach the leaf into the caller's path one after the other.

{% gist https://gist.github.com/d-tsuji/14daf6128f641fd477945e7697947a5c %}

- dir_test.go

We can see that the list of files can be obtained as expected by the following tests.

{% gist https://gist.github.com/d-tsuji/87ce350fcf7fb08c9173f4e98e469896 %}

```
$ go test -v
=== RUN   TestDirwalk
--- PASS: TestDirwalk (0.01s)
PASS
ok      github.com/d-tsuji/go-sandbox/mypkg   0.016s
```

## Summary

Here's an example implementation that can retrieve all the files under a directory and handle errors with care. I hope this has been helpful to you.