Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications.

free-ebook-for-react-js-beginners


This react.js ebook include the following things. I haven't cover the topic in detail and you can go through the below topic and easily understand the react.


  1. Overview.
  2. Why we used react.js
  3. Why react.js is a great choice to start.
  4. Why react is great performer.
  5. Features of react.
    1. Components
    2. Virtual DOM
    3. Declarative
    4. Unidirectional data flow
    5. Isomorphic friendly
    6. JSX
  6. How to create component and jsx into react.
  7. React props and states why we used that.
  8. what are the testing frameworks we need in react ex. chai,mocha,jest,enzyme
  9. A few testing examples of react.js testing component.
  10. Usefull links for testing and learning.



Apache SSL Config

In this article i'll show you how to configure your website with ssl. It is also captured the user who go directly mydomain.com without www. Please note that this requires two sets of ssl certificates, unless you have wildcard ones.

In ubuntu 16.04 the file location is /etc/apache2/sites-available/default-ssl.conf  and enabled by running a2ensite default-ssl.conf . Also, don't forget to enable ssl with sudo a2enmod ssl.

# www.mydomain.com
<VirtualHost *:443>
    ServerName www.mydomain.com

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/www.mydomain.com/cert.pem
    SSLCertificateKeyFile /etc/apache2/ssl/www.mydomain.com/private.pem
    SSLCertificateChainFile /etc/apache2/ssl/www.mydomain.com/chain.pem

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/my-site/public_html
    <Directory /var/www/my-site/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

# capture users going to mydomain.com without the www.
<VirtualHost *:443>
    ServerName mydomain.com

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/mydomain.com/cert.pem
    SSLCertificateKeyFile /etc/apache2/ssl/mydomain.com/private.pem
    SSLCertificateChainFile /etc/apache2/ssl/mydomain.com/chain.pem

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/my-site/public_html
    <Directory /var/www/my-site/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Reverse Proxy serve different folder NGINX

In this post i'll show you how we can configure NGINX to serve applications form the different directories. I have two application both are running at different ports, 8080 and 8090. I want to expose those APIs just like they are serving from a single source.

I want to expose those APIs just like they are serving from a single source. nginx config file /etc/nginx/site-available

server {
 
    listen              443 ssl;
    server_name         app.yourapp.com;
    ssl_certificate     /etc/nginx/ssl/app.yourapp.com.crt;
    ssl_certificate_key /etc/nginx/ssl/app.yourapp.com.key;
 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
 
    location /v1/ {
            proxy_pass http://localhost:8090;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }
 
    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
 }
}

If you add multiple application at same host. we have configured NGINX reverse Proxy for two apps using location block, v1 is listening at 8090 and / is listening at 8080.

You can access the app : https:://app. yourapp.com and https:://app.yourapp.com/v1

If you are new to nginx server so you can check this link to use nginx.

Install Typescript in ubuntu

For now I just know of the one main way to install Typescript, but as and when I find out more ways, such as a PPA, I'll post them here.

sudo apt update && sudo apt install node-typescript -y

Finally Clause in PHP

PHP has supported the finally clause.Finally will executed after a try block no matter what is your condition. if the try block threw an exception or not.

<?php

try 
{
    print "Start executing try block BEFORE exception." . PHP_EOL;
    throw new Exception("This is my exception");
    print "Executing try block AFTER exception thrown." . PHP_EOL;
} 
catch (Exception $e) 
{
    print "Executing the catch block." . PHP_EOL;
} 
finally 
{
    print "Executing 'finally' block." . PHP_EOL;
}

print "Executing code after finally." . PHP_EOL;

Start executing try block BEFORE exception.
Executing the catch block.
Executing 'finally' block.
Executing code after finally.

so finally is executed even if exception occurred. we can understand this with the below two examples.

try {
    throw_exception();
} catch (ExceptionTypeA $e) {
    echo $e->getMessage();
}

example(); // Will not execute if throw_exception throws an ExceptionTypeB

But this will execute.

try {
    throw_exception();
} catch (ExceptionTypeA $e) {
    echo $e->getMessage();
} finally {
    some_code(); // Will be execute even if throw_exception throws an ExceptionTypeB
}

As you can see the finally block is still executed, even though something went wrong within our exception handling.

Calling abstract classes in TypeScript

Abstraction is an Object Oriented programming concept whereby a class can specify how an inherited class should implement the class itself, including any abstract methods specified.The concept of abstraction is we are hiding the complexity of the implementation from inherited classes and we allow them to implement the functionality themselves . 

Abstraction can be achieved by using the abstract keyword - which can be applied to both classes and methods specified in classes.

Let's take an example of abstract class :

abstract class Warrior {
  readonly name: string;
  public weapon: string;
  constructor(name: string) {
    this.name = name;
  }

  abstract arm(weapon: string): void;
}


If we now attempt to instantiate this class we'll get an error:

const peter = new Warrior('Peter, the Nomad'); // Cannot create an instance of the abstract class 'Warrior'.

Now we need to implement the abstract class then we need to create a subclass and extend it using the extends keyword.

class SuperWarrior extends Warrior {
  constructor(name: string) {
    super(name);
  }
  arm(weapon: string): void {
    console.log(`${this.name} is a super warrior fighting with ${weapon}`);
  }
}


Now we have a subclass we can create our warriors.

const warrior = new SuperWarrior('John, the Nomad');
warrior.arm('lance'); // John, the Nomad is a super warrior fighting with lance



we can also utilise Interfaces and implement them for classes

interface IWarrior {
  name: string;
  weapon: string;
  arm(weapon: string): void;
}
abstract class Warrior implements IWarrior {
  readonly name: string;
  public weapon: string;
  constructor(name: string) {
    this.name = name;
  }

  abstract arm(weapon: string): void;
}

class SuperWarrior extends Warrior {
  constructor(name: string) {
    super(name);
  }
  arm(weapon): void {
    console.log(`${this.name} is a super warrior fighting with ${weapon}`);
  }
}

const warrior: IWarrior = new SuperWarrior('John, the Nomad');
warrior.arm('lance');

Install Machine Learning Tool in Python

In this article i will show you how to install tensorflow in python3. It's quite easy in ubuntu to set the tensorflow which is an open-source machine learning software.

Run the following commands/script to get tensorflow (CPU only) installed on your Ubuntu 16.04 server.

# Install necessary python packages.
sudo apt-get install python3-pip python3-dev -y

# Upgrade pip using this
pip3 install --upgrade pip

# Install tensorflow (cpu only)
pip3 install tensorflow

If you want to use an NVIDIA GPU for tensorflow then run this instead:

# Install necessary python packages.
sudo apt-get install python3-pip python3-dev -y

# Upgrade pip
pip3 install --upgrade pip

# Install tensorflow with GPU support
pip3 install tensorflow-gpu

That seemed a little too easy, so let's just write a small test script that uses the tensorflow library that we have installed it correctly:

#!/usr/bin/python3
import tensorflow as tf
hello = tf.constant("Hello, Tensflow!")
sess = tf.Session()
print(sess.run(hello))

If you execute this output should be :

b'Hello, Tensflow!'

Now you have successfully installed tensorflow in your system. If you want to read more about the tensorflow then follow the link.


Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications...

Popular