NodeJS: JavaScript powering the backend.

Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. NodeJS is a JavaScript engine that you can install in your own system.

Also, NodeJs makes it possible to use JavaScript in backend development as a backend programming language. (Cool! isn’t it.)

You need to know this.

Node isn’t a program that you simply launch like Word or Photoshop: you won’t find it pinned to the taskbar or in your list of Apps. To use Node you must type command-line instructions, so you need to be comfortable with (or at least know how to start) a command-line tool like the Windows Command Prompt, PowerShell, or the Git shell.

Installation Steps

  1. Download the Windows installer from the Nodes.js® web site.
  2. Run the installer (the .msi file you downloaded in the previous step.)
  3. Follow the prompts in the installer (Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings).

Now to be sure that everything is fine and to confirm node installation, You need to run the following code in your preferred terminal.

  • Check node version: node -v
  • Check npm version: npm -v
  • Confirm installation of node: node hello.js
Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\docs> node -v
v10.14.2

C:\Users\docs> npm -v
6.4.1

C:\Users\docs> node hello.js
Node is installed!

Here is an actual example from my very own system.

If you have any question in your mind, feel free to comment below.

Thank You.

Your PHP installation appears to be missing the MySQL extension, required by WordPress

The error message “Your PHP installation appears to be missing the MySQL extension which is required by WordPress” can appear when you are using a PHP version which is incompatible with your scripts version. Meaning your WordPress installation is most likely outdated.

Since the ‘MySQL’ extension is no longer supported from PHP 7.0 and beyond, changing your PHP version to 5.6 or lower will fix the issue. This can be done via your website’s control panel’s PHP Configuration section.

So, let’s do it first and then we will see some probable causes of this error.

Steps:

Step 1- Login to your Cpanel.


Step 2- Find PHP PEAR Packages and click on it. and then click on show available modules.

Step 3- Find MYSQL and install the 3 extensions shown in the image above.

Step 4- Now Go to select PHP version.

Step 5- Now find MySQL (Use Ctrl + F), select it and save it.

That’s it. The problem is fixed. Let’s get to some probable causes of this error.

Probable causes of this error.

1. PHP’s MySQL extension not installed.

The quickest way to check if your PHP has MySQL support is to put the following code into a file called info.php in your site and access it from a browser.

<?
phpinfo();
?>

A MySQL section like this will be shown.
If it’s not shown there, then you don’t have the PHP’s MySQL extension installed.

In Ubuntu servers and RedHat compatible servers, use the following commands respectivly:

# apt-get install php5-mysqlnd

# yum install php-mysql

2. Check if PHP’s MySQL extension directory is misconfigured.

Another cause of the ‘Your PHP installation appears to be missing the MySQL extension which is required by WordPress’. could be that the PHP extension directory is not configured properly.

In order to fix this, locate which PHP.ini file is being loaded and ensure that the appropriate “extension_dir” value is being used. So let’s open up the info.php file we created in Step 1 via our web browser.

Look for the line called “Loaded Configuration File”. The file path noted there is the actual location to the PHP configuration file.

Now, look for the entry called “extension_dir“. It should either be commented, or it should have the correct path to PHP extensions. It should never be left blank.

If you are not sure, just comment the line, and restart the web server.

Simply updating PHP and WordPress might also solve the problem.

In case you are running PHP 5, run the following commands:

apt-get update
apt-get install php-mysql

Restart the appropriate service for the changes to take effect.

This may have solved your problem. Feel free to comment below.

Thank You.

Fix Error Too Many Redirects on WordPress Admin page or Blog

There are several cases for the cause and multiple solutions also:

1 Add these 2 lines in wp-config.php file

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

2 Edit these settings in database directly using PhpMyAdmin in table options or wp_options in option_id, option_name (1,siteurl) and (2,home)

wp_options table

3 You can do the same by Editing wp-config.php and adding these 2 lines

define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');

4 Fix your .htaccess file with default one
Check here for default .htaccess for wordpress

Programming Paradigm.

Hi Everyone!

Today we are going to talk about programming paradigm. And in pronounces, the ‘g‘ is silent in ‘paradigm’.

So, in layman’s language programming paradigm is just the style of programming. Their are various styles of programming.

Every developer is different, hence is the style. Here we are about to talk about the most commonly used styles or pattern of programming.

Different Paradigms:

1. Imperative/procedural programming.

Imperative programming consists of sequence of statements and values are stored in memory after the implementation of statements.

Memory utilization is low. And mostly contains Variables & Iterations. Quite simple to implement.

Yet this style of programming has some demerits.

  • Complex problems can not be implemented.
  • Parallel programming is not possible.
  • Less productive.

2. object oriented programming.

Here the data $ functions are bound in one entity called class. In this pattern of programming everything is modeled as object. It follows the modular programming approach.

Mostly known for Data abstraction, encapsulation, inheritance, polymorphism. It is also quite easy to debug and modify.

Just one demerit to name is:

Methods (fx) of class are hidden.

3. functional programming.

To be honest this is what I prefer.

Here all the computations are expressed in functions. Complex functions can be developed from a single function.

Due to a re-usable functional approach, this style becomes quite comprehensible. Large number of functions can be mentained.

  • Consumes large amount of time and memory.
  • Not recommended for commercial applications.

4. Logical Programming.

Here the computations are expressed in mathematical logic. It follows the declarative programming approach.

Development is quite fast as it uses true or false (boolean) statements.

Known demerit are:

  • Slow execution
  • True and false can not solve most of the problems.

So, this is it from my side for this article. Please let us know what’s your way of programming.

  • Functional,
  • Logical, or
  • Object oriented.

See you soon in the next article.

Thank You.

What is MVC in programming.

Hi Everyone!

This concept is a bit difficult to understand, but that does not stop me from writing about it. I will try to be as clear and simple as I can.

We have a lot to cover, So let’s just dive into it. I have also included diagrams and example code of MVC below.

MVC:

MVC stands for “Modal View Controller” and it is a “Software architectural design pattern“, Which in turn is one of the most frequently used patterns.

It separates application functionality. And promotes organized programming.

popular frameworks that uses mvc concept.

  • Ruby on rails (RUBY)
  • Codeigniter (PHP)
  • Laravel (PHP)
  • Angular (JS)
  • Express (JS)
  • Django (PYTHON)
  • Flask (PYTHON) , e.t.c…

Now let’s break it down to the 3 components – MODAL, VIEW and  CONTROLLER.

modal:

Modal is responsible for getting and manipulating the data. It can also pull data from a JSON file.

It is the logic related to data which interacts with the database (select, update, insert, delete).

It communicates with the controller. And depending on the framework is also capable of updating the view.

view:

You got it!

It is the actual view of the application, the user interface. It is what the user sees when they interact with the application.

Usually the content of this part is HTML and CSS with dynamic values. It also communicates with the controller.

It’s dynamic values on the UI are passed from the controller. Depending on the framework template engine may vary. Template engine allows the dynamic data.

controller:

Controller takes in user input, so this could be from a user visiting a page, clicking a link or submitting a form which makes a get and post request.

Basically the main thing here is processing a request (GET, POST, PUT, DELETE).

You can think of the controller as a middleman between MODAL and VIEW. Controller gets the data from the Modal and passes it to the View.

Now i am sharing two diagrams and a code example for better understanding. The code shared is just an dummy code it is not going to work.

MVC (Modal View Controller) diagram.

Example code:

http://your-app.com/users/profile/1
/routes
    users/profile/:id = Users.getProfile(id)
/controllers
    class Users {
          function getProfile(id) {
              profile = this.UserModal.getProfile(id)
              renderView('users/profile', profile)
     }
/modals
     class UserModal {
           function getProfile(id) {
               data = this.db.get('SELECT * FROM users WHERE id = id')
               return data;
      }
/views
     /users
          /profile {{profile.name}}

Email: {{profile.email}}
Phone: {{profile.phone}}

That’s all for this article, see you soon in some other article.

Thank You.

How to increase EBS storage block size on a running spot instance in AWS?

So, you created a aws group with a small ebs storage size and now that the site is in production, storage disk is full and it was mounted as root storage, now you are asking “MY AWS INSTANCE STORAGE IS FULL, WHAT TO DO?”
or “How do I increase the EBS volume size of a running instance?”

So, here is the simple solution:

There are two commands which will help you

$ lsblk

and

# df -h

So, initially if you login via SSH (using PUTTY or anything else) you will see something like this:

So, what you need to do is, you need to go to aws console and edit block size in EC2 management

Go to EBS > Volumes
Right Click the volume you need to expand and choose MODIFY VOLUME
Enter the new size you want for your block

Now run the command lsblk and df -h and you will notice the old size and new size under xvda and xvda1

Size available but not used

If you dont see the updated new size, please use init 6 or restart the instance using any other command

You now need to use utility growpart so use command


sudo apt install cloud-utils

If you are out of space, please remove any old files which are of no use anymore to free up some Mega Bytes
After that, simply use


sudo growpart /dev/xvda 1

and
sudo resize2fs /dev/xvda1
resize2fs command
lsblk after resize
df command after resize

Reference: 
https://stackoverflow.com/a/43251901/2229148


tk120404

Understanding “this” keyword in JavaScript.

‘Hi Everyone!

In this article, we are about to discuss  ‘this’ keyword in JavaScript. It is a very important part of object-oriented JS programming. Hence it becomes crucial for serious developers to understand  ‘this’ keyword.

It is also one of the most confused concepts of JavaScript.

What is ‘this’?

Understanding 'this':

To be able to understand what I am about to talk, you should be familiar with the basics of JavaScript. e.x – Variables, Objects, Functions, etc…

There isn’t a single word that describes ‘this' well, so I just think of it as a special variable that changes depending on the situation. Those different situations are captured below.

case 1:

In a regular function (or if you’re not in a function at all), 'this' points to'window' This is the default case.

function logThis() {
console.log(this);
}

logThis(); // window

// In strict mode, `this` will be `undefined` instead of `window`.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

Case 2:

When a function is called as a method, 'this' points to the object that’s on the left side of the dot.

/*
 * You can also think of this as the "left of the dot" rule. 
 * For example, in myObject.myMethod(), `this` will be myObject
 * because myObject is to the left of the dot.
 *
 * Of course, if you're using this syntax myObject['myMethod'](),
 * technically it would be the "left of the dot or bracket" rule,
 * but that sounds clumsy and generally terrible.
 *
 * If you have multiple dots, the relevant dot is the one closest 
 * to the method call. For example, if you have one.two.hi();
 * `this` inside of hi will be two.
 */

var myObject = {
  myMethod: function() {
    console.log(this);
  }
};

myObject.myMethod(); // myObject

Case 3:

In a function that’s being called as a constructor, 'this' points to the object that the constructor is creating.

function Person(name) {
  this.name = name;
}

var gordon = new Person('gordon');
console.log(gordon); // {name: 'gordon'}

Case 4:

When you explicitly set the value of 'this' manually using,'bind''apply' or,'call' it’s all up to you.

function logThis() {
  console.log(this);
}

var explicitlySetLogThis = logThis.bind({name: 'Gordon'});

explicitlySetLogThis(); // {name: 'Gordon'}

// Note that a function returned from .bind (like `boundOnce` below),
// cannot be bound to a different `this` value ever again.
// In other words, functions can only be bound once.
var boundOnce = logThis.bind({name: 'The first time is forever'});

Case 5:

In a callback function, apply the above rules methodically.

function outerFunction(callback) {
  callback();
}

function logThis() {
  console.log(this);
}

/*
 * Case 1: The regular old default case.
 */
 
outerFunction(logThis); // window

/*
 * Case 2: Call the callback as a method
 */
 
function callAsMethod(callback) {
  var weirdObject = {
    name: "Don't do this in real life"
  };
  
  weirdObject.callback = callback;
  weirdObject.callback();
}

callAsMethod(logThis); // `weirdObject` will get logged to the console

/*
 * Case 3: Calling the callback as a constructor. 
 */
 
function callAsConstructor(callback) {
  new callback();
}

callAsConstructor(logThis); // the new object created by logThis will be logged to the console

/*
 * Case 4: Explicitly setting `this`.
 */
 
function callAndBindToGordon(callback) {
  var boundCallback = callback.bind({name: 'Gordon'});
  boundCallback();
}

callAndBindToGordon(logThis); // {name: 'Gordon'}

// In a twist, we give `callAndBindToGordon` a function that's already been bound.
var boundOnce = logThis.bind({name: 'The first time is forever'});
callAndBindToGordon(boundOnce); // {name: 'The first time is forever'}

Conclusion:

So, this was all about “this”.

The value of ‘this’ keyword depends on the situation, analyze the situation and figure out what ‘this’ represents.

You gave your precious time to read this article.

Thank You.

Everything is a ToDo list.

Hi Everyone!

Today’s topic might not be clear from the heading, so let me make it clear over here. This post is a bit different so brace your self to think a bit.

In the field of programming, it is very important to understand the fundamentals and core concepts of programming. This field requires you to think differently.

Most people find coding quite tough and the reason being the way they think about web-applications. Anyone can learn the syntax of a computer language, and print ‘Hello World’.

But to literally build something you got to Think Differently…

And that’s what we are going to do today. Don’t go to the different purposes of these web-applications, instead try to see the common pattern that I am trying to point out.

Everything is a todo list.

Every web-application is a kind of todo list app. Let us see how.

ToDo List app:

The picture below is from a todo list web app.

Enter your task to be done and it will add it to the list.

Google is a kind of ToDo List app:

Google is a kind of todo list app, instead of tasks in the list there are the search results.

Enter your query and it gives you the list of search results.

E-commerce(Amazon) shopping cart:

A shopping cart is also a kind of todo list app. Instead of tasks, there are products and items on the list that you saved.

Select your product and it will be added to the list of the cart.

In fact, messaging apps are a kind of ToDo list.

All messaging apps are also a kind of todo list. the only difference is that the text input bar is at the bottom.

See the first image of todo list app, I am about to convert it to a messaging app. Here we go.

conclusion:

Every web-application is a kind of todo list app. Very rarely you would found an application that does not fits into this pattern.

Once again (Don’t consider the functionality of these sites, instead try to see the pattern, I am trying to point out.)

Hence,

A todo list app is a great place to start for beginners.  Walk your way through an advance todo list app (like the one shown in the image above.) to get familiar with concepts used in almost all web applications.

Amazing new articles are about to come, stay tuned!

Thank You.

The most difficult CS subjects.

Hi Everyone!

Let’s talk about the most difficult CS subjects and why these subjects are considered difficult.

These are the subjects that really need an astonishing amount of hard work to excel and master them.

So, without any further due, let’s just dive into this.

The hardest CS subjects:

1.ARTIFICIAL INTELLIGENCE: Giving consciousness to machines, and making them able to take their own decision. This is the most difficult subject in the industry because here you have to be a multi-talented person.

  • Your mathematics needs to be strong enough.
  • You should know how to handle the database.
  • You should be able to develop your own algorithms.
  • Offcource, you need to know how to code.

And the thing that makes AI even more difficult is that it isn’t static, the system by itself gets better and better. Hence to be in the game you have to keep improving yourself.

IT is said about AI that:

“You can initiate it, but you can’t stop it.”

2.THEORY OF COMPUTATION: You might not have heard of it ever. You gave a command to the computer to do ‘X’ and it did. But have you ever imagined how the computer did it – well that’s what is Theory of computation.

The study of that process by which a computer implements a command is called Theory of computation.

Here the expert never asks ‘What?’,  instead, they only ask ‘How?’

They don’t care WHAT the result is, but HOW that result came into existence.

3.MICROPROCESSORS / LOGICAL CHIPS: Those small computers and chips that can do processing for you. This is what you have in all your electronic devices including your smartphones.

It is a big deal to program these processors.

4. ADVANCE DATABASE: You know this, the management and storing of data in a systematic way. It is easy to store data when it is in small quantity. But when it becomes huge it becomes a nightmare to store and maintain it.

It is an art to store and manage a huge amount of data.

5. COMPILER DESIGN: Converting high-level language into machine language. A very rough way to understand it is this:

This is all about creating a software that makes other software.

SO, these were the most difficult subjects of computer science. If you mastered these subjects you can get a huge payoff.

If you liked it then stay tuned for more such articles, and you can also check our previous articles.

Thank You.

Avoid these bad coding habits.

Hello Everyone!

When it comes to coding, most people think it is something mystical that only geeks can understand. Believe me, it is not like that my friend. Anyone can code with a fair amount of practice.

There is nothing mystical about it.

Coding is a skill like any other. Like language learning, there’s grammar and vocabulary to acquire. Like math, there are processes to work through specific types of problems. Like all kinds of craftsmanship and art-making, there are techniques and tools and best practices that people have developed over time, specialized to different tasks, that you’re free to use or modify or discard.

Here we are about to see a few bad coding habits that you must avoid.

Avoid these bad coding practices:

1. Saying “I’ll fix it later”.

The habit of postponing code fixes is not merely a problem of priorities. Organizing your issue tracker might generate some progress, but you also need to have a way of tracking smaller issues that come up. Adding “TODO” comments is a quick way of making sure you don’t miss anything.

2. Insisting on a one-liner solution

Being obsessive about writing efficient, elegant pieces of code is a common trait of programmers. It’s like solving a puzzle—you find a combination of functions and regular expressions that turn 20 code lines into 2 or 3. Unfortunately, it doesn’t always result in readable code, and that’s generally the far more important outcome. Make your code accessible first, then clever.

3. Difficulty seeing through recursion

The idea of recursion is easy enough to understand, but programmers often have problems imagining the result of a recursive operation in their minds, or how a complex result can be computed with a simple function. This makes it harder to design a recursive function because you have trouble picturing “where you are” when you come to writing the test for the base condition or the parameters for the recursive call.

4. your code is a mess

Symptoms
  1. Doesn’t follow a consistent naming convention.
  2. Doesn’t use indentation, or uses inconsistent indentation.
  3. Doesn’t make use of whitespace elsewhere, such as between methods (or expressions).
  4. Large chunks of code are left commented-out.
Programmers in a hurry commit all these crimes and come back to clean it up later, but a bad programmer is just sloppy. Sometimes it helps to use an IDE that can fix indentation and whitespace with a shortcut key, but there are programmers who can even bludgeon Visual Studio’s insistence on proper indentation by messing around with the code too much.

5.Reinventing the wheel all the time

Don’t write code you don’t need to. Perhaps someone else has spent a good deal of time on your problem already, and he or she might have a well-tested solution that you can reuse. Save yourself some trouble.

Conclusion.

As the old saying goes, “If it walks like a duck and quacks like a duck, it’s probably a duck.” The same is true for bad code. If it looks like bad code and smells like bad code, it’s probably bad code. The infallible developer does not exist. The almighty developers that came before may have made a mistake, and you will too. It is how coding works.
So, this is it for this article. We will surely talk about good coding habits and practices in upcoming articles.
Thank You.