teleren/devto huggingface dataset:
5 Command Line Tips and Tricks
Tags: linux, bash, beginners
Published: 2021-05-23 09:24:32


You're a Linux sysadmin or developer, it's your job to get things done. The [command line](https://www.gnu.org/software/bash/) is the best way to perform some tasks, such as copying or moving files. You can even use it to manipulate strings of text and other data.

Linux has a long history and a lot of great features, such as multiple command line options for each executable, shell aliases, built-in help, and powerful pipes. Unfortunately, all of these features become useless if you don't know how to use them properly. 

Here are 5 tips that could make you more productive at the shell prompt.

## Listing files :clipboard:

When entering commands in Linux, you may skip some of the parameters that are included in them. For example, if you want to view all files inside a directory, you may enter `ls` by itself instead of `ls -a`. Both of these commands will list all files inside of this directory.

It is also important to note that Linux command lines are case sensitive, so make sure to pay attention to how you type them. For example, "ls" and "LS" are two different commands.

## Memorize commands :computer:

There are many commands for Linux: bash, tmux, vim, gpg, git, grep and many others. It would be a waste of time to look up every command all the time. 

A better way is to memorize them, you can use [this site](https://www.practicelinux.com/) to memorize Linux commands.

## Get to know your command line history

Did you know that Linux has a built-in command line history? 

Just press the up arrow key to go back in your command line history. If you press it again, you can cycle through your previous commands.

This may not sound like much, but it sure beats having to retype a complex command or the output of a previous command.

## Kill programs if they hang

Use the kill command to send a signal to a program and kill it. You can use pkill to send signals to processes by name. For example, you can use the following command to send the kill signal to all Firefox processes: 

```bash
sudo pkill -9 -f firefox
```

![cat on linux  bash](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wkitljl67346prh41u0v.gif)

## Redirect outputs of one command to a file

You can store the command line output by using the `>` character. This saves all of the command output to a file. For example the command below stores the files in a file:

```bash
ls -l > output.txt
```

## Alias

The command alias lets you save commands. This saves you a lot of typing. You can store them in your .bashrc file to reopen every start. 

You can set different aliases:

```bash
alias c="clear"
alias cl="c; ls"
alias ca="c; la"
alias x="exit"
```

That way you can type `c` to clear the screen, `x` to exit etc. You can save any command you want.

![linux alias](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2tixqecf7hj8456ic2sx.gif)
Understanding Kubernetes in a visual way (in 🎥 video): part 14 – Horizontal Pod Autoscaler
Tags: kubernetes, devops, docker, beginners
Published: 2021-05-23 10:46:10

---
title: Understanding Kubernetes in a visual way (in 🎥 video): part 14 – Horizontal Pod Autoscaler
published: true
description: Serie of videos about Kubernetes. Explaining in a visual way Kubernetes principles.
tags: Kubernetes, DevOps, Docker, beginners
series: Understanding Kubernetes in a visual way - (in video) in video
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tgwwcp49t8b777ikb3td.jpg
---

Understanding Kubernetes can be difficult or time-consuming. In order to spread knowledges about Cloud technologies I started to create sketchnotes about Kubernetes, then I've auto-published a book and since now I've started a new serie of video! :-)

I imagined a serie of short videos with a mix of sketchnotes and speech.

I think it could be a good way, more visual, with audio & video to explain Kubernetes (and others technologies).

This episode is focused on HPA (Horizontal Pod Autoscaler).

{% youtube IaTi7ltqAbo %}

The video is in French BUT I done the subtitles in english (and french too).

If you liked the video and are interested to watch another ones, please give me some feedbacks (and you can also subscribe to [my Youtube channel](https://www.youtube.com/channel/UCrRk0kOP58lBMl9B8ZS8Vlg), if you want to ❤️).

Here the illustrations that you can see in the video:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g933zu47tkrbtvipdts0.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qicwu43s4j0fcrkqjoe.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gagxdd7iw2zatrkx6nme.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhhtsaxqqe9qiu5g2toy.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o24spezzkx8bsotkzsr2.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwb4xiug34g3no2cz6xl.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/psjuvp5nn5tthejhctj8.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxnkj3hiy6a6ym50ztlf.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u93j8z8rx9l8rvbgwjzs.jpg)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y4ojo8135h74z1cr2twn.jpg)

If you are interested, I published all the sketchnotes on Kubernetes (and new ones!) to make a "book" of 165 pages: ["Understanding Kubernetes in a visual way"](https://gumroad.com/aurelievache#uCxcr).

If you like theses sketchnotes, you can follow me, I will publish others sketchs shortly :-).
How to get HTTPS working on localhost
Tags: tutorial, devops, nginx, linux
Published: 2021-05-23 10:34:08

The simplest way is to use [mkcert](https://github.com/FiloSottile/mkcert) utility.

It is easy to use tool for making local development SSL/TLS certificates. 

## Installation

At first, you need to install it. You can download a binary file from [here](https://github.com/FiloSottile/mkcert/releases) to use it immediately without installation. Or follow the installation [guide](https://github.com/FiloSottile/mkcert#installation) for your OS.

## Usage

Run command to create local CA (Certificate Authority).
```bash
mkcert -install
```

Run command to create certificate files.
```bash
mkcert localhost
```

That's it. 

You have two SSL certificate files now: *.pem which is a certificate file and *key.pem which is a key file. 

Use these files in the configuration of your local webserver.

If you want to know how to generate it manually, read the [How to get HTTPS working on localhost](https://bogomolov.tech/localhost-https/) article on my website. The article has a simple Nginx example of configuration to use generated SSL certificate.
Why You Should Learn Vim
Tags: vim, linux, beginners
Published: 2021-05-23 10:04:02

Vim is the best text editor out there. I have been using it for almost a decade now and I’m not going back to Sublime Text or Atom or even Notepad. The fact that you can do all of your development work in the same tool that is also used to write your code is amazing.

Vim is a powerful text editor with a lot of history and a certain aura of mystique around it. In this article, I'll try to dispel some of the myths around Vim and explain why you should learn to use it on the command line.

Anyone who spends significant time in front of a terminal should consider learning to use vim.

## It's everywhere :cool:

First, why not learn to use Emacs or [insert favorite text editor here]? The two main reasons I like Vim are that it's ubiquitous and easy to use. Most server installations have Vim available. There's even a version included with Mac OS X.

You can use it while coding, writing articles, notes, or even making spreadsheets. It can literally be everywhere you are! You can edit files through ssh! 

## Useful skill :computer:

Unlike the latest frontend framework or latest shiny language, vim always stays the same through the years. So it's good to learn vim.

Vim has been the main editor used by most Linux users for at least 15 years, so you'll almost certainly find it on any server where you need to log in via SSH.

[Learn Vim](https://vim.is/) by interactive exercises, no need to struggle with man pages or blogs.

## Keyboard shortcuts for everything

You can use the keys to navigate your code and vim. Press `gg` to move to the top of the file, press `G` to move to the end of the file, press `/` to search etc.

Once you know the shortcuts, it's a lot easier than grabbing your mouse and going to the menu bar, click edit, click find etc. It saves you a lot of time when coding.

## Great for coding

Any reasonably recent version of Vim has strong support for all kinds of programming languages, so it's great for editing source code.

Vim supports all kinds of plugins and can be used even over an ssh connection to a sever. 

On top of that, you can use plugins like [YouCompleteMe](https://github.com/ycm-core/YouCompleteMe) for code completion and [NerdTree](https://github.com/preservim/nerdtree) for a file browser.

![vim syntax highlighting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jeuajhzjf9dbpv65phaf.png)
Optional Chaining ?.
Tags: beginners, javascript
Published: 2021-05-23 10:03:31

Chaining operator will give us `undefined` when reference that we want to use is `nullish` instead of error, it's very usefull when the content of an object don't have guarantee as to which properties are required

```js
const ourObject = {
    name:'Alina',
    pet:{
        name:'kitty',
        type:'cat'
    }
}
const dogName = ourObject.dog.name;
console.log(dogName)
```

Because dog is not exist at `ourObject` then it will return `Uncaught TypeError: Cannot read property 'name' of undefined`


To prevent those error we can use optional chaining, so instead of error this code will return `undefined`

```js
const dogName = ourObject.dog?.name
console.log(dogName)
// Undefined
```

It also work for checking methods inside object 

```js
console.log(ourObject.nonEksistingMethod())
//Uncaught TypeError: ourObject.someNonExistentMethod is not a function

console.log(ourObject.someNonExistentMethod?.())
// Undefined    
```
Compare two arrays regardless of order - JavaScript
Tags: javascript, codepen
Published: 2021-05-23 10:03:17

// `a` and `b` are arrays
const isEqual = (a, b) => JSON.stringify(a.sort()) === JSON.stringify(b.sort());

// Examples
isEqual([1, 2, 3], [1, 2, 3]);      // true
isEqual([1, 2, 3], [1, 3, 2]);      // true
isEqual([1, 2, 3], [1, '2', 3]);    // false
Merge Sort, Its not hard!
Tags: cpp, algorithms
Published: 2021-05-23 09:57:46

Merge sort works on the principle of divide and conquer algorithm. It is one of the most efficient sorting algorithm. The top down merge sort approach uses recursion. We break/divide the array into subparts (till single element).  
This sorting algorithm recursively sorts the subparts and then merges them into a single sorted array.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gn9gqg87suoixw5fed45.png)

There are 4 important points where all the process of merge sort takes place:
1. Find the middle element of the array.
2. Call mergeSort function for the first half.
3. Call mergeSort function for the second half.
4. Merge the two halves into a single sorted array, and yes, this 
   is the answer!
Ain't that easy? it is!


Below is the function mergeSort() in C++ language:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7x3dpu4c4igpigl8o196.PNG)

Time Complexity:

Total T(n) work is done which is divided as:
1. k amount of constant work,
2. T(n/2) work for 2 halves,
3. Merge two halves = k1n,
4. Copy elements to input array = k2n, So, 
T(n) = k + T(n/2) + T(n/2) + k1n + k2n
T(n) = 2T(n/2) + Kn    {K here is the sum of all constants - k, k1, k2}

The recurrence relation that we'll get-
T(n) = 2T(n/2) + Kn
After solving this recurrence relation, we'll come to the conclusion that the time complexity for merge sort is-
O(nlogn)

Space Complexity:

Space complexity is the maximum space required at any point of time during execution of a program.
In merge sort, we use recursion on half part of the array, So the calling will be done as (n is size of the array): 
n -> n/2 -> n/4 -> n/8 ... and so on
that is, logn function waiting in the call stack.
-> klogn space for storing functions
-> kn for array
So the maximum space required is kn,
Space Complexity will be O(n).




I hope now you can do problems on merge sort :)
The Usage of Website To Your Business
Tags: webdev, javascript, django, html
Published: 2021-05-23 09:12:23

The Usage of Website To Your Business

Many companies and start-ups don't know the essential and aid the website offers their company. Today, having a website is as crucial as having a shop, office or telephone number. Research has found that 6/10 customers expect brands to have content online about their business.

Here are the great help the website offers your company.

ONLINE PRESENCE 24/7

Having website is like having a shop or office where people can find, locate and patronize you, though it may sound odd. But, website offers your company a global location and recognition.

Your company will be searchable and recognize all over the world. 🌎🌎

INFORMATION EXCHANGE

Unlike the olden days and method of exchanging information. At its simplest, a website provides a quick and easy way of communicating information between buyers and sellers. You can list your opening hours, contact information, show images of your location or products, and use contact forms to facilitate enquiries from potential customers or feedback from existing ones.

MARKET EXPANSION

As your website is accessible to individuals all over the world, the ability to break through geographical barriers has never been easier. Anyone, from any country, will be able to find your company and as such, is now a potential customer.

IT CUT COSTS

As well as simply displaying information, your website can sell goods & services or products directly to your  consumers; in some cases removing the need to use “brick-and-mortar” stores which involve large operating costs (staff wages, rental, utilities to name just a few). Eliminating these overheads will also allow you to lower your prices, giving your business that real competitive edge.

ADVERTISING

Technology advancement has make human work easier. Many software tools have been design to make advertisement easy.

Social medias (Facebook, Instagram and WhatsApp), Google Adsense give you the power to reach customers with much more accuracy and reliability than with traditional offline advertising methods. SEO and online advertising are a great way to help build up awareness, with SEO, when customers is searching for a specific product, your company will be the one to appear on the search engine. If it’s done correctly, traffic to your website would increase.

COMPETITOR ONLINE

If you don’t have a website it is highly likely that your competitor will do, this means that you are missing out on gaining new customers and can be in the forefront of their minds. It is crucial that no opportunities are missed and are gained by the competition.

GROWTH OPPORTUNITY

Websites, in general, are great ways to in providing a place that potential investors can be referred to. It shows what your company is about, what it has achieved and what it can achieve in the future.

Looking for forward to your business growth.

Mubar Dauda
AI Practitioner, Front-end Dev, Karateka.
My javascript / tech / web development newsletter for 2021-05-22 is out!
Tags: javascript, tech, webdev, discuss
Published: 2021-05-23 08:56:27

---
title: My javascript / tech / web development newsletter for 2021-05-22 is out!
published: true
description: A roundup of all the best javascript, tech and web development links posted to my linkblog in the past week
tags: javascript, tech, webdev, discuss
---
In this week’s edition:

EdgeWorkers, experience creation, deno, React vs Vue, Jamstack, Eleventy, DPR, serverless, TSMC, Twitter verifications, Amazon & MGM, iMacs, telecoms, Future of Tipping, cool bots, spoken languages

https://markjgsmith.substack.com/p/mark-smiths-newsletter-22-05-2021

Would love to hear any comments and feedback you have.

[@markjgsmith](https://twitter.com/markjgsmith)
What is Currying?
Tags: javascript
Published: 2021-05-23 07:54:44

If you are present in the world of Javascript long enough then you would have come across a term known as ‘Currying’. Although this is an advanced technique understanding it is not that hard. We can define Currying as, a technique of evaluating function with multiple arguments, into sequence of functions with single argument. Confused ?. Good because while learning new concepts in programming confusion is your best friend. 

In other words, when a function, instead of taking all arguments at one time, takes the first one and returns a new function that takes the second one and returns a new function which takes the third one, and so forth, until the last function returns the data that you want. In short, currying doesn't call a function , it just transforms it.

#### We will look at the syntex first
```javascript
function Myfunction(a) {
        return (b) => {
           return (c) => {
             return a * b * c
             }
            }
         }
```

#### Example
We’ll create a helper function `curry(f)` that performs currying for a two-argument `f`. In other words, `curry(f)` for two-argument `f(a, b)` translates it into a function that runs as `f(a)(b)`.

```javascript
function curry(f) { // curry(f) does the currying transform
  return function(a) {
    return function(b) {
      return f(a, b);
    };
  };
}

// usage
function sum(a, b) {
  return a + b;
}

let curriedSum = curry(sum);

alert( curriedSum(1)(2) ); // 3
```
More advanced implementations of currying, such as [_.curry](https://lodash.com/docs/4.17.15#curry) from lodash library, return a wrapper that allows a function to be called both normally and partially:

```javascript
function sum(a, b) {
  return a + b;
}

let curriedSum = _.curry(sum); // using _.curry from lodash library

alert( curriedSum(1, 2) ); // 3, still callable normally
alert( curriedSum(1)(2) ); // 3, called partially
```
### Advanced curry implementation

Your curried function may look something like this:

```javascript
function checkStock(stockID){ 
   //some check code 
   if(err){throw err;} 
 
   return (warehouseID) => { 
      //some check code 
      if(err){throw err;}
      return(stockDeduct)=> { 
        //some check code         
        if(err){throw err;}
         return stockID 
                + ' from ' + warehouseID
                + ' is reduced by ' + stockDeduct;      
      }
   }
}
```
```javascript
let orderItem298 = checkStock('FN9382')('SOUTH')(3); // FN9382 from SOUTH is reduced by 3
```
Create a new Angular 4 Component – Multiple Components Angular Application
Tags: angular, component
Published: 2021-05-23 07:35:20

https://grokonez.com/frontend/angular/create-new-angular-4-component-multiple-components

Create a new Angular 4 Component – Multiple Components Angular Application

The previous <a href="https://grokonez.com/tool/setup-angular-ide-spring-tool-suite">post</a>, We had introduced how to set up an <strong>Angular 4 App</strong> with <strong>SpringBootSuite</strong>. In the tutorial, <strong>JavaSampleApproach</strong> will show you how to create a new <strong>Angular 4 Component</strong> and build an Angular Application with multiple Components.

Angular 6:
- <a href="https://grokonez.com/frontend/angular-6-component-how-to-create-integrate-new-angular-6-component">Angular 6 Component – How to create & integrate New Angular 6 Component</a>

Related articles:
- <a href="https://grokonez.com/spring-framework/spring-boot/integrate-angular4-springboot-web-app-springtoolsuite">How to integrate Angular 4 with SpringBoot Web App and SpringToolSuite</a>

<!--more-->
<div id="tuttoc" class="jsa-toc"></div>

<div id="tutcontents">
<h2>I. Technologies</h2>
– Angular 4
– SpringToolSuite: Version: 3.8.0.RELEASE
<h2>II. Angular Component</h2>
Example:
<pre><code class="language-javascript">import { Component, OnInit } from '@angular/core';
import { Customer } from './customer';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent implements OnInit {
  customers: Customer[];
  selectedCustomer: Customer;

  constructor() {}

  getCustomers() {
     ...
  }

  ngOnInit(): void {
     this.customers = this.getCustomers();
  }

}</code></pre>

What is <strong>Component</strong>?
-> Component is a basic building block of <strong>Angular Application</strong>. It allows us to mark a logic class, and additional metadata for processing at runtime. Components have a template (in above code is '<strong>./app.component.html</strong>') and only one component can be instantiated per an element in a template. 
A component must belong to an <strong>NgModule</strong>. So you should declare it in a <strong>NgModule</strong>:

More at:

https://grokonez.com/frontend/angular/create-new-angular-4-component-multiple-components

Create a new Angular 4 Component – Multiple Components Angular Application
Solving unauthorized tokens for testing
Tags: postman, testing, api, javascript
Published: 2021-05-23 07:18:56

A major part of building an API is testing. We use postman extensively for testing our APIs. The catch is our APIs are protected using JWT tokens. So while testing there is chance that your tokens might expire and you start receiving unauthorized exceptions thereafter. 

Sure it is simple for developers we can easily get a token from the database (provided we save it). But what about the QA team or the mobile-app teams. The web team is smart enough to copy the token from the browser network request. Ha ha :D 

That is when postman came to our rescue. Postman has something called **pre/post request scripts**. In simple terms these are functions that run **before/after** your API request. This felt like something we could use.

1. We created an API in our project that would take a JWT token and return a new token for that particular user. Kind of like a refresh token logic. We kept it simple however.
2. We then wrote this piece in our post request script (The Tests tab) 

```
if (pm.response.code == 401 || pm.response.code == 403)
{
    console.log("Token refreshment needed!");
    
    // expired token from the environment variables
    const token = pm.environment.get('token');

    const baseUrl = pm.environment.get('url');
    const url = baseUrl + '<refresh-url>';

    const options = 
    {
        'method': 'GET',
        'url': url,
        'header': 'Authorization:Bearer ' + token
    };

    pm.sendRequest(options, function (error, response)
    {
        const resp = response.json();
        const newToken = resp["token"];

        pm.environment.set('token', newToken);
    });
}
```

What the script basically does is. Whenever a token expires, the reponse returns an unauthorized exception. This is caught by **pm.response.code** section as it will have either 401 or 403 status code usually. 

Once we get an unauthorized exception we are simply calling our refresh url to get a new token for this user. With **pm.environment.set('token', newToken)**, we are basically assigning the newly generated token to the token environment variable.

With this, on the first click if a token expires, you can click again and the request will get you a response.


Hope it helps. Let us know your comments.

Happy programming!!!