Friday, March 29, 2019

You Might Not Need The mapDispatchToProps Function



REF:
  1. https://daveceddia.com/redux-mapdispatchtoprops-object-form/ (vvi)
  2. https://medium.com/@learnreact/container-components-c0e67432e005
  3. https://blog.bam.tech/developper-news/4-ways-to-dispatch-actions-with-redux
  4. https://redux.js.org/introduction/three-principles 
  5. https://react-redux.js.org/introduction/quick-start (official documentation)
https://redux.js.org/introduction/three-principles 

Wednesday, March 20, 2019

Create indexing on json field


ALTER TABLE missions ADD COLUMN start_date VARCHAR(256)
GENERATED ALWAYS AS ( JSON_UNQUOTE(JSON_EXTRACT(`mission_data`, '$.start_date'))) VIRTUAL;

ALTER TABLE missions ADD COLUMN end_date VARCHAR(256)
GENERATED ALWAYS AS ( JSON_UNQUOTE(JSON_EXTRACT(`mission_data`, '$.end_date'))) VIRTUAL;

CREATE INDEX idx_tbl_missions_start_date ON missions(start_date);
CREATE INDEX idx_tbl_missions_end_date ON missions(end_date);

insert into missions(customer_id, mission_ref_no, mission_data, order_no) values(
    'abdullahalawal177@gmail.com',
    'Mission Ref1903- 21032019',
    '{"tva": 35.58, "sipsi": {"is_selected": true}, "duration": 2, "end_date": "2019-04-15", "carte_btp": {"is_selected": false}, "ref_number": "Mission Ref1903", "start_date": "2019-03-19", "unit_price": 60, "car_sticker": {"is_selected": false}, "total_price": 213.48, "package_type": "confort", "representation": {"end_date": "2019-04-15", "start_date": "2019-03-19", "is_selected": true, "number_of_month": 2, "type_of_secondment": "Usual", "number_of_employees": 1}, "arrival_country": "FR", "sub_total_price": 177.9, "renew_ref_number": null, "departure_country": "AF", "number_of_workers": 1, "sector_of_activity": "Transport", "type_of_secondment": "Usual", "informative_document": {"languages": [], "is_selected": false}, "is_permission_granted_to_ps": false}',
    '1552972234624'  
)

select * from missions where mission_ref_no = 'Mission Ref1903- 21032019'
select * from missions where start_date = '2019-03-19'


delete from missions where mission_ref_no = 'Mission Ref1903- 21032019'

ALTER TABLE missions DROP COLUMN start_date

ALTER TABLE missions DROP COLUMN end_date


//for notifications

ALTER TABLE notifications ADD COLUMN notification_created_for_status VARCHAR(256)
GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(`attribute`, '$.notification_created_for_status'))) VIRTUAL;


CREATE INDEX idx_notifications_notification_created_for_status ON notifications(notification_created_for_status);

ALTER TABLE notifications
DROP COLUMN notification_created_for_status


Ref:
  1.  https://www.dbrnd.com/2016/10/mysql-5-7-how-to-create-an-index-on-json-data-type-column-generated-virtual-column/
  2. https://www.compose.com/articles/mysql-for-json-generated-columns-and-indexing/

Friday, March 15, 2019

Need to practice

  1. https://codepen.io/anon/pen/aMYmNN?editors=0010
  2. https://reactjs.org/docs/lifting-state-up.html
  3. need to concentrate 10 and 11
  4. celcius and franhite example
  5. https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todos (vvI) (done)
  6. https://dev.to/achowba/building-a-modal-in-react-15hg (modal showing)
    1. <!DOCTYPE html>
      <html lang="en">
      <head>
        <title>Bootstrap Example</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
      </head>
      <body>

      <div class="container">
       

      <div class="modal fade in" id="myModal" role="dialog" style="display: block;">
          <div class="modal-dialog">
         
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">×</button>
                <h4 class="modal-title">Modal Header</h4>
              </div>
              <div class="modal-body">
                <p>Some text in the modal.</p>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              </div>
            </div>
           
          </div>
        </div>
      <div class="modal-backdrop fade in"></div>
      </body>
      </html>

Thursday, March 14, 2019

Javascript ES6 Class example

ES6 Class Basics

JavaScript’s prototypal inheritance model can appear confusing to developers with an understanding of the classical inheritance used in languages such as C++, C#, Java and PHP. JavaScript classes are primarily syntactical sugar, but they offer more familiar object-oriented programming concepts.
A class is a template which defines how objects of that type behave. The following Animal class defines generic animals (classes are normally denoted with an initial capital to distinguish them from objects and other types):
class Animal {

  constructor(name = 'anonymous', legs = 4, noise = 'nothing') {

    this.type = 'animal';
    this.name = name;
    this.legs = legs;
    this.noise = noise;

  }

  speak() {
    console.log(`${this.name} says "${this.noise}"`);
  }

  walk() {
    console.log(`${this.name} walks on ${this.legs} legs`);
  }

}
Class declarations execute in strict mode; there’s no need to add 'use strict'.
A constructor method is run when an object of this type is created, and it typically defines initial properties. speak() and walk() are methods which add further functionality.
An object can now be created from this class with the new keyword:
const rex = new Animal('Rex', 4, 'woof');
rex.speak();          // Rex says "woof"
rex.noise = 'growl';
rex.speak();          // Rex says "growl"

Getters and Setters

Setters are special methods used to define values only. Similarly, Getters are special methods used to return a value only. For example:
class Animal {

  constructor(name = 'anonymous', legs = 4, noise = 'nothing') {

    this.type = 'animal';
    this.name = name;
    this.legs = legs;
    this.noise = noise;

  }

  speak() {
    console.log(`${this.name} says "${this.noise}"`);
  }

  walk() {
    console.log(`${this.name} walks on ${this.legs} legs`);
  }

  // setter
  set eats(food) {
    this.food = food;
  }

  // getter
  get dinner() {
    return `${this.name} eats ${this.food || 'nothing'} for dinner.`;
  }

}


const rex = new Animal('Rex', 4, 'woof');
rex.eats = 'anything';
console.log( rex.dinner );  // Rex eats anything for dinner.

Child or Sub-Classes

It’s often practical to use one class as the base for another. If we’re mostly creating dog objects, Animal is too generic, and we must specify the same 4-leg and “woof” noise defaults every time.
A Dog class can inherit all the properties and methods from the Animal class using extends. Dog-specific properties and methods can be added or removed as necessary:
class Dog extends Animal {

  constructor(name) {

    // call the Animal constructor
    super(name, 4, 'woof');
    this.type = 'dog';

  }

  // override Animal.speak
  speak(to) {

    super.speak();
    if (to) console.log(`to ${to}`);

  }

}
super refers to the parent class and is usually called in the constructor. In this example, the Dog speak() method overrides the one defined in Animal.
Object instances of Dog can now be created:
const rex = new Dog('Rex');
rex.speak('everyone');      // Rex says "woof" to everyone

rex.eats = 'anything';
console.log( rex.dinner );  // Rex eats anything for dinner.

Static Methods and Properties

Defining a method with the static keyword allows it to be called on a class without creating an object instance. JavaScript doesn’t support static properties in the same way as other languages, but it is possible to add properties to the class definition (a class is a JavaScript object in itself!).
The Dog class can be adapted to retain a count of how many dog objects have been created:










REF:
https://www.sitepoint.com/javascript-private-class-fields/
  1. First install nodejs
  2. npm i -g create-react-app
  3. create-react-app my_project_name
  4. cd my_project_name
    
    

Wednesday, March 13, 2019

Laravel Project Version Downgrade

If your server doesn't have php 7.1 and above and you are only restricted to use php7.0 do as below:
  1. Delete vendor folder
  2. Delete composer.lock file
  3. Add this to composer.json file under config
    "platform": {
       "php": "7.0.0"
    }
As well, ensure PHP version under require is set to 7.0.0 as shown below in config.platform.php:
    "config": {
        "platform": {
            "php": "7.0.0"
        }
     }
  1. Run composer install using CMD
  2. composer install --ignore-platform-reqs 

    if you get the error: 
    This package requires php >=5.5.9 but your PHP version (5.5.6)
       does not satisfy that requirement.
     

This now will make sure that only dependencies compatible with php7.0 are installed

Monday, March 11, 2019

20190312_Image








Chess tactics

  1. Move defensively as much as possible. Don’t move pieces and pawns to squares where they can’t be defended immediately. Don’t expose your strong pieces to attack by weaker enemy pieces.
  2.  Do not make pawn moves without careful planning
  3. Complete your development before moving a piece twice or starting an attack
  4. Open with either the e-pawn or the d-pawn.
  5. Wherever possible, make a good developing move which threatens something or adds to the pressure on the centre.
  6. Develop knights before bishops.
  7.  During the first few moves, pay special attention to the vulnerable KB2 square on both sides
  8.  
  9.  
  10.  
  11.  
  12.  
  1. More detail on winning the race:
    • move pieces not pawns, and
    • move them to their best squares in one move if you can, and also
    • try to gain time if you can by aggressive moves. 



REF:
  • https://exeterchessclub.org.uk/content/ten-rules-opening

Thursday, March 7, 2019

Laravel command

php artisan make:model Notification -mcr
php artisan make:model Notification -m
php artisan migrate
php artisan migrate:rollback --step=1
php artisan migrate:rollback 
php artisan migrate:refresh--step=1 
php artisan make:middleware Admin
composer create-project laravel/laravel="5.5" myProject 
php artisan migrate:refresh --seed 
 

Wednesday, March 6, 2019

Git and linux common command


Git commnad

  1. git init: (Initialize the local directory as a Git repository.)
  2. git add: (Add the files in your new local repository. and staging)
  3. git reset HEAD file_name: (for unstage)
  4. git commit -m "First commit" (commit the code)
  5. git remote add origin remote_repository_url (Sets the new remote)
  6. git pull origin development : (pull from remote)
  7. git push origin master (push the code)
  8. git config --list (show the git config )
  9. git config --system --unset credential.helper
    git config --global --unset credential.helper
    git config --global credential.helper manage (chage the git config: u can use any one maybe)
  10. git log --oneline -5
  11. git log --oneline -5 origin/development
  12. git branch
  13. git checkout branch_name  
  14. git cherry-pick sha1
  15. git commit --amend 
  16. git reset HEAD~ ( git reset last commit)
  17. git marge <branch_name> you have to location destination branch(like master)
    1. let now you are in master branch and want to marge branch1
      1. so command lik git marge branch1
  18. git cherry-pick <sha1> cherry pick is used to replace in the top of current branch.
  19. git checkout <prev_sha1> <filename>  file change to sha1 commited file
  20. git push origin -u <branch_name> it will create a branch in remote. -u = upstream
  21. git stash    "current changes keep in the drap mode"
  22. git stash pop
  23. git stash list
  24. git checkout . "that means current change will be removed"
  25. git reset c602b9fc --hard   " it will remove all the commit after c602b9fc and head will be c602b9fc"
  26. merge is used to merge two branches. follow the two steps
    1. git checkout master 
    2. git marge <features1> merge is used to merge two branches
     



git reset c602b9fc --hard
git push origin master --force



     


https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line

Linux common command:

  1. sudo tail -n 20 /var/log/nginx/error.log  (to see the log of nginx server)
  2. chmod -R <permissionsettings> <dirname> (change the folder permision and its subfolder and files)
    1. chmod 755 -R  <folder-name>
  3. pwd (to check the current directory) 
  4.  cat <filename> : is used to check file text
  5. file edit way:********* ()
    1.  vi filename
    2.  (Enter) i
    3.  change the text
    4.  Esc
    5.  :wq
    6.  enter
  6. exit file without saving
    1. :q (enter)
  7. Access EC2 using ssh
    1. chmod 400 SPWStaging-ASDAccount.pem (first time)
    2. ssh -i "SPWStaging-ASDAccount.pem" ec2-user@ec2-18-212-2-219.compute-1.amazonaws.com
    3. sudo su (ec2-user is used as a super user)
  8. wget <url> to download the from internet
  9. unzip to extrac the file in linux
  10. sudo useradd <user_name>  adding user in linux
  11. sudo passwd <user_name>  set the password
  12. sudo userdel <user_name> deleting the user
  13. sudo groupadd <groupd_name> add the group in linux command
  14. sudo touch <file_name>  create the file
  15. sudo vi <file_name> to open the file in file text check 5 point
  16. sudo cp <file_name> <folder_name> copy the file to specific folder
  17. sudo mv <file_name> <folder_name> to move the file
  18. sudo rm <file_name> to remove the file
  19. sudo mkdir <directory_name> to create a directory in linux
  20. sudo rmdir <directory_name> to remove the directory in Linux
  21. sudo grep -i <string_name> <file_name> just like as ctrl+f features in command line. Flag: -n, -v,-c, -i
  22. sudo sort <file_name> sort the file string
  23. ls -l  to show the file list with permission
  24. chown <user_name> <file_name> to change ownership of file like "Tushar(user) to root user"
  25. chmod <permission_number (777)> <file_name>  (pronounce: ch-mod/ch-own)
    1. 777 means 
    2. first 7 = user permission
    3. second 7 = group permission
    4. third 7 = other user of that group user
  26. id - show the user id
  27. tar -cvf <file_name> <source_folder_name>  to zip as the file
  28. tar -xvf <file_name> unzip tar the file
  29. cut -c1-2 <file_name> to cut the string from the file. here c means column  from 1 to 2
  30. sed 's/<replaced_string>/<replace_by_string>' <file_name>
    1. to replace the string in file
  31. history <last_history_showing_number>  show the list of history
    1. history 5 
  32. free -k/-m is used to check memory space in the system
  33. ssh-keygen -t rsa  to create public private key to get access. from the next time just type enter
    1. to generat  the key

  34. ifconfig / ip a  to check the ip address
  35. env for the environment variale
  36. sudo app-get install pinta   to install the software in ubuntu
  37. scp -i ec2-access.pem /home/cefalo/Tushar/a2n/boilerplate/sveltekit/node_modules.zip ubuntu@ec2-63-33-70-8.eu-west-1.compute.amazonaws.com:/opt/boilerplate/boilerplate-sveltekit    // upload local zip to aws ec2

Ref:
  1. https://hackr.io/blog/basic-linux-commands
  2. https://www.computerhope.com/unix/uchown.htm
  3. https://www.edureka.co/blog/linux-commands/
  4. https://www.guru99.com/must-know-linux-commands.html
  5. https://www.howtogeek.com/412055/37-important-linux-commands-you-should-know/







ggggggggggggggggggg






Autoboxing and Unboxing

  Autoboxing  is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper cl...