Sunday, 22 December 2019

Streamlining the usage of GITHUB


Streamlining the usage of Github with Commands
1. Start a new git repository under one directory locally
In this step, we need to build a local git repository and decide which files will be added.
A new repo from scratch
¯  Create a directory to contain the project.
¯  Go into the new directory.
¯  Type git init. , use rm -rf .git to reverse this operation
¯  Write some code.
¯  Type git add . to add all the files if you do want to track all of them.
A new repo from an existing project
Say you have got an existing project that you want to start tracking with git.
  • Go into the directory containing the project. If in this repo, there is already a git that belongs to other authors, then use rm -rf .git to remove tis git and start your own.
  • Type git init.
  • Type git add to add all of the relevant files.

   git add -n . #to see what will be added
Note: If we have files that larger than 100M, use gitignore
You’ll probably want to create a .gitignore file right away, to indicate all of the files you don’t want to track. The .gitignore file is not added to a repository by default.
Ø  The problem is that .gitignore ignores just files that weren't tracked before (by git add). Run git reset name_of_file to unstage the file and keep it.
Ø  In case you want to also remove given file from the repository (after pushing). These files are libraries/documentation you don’t want to delete but also don’t want to push to github. Let say you have your project in folder your_project and a doc directory: your_project/doc.
1.      Remove it from the project directory (without actually deleting it): git rm --cached doc/*
2.      If you don’t already have a .gitignore, you can make one right inside of your project folder: project/.gitignore using echo "" > .gitignore or vi command
3.      Put doc/* in the .gitignore
4.      Stage the file to commit: git add .gitignore
5.      Commit: git commit -m "message".
6.      Push your change to github.
      2. Connect it to github and push files
             Now we have shown the github which file we want to track and submit.
             Type git commit -m "message" to initiate the submission.
             Additionally useful commands:

                      git status # to check the current state
You’ve now got a local git repository. You can use git locally, like that, if you want. But if you want the thing to have a home on github, do the following.
  • Go to github.
  • Log in to your account.
  • Click the new repository button in the top-right. You’ll have an option there to initialize the repository with a README file, but I don’t.
  • Click the “Create repository” button.
Now, follow the second set of instructions, “Push an existing repository…”, to use ssh connection, (if you set up ssh in “Your first time”, then you won’t have to type your password every time you push things to github)


$ git remote add origin git@github.com:username/new_repo.git
$ git push -u origin master
To use https connection, you’ll have to type your github password every time you push to github.

$ git remote add origin https://github.com/username/newrepo.git
$ git push -u origin master

To definitely be able to login using https protocol, you should first set your authentication credential to the git Remote URI:

git remote set-url origin

https://yourusername@github.com/user/repo.git
Then you’ll be asked for a password when trying to git push. If this error pop out, error: src refspec master does not match any.
Problem                                               
When pushing a new repository to Bitbucket Server, the following error is returned from the Git client:

git push -u origin mastererror: src refspec master does not match any.
error: failed to push some refs to 'http://stash.company.com/scm/PROJECT/REPO.git'
Cause
This is caused by the repository still being empty. There are no commits in the repository and thus no master branch to push to the server.
Resolution
Create the first commit inside of the repository and then it can be pushed. For example, the following with create an initial commit and push it to the server.

touch initialgit add initialgit commit -m "initial commit"
git push -u origin master
If we remote github is different comprared with local, push with — force

git push origin <your_branch_name> --force
If error fatal: remote origin already exists prompts out, As the error message indicates, there is already a remote configured with the same name. So you can either add the new remote with a different name or update the existing one if you don’t need it:
Check the current configuration:

vi .git/config
Update the existing one:
you can do a $ git remote -v to see what that origin which already exists is, If you think this is there by some error, you can update it like so:

$ git remote set-url origin git@github.com:username/first_app.git
Or another option is to do it in the config files.
To add a new remote:
called for example github instead of origin (which obviously already exists in your system), do the following:

$ git remote add github git@github.com:ppreyer/first_app.git
Remember though, everywhere in the tutorial you see “origin” you should replace it with “github”.
For example 
$ git push origin master should now be 
$ git push github master.
IF we deleted directories and what to update again:

How to delete files permanently from your local and remote git repositories
If you frequently have to set up git version control system for existing projects then you would very likely run into the problem of having to remove files, which should not have been in git, from git after they were added. Running a git rm will only delete the file from the head and the file would still remain in the repository. This may be alright for small files but this could be troublesome for large files as these would unnecessarily bloat the git repository. But don't worry git being a 'swiss army knife' of version control systems there is a solution to delete files permanently from both your local and remote git repositories.
Do note that this is not a newbie solution and you have to do your bit of reading up on these commands and their implications before you actually run this on a production repository. Also note that you have to have RW+ permissions on the repository to do non-fast-forward pushes
CD to your local working folder and run the following command
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all
replace FOLDERNAME with the file or folder you wish to remove from the given git repository.
Once this is done run the following commands to clean up the local repository

rm -rf .git/refs/original/
git ref log expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

Now push all the changes to the remote repository
git push --all --force
This would clean up the remote repository.
Now you will have to recreate the .git folders of all the working copies of the repository. This would include cloned repositories by other developers or the cloned repositories at the live and dev sites. You can do this by cloning the repository afresh into a temporary folder and the move the .git folder from the newly cloned repository to the local repository after deleting the existing .git folder from in there. Do remember to checkout the same branch as is already checked out in the local repository in the temporary repository before you move the .git folder to the local repository.
Remember to make a backup copy of the latest repository and the latest local files before you do any of these things so that you can fall back to a working repository if you run into issues.
3. Others
Switching remote URLs from SSH to HTTPS
Open Git Bash.
Change the current working directory to your local project.
List your existing remotes in order to get the name of the remote you want to change.

git remote -v origin git@github.com:USERNAME/REPOSITORY.git (fetch)
origin git@github.com:USERNAME/REPOSITORY.git (push)
Change your remote’s URL from SSH to HTTPS with the git remote set-url command.

git remote set-url origin

https://github.com/USERNAME/REPOSITORY.git
Verify that the remote URL has changed.
git remote -v # Verify new remote URL origin

https://github.com/USERNAME/REPOSITORY.git (fetch) origin https://github.com/USERNAME/REPOSITORY.git (push)
The next time you git fetchgit pull, or git push to the remote repository, you'll be asked for your GitHub username and password.
If you have two-factor authentication enabled, you must create a personal access token to use instead of your GitHub password.
You can use a credential helper so Git will remember your GitHub username and password every time it talks to GitHub.
Switching remote URLs from HTTPS to SSH
Open Git Bash.
Change the current working directory to your local project.
List your existing remotes in order to get the name of the remote you want to change.
git remote -v origin https://github.com/USERNAME/REPOSITORY.git (fetch) origin https://github.com/USERNAME/REPOSITORY.git (push) 
Change your remote’s URL from HTTPS to SSH with the git remote set-url command.

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
Verify that the remote URL has changed.

git remote -v # Verify new remote URL origin

git@github.com:USERNAME/REPOSITORY.git (fetch) origin

git@github.com:USERNAME/REPOSITORY.git (push)
To Track Forked Repo
We need this if we forked a branch from others’ github, we might have the origin already existed.
origin  https://github.com/CLOUD/Fast-Arena-CAAE.git (fetch)
origin  https://github.com/CLOUD/Fast-Arena-CAAE.git (push)
$ git checkout -b branch_name #give it a new branch name
This command will build a branch and get into this branch. Then we do
$ git add .
$ git commit .
$ git push origin branch_name


Tuesday, 22 October 2019

Python scripting to find the less price of a product in flipkart?

i did this in Visual studio

flipkart.py

import requests
from bs4 import Beautifulsoup
import smtplib
import time

URL='https://www.flipkart.com/samsung-860-evo-500-gb-laptop-desktop-internal-solid-state-drive-mz-76e500bw/p/itmf29fsy7vd2rrs?pid=IHDF29FSXVK2XCNC&lid=LSTIHDF29FSXVK2XCNCZOBQMG&marketplace=FLIPKART&spotlightTagId=BestsellerId_6bo%2Fjdy%2Fdus&srno=s_1_1&otracker=AS_QueryStore_OrganicAutoSuggest_0_14_na_na_pr&otracker1=AS_QueryStore_OrganicAutoSuggest_0_14_na_na_pr&fm=SEARCH&iid=05be7843-7804-4652-9201-19c258483fd9.IHDF29FSXVK2XCNC.SEARCH&ppt=sp&ppn=sp&ssid=i63km5673k0000001574335050122&qH=af4522800d2749f5'

# in flipkart you type any of the product name copy link

headers={"user_Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/.0.04.97 Safari/537.36'}

# type in google my user agent
page=requests.get(url,headers=headers)
soup=Beautifulsoup(page.content,'html.parser')

#print(soup.prettify())

title=soup.find(id="Product Title").get_text()
price=soup.Find(id="price block_our price").get_text()

converted_price=float(price[0:5])
print (converted_price)

if(converted_price<5000):
    send_mail()
    print (converted_price)
    print (title.strip())
if(converted_price>6000):
    send_mail()
def send_mail():
server=smtplib.SMTP('smtp.gmail.com',567)
server.ehlo()  #Elho command tells us email server is sending a email to another
server.starttls
server.ehlo()
server.login('prathyusha@gmail.com','generated password')

#google two step verification (you have to enable)
#google App Passwords
#generate the password

subject='price fell down'

body='check the flipkart link https://www.flipkart.com/samsung-860-evo-500-gb-laptop-desktop-internal-solid-state-drive-mz-76e500bw/p/itmf29fsy7vd2rrs?pid=IHDF29FSXVK2XCNC&lid=LSTIHDF29FSXVK2XCNCZOBQMG&marketplace=FLIPKART&spotlightTagId=BestsellerId_6bo%2Fjdy%2Fdus&srno=s_1_1&otracker=AS_QueryStore_OrganicAutoSuggest_0_14_na_na_pr&otracker1=AS_QueryStore_OrganicAutoSuggest_0_14_na_na_pr&fm=SEARCH&iid=05be7843-7804-4652-9201-19c258483fd9.IHDF29FSXVK2XCNC.SEARCH&ppt=sp&ppn=sp&ssid=i63km5673k0000001574335050122&qH=af4522800d2749f5      #first url you have to paste https://www.amazon.de/-----'

msg=f"subject:{subject}\n\n {body}"
server.send_mail(
         'pratyusha@gmail.com'
'anu@gmail.com'
        msg
)
print ('Hey Email has been sent!')
server.quit()
while(True):
check_price()
time.sleep(60 * 60)

Sunday, 22 September 2019

INSTALL JAVA 8 AND TOMCAT 7 IN A AWS EC2 RHEL INSTANCE?

login as: ec2-user
Authenticating with public key "imported-openssh-key"
Last login: Mon Mar 18 06:11:11 2019 from 183.82.115.14
[ec2-user@ip-172-31-33-91 ~]$ sudo -i
[root@ip-172-31-33-91 ~]# ls





    cd /opt/
    wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz"
    yum install wget -y
    wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz"
    tar xzf jdk-8u201-linux-x64.tar.gz
    cd jdk1.8.0_201/
    alternatives --install /usr/bin/java java /opt/jdk1.8.0_201/bin/java 2
    alternatives --config java
    alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_201/bin/jar 2
    alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_201/bin/javac 2
    alternatives --set jar /opt/jdk1.8.0_201/bin/jar
    alternatives --set javac /opt/jdk1.8.0_201/bin/javac
    export JAVA_HOME=/opt/jdk1.8.0_201
    export JRE_HOME=/opt/jdk1.8.0_201/jre
    export PATH=$PATH:/opt/jdk1.8.0_201/bin:/opt/jdk1.8.0_201/jre/bin
    clear
    cd ..
    java --version


If PATH didnt set properly use this lines

    javexport JAVA_HOME=/opt/jdk1.8.0_201
    export JRE_HOME=/opt/jdk1.8.0_201/jre
    export PATH=$PATH:/opt/jdk1.8.0_201/bin:/opt/jdk1.8.0_201/jre/binexport                     
    JAVA_HOME=/opt/jdk1.8.0_201
    export JRE_HOME=/opt/jdk1.8.0_201/jre
    export PATH=$PATH:/opt/jdk1.8.0_201/bin:/opt/jdk1.8.0_201/jre/bina
    java -version
 
 
 
TOMCAT 7 Installation 
 
    wget http://mirrors.wuchna.com/apachemirrer/tomcat/tomcat-7/v7.0.92/bin/apache-tomcat-                  7.0.92.zip
    yum install wget -y
    wget http://mirrors.wuchna.com/apachemirrer/tomcat/tomcat-7/v7.0.92/bin/apache-tomcat-                  7.0.92.zip
    cd /tmp
    wget http://www-us.apache.org/dist/tomcat/tomcat-7/v7.0.92/bin/apache-tomcat-7.0.92.tar.gz
    cd ..
    cd /opt
    wget http://mirrors.estointernet.in/apache/tomcat/tomcat-7/v7.0.93/bin/apache-tomcat-                         7.0.93.zip
    ls
    unzip apache-tomcat-7.0.93.zip
    yum install unzip
    unzip apache-tomcat-7.0.93.zip
    ls
    cd apache-tomcat-7.0.93
    ls
    cd lib
    ls
    chmod 777 startup.sh
    chmod 777 catalina.sh
    sh startup.sh
    ls
    clear
    ls
    cd /opt/apache-tomcat-7.0.93
    vi conf/tomcat-users.xml

In tomcat-users.xml paste this lines to get


<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <role rolename="admin-gui"/>
  <role rolename="admin-script"/>
  <user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx,           manager-status, admin-gui, admin-script"/>
</tomcat-users>

wq!

chmod 777 conf/tomcat-users.xml
cd bin

sh startup.sh
sh shutdown.sh
sh startup.sh

Saturday, 14 September 2019

PYTHON

Python :-

1. High-level programming languages are close to business problems.
Whereas low-level programming languages are close to system's problems.
Example of high-level programming languages: Python, Java, c#, Rube etc.
Low-level Programming languages: C, Assembly programming languages etc..
A high-level programming language makes the process of translating business requirements to computerized solutions faster than low-level languages.

2. Interpreted
    Python is interpreted programming language. Code which is written in english, has to be translated to binary code and understood by a computer. This is the process of translation.
There are two types of translations
1. Compilation. 
2. Interpretation.
In compilation a compiler translates all the lines of code at the same time then starts the execution. In interpretation an interpreter takes the first line, translates to machine code and executes, then takes the second line and so on.

3. Multi-purpose  :-
Python can be used for developing multiple application types. Web Applications using django, flask Data analysis using pandas, numpy, bokeh Devops Automation using boto Embedded apps using raspberry pi API Deeplearning using google's Tensorflow API

4. Not just a scripting language Python is a general purpose language. One can use python as a scripting language or as a programming language, the puspose for which we use different. In automation field, python programming is called as scripting. And in application development side, it is called programming. In both cases, a single set of python keywords and constructs are used. As a computer language there is no difference between scripting and Programming in python.

5. Extensible :- 
High-level languages are not performant, because they are more focused to provide developer friendly environment than optimizing for speed.     In real-time and time-critical applications, when performance required, we still have to consider languages with low-level features, like C and C++. Python provides futures required to merge other programming languages with python code. Java code can be used in python using 'jython', C# code can be accessed using 'IronPython'.

6. Multi paradigm  :-
Python welcomes programmers from various backgrounds, as python supports procedural, functional and object oriented programming styles.
Software Installation All the code examples in this book, are developed and tested using cutting edge tools, jupyter notebook and PyCharm IDE.


Variables:-
varaibles are place holders for values. Variables are for identification. Variables make things reusable. If we define variables, we do not need to change entire expression, instead change the values assigned to variables.






























Docker commands

1.  When do you use Docker?
     
  • For replicating the environment on your server, while running your code locally on your laptop
  • For Docker CI/CD during numerous development phases (dev/test/QA)
  • For distributing your app’s OS with a team, and as a version control system.
2.  How do you setup a docker locally?

      Download a Docker edition and the Docker Toolbox

  • Make sure your BIOS has Virtualization Technologies, AMD-V, or KVM enabled
  • Install the Extension Pack in the Oracle Virtual Box and Run the Setup.
3.  How Do You Use a Docker?

  • The biggest advantage of VMs is that they create snapshots which can be revisited instantly later. Docker containers further enhance the lightweight process virtualization by being OS independent and using the Linux Kernel’s functionality. They are created from Docker images – like snapshots. Docker images are created using a Docker file which can be customized or used as is. The default execution driver for creating a docker container is ‘libcontainer’.  Docker Hub can be used for searching docker images and seeing the way they have been built.
    • To create a Docker container, download the ‘hello world’ image, by typing the following command in the terminal –
    $ docker run hello world
    • For checking the number of images on your system, use the following command –
    $ docker images
    • For searching an image in the Docker Hub –
    $ docker search <image>

    4The base commands used for the Docker CLI.

    • docker run             -         Runs a command in a new container.
    • docker start           -         Starts one or more stopped containers
    • docker stop           -         Stops one or more running containers
    • docker build          -        Builds an image form a Docker file
    • docker builder       -        Manage Builds
    • docker pull            -        Pulls an image or a repository from a registry
    • docker push           -       Pushes an image or a repository to a registry
    • docker export        -       Exports a container’s file system as a tar archive
    • docker exec           -       Runs a command in a run-time container
    • docker search        -       Searches the Docker Hub for images
    • docker attach         -      Attaches to a running container
    • docker commit      -      Creates a new image from a container’s changes
    • docker checkpoint   -    Manage checkpoints
    • docker configs         -    Manage Docker configs
          docker info              -     Display system-wide information
          docker export          -     Export a container’s filesystem as a tar archive
            docker kill               -     kill one or more running containers







Streamlining the usage of GITHUB

Streamlining the usage of Github with Commands 1. Start a new git repository under one directory locally In this step, we need to bui...