Sunday, February 23, 2020

GIT

Reference Link
https://www.vogella.com/tutorials/Git/article.html

GIT is Distributed Version Control where as CVS is Central Code Repository
GIT will understand text files.
GIT will not be useful for non text files like
    a. images,movies,music,fonts
    b. word processing,spreadsheet,pdf


We need to install Git from https://git-scm.com/ in our system and install it

to look for the version of git
git version

To update the git use the below command
git update-git-for-windows

As git update is deprecated

To list command of git use the below command
git help

get help -g  --> to view the guides
get help -a  --> to get list of sub commands

to clone a GitHub repository use the below command

git clone <<url>>



To know the git configuration

git config --global --list

To initialize git in a directory use below
git init



http://git-scm.com --> To download Git
https://help.GitHub.com/articles/set-up-git


to verify Git version then use
git --version


System Level Configuration

c:\Program Files\Git\etc\gitconfig
c:\program data\Git\config

/etc/gitconfig (Unix)

To set the configuration at System level use the below
git config --System

User Level

c:\Users\<<username>>\.gitconfig

~/.gitconfig (Unix)

To set the configuration at User level use the below
git config --global

Project Level

<<project>>\.git\config

To set configuration at project level
git config

to view the configurations which was set the use the below command

git config --list


To remove a config property then use the below
git config --global --unset-all core.editor

To remove the section from config then use the below
git config --global --remove-section user

For just one repo:
git config user.name "Your Name Here"
git config user.email your@email.com

For (global) default email (which is configured in your ~/.gitconfig):
git config --global user.name "Your Name Here"
git config --global user.email your@email.com

Help command in Git

git help
git help log
git help init

man git-log or git help log are same 



To initialize the repository then we will use the below command in a directory where you project is present
   git init

Once the above command is given the following hidden directory or folder will be created
 .git

Inside .git you will see following directories /folder  OR files

Folders
   hooks
   info
   objects
   ref
   branches (will be created later)
   logs ( Will be created later)

Files
   description
   config 
   HEAD
   index ( Will be created later)
   COMMIT_EDITMSG ( Will be created later)
 
We actually do the below basic steps in Git
a. Make Changes in the files
b. Add the changes to staging
c. Commit the changes to the repository with a message

Commit message best practices
  a. Short single-line summary (less than 50 characters)
  b. Optionally followed by a blank line and more complete description
  c. Keep each line to less than 72 characters
  d. Write commit message in present tense, not past tense
      -"fix bug" or "fixes bug", not "fixed bug"
  e. Bullet points are usually asterisks or hyphens
  f. can add "Ticket number" from bugs or support requests
  g. can develop shorthand for our organization
       - "[css,js]"
       - "bugfix:"
   

Git refers to commits (SHA-1)
    Git refers to a change as a change set. So for a change set git generates a checksum for each change set.

To generate a checksum using SHA-1 hash algorithm. It is 40-character hexadecimal string

HEAD pointer in git moves to the current branch when we commit a change set.



To add new file(s) or modified file(s)  into the repository then below command can be used
        git add filename.txt
       git add .    --> To add/modify all the files use this command

To commit the changes the below command will be used
      git commit -m "Initial commit"

To add and commit then use the below (new files and deletion of files the below command will not work properly and all modifications will be committed so make sure to use it)
      git commit -ma <<Commit Message>>

To know the status between repository, staging and working directory and about the file changes
      git status

To get the list of logs then use the below command
     git log

To identify the changes between staging and working directory
     git diff 
     git diff  <<filename>>
     git diff --color-words <<filename>>

To identify the changes between staging and Repository
     git diff --staged
    git diff  --staged <<filename>>
   git diff --staged --color-words <<filename>>

 To delete the files we have two approach

Approach 1 :
        a. Delete the file from Operating system and move the  file to trash
        b. git rm <<filename>>
        c. git status
        d. git commit -m "File deleted "

Approach 2:
       a. git rm <<filename>>
       b. git status 
       c. git commit -m "message"

git rm --cached <<filename>> --> Will delete from staging

To rename a file we have two approach

Approach 1 :

Approach 2 :
        a. git mv <<filename>> <<new _filename>>
        b. git status 
        c. git commit -m "message"

To replace a file in working directory from repository then use the following command

             git checkout -- <<filename>> ( -- is making sure we are in current repository rather than
getting the branch name )
             git checkout -- <<directory>>


To undo the changes from staging then use the below command

          git reset HEAD <<filename>>


To ammend the changes to the last commit use the below command. Note ammend can be used for the latest head not to the previous head.




To revert the changes in the repository then use the below command
   git revert <<SHA-1 key>>

To undo multiple commits
    git reset

      --soft 
            Does not change staging index or working directory

      --mixed (default)
            Changes staging index to match repository
            Does not change working directory

      --hard
            Changes Staging index and working directory


      git reset -- soft <<SHA key>>
      git reset -- mixed <<SHA key>>
      git reset -- hard<<SHA key>>

To remove all the untracked files and if the file is added to staging then it will not delete by below command

    git clean -n --> shows which un-tracked files will be deleted 
    git clean -f --> deletes the file which are un-tracked 


To ignore a particular file then we need to create file (.gitignore) in project directory
 
      project/.gitignore --> The file contains all untracked files
      very basic regular expressions
            * ? [aeiou] [0-9]
       negate expression with
            *.php  --> ignore all php files
             !index.php --> don't ignore index.php file
       ignore all files in a directory with trailing slash
             assets/videos/
      comment lines begin with #, blank lines are skipped in the .gitignore

https://help.github.com/articles/ignoring-files/
https://github.com/github/gitignore


To have the ignore at user level then use the below

git config --global core.exludesfile ~/.gitignore_global

Before using the above command create a file .gitignore_global
     
         
tree-ish
    a. full SHA-1 hash
    b. short SHA-1 hash
           at least 4 characters
           unambiguous(8-10 characters)
    c. HEAD pointer
    d. branch reference , tag reference
    e. ancestry
             parent commit
                     HEAD^,
                     HEAD~1
             grandparents commit


  git ls-tree HEAD
  git ls-tree HEAD^



Different  options in log

git log --since="2017-09-25"
git log --before="2017-09-25"
git log  --since =" 2weeks ago" --until="3 weeks ago"
git log  --author="pavan"
git log --grep="<<text>>"
git log --oneline
git log <<sha-1>> ..<<SHA-1>> --oneline
git log <SHA1>... <<filename>>  --> To identify what changes have happened from the mentioned sha key
git log -p <<SHA1>>.. <<filename>> --> shows the difference also
git log --format=online --> this returns the full SHA key
git log --graph
git log --online --graph -all --decorate


To know what changes are done in change set then pass the SHA key

git show <<SHA1-key>>

git show --format=online HEAD~3


To compare two different commits

git diff <<SHA-1Key>>
git diff <<SHA-1Key>>..<<SHA-1Key>>
git diff <<SHA-1Key>>..<<SHA-1Key>> <<filename>>
git diff <<SHA-1Key>>..HEAD <<filename>>
git diff  --stat --summary <<SHA-1Key>>..HEAD
git diff  -w <<SHA-1Key>>..HEAD //To ignore the space changes


Branches

In Git branches are cheap
  - try new ideas
  - isolate features or sections of work
One Working directory
Fast context switching

The below command will get the list of branches 
      git branch
      git branch -a   --> to know the local and remote branch
      git branch -r --> To know the remote branch

To create a branch use the below command 
   git branch <<branch_name>>

To switch to branch use the below
    git checkout <<branch_name>>

To checkout and create branch in single command 
   git checkout -b <<branch_name>>


While switching branches we need to make sure there are no uncommitted changes in the working directory if so then the following three option we have 
a. checkout the previous file from the branch
b. Commit the changes to branch. (Even if you add the changes to staging it will not allow to swtich unless you commit to the branch)
c. stash the changes 

Note: All tracking folder or files need to be clean while switching branches. If we have any new file or folder which or not tracked then it will not allow to switch between branches.


To compare two branches then we can use the below command 

 git diff <<branch_name>>..<<branch_name>>

To know the branch ancestor then use the below command in the branch 

  git branch --merge

To rename the branch
   git branch --move <<branch_name>> <<new_branch_name>>

To delete the branch
  git branch -d <<branch_name>>
  git branch -D <<branch_name>> //When using -D be caution that it will delete even the changes are not merged into the master


To merge a branch A to B then we should be in B and then use the below command 
    git checkout A
    git merge B

git merge --abort


git stash save <<Message for stash to remember>>

git stash list

git stash show stash@{0} (stash@{0} will be replaced with the exact stash number)

git stash apply  <<stash number>>

git stash pop <<stash number>>

git stash drop <<stash number>>

git stash clear 

git remote 


Vendor who build repository on top of GIT are 
a. Github
b. Gitlab
c. Bitbucket
d. Coding

https://medium.com/flow-ci/github-vs-bitbucket-vs-gitlab-vs-coding-7cf2b43888a1

Saturday, February 22, 2020

typescript


To look for tsc command options use the below the url
https://www.typescriptlang.org/docs/handbook/compiler-options.html


To declare a variable in typescript we use the keyword "let"

Data types available in Type script


number
string
boolean (default value is undefined in Typescript)
unionTypes (to hold multiple datatypes but it is restricted to use those only)
any (We can have any datatype for the variable)

Boolean (default value is undefined in Typescript)
Date
String



Eg:

let unionTypes : string | number;
unionTypes = 'pavan';
unionTypes = 10;

let employee : any;
employee = 10;
employee = "kumar";

employee = {id :10, name: "pavan", age:10};

Typescript is case sensitive. To log we can use

console.log("Sample")


Variable declaration

let <<variablename>>: <<datatype> = <<value>>

Eg :
let fname: string = 'pavan'; 

To compile(i.e. Transpilation ) the typescript file to javascript we can use below command
tsc <<typescriptfilename>>

To run the javascript file using node use below command
node <<javascriptfilename>>


Generic Array can be used

let departments : Array<string> = new Array<string>();

departments.push("IT");
departments.push("Marketing");

***********************************************
Both will be same
let employeenames : string[] = [];
employeenames.push("Pavan");
employeenames.push("anusha");

let studentnames : Array<string> = new Array<string>();
studentnames.push("kumar");
studentnames.push("venkata");

using typescript using new Array() is fine but in JavaScript don't use it.

https://www.w3schools.com/js/js_arrays.asp

If you want know about map reduce in JavaScript
https://medium.com/poka-techblog/simplify-your-javascript-use-map-reduce-and-filter-bd02c593cc2d


***********************************************

Loop

 a. foreach
 b. for of
 c. for in : This gives index

departments.forEach(function (dept){
  console.log(dept);
});

for(let dept of departments){
    console.log(dept);
};

for(let dept in departments){
    console.log(dept);
};

Arrow or Lamda Expression

departments.forEach((dept) => {
  console.log(dept);
});

Class 
  Make sure class name is Pascal (i.e Employee, Student,EmployeeInfo)
  variable at class level will not be having let keyword
  constructor overloading is not allowed in typescript

Access modifiers 
  private
  public  - this is the default when not specified
  protected

We have get and set for private variables/members/properties of the class to be accessed but the name of the method needs to be different and those are treated as properties rather than a method.
To verify it we can use typeof as
console.log(typeof emp.getempid )

Note : If you treat getter and setter as methods then we will get below error
"This expression is not callable. Type 'Number' has no call signatures"
"This expression is not callable. Type 'string' has no call signatures"

readonly is used to make sure the value once assigned is not changed

class Employee {
     id : number;
     name: string;
    address:string;
}


class Employee {
    private id : number;
    name: string;
    address:string;
readonly department = 'IT';

    constructor(name:string, address:string) {
        this.name = name;
        this.address = address;
    }

    get getempid(){
        return this.id;
    }

    set setempid(id:number){
        this.id= id;
    }
}

let emp = new Employee('Pavan','Carsoncity');
emp.setempid= 10;

console.log(emp.getempid);


Ignore this error message when you compile the code

error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.


Function creation in Typescript class 

functionname() : <<returntype>>{
}

Eg :
addEmployee(name:String, age:number): void{
    this.name = name ; 
    this.age = age;
}

Interface
Below is the example for interface

Interface and Class in single file
interface IStudent{
addStudent();
}

class Student implements IStudent{
addStudent(){
}
}


Interface and class in different files

Iemployee.interface.ts
export interface IEmployee{
addEmployee();
editEmployee();
}

employeeservice.ts
import { IEmployee } from './Iemployee.interface';

export class EmployeeService implements IEmployee {
addEmployee(){
return 1;
}

getEmployee(){
return "1";
}

editEmployee(){
}
}

Module in Typescript

Similar to package in java we have in typescript

export class <<className>>{
}

import {} from '<<relativepath>>'


Typescript configuration : 

    tsc -init

Above command will generate a file "tsconfig.json" with configuration which will be used during build .

To build the typescript files 

tsc -p .\tsconfig.json

To get the map between the Js and typescript  then make sourceMap as true in tsconfig.json

Type definition in typescript
https://github.com/DefinitelyTyped/DefinitelyTyped

Sunday, February 16, 2020

REST API for data for testing

https://docs.simplyrets.com/api/index.html#/--> property

https://github.com/Aakashdeveloper/public-apis#patent