teleren/devto huggingface dataset:
What Is Terraform CDK? - Terraform code in JavaScript
Tags: terraform, typescript, python, csharp
Published: 2021-10-28 14:16:10

### What is Terraform🤔?
[Terraform](https://www.terraform.io/) is an **open-source** infrastructure as a code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. It was developed by [HashiCorp](https://www.hashicorp.com/)

### What is Terraform CDK?
[Terraform CDK](https://github.com/hashicorp/terraform-cdk) is a tool developed by terraform developers which allows you to write your infrastructure in your favorite language
- It supports TypeScript, Python, C#, Go(Beta), and Java Currently.

### Getting started 😃
Before we get started install cdktf-cli by running `npm i -g cdktf-cli@latest` and then run `cdktf init` to initialize a broiler code for you. Choose the language and name as your choice. For this instance, I will be using typescript.

![Terraform-CDK-Prebuilt-Providers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jnjh4qtixbszf15g4xd.png)

 
Let's add AWS providers and try to make an EC2 Instance. There are some prebuilt providers like the following for typescript. So in this case we install the AWS provider by running `npm i @cdktf/provider-aws`

![Terraform-CDK-languages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/273c5szre8pfaq9rk2eg.png)
 
If in case you are using any other language then you can add your providers to the **terraformProviders** field in the cdktf.json file and run `cdktf get` to install the constructs and convert them to your native language

{% gist https://gist.github.com/raghavmri/d9a4f6c441e885b369727bb57764cad8 %}

Here's my Typescript Code
{% gist https://gist.github.com/raghavmri/ee0d2321868277ffd170716c83c9588c
%}

Running `cdktf synth` will create a directory called **cdktf.out** where you will have your stack named folder which contains the terraform files.

Now you can run `terraform init` & `terraform plan` to initialize terraform and review your infrastructure resources and if you want to go ahead and apply the changes run `terraform apply`

### Notes
- You must have to terraform installed in order for cdktf to work. You can Download the latest version by visiting this [link](https://www.terraform.io/downloads.html)
- If you guys want me write the same for other language do let me know in the comment section below.

### Video Reference 
{% youtube fgLkbNZQOh0 %}
REACH LANGUAGE BASICS
Tags: blockchain, programming, devjournal
Published: 2021-10-28 09:15:46

Reach is a programming language that has been designed to work on POSIX systems with make, Docker and Docker Compose installed.

In my case, I am operating on Linux OS. The first thing that I had to do was make sure that I created a directory where I am going to install the necessary files. To do this, I used the command $ mkdir reach.

To run Reach in your project repository you can run the following command : $ curl https://docs.reach.sh/reach -o reach ; chmod +x reach. Run this command within the new directory that you just created. In this case (reach).  

To initialize a new Reach project, you can run the command $ reach init or $ ./reach init . This creates a template which contains an index.rsh & a index.mjs file.

Once you have prepared your code and are now ready to run the program, you can go ahead and execute the command $ reach run or $./reach run.

What happens when this command is run is that your program is compiled with reach, a docker image is build. This image depends on the Reach Javascript standard library. A container that is based on that particular image is executed while connected to the network.

You can halt all dockerized Reach apps and devnets by running the command $ ./reach down. 

To create templated Dockerfile and package.json files for a simple Reach app use the command $ ./reach scaffold.

To execute a simple react app ,especially for frontend, use the command $ ./reach react. This command assumes that the frontend React JS program is named index.js and the reach program is called index.rsh.

To execute a private Reach devnet, you can use the command $ ./reach devnet. The option --await-background is supported and runs in the background and awaits availability.

The command $ ./reach docker-reset kills and removes all docker containers. 

You can upgrade your reach installation by executing $./reach upgrade

Additionally, you can update your docker images by executing the command $ ./reach update.

To check the version on reach that you currently have installed you can run the command $./reach version.

To see the exact version of Reach Docker images that you are using, you can run the command $./reach hashes.
PHP Interfaces
Tags: php, programming, tutorial
Published: 2021-10-28 11:16:27

###Interfaces
Interfaces allow you to create code which specifies which methods a class must implement, without any of the methods having their contents defined. Interfaces can be used in different classes this is referred as **Polymorphism.**

Interfaces are almost like abstract classes , difference being:
- all methods must be public in an interface unlike in an abstract class where they can be `protected` or `public`
- interfaces are declared with the `interface` keyword
- classes can inherit from other classes but still use  interfaces unlike abstract classes

Its however important to note all interface methods are abstract without the `abstract` keyword
To use an interface, a class must use the `implements` keyword. See example below:

```
<?php
interface Vehicle{
  public function typeOfFuel();
}
class Lorry implements Vehicle{
  public function typeOfFuel(){
    echo "I use Diesel";
  }
}
class Sedan implements Vehicle{
  public function typeOfFuel(){
    echo "I use Petrol";
  }
}
class Hatchback implements Vehicle{
  public function typeOfFuel(){
    echo "I use electricity";
  }
}

$lorry = new Lorry();
$lorry->typeOfFuel();
echo "\n";
$sedan = new Sedan();
$sedan->typeOfFuel();
echo "\n";
$hatchBack = new Hatchback();
$hatchBack->typeOfFuel();
```
Text translation application
Tags: javascript, programming, react, gatsby
Published: 2021-10-28 14:21:54

I have created a text translation application . It supports 16 languages this time. Have a look on it . I have used Gatsby while developing this application. Please have a look my article in medium i will appreciate your feedback.

<a href="https://shamazsaeed.medium.com/text-translation-application-in-gatsbyjs-d92065fd3fea">https://shamazsaeed.medium.com/text-translation-application-in-gatsbyjs-d92065fd3fea</a>
Code Smell 102 - Arrow Code
Tags: oop, javascript, cleancode, refactoring
Published: 2021-11-15 03:04:25

Code Smell 102 - Arrow Code

*Nested IFs and Elses are very hard to read and test*

> TL;DR: Avoid nested IFs. Even Better: Avoid ALL IFs

# Problems

- Readability 

# Solutions

1. Extract Method

2. Combine Boolean Conditions

3. Remove accidental IFs

# Context

In procedural code, it is very common to see complex nested ifs. This is more related to scripting than object-oriented programming.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/0313b55715cf050e4eadb80e7b0ffad2)
```javascript
if (actualIndex < totalItems)
    {
      if (product[actualIndex].Name.Contains("arrow"))
      {
        do
        {
          if (product[actualIndex].price == null)
          {
            // handle no price
          }
          else
          {
            if (!(product[actualIndex].priceIsCurrent()))
            {
              // add price
            }
            else
            {
              if (!hasDiscount)
              {
                // handle discount
              }
              else
              {
                // etc
              }
            }
          }
          actualIndex++;
        }
        while (actualIndex < totalCounf && totalPrice < wallet.money);
      }
      else
        actualIndex++;
    }
    return actualIndex;
  }  
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/a01fc3411e8aff647a2ff0812f313318)
```javascript
foreach (products as currentProduct)
  addPriceIfDefined(currentProduct)

addPriceIfDefined() 
{
  //Several extracts
}
```

# Detection

[X] Automatic 

Since many linters can parse trees we can check on compile-time for nesting levels.

# Tags

- Readability

- Complexity

# Conclusion

Following [uncle bob's advice](https://learning.oreilly.com/library/view/97-things-every/9780596809515/ch08.html), we should leave the code cleaner than we found it.

Refactoring this problem is easy.

# Relations

{% post https://dev.to/mcsee/code-smell-78-callback-hell-287f %}

{% post https://dev.to/mcsee/code-smell-03-functions-are-too-long-4hji %}

{% post https://dev.to/mcsee/code-smell-36-switch-case-elseif-else-if-statements-h6c %}

# More Info

- [C2 Wiki](http://wiki.c2.com/?ArrowAntiPattern)

- [Flattening Arrow Code](https://blog.codinghorror.com/flattening-arrow-code/)

* * *

> The purpose of software engineering is to control complexity, not to create it.

_Pamela Zave_
 
{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}
Third week TaskForce 4.0 BootCamp
Tags: codeofafrica, awesomitylab, taskforce
Published: 2021-11-15 05:04:42

Hello folks, it's been a while; I hope you are doing great and safe.
Today's top is essential in software development, which is database design. In software development, we need to store data for future use in data analysis and decision making. For keeping and retrieving our data, we should prepare where we will keep it conveniently.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7l6kdcwwo0ple3aay4g.jpg)

When it comes to database design, it means data security in a database and easy access, removing data redundancy or repeating of the data, because it can increase the cost for data, as a developer should minimize the cost but increase the efficiency of the database's application.

In database design consists of many things. According to its definition, it is a collection of steps that help create, implement, and maintain data in a database's system.  The main goal of database design is to produce physical and logical models of structures of a database system.

ERD stands for Entity Relationship Diagram. ERD is a diagram that displays the relationship of entity sets stored in a database; ERD will help us determine a good database design by showing the entity, relationship, and attributes within a particular database.

An entity in a database is a thing, person, place, unit, object or any item about which the data should be captured and stored in the form of properties, workflow and tables.

A relationship is it shows how the tables will share the data between them. It shows which table has a foreign key from another table and which cardinality, like many-to-many, many-to-one, and one-to-one.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnpgkj5iwp3d9auf0r0t.PNG)
In ERD, we determine which are strong and weak entities according to their relationship associated in a database; a strong entity is the one whose existence does not depend on any other entity in a schema. While a weak entity is an entity that cannot be identified uniquely by its attributes alone; therefore, it must use a foreign key in conjunction with its attributes to create a primary key.

As we have seen above, before diving into coding, first spend your time designing a database to save future database useability.

Thank you, #AwesomityLab, #taskForce, and #CodeOfAfrica, for helping me to know this excellent concept you provided to me.

Thank you folks for reading; let's wait next week for what will come with us.
Let's Build Express Server. Beginners Guide
Tags: javascript, webdev, beginners, node
Published: 2021-11-15 09:53:52

## What Is Express Js?
Express Js Is Web Framework For Node.js

## Where To Use Express Js
- Most Popular Use Of Express Js In the Current Time Is To Create Web Apis.
- Also Some People Are Using To Create Full-stack Web App With using Pug, Ejs, Or Basic HTML

> here we are going to create a simple API to understand concepts of express

## Getting Started

### Requirements
- You need Node.js Installed In Your System. You can download node.js from [Node.js](https://nodejs.org/en/)

- Open New Directory And Write This command to initialize a new project.
` npm init -y`

-Now install express as dependencies for your project
`npm install express`

## Create basic hello world API

1. Create index.js file and import express js & initialize the app

![Express Import & init app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kp5d08lre1s2qsxnnuqr.png)

2. Create an endpoint 

>in simple term endpoint is a path where you are getting expected data
`/users return all users`
`/products returns all products`

![endpoint creatiion](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h2zjzs7u8btdijv8b172.png)
here we have created endpoint `/` where we are sending hello world as a response.

3 Open a port for connections

![Open Port](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0vkpl9sr0i8f9yf4cs89.png)


4. Run application
> write `node index.js` to start the application

![shell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7ae0jnjbbekt29dywvz.png)

5. open localhost:3000 on browser
![browser image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wavta22hcqth6i49ekcu.jpg)

#hooray you made it 🥳

### what now
now try to render Html. try to create forms & process data using any database.
> find material online and create your own express apps.
ใช้คำสั่ง docker บน Ubuntu โดยไม่ต้องใช้ sudo
Tags: docker, ubuntu
Published: 2021-11-16 00:56:26

หลังจากลง Docker บน Ubuntu แล้วนั่นเราจะใช้งานมันได้เราต้องใช้สิทธิ์ root ซึ่งต้องสั่ง docker โดยใช้ sudo เช่น `sudo docker ps`

แต่ถ้าเราอยากสั่งโดยไม่ต้องใช้ sudo ก็สามารถทำได้โดยเพิ่ม user ของเราเข้าไปใช้ usergroup ที่ชื่อว่า `docker` ด้วยคำสั่งแบบนี้

```
sudo usermod -aG docker $USER
```

หลังจากนั้น logout แล้ว login อีกที (ถ้าไม่ได้ก็จัดการ restart OS อีกรอบ) เราก็สามารถสั่งคำสั่ง `docker` ด้วย user เราเองโดยไม่ต้องใช้สิทธิ์ root ผ่าน sudo อีกแล้ว เช่น

```
docker run hello-world
```

![docker without sudo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4b4d06n8a9t49zyrcnu8.png)
 
อ้างอิง: https://docs.docker.com/engine/install/linux-postinstall/
Microsoft Learn Student Ambassador Program
Tags: microsoft, beginners, programming, azure
Published: 2021-11-16 03:37:01

## What Is Microsoft Learn Student Ambassadors Program?

Microsoft Learn Student Ambassador program is aimed at bringing students all over the world who has interest in technology together. These students get the opportunity to connect and interact with others on topics they are passionate about (mostly Microsoft Technologies). Also, they are able to organize events to teach each other various tech stacks.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niquvej8dxlcm3rqqb85.png)
## Application Requirements
You must be 16 years or older.
You must be enrolled in an accredited academic institution(eg: college, university).
You must not be a Microsoft or Government employee.
You need to at least have some basic knowledge in coding.
## Why Should You Join?
There are a lot of benefits for joining this amazing program. A few of them are listed below:

Free Swag Box from Microsoft
Access to Microsoft 365
Access to TechSmith products(i.e Camtasia and Snagit)
Name.com voucher
Azure credits
LinkedIn Learning Voucher
Free access to one or more Microsoft Certification voucher and more.
**NOTE**: Some of these benefits are given to you based on the milestone you have achieved.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gkytgck47iapu98ep0lf.jpeg)

## Apply Here
To apply, Use this Link: [Apply for MLSA](https://studentambassadors.microsoft.com/)


I hope that this was helpful to you. If you have any questions, please drop it in the comment section below and I will make sure to answer all questions you have. Also, you can connect with me on:
[Twitter](https://twitter.com/aniketmishra0)
[LinkedIn](https://linkedin/in/aniketmishra0)
Setup Passport functionality in Laravel
Tags: laravel, passport, php, mysql
Published: 2021-11-16 03:50:43


First of all install laravel new project by composer
composer create-project laravel/laravel laraERP

Important: please add namespace inside RouteServiceProvider
 protected $namespace = 'App\Http\Controllers';

Now, install passport functionality inside our laravel project
composer require laravel/passport      


Read more: https://easycodesardar.blogspot.com/2021/11/Setup%20Passport%20functionality%20in%20Laravel.html
Automated testing for staging Apps
Tags: ci, heroku, reviewapp, actionshackathon21
Published: 2021-11-16 05:41:30

I have developed a process to update the pull request status based on staging app deployment using Github Actions and Heroku API.

Entire journey and workflow can be found here: https://niteo.co/blog/staging-like-its-2020

The journey consists of:
* A simple custom [GitHub Action](https://github.com/marketplace/actions/heroku-review-app-deployment-status) for small & medium projects. It takes care of all the burden.

* A bit complex process for larger projects which can be helpful in reducing unnecessary costs.
Node v17.0.1 bug
Tags: react, javascript, node
Published: 2022-08-03 13:52:44

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afxj0qj7q6fce7hkv4g1.PNG)
Error encountered when running yarn start, npm start.

Probably caused by issue with webpack [digital envelope routines::unsupported](https://github.com/webpack/webpack/issues/14532).

A quick fix is configuring package.json script.
<pre>
"start": "react-scripts --openssl-legacy-provider start"
</pre>
Root cause analysis for enterprise & SMB infrastructure. Feedback is appreciated!
Tags: monitoring, devops, machinelearning, serverless
Published: 2021-11-16 14:25:01

For the past few months, my team worked hard on developing our new incident root cause solution - Incident Timeline.

InsightCat launched the Incident Timeline, the root cause analysis solution developed for IT experts who manage, view, and investigate software incidents. The solution is implemented in the InsightCat platform to provide IT specialists with automated root cause analysis, downtime details, and behavior.

Incident Timeline allows you to:

📷 Obtain root cause analyze
📷 Surface relevant insights
📷 Enhance observability

Check out InsightCat's new update below and see how it works in practice or you can register to InsightCat and try Incident Timeline for free.

Any feedback is appreciated, don't hesitate to share it in the comment section :)

InsightCat registration: https://portal.insightcat.com/register
Website: https://insightcat.com/
Easy way to exclude files during git add
Tags: git, webdev, tutorial, productivity
Published: 2021-11-16 16:00:58

Every day we use the **"git add"** command a lot to add our changes to the index for new commits, but have you ever wondered how we can add all the changed files with some files excluded during the execution of this command (not with .gitignore)? If the answer is yes, then this article will help you to understand how certain files can be excluded during the git add command.

## TLDR; command to exclude specific file

```
git add -A ':!<file_path>'
```

## Problem

One day I was put in a situation where I need to add some files for my new commit but I also need to exclude a few files during that execution and those files will get added later on once my work is done on those.

**One way to do this is to hit the below command**

```
git add <file_path> <file_path> ... <file_path>
```

Basically, If I have done changes to under 13 files and wanted to exclude only 3 files from those, that means 10 files need to be added with the git add command, then I have to copy all those 10 files path and paste it to the terminal manually and it will have become little bit tedious task. Let’s look at the example.


```
git add Dockerfile \
README.md \
nest-cli.json \
package-lock.json \
package.json \
src/app.controller.spec.ts \
src/app.controller.ts \
src/app.module.ts \
src/app.service.ts \
src/main.ts

```

After this command, you can now check for the staged files by hitting.


```
git status
```

## Solution

But what if this process can be done inversely🤔? Like instead of passing 10 files paths I could just pass 3 files path, 👀 yes you heard it right this can be possible with git add with the below example.


```
git add -A ':!.eslintrc.js' ':!.gitignore' ':!.prettierrc'
```


And now when you hit **git status** it will show all 10 files added to the index apart from the 3 excluded files. It's like a **NOT (!) operator** under the git add path option.

> Hope you enjoyed this content, please share your thoughts under comment and also get in touch with me on [Twitter](https://twitter.com/KodeWithChirag).
[git] find semantic version tags
Tags: glob, git, semantic
Published: 2021-11-16 16:28:19

Sure, you could use grep/sed, but can it be done with `glob(7)`? Supply a pattern to `git describe` or `git tag` to print the matching tags.

```
git tag --list 'v[[:digit:]]*[\.][[:digit:]]*[\.][[:digit:]]*'
```

Maybe there's a better way 🤷🏼. 

## Why? 

In a ci/cd environment, I wanted to be able to build and publish new releases of a binary if and when the latest commit has a semantic version tag attached.
I must be stupid
Tags: beginners, programming, tailwindcss, vscode
Published: 2021-11-17 02:02:15

I follow tutorials for everything to do with programming and computers, but I can't seem to get anywhere with them, and when I see just one error, I have the tendency to give up trying any further.

So, I am begging for assistance on the most basic of levels, if possible.  PLEASE someone, anyone, tell me like I'm 5 years old, how do you install tailwindcss into VS Code?

I just followed the steps of a tutorial for this process from 9/21, and things seemed to be going well, until things didn't for me (which seems to be the case for every single tutorial I've followed in the past)
How to set default object parameter in Javascript
Published: 2021-11-19 06:14:00

Hello Devs, 
Do you find any error when you set the default object as parameter? Let's talk about it.

```javascript
const fullName = ({fname, lname})=> {
    console.log(fname + ' ' + lname)
}

fullName({fname:'Sajidur', lname:'Rahman')

//your@console:~$ Sajidur Rahman
```
I Guess you already know what's going on in this simple function. In this topic this is our demo function.


```javascript
const fullName = ({fname='Jhon', lname='Doe'})=> {
    console.log(fname + ' ' + lname)
}

fullName({fname='Sajidur'})

//your@console:~$ Sajidur Doe
```
This parameter is an object where we set 2 properties with default value. If we don't pass any of the property, then default property will  use. We pass only `fname` that's why default `lname` use. 

```javascript
const fullName = ({fname='Jhon', lname='Doe'})=> {
    console.log(fname + ' ' + lname)
}

fullName()

//your@console:~$ TypeError: Cannot read property 'fname' of undefined

```
If we don't pass any parameter, then we will find this error. But why? We set default parameter right?  
No, we didn't. We just set the default property value of an object. That object is our actual parameter. 

```javascript
const fullName = ({fname='Jhon', lname='Doe'} = {})=> {
    console.log(fname + ' ' + lname)
}

fullName()

//your@console:~$ Jhon Doe
```
Now set a default parameter as an empty object `{fname='Jhon', lname='Doe'} = {}`. Now it works, but why? Let's talk about it step by step.

1. This whole object `{fname='Jhon', lname='Doe'}` is a single parameter.  For this parameter default parameter value is `{}`. When the parameter is undefined that time this `{}` empty object will appear.

2. Now we have empty object. But we already set some default properties with value for empty object right? `fname='Jhon', lname='Doe'` Those properties now appear here with their default value.

 
So Dev, I hope you understand and find the solution if you stuck on this issue.