teleren/devto huggingface dataset:
How useful is learning VI/VIM for a new programmer?
Tags: vim, linux, productivity
Published: 2021-05-09 13:13:23

I've been using a text editor called "vim" for more than a year now, and it has changed my programming life. Let's take a look.

If you are going to be writing code in [Python](https://python.org), then it would be useful to learn to use a text editor called "Vim". I don't say that because I wrote the book on this topic (I didn't), but because it will help you be more efficient as a programmer. 

Vim is an extremely powerful text editor used by programmers and system administrators around the world. Often described as a "programmer's editor", it's not always the easiest thing to get started with. If you've ever wanted to give it a try, but are unsure where to begin, try [these exercises](https://vim.is/)

## Why vim?

Vim is one of the most popular text editors in the world. It’s been heavily used for over 30 years for its simplicity, flexibility and the speed at which it allows its users to navigate their files. Vim has a very steep learning curve, but if you’re willing to put in the work, the benefits are innumerable: 

* 1) you’ll learn one of the most powerful text editors in existence; 
* 2) you will gain a skill that will serve you for the rest of your life; 
* 3) you will be able to edit files and folders on remote computers;

Vim is a classic. It is a venerable text editor, and has been around since 1991 when Bram Moolenaar first announced that he had started working on it. Vim has stood the test of time, and there are good reasons to learn it today. Vim’s design is minimalist and follows the KISS (Keep It Simple Stupid) principle. The core editor is very small, with all additional features being optional plugins.

You can also use Vim inside popular IDE's. Getting all the benefits of the IDE plus all the benefits of vim.

![vim inside vscode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51q3rxiffpjskcs0ae0z.png)
[Javascript]
Tags: javascript
Published: 2021-05-09 13:06:38

## Setting up
### Jest
```sh
npm install -g jest
npm root -g

# Run test
jest test.js --watch
```

### debugger
```javascript
function funcName() {
  //  
  debugger;
  //
}
```

```sh
node inspect test.js

# continue
debug> c

# enter repl to check the variables
debug> repl

```

### Null vs Undefined
```javascript
let test;
console.log( test ); // undefined

test = null
console.log( test ); // null

console.log( 1 + null ); // 1
console.log( 1 + undefined ); // NaN

console.log( null == undefined ); // true
console.log( null === undefined ); // false
```

### Reverse String
```javascript
function reverse(str) {
}
```

### Memoization - Fibonacci
```js
function memoize(fn) {
  const cache = {};
  return function (...args) {
    if (cache[args]) {
      return cache[args];
    }

    const result = fn.apply(this, args);
    cache[args] = result;

    return result;
  };
}

function slowFib(n) {
  if (n <= 1) return n;

  return fib(n - 1) + fib(n - 2);
}

const fib = memoize(slowFib);
```
Not event 0 == "" but 0 == " " too.
Tags: javascript, programming
Published: 2021-05-09 13:03:36

```
    > 0 == ""
      True

    > 0 == " "
      True

    > 0 == "        "
      True

    > 0 == "0"
      True
```
When we use == operator to do a comparison operation. There are a few cases we should be careful of, for example when we use “==” to compare 0 with “” or “ “ because all of the cases return true.

The reason is the operand on the right hand of operator == is automatically transformed to the same type as the left hand operand. In this case, the left hand operand’s type is Number so the right hand operand is transformed to the type Number as well [1].

We can see this when we try to explicitly transform these strings to type Number.

```
> Number("0")
  0
> Number("1")
  1
> Number("")
  0
> Number("     ")
  0
> Number("a")
  NaN
> 0 == Number("0")
  true
> 0 == Number(" ")
  True
```


It looks pretty strange when Number(“”) or Number(“ “) return 0 and Number(“a”) return NaN.

As stated in mozilla.org[2] that  “In most cases, **using loose equality is discouraged.** The result of a comparison using strict equality is easier to predict, and may evaluate more quickly due to the lack of type coercion.”. The summary of how type conversion works in Javascript when using == operator is shown in this table [3].

Ref:
[1] 
[https://262.ecma-international.org/5.1/#sec-11.9.3](https://262.ecma-international.org/5.1/#sec-11.9.3)

[2]
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness)

[3]
[https://dorey.github.io/JavaScript-Equality-Table/](https://dorey.github.io/JavaScript-Equality-Table/)
How to force TypeScript’s tsc to rebuild your files
Tags: typescript, programming, computerfrustration
Published: 2021-05-11 19:44:45

---
title: How to force TypeScript’s tsc to rebuild your files
published: true
date: 2021-05-09 12:21:32 UTC
tags: typescript,programming,computerfrustration
canonical_url: https://www.solarwinter.net/how-to-force-tsc-to-rebuild-your-files/
cover_image: https://www.solarwinter.net/content/images/2021/05/pexels-andrea-piacquadio-3807738.jpg
---

I’ve noticed when using `tsc` in watch mode that sometimes - especially if a file has been renamed - it doesn’t realise the file needs recompiling. This state persists across reboots, restarting the watcher, all the usual stuff.

The last time I hit this was when I needed to re-order the seed files I’m using for this project. A file that had been last needed to be first, everything had to move around as I use numbers in the filenames to ensure the seeding order is clear. Mostly it works really well.

Renaming the files wasn’t a problem, but suddenly the `lib/seeds` directory has two sets of seeds in. The results from that - as you’d expect - were not good.

`rm lib/seeds/*`, re-run and … nothing. Hmm.

Maybe it needs prompting to recompile them? `touch src/seeds/*` and still nothing.

Last time this happened I rebooted the laptop and everything. This time, thankfully, I remembered before I got that far.

The only solution I’ve found? Delete `tsconfig.tsbuildinfo` and rebuild. From the filename I assume it seems caches the build info in that file, which is entirely reasonable. It just doesn’t always figure out when the cache is out of date.

Hope that saves someone a few reboots and some time.
I am starting a technical blog!!!
Tags: python, codenewbie, techblog, technicalwriting
Published: 2021-05-09 12:19:05

I have always wanted to write technical articles and blog posts, but every single time, I have also asked myself if I can really handle the stress/work that comes with putting long words together.

Well, I finally got the inspiration to start writing when  [Chioma](https://www.linkedin.com/in/mbaoma-chioma-mary) shared a blog post where [Ifihan ](https://www.linkedin.com/in/ifihan-olusheye)  wrote about the differences and similarities between Lists and Tuples in python. 

I jokingly replied *“Lemme carry my pen and write about sets vs dictionaries”*, I had expected her to send a “lol” response or a laughing emoji in return but nah, she replied “oya”, meaning, do it! Then it dawned on me that I just got trapped in my own net😂. 

![chat snapshot](https://res.cloudinary.com/dclfepekx/image/upload/v1619548677/chat_screenshot_h2ruef.jpg)

## So, why did I make that comment in the first place? 
 
Lists and Tuples are two of the 4 built-in data types in Python with Sets and Dictionaries completing them. So, I thought, if someone wrote about Lists and Tuples, let me complement the job with the remaining two members of the built-in data types family. This was all I needed to start!

My first article will be out in no time. Instead of writing about Sets and Dictionaries, I will be writing about the Python programming language itself, bringing you into the world of Python (installation steps and a guide to running your first program). 

So take this as my debut post. Moving forward, I will be using this platform to share my thoughts, knowledge and new learnings on things related to Python, Microsoft Azure, Developer tools, and technology in general.

Peace💚✌️
Migrating to AWS CDK v2
- the missing GO manual
Tags: aws, cdk, go
Published: 2021-05-09 12:18:27

I like using GO, so I use AWS CDK in the new GO flavour also.

AWS has now released the AWS CDK v2 and nicely documented how to upgrade TypeScript, JavaScript, Python, Java and C#.

See [AWS Docu](https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-v2.html).

The GO part is missing ...

Trying `cdk ls` on a GO CDK app will get you:

```bash
cdk ls
This CDK CLI is not compatible with the CDK library used by your application. Please upgrade the CLI to the latest version.
(Cloud assembly schema version mismatch: Maximum schema version supported is 9.0.0, but found 10.0.0)
```

Here is the fix:

## 1 - Change AWS CDK import

```go
 import (
     
        
-       "github.com/aws/aws-cdk-go/awscdk"
+       "github.com/aws/aws-cdk-go/awscdk/v2"
 )
``` 

## 2 - Change construct imports

```go
   import (
-       "github.com/aws/aws-cdk-go/awscdk"
-       "github.com/aws/aws-cdk-go/awscdk/awsssm"
+       "github.com/aws/aws-cdk-go/awscdk/v2"
+       "github.com/aws/aws-cdk-go/awscdk/v2/awsssm"
)
```

## 3 Change Constructs Programming Model import:

```go
 
   import (

-       "github.com/aws/constructs-go/constructs/v3"
+       "github.com/aws/constructs-go/constructs/v10"
 )
```


## 4 - delete some feature flags in `cdk.json`

E.g. if you get

```bash
panic: "Unsupported feature flag '@aws-cdk/core:enableStackNameDuplicates'. This flag existed on CDKv1 but has been removed in CDKv2. CDK will now behave as the same as when the flag is enabled."
```

Delete the line in `cdk.json`

## 5 - Update to new modules

```bash
go mod tidy
```


## 6 - Pinpoint cdk version

Instead of installing cdk globally (`npm i cdk -g`) you may use a specific version of the cdk with

```bash
npx cdk@2.0.0-rc.1 ls
```

Without prior installation.

## 7 - Use aws sdk pointer building instead of jsii

Instead of

```go
	cluster := ecs.NewCluster(stack, jsii.String("ALBFargoECSCluster"),...
```

use 

```go
	cluster := ecs.NewCluster(stack, 
aws.String("ALBFargoECSCluster"), ...
```

With the import of 

```go
"github.com/aws/aws-sdk-go-v2/aws"
```

# Here I GO again

That fixed it for me!

Hope this will help you.

For a chat - contact me on twitter @megaproaktiv
MariaDB: Update database charset / collation
Tags: mariadb, mysql, charset, wordpress
Published: 2021-05-09 11:54:00

I made a mistake when I made a [MariaDB](https://mariadb.org/) database for a [WordPress](https://wordpress.org/) website.

The website would use Japanese and therefore the database charset should have been set "utf8mb4" as. I, however, did `CREATE DATABASE` without specific options and so it was "c" instead of "utf8mb4" unfortunately.

I updated its charset and collation with this SQL:

```sql
-- accessing through `mysql -u <user> -p`
ALTER DATABASE <database> \
    CHARACTER SET='utf8mb4' \
    COLLATE='utf8mb4_unicode_ci' \
    ;
```

Well, it is also able to get charsets via SQL:

```sql
SELECT SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME \
    FROM information_schema.SCHEMATA;
```

Reference:

- [MariaDB - Setting Character Sets and Collations](https://mariadb.com/kb/en/setting-character-sets-and-collations)
[Python] Django 101
Tags: python, django
Published: 2021-05-09 11:09:54

## Install

```sh
python3 -m venv ./venv
source ./venv/bin/activate

# Escape from venv
deactivate

# Check packages installed in the venv
pip freeze

# Create project & app
pip install django
django-admin startproject PROJECT-NAME
python manage.py start app APP-NAME
```

## Commands
```sh
# Run server
python manage.py runserver

# Create migrations
python manage.py makemigrations

# Run migration
python manage.py migrate

# Collect static files
python manage.py collectstatic
```

## Postgres DB setup
```sh
sudo -u postgres psql

postgres=# CREATE DATABASE myproject;
postgres=# CREATE USER myprojectuser WITH PASSWORD 'password';
```
Difference Between malloc() and calloc() with Examples
Tags: dynamicmemoryalloction, malloc, colloc, realloc
Published: 2021-05-09 10:57:29

The name malloc and calloc() are library functions that allocate memory dynamically. It means that memory is allocated during runtime(execution of the program) from the heap segment.

Initialization: malloc() allocates memory block of given size (in bytes) and returns a pointer to the beginning of the block. malloc() doesn’t initialize the allocated memory. If we try to access the content of memory block(before initializing) then we’ll get segmentation fault error(or maybe garbage values).'

void* malloc(size_t size);

void* calloc(size_t num, size_t size);

Number of arguments: Unlike malloc(), calloc() takes two arguments:
1) Number of blocks to be allocated.
2) Size of each block.
Return Value: After successful allocation in malloc() and calloc(), a pointer to the block of memory is returned otherwise NULL value is returned which indicates the failure of allocation.
For instance, If we want to allocate memory for array of 5 integers, see the following program:-
int main()
{
    int* arr;
  
    // malloc() allocate the memory for 5 integers
    // containing garbage values
    arr = (int*)malloc(5 * sizeof(int)); // 5*4bytes = 20 bytes
  
    // Deallocates memory previously allocated by malloc() function
    free(arr);
  
    // calloc() allocate the memory for 5 integers and
    // set 0 to all of them
    arr = (int*)calloc(5, sizeof(int));
  
    // Deallocates memory previously allocated by calloc() function
    free(arr);
  
    return (0);
}
We can achieve same functionality as calloc() by using malloc() followed by memset(),

ptr = malloc(size);
memset(ptr, 0, size);

Note: It would be better to use malloc over calloc, unless we want the zero-initialization because malloc is faster than calloc. So if we just want to copy some stuff or do something that doesn’t require filling of the blocks with zeros, then malloc would be a better choice.
Detect GraphQL breaking changes on any CI with graphql-inspector
Tags: graphql, ci, buildkite
Published: 2021-05-09 10:55:01

> [GraphQL Inspector](https://graphql-inspector.com) is a set of tools to help you better maintain and improve GraphQL API as well as GraphQL consumers.

GraphQL Inspector provides an amazing GitHub action with a lot of cool features. But if you are using another CI you will have to code them yourself.

When integrating GraphQL Inspector to detect breaking changes on pull requests using Buildkite, I wanted to allow a GraphQL breaking change to be merged if it was intentional. An easy way to do this is to add a label to the pull request named "GraphQL breaking change".

Hopefully, the following script can help you to achieve this easily using the GitHub API. It should also be fairly simple to make it work with Gitlab.

## Step 1 - Make the CI fail if a breaking change is present

To simply detect a breaking change just add the following script as part of your CI.

```sh
# checkGraphqlBreakingChanges.sh

#!/usr/bin/env bash
set -e

yarn graphql-inspector diff 'git:origin/main:./schema.json' 'schema.json'
```

If a breaking change is present this script will fail.

## Step 2 - Allow a breaking change to be merged if a GitHub label is present on the PR

Create a new pull request label via the GitHub UI named "GraphQL breaking change".

The script works directly with Buildkite but you will have to replace the `BUILDKITE_PULL_REQUEST` env variable with the one provided by your CI.

Your CI env needs to have access to a `GITHUB_USER` and `GITHUB_USER_TOKEN` allowing the script to query the GitHub API.

```sh
# checkGraphqlBreakingChanges.sh

#!/usr/bin/env bash
set -e

# Label allowed
ALLOW_LABEL="GraphQL breaking change"

# We only want to run this logic if we are on a pull request
if [ -z "$BUILDKITE_PULL_REQUEST" ]; then
    echo "Skipping, not a pull request..."
    exit 0
fi

# Get the labels array from the Github API for the pull request
GITHUB_PR_LABELS=$(curl -u $GITHUB_USER:$GITHUB_USER_TOKEN \
  -s "https://github.com/api/v3/repos/my-org/my-repo/pulls/$BUILDKITE_PULL_REQUEST" \
  | jq '.labels[].name')

# If label is set on the pr we stop the execution as breaking change is intentional
if [[ ${GITHUB_PR_LABELS[*]} =~ "$ALLOW_LABEL" ]]; then
    echo "Skipping, because label is set..."
    exit 0
fi

yarn graphql-inspector diff 'git:origin/main:./schema.json' 'schema.json'
```
Go Doc
Tags: go
Published: 2021-05-09 10:46:30

####Go help developers generate documents by using godoc

Reference: https://golang.org/doc/effective_go
<hr>

Generating godoc is fairly easy. The developer just put the comment on top of the file before the package clause, then the doc will be generated automatically.

####There are two types of comment - block comment, and line comment

1.Block comment `/* */` use for several lines of comment
```
/*
Package regexp implements a simple library for regular expressions.

The syntax of the regular expressions accepted is:

    regexp:
        concatenation { '|' concatenation }
    concatenation:
        { closure }
    closure:
        term [ '*' | '+' | '?' ]
    term:
        '^'
        '$'
        '.'
        character
        '[' [ '^' ] character-ranges ']'
        '(' regexp ')'
*/
package regexp
```

2.Line comment `//` use for a simple comment
```
// Package path implements utility routines for
// manipulating slash-separated filename paths.
```

<b>For multi-file packages, the package comment only needs to be present in one file. </b>

###What should be in the comment?
1. Package introduction
2. Package explanation as a whole

Other than that you could comment on top of functions, interfaces or type, etc. to add further explanation

##How to see godoc locally
A. cd into the package then run
```
go doc
```
This will show the doc in the terminal
<hr>
B. If you want to see it on the local web

1.Make sure you have the `go.mod` file in the root directory
if you don't have it yet run
```
go mod init example/path
```
2.run
```
godoc
```
then it will run on localhost:6060

if you want to, you can specify your own port
```
godoc -http=localhost:8080
```
Express's json() and urlencoded() Explained
Published: 2021-05-09 03:02:10

Express is a Node.js framework best known by beginners for simplifying syntax in building basic back-end servers. Express.js comes with a lot of built in modules and functions, and we're going to talk about two of them specifically today: .json() and .urlencoded(). 

.json() and .urlencoded() are express middleware functions that parse data in outgoing requests. Let's break that down: 

### 1.) They are middleware functions 

So what is middleware?

Middleware is a function or piece of code that is called (run) between when a server gets a request from a client and when it sends a response back to the client. Middleware can take many forms, like simple logs:

```
console.log('server listening on port ${port})
```

or functions that manipulate incoming or outgoing data (such as `.json()` and `.urlencoded()`)

### 2.) They parse outgoing requsts

Both are used to parse data that goes out on the `req` object. Usage of .json() and .urlencoded() depends on the encoding of data you are sending in your server request.

Because they are used on the `req` side of a server call, you only need them for POST and PUT requests, or any outgoing request that carries data. They aren't needed for GET or DELETE requests.

Incidently, both used to be part of `body-parser` which was in itself a piece of middleware that was taken out and separated from Express, but since Express 4.16.0 they're back into Express and use the `express.FUNCTIONNAME()` syntax.


## So what exactly is the difference and how can I use them?



### `.json()`

Express.json() expects request data to be sent in JSON format, which often resembles a simple JS object:

```
{"Name": "Pikachu", "Type": "Banana", "Number In Stable": 12}
```

### `.urlencoded()`

Express.urlencoded() expects request data to be sent encoded in the URL, usually in strings or arrays:

```
.../Name=Pikachu&Type=Banana&Number+In+Stable=12
```


### You can call them using 

```
express.json()

or

express.urlencoded()
```

but if you want them to be used every time a request is made on the server (which is a typical use case), you can also use `app.use`:

```
app.use(express.json())

or 

app.use(express.urlencoded())
```


## Summary 

`express.json()` and `express.urlencoded()` are helpful express middleware parser functions that let you parse outgoing request data depending on the encoding of data you're sending to the server.
WhatsApp Clone (Backend & FrontEnd)
Tags: flutter, node
Published: 2021-05-09 10:32:37

Hi guys, I created the WhatsApp Clone using Flutter. Please check out the screenshots of the app & source code in my GitHub -https://github.com/DevStack06/Whatsapp-Clone-Flutter And please do star the repo if you liked it!!


You can also check the Youtube Playlist, which will cover both Front-End and Backend Development: https://youtube.com/playlist?list=PLtIU0BH0pkKovuEaNsrGE_Xd5Tz3m1zeC

Any suggestions are warmly welcomed, and it is open source so feel free to contribute ✌️✌️✌️.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06663si6zj6louvdksh9.png)
How to make your footer stay at the bottom of the page.
Tags: css, beginners, codenewbie
Published: 2021-05-09 10:30:28

I recently met an issue with positioning a footer. After finding a solution, I decided to document it in this post.

Our goal is to:
- Make the footer stay at the bottom even when the content is not filling the screen.
- Make the footer appear at the end of the document when the screen is full of content (instead of overlapping the bottom section)

#### 1. Give your container a min-height of 100vh

The body tag which holds your content should be given a minimum height of 100vh. This will ensure that the body will always take full height of the page even when its content is not filling the page. You can apply this to the body or the container which has the footer as the last tag.

```css
body {
 min-height: 100vh;
}
```

#### 2. Make your body a flexbox
Make your body a flexbox by giving it a `display` property with the value of `flex` and also change its direction by using `flex-direction` set to column

```css
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
```

#### 3. Give the footer a margin-top of auto

Assuming your body has a similar layout to this;

```html
<body>
  <header>...</header>
  <main>...</main>
  <footer>...</footer>
</body>
```
You can give your footer tag a `margin-top` property with the value of `auto`

```css
footer {
  margin-top: auto;
}
```

And that's it three simple steps :)

Thank you for reading this article ♥️. Feel free to ask any questions you may have down below and I'll get back to you.
How should beginners learn C programming?
Published: 2021-05-09 10:28:04

C is a procedural language where the instructions are executed step by step. It is portable and faster than most programming languages like Python, Java etc. C programming can be used to develop operating systems, databases, embedded systems, and so on.
# Why should you learn C programming?
•	C helps you understand the internal architecture of the computer.
•	It helps you store and retrieve information from the computer.
•	If you learn C, it would be easier for you to learn other programming languages too.
•	It opens up a lot of job opportunities too.
# Tips for beginners
•	Start off by understanding the basics of each topic.
•	Practice is key. To understand any topic perfectly you must start by practicing easy programs then gradually increase the difficulty level.
•	There are a lot of online platforms with fun challenges that you can use to strengthen your programming skills.