Wednesday, July 25, 2018

Install & configure docker on a fresh Linux OS

I am going to describe how to install docker & explain those necessary command.

Step 1: First of all we need to update our os with the latest packages.
Run:
 sudo apt-get update  
Key points:
sudo − The sudo command is used to ensure that the command runs with root access.
apt-get - update the OS with the latest packages from the Internet on to the Linux system.
update − The update option is used ensure that all packages are updated on the Linux system.


Step 2: Now time to add some certificates & transfer protocols, it will be required to work with the Docker site later on to download the necessary Docker packages.
Run:
 sudo apt-get install apt-transport-https ca-certificates  
Key points:
apt-transport-https - https download transport for APT. This package enables the usage of 'deb https://foo distro main' lines. in the /etc/apt/sources.list so that all package managers using the. libapt-pkg library can access metadata and packages available in sources. accessible over https (Hypertext Transfer Protocol Secure).
ca-certificates - It is a digital certificate that is used to verify the identity of 3rd parties, and encrypt data between you and said 3rd party.

Step 3: This step is to add the Docker’s official GPG GPG key. This key is required to ensure that all data is encrypted when downloading the necessary packages for Docker.
Run:
 sudo apt-key adv \ --keyserver hkp://ha.pool.sks-keyservers.net:80 \ --recv-keys 58118E89F3A912897C070ADBF76221572C52609D   
Key points:
The following command will download the key with the ID 58118E89F3A912897C070ADBF76221572C52609D from the keyserver hkp://ha.pool.sks-keyservers.net:80 and adds it to the adv keychain. Please note that this particular key is required to download the necessary Docker packages.
Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
Run:
 sudo apt-key fingerprint 0EBFCD88  
Returns as:
 pub  4096R/0EBFCD88 2017-02-22  
    Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88  
 uid         Docker Release (CE deb) <docker@docker.com>  
 sub  4096R/F273FCD8 2017-02-22  

Step 4: Next, depending on the version of ubuntu you using, you need to add the relevant repository to the docker.list for the apt package manager so that it will be able to detect the docker packages from the docker site & download them accordingly.
Run:
 sudo add-apt-repository \  
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \  
   $(lsb_release -cs) \  
   stable"  
Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well. To add the edge or test repository, add the word edge or test (or both) after the word stable in the commands below.
Note: The lsb_release -cs sub-command below returns the name of your Ubuntu distribution, such as xenial. Sometimes, in a distribution like Linux Mint, you might need to change $(lsb_release -cs) to your parent Ubuntu distribution. For example, if you are using Linux Mint Rafaela, you could use trusty.

Step 5: Update the apt package index.
Update packages:
 sudo apt-get update  

Step 6: Install the latest version of Docker CE
Run:
 sudo apt-get install docker-ce  
Alternative:
(If you want to install a certain version of docker ce then list that available versions in the repo, then select and install:
Listing version madison version of docker ce:
Run:
 apt-cache madison docker-ce  

To run each command of docker without 'sudo' docker will throw an error like:
 Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/containers/json: dial unix /var/run/docker.sock: connect: permission denied  

Solution:
The error message tells you that your current user can’t access the docker engine, because you’re lacking permissions to access the unix socket to communicate with the engine.
As a temporary solution, you can use sudo to run the failed command as root.
However it is recommended to fix the issue by adding the current user to the docker group:
Run this command in your favourite shell and then completely log out of your account and log back in (if in doubt, reboot!):
Run:
 sudo usermod -a -G docker $USER  

Reboot your pc to ensure commands are running with right permission.

Testing Step:
To test docker is running perfectly or not, Run:
 docker --version  
More testing, Run a container:
 sudo docker run hello-world  

It will for look in local if that repo is available in local or not, if not it will download it from docker hub & you are all set to go with docker! :D



Sources:

Monday, July 23, 2018

Upgrade Ubuntu OS version 14.0 / 16.04 / 18.04

We can upgrade our ubuntu os very easily with a few steps, I will mention here three step today:
  1. Using command line.
  2. Using a bootable device pendrive/harddisk/cd
  3. Using ubuntu interface



1. Using command line:
1. To upgrade to Ubuntu 18.04, first run the following command to upgrade existing software.sudo apt update && sudo apt dist-upgrade2. Then make sure you have update-manager-core package installed.sudo apt install update-manager-core3. After that, run the following command to begin the upgrade process.do-release-upgrade4. Then follow the on-screen instruction to upgrade to Ubuntu 18.04. Once the upgrade is finished, reboot your Ubuntu desktop or server. To check your Ubuntu version, run:

lsb_release -a

Output:
No LSB modules are available.


Distributor ID: Ubuntu
Description: Ubuntu 18.04 LTS
Release: 18.04
Codename: bionic

You also need to re-enable third-party repositories such as PPA because they are disabled during upgrade.


2. Using a bootable device pendrive/harddisk/cd
We will follow some steps to upgrade ubuntu os via bootable device
1. Restart your pc & keep press F12 button continiously it will open up the BIOS of you device
2. Enable boot from usb port
3. Make your pendrive/hd bootable
4. Download a version of ubuntu from the ubuntu website & put that directly in your bootabe device
5. Put the bootable device in any of your usb port & restart your pc, keep pressing F12 &  select the 6. device you want to boot from then hit enter button
6. Then follow the on-screen instruction to upgrade


3. Using ubuntu interface
1. We can update ubuntu version as easily as an android app update by os interface.

2. search for Software & Updates… then select it to open, Set 'Notify me of a new Ubuntu version' as 'For any new version'

3. Before upgrading Ubuntu you should always make sure the desktop is updated with the latest packages… This is the standard process. To update Ubuntu packages, open Dash again and search for Software Updater, then select to open it, when open it click on the 'Install Now' button.


4. Now click on ALT+F2 at once, it allows to run a ubuntu command. Run there as 'update-manager -cd' After that, it should open the upgrade wizard to upgrade Ubuntu, Click the Upgrade button to begin the wizard… follow the on-screen instructions and continue

Sunday, May 7, 2017

React component lifecycle

ReactJs Life Cycle

Component lifecycle বলতে বোঝায়, একটি React component এ যে সমস্ত ডিফল্ট ফাংশান থাকে তার ঠিক কোনটার পর কোনটা এক্সিকিউট হয়। উদাহরণ হিসাবে বলা যায় কোন class যখন এক্সিকিউট হয় তখন _construct ফাংশানটি সবার আগে এক্সিকিউট হয় এবং _destruct ফাংশান ওই class এর অন্যসব ফাংশান এক্সিকিউট হওয়ার শেষে এক্সিকিউট হয়।
ঠিক তেমনিভাবে যখন কোন
React component এক্সিকিউট হয় তখন অন্য সব ফাংশান এক্সিকিউট হওয়ার আগে
componentWillMount() এক্সিকিউট হয়।

Component render হওয়ার সময় যে order অনুযায়ী component এর ফাংশানগুলো এক্সিকিউট হয় সেই Order অনুযায়ী অন্য ফাংশানগুলো বর্ননা করবো।
Ø  ১)componentWillMount এক্সিকিউট হয় render() ফাংশান এক্সিকিউট হওয়ার আগে, ঠিক যখন component টি তার parent component এর সাথে mount হয় তার আগে।
Ø  ২)componentDidMount এক্সিকিউট হয় component টি তার parent component এর সাথে mount হয়ে যাওয়ার পর। এখানেই সাধারণত state আপডেট করতে হয় component টি usable করার জন্যে। এছাড়াও ajax request এর মাধ্যমে ডাটা কালেকশান এখানেই করতে হয় Component এ ইউজ করার জন্য। তাহলে মোটকথা component টি ইউজ করার উপযোগী করতে যা কিছু করা দরকার এই ফাংশানেই করা হয়।
Ø  ৩)componentWillReceiveProps এক্সিকিউট হয় কোন child component এ তার parent component যখন props গুলো push করে তার ঠিক আগেই। এবং সেটা child component টি ২য় বার render হওয়ার আগেই।
Ø  ৪)shouldComponentUpdate ফাংশানটি রিটার্ন করে True অথবা False, বাই ডিফল্ট এটি সব সময় ট্রু রিটার্ন করে। যখনই কোন component আপডেট করার প্রয়োজন হয় সেটা State অথবা Props চেঞ্জ করার কারণে হোক তখনই shouldComponentUpdate ফাংশানটি এক্সিকিউট হয়। কোন কারণে প্রোগ্রামার যদি মনে করে তার এই কমপোনেন্টটি আপডেট করার কোন প্রয়োজন নেই তাহলে সে shouldComponentUpdate ফাংশানটির মধ্যে থেকে False রিটার্ন করে রাখতে পারে।
Ø  ৫) componentWillUpdate Render ফাংশানটি কল হওয়ার ঠিক আগেই এবং shouldComponentUpdate ফাংশানটি এক্সিকিউট হওয়ার পরেই componentWillUpdate ফাংশানটি এক্সিকিউট হয়।
Ø  ৬)render() রেন্ডার ফাংশান এক্সিকিউট হয়ে childComponet টি ঠিক যে কারণে ইউজ করা করা হচ্ছে সেই কাজটিই করে থাকে। এটি তার parent component কে HTML রিটার্ন করে।
Ø  ৭) componentDidUpdate এক্সিকিউট হয় render ফাংশান কল হওয়ার পরেই।
Ø  ৮) componentWillUnmount কোন কম্পোনেন্ট এর কাজ যখন শেষ হয়ে যায় তখন সেটি তার parent component থেকে unmount হয়ে যায়। এবং এটিই কোন একটা ফাংশানে ইউজ করা function গুলোর সবার শেষে এক্সিকিউট হয়।

আরো ক্লিয়ার আইডিয়ার জন্যে আমরা কয়েকটি ভাগে ভাগ করতে পারি যেমন যখন কোন component Initially Call হয় তখন কোন-কোন লাইফসাইকেল মেথড কল হয় এবং তাদের কোনটির পর কোনটি কল হয়।
যখন কোন component এর কোন state change হয় তখন কোন-কোন লাইফসাইকেল মেথড কল হয় এবং তাদের কোনটির পর কোনটি কল হয়।
যখন কোন component এর কোন props change হয় তখন কোন-কোন লাইফসাইকেল মেথড কল হয় এবং তাদের কোনটির পর কোনটি কল হয়।

Initially Call

উপরের ইমেজটিতে যেমন দেখতে পাচ্ছেন যখন ই কোন component কে কল করা হয় ফাংশানগুলি একটির পর একটি কল হতে থাকে।
GetDefaultProps এই ফাংশানটিতে component টি তে used props গুলোর টাইপ বলে দেওয়া থাকে যেমন কোন props string হবে না কি integer হবে।
ঠিক একই ভাবে GetInitialState এ component এ used states গুলোর জন্যর initial state নির্ধারন করে দেওয়া হয়। বলে রাখা ভালো এখানে কোন Initial state সেট করলে তাতে component re-render হয় না।
ComponentWillMount, Render এবং ComponentDidMount ফাংশানগুলির ব্যাপারে আগেই বর্ননা করেছি।









When state changes

ছবিতে যেমনটি দেখতে পাচ্ছেন, যখন কোন component এর কোন state change করা হয় তখন ফাংশানগুলি একটির পরে অন্যটি ক্রমান্বয়ে এক্সিকিউট হয়ে থাকে। ফাংশানগুলি কিভাবে কাজ করে তার বর্ননা উপরে আগেই করেছি।

When Props Changes

ছবিতে যেমনটি দেখতে পাচ্ছেন, যখন কোন component এর কোন state change করা হয় তখন ফাংশানগুলি একটির পরে অন্যটি ক্রমান্বয়ে এক্সিকিউট হয়ে থাকে। ফাংশানগুলি কিভাবে কাজ করে তার বর্ননা উপরে আগেই করেছি।

Demo Code: https://github.com/imtiazUAP/react_scratch/tree/develop-1/learning/reactComponent_lifeCycle


https://facebook.github.io/react/docs/react-component.html

Wednesday, April 5, 2017

Dynamic dropdown list in reactJs

type="vertical"
control="select"
id="number-of-devices"
label="Number of devices"
required={true}
value={this.state.devices}
onChange={e => this.setState({devices: e.target.value})}
options={this.getDevices()}
/>

getDevices() {
let i = 0;
let devices = [];
while (i <= this.props.pay.number_of_devices) {
   devices.push({label: i, value: i})
   i++;
}
return devices;
}

Sunday, January 8, 2017

Starting with Webpack

INSTALLING WEBPACK

You need to have node.js installed.
$ npm install webpack -g
This makes the webpack command available.

SETUP THE COMPILATION

Start with a empty directory.
Create these files:

add entry.js

document.write("It works.");

add index.html

<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <script type="text/javascript" src="bundle.js" charset="utf-8"></script>
    </body>
</html>
Then run the following:
$ webpack ./entry.js bundle.js
It will compile your file and create a bundle file.
If successful it displays something like this:
Version: webpack 1.14.0
Time: 12ms
    Asset     Size  Chunks             Chunk Names
bundle.js  1.42 kB       0  [emitted]  main
chunk    {0} bundle.js (main) 28 bytes [rendered]
    [0] ./tutorials/getting-started/setup-compilation/entry.js 28 bytes {0} [built]
Open index.html in your browser. It should display It works.

SECOND FILE
Next, we will move some code into an extra file.

add content.js

module.exports = "It works from content.js.";

update entry.js

- document.write("It works.");
+ document.write(require("./content.js"));
And recompile with:
$ webpack ./entry.js bundle.js
Update your browser window and you should see the text It works from content.js..
webpack will analyze your entry file for dependencies to other files. These files (called modules) are included in your bundle.js too. webpack will give each module a unique id and save all modules accessible by id in the bundle.js file. Only the entry module is executed on startup. A small runtime provides the require function and executes the dependencies when required.

THE FIRST LOADER

We want to add a CSS file to our application.
webpack can only handle JavaScript natively, so we need the css-loader to process CSS files. We also need the style-loader to apply the styles in the CSS file.
Run npm install css-loader style-loader to install the loaders. (They need to be installed locally, without -g) This will create a node_modules folder for you, in which the loaders will live.
Let’s use them:

add style.css

body {
    background: yellow;
}

update entry.js

+ require("!style!css!./style.css");
document.write(require("./content.js"));
Recompile and update your browser to see your application with yellow background.
By prefixing loaders to a module request, the module went through a loader pipeline. These loaders transform the file content in specific ways. After these transformations are applied, the result is a JavaScript module.

BINDING LOADERS

We don’t want to write such long requires require("!style!css!./style.css");.
We can bind file extensions to loaders so we just need to write: require("./style.css")

update entry.js

- require("!style!css!./style.css");
+ require("./style.css");
document.write(require("./content.js"));
Run the compilation with:
webpack ./entry.js bundle.js --module-bind 'css=style!css'
Some environments may require double quotes: –module-bind “css=style!css”
You should see the same result:
A CONFIG FILE
We want to move the config options into a config file:

add webpack.config.js

module.exports = {
    entry: "./entry.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.css$/, loader: "style!css" }
        ]
    }
};
Now we can just run:
webpack
to compile:
Version: webpack 1.14.0
Time: 163ms
    Asset     Size  Chunks             Chunk Names
bundle.js  10.7 kB       0  [emitted]  main
chunk    {0} bundle.js (main) 8.85 kB [rendered]
    [0] ./tutorials/getting-started/config-file/entry.js 64 bytes {0} [built]
    [1] ./tutorials/getting-started/config-file/style.css 943 bytes {0} [built]
    [2] ../~/css-loader!./tutorials/getting-started/config-file/style.css 197 bytes {0} [built]
    [3] ../~/css-loader/lib/css-base.js 1.51 kB {0} [built]
    [4] ../~/style-loader/addStyles.js 6.09 kB {0} [built]
    [5] ./tutorials/getting-started/config-file/content.js 45 bytes {0} [built]
The webpack command-line will try to load the file webpack.config.js in the current directory.

A PRETTIER OUTPUT

If the project grows the compilation may take a bit longer. So we want to display some kind of progress bar. And we want colors…
We can achieve this with
webpack --progress --colors

WATCH MODE

We don’t want to manually recompile after every change…
webpack --progress --colors --watch
Webpack can cache unchanged modules and output files between compilations.
When using watch mode, webpack installs file watchers to all files, which were used in the compilation process. If any change is detected, it’ll run the compilation again. When caching is enabled, webpack keeps each module in memory and will reuse it if it isn’t changed.

DEVELOPMENT SERVER

The development server is even better.
npm install webpack-dev-server -g
webpack-dev-server --progress --colors
This binds a small express server on localhost:8080 which serves your static assets as well as the bundle (compiled automatically). It automatically updates the browser page when a bundle is recompiled (SockJS). Open http://localhost:8080/webpack-dev-server/bundle in your browser.

The dev server uses webpack’s watch mode. It also prevents webpack from emitting the resulting files to disk. Instead it keeps and serves the resulting files from memory.

Main article is here: http://webpack.github.io/docs/tutorials/getting-started/