Sunday, January 26, 2014

GLANCE @ GIT


Create a new repository

Create a new directory, open it and perform a "$ git init" to create a new git repository.
eg:
$ mkdir example.git
$ cd example.git
$ git init [--bare]

Checkout a repository

Create a working copy of a local repository by running the command
"$ git clone /path/to/repository
when using a remote server, your command will be
"$ git clone username@host:/path/to/repository".

Workflow

Your local repository consists of three "trees" maintained by git. the first one is your Working Directory which holds the actual files. the second one is the Index which acts as a staging area and finally the HEAD which points to the last commit you've made.






Add & Commit 

You can propose changes (add it to the Index) using
"$ git add <filename>"
"$ git add *"
This is the first step in the basic git workflow. To actually commit these changes use
"$ git commit -a -m "Commit message"
Committing your changes "$ git commit"
Committing files from working directory skipping staging area " $ git commit -a"
Viewing commit history: "$ git log"

Now the file is committed to the HEAD, but not in your remote repository yet.

Pushing Changes

Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute:
"$ git push origin master"
Change master to whatever branch you want to push your changes to.
If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with
"$ git remote add origin <server>"
Now you are able to push your changes to the selected remote server

Forking

Forking and updating a repo:

  1. Fork this repository: This is a GitHub operation, in which you are making a copy of Joe's repository (including the files, commit history, issues, and more). This repository now lives in your GitHub account. Nothing has yet happened to your local computer.
  2. Clone your repo: This is a Git operation, in which you are using Git to tell GitHub "please send me a copy of my repo" The repo is now stored on your local computer.
  3. Update some files: You can now make updates to the files in whatever program or environment you like.
  4. Commit your changes: This is a Git operation, in which you are using Git to tell GitHub "here are my changes" Pushing does not happen automatically, so until you do this step, GitHub does not know about your commits.
  5. Push your changes to your github repo: This is a Git operation, in which you are using Git to tell GitHub "here are my changes" Pushing does not happen automatically, so until you do this step, GitHub does not know about your commits.
  6. Send a pull request to Joe: If you think that Joe might like to incorporate your changes, you send him a pull request. This is a GitHub operation, in which you are communicating your changes to Joe, and "requesting" that he "pull" form your repo. It is up to him whether he pulls from you or not.

Syncing a fork

Let's say that Joe and other contributors have made some more updates to the game, and you've thought of some more updates you'd like to make. Before you do anything else, it's best to "sync your fork" so that you are working on the latest copy of the files. Here's what you do:
  1. Fetch changes from Joe's repo: This is a Git operation, in which you are using Git to tell GitHub that you would like to retrieve the latest files from Joe's repo.
  2. Merge those changes into your repo: This is a Git operation, in which you are updating the repo on your local computer with those changes (which have been temporarily stored in a "branch"). Note: Steps 1 and 2 are often combined into a single Git operation called a "pull".
  3. Push the updates to your GitHub repo:(optional): Remember that your local computer does not automatically update your GitHub repo. Therefore, the only way to get your GitHub repo up-to-date is by pushing up the latest changes. You can either do this right away, or you can wait until you have made some updates of your own and committed them locally.
Take note of the contrast between the workflow for forking and the workflow for syncing: When you initially fork a repo, the flow of information is from Joe's repo to your repo, and then down to your local computer. But after that initial process, the flow of information is from Joe's repo to your local computer, and then up to your repo.

Branching

Branches are used to develop features isolated from each other. The master branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.
create a new branch named "feature_x" and switch to it using
"$ git checkout -b feature_x"
switch back to master
"$ git checkout master"
and delete the branch again
"$ git branch -d feature_x"
a branch is not available to others unless you push the branch to your remote repository
"$ git push origin <branch>"
Checking Status of the files: "$ git status "

Update & Merge




To update your local repository to the newest commit, execute
[fetch+merge]"$ git pull"
[fetch + rebase] "$git pull --rebase"
in your working directory to fetch and merge remote changes.
to merge another branch into your active branch (e.g. master), use
"$ git merge <branch>"
in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After
changing, you need to mark them as merged with
"$ git add <filename>"
before merging changes, you can also preview them by using
"$ git diff <source_branch> <target_branch>"

Tagging

it's recommended to create tags for software releases. this is a known concept, which also exists in SVN. You can create a new tag named 1.0.0 by executing
"$ git tag 1.0.0 1b2e1d63ff"
the 1b2e1d63ff stands for the first 10 characters of the commit id you want to reference with your tag. You can get the commit id with
"$ git log"
you can also use fewer characters of the commit id, it just has to be unique.

Replace local changes

In case you did something wrong (which for sure never happens ;) you can replace local changes using the command
"$ git checkout -- <filename>"
this replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept.
If you instead want to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it like this
"$ git fetch origin"
"$ git reset --hard origin/master"

Useful Hints

gitk: built-in git GUI
Use colorful git output: "$ git config color.ui true"
Show log on just one line per commit: "$ git config format.pretty oneline"
Use interactive adding: "git add -i"

Exceptions:

#1: fatal: This operation must be run in a work tree [duplicate]
Explanation: You repository is bare, i.e. it does not have a working tree attached to it. You can clone it locally to create a working tree for it, or you could use one of several other options to tell Git where the working tree is, e.g. the --work-tree option for single commands, the GIT_WORK_TREE environment variable, or the core.worktree configuration option.
"$ git config core.bare false"

Quick Reference:

Cloning a remote repo (that you created or forked on GitHub)

  • git clone < your-repo-URL >: copies your remote repo to your local machine (in a subdirectory with the repo's name), and automatically creates an "origin" handle
  • git remote add upstream < forked-repo-URL >: adds an "upstream" handle for the repo you forked
  • git remote -v: shows the handles for your remotes
  • git remote show < handlename >: inspect a remote in detail

Tracking, committing, and pushing your changes

  • git add < name >: if untracked, start tracking a file or directory; if tracked and modified, stage it for committing
  • git reset HEAD < name >: unstage a changed file
  • git commit -m "message": commits everything that has been staged with a message
    • -a -m "message": automatically stages any modified files, then commits
    • --amend -m "new message": fixes the message from the last commit
  • git push origin master: pushes your commits to the master branch of the origin

Syncing your local repo with the upstream repo

  • git fetch upstream [master]: fetch the upstream and store its master branch in "upstream/master"
  • git merge upstream/master: merge that branch into the working branch

Viewing the status of your files

  • git status: check which files have been modified and/or staged since the last commit
  • git diff: shows the diff for files that are modified but not staged
    • --staged: shows the diff for files that are staged but not committed

Viewing the commit history

  • git log: shows the detailed commit history
    • -1: only shows the last 1 commit
    • -p: shows the line diff for each commit
    • -p --word-diff: shows the word diff for each commit
    • --stat: shows stats instead of diff details
    • --name-status: shows a simpler version of stat
    • --oneline: just shows commit comments
  • gitk: open a visual commit browser

Managing branches

  • git branch: shows a list of local branches
    • < branchname >: create a new branch with that name
    • -d < branchname >: delete a branch
    • -v: show the last commit on each local branch
    • -a: show local and remote branches
    • -va: show the last commit on each local and remote branch
    • --merged: list which branches are already merged into the working branch (safe to delete)
    • --no-merged: list which branches are not merged into the working branch
  • git checkout < branchname >: switch the HEAD pointer to a different branch
    • -b < branchname >: create a new branch and switch to it

Removing, deleting, and reverting files

  • git rm < name >: deletes that file from the disk, then stages its deletion
    • --cached < name >: stops tracking a file, then stages its deletion (but does not delete it from the disk)
  • git mv < oldname > < newname >: renames the file on disk, then stages the deletion of the old name and addition of the new name
  • git checkout -- < name >: revert a modified file on disk back to the last committed version

Other basic commands

  • git init: initialize Git in an existing directory
  • git config --list: shows your Git configuration
  • touch .gitignore: create an empty .gitignore file

GIT Daily workflow



    Whole Idea is to keep your repository latest and pull others changes and resolve conflict if any:

    Note:
    1. $ git branch (is local branch on your machine)
    2. $ git fetch origin (Remote Branch to your reposioty)

    1. $ git fetch upstream (Remote Branch to company/project repository)


    1. Takes latest from Remote (upstream):
      1. $ git fetch upstream master
      2. $ git merge upstream/master
    2. Resolve conflicts:
      1. $ git add .
      2. $ git commit -a -m "your_message"
      3. $ git status
    3. Bring these changes to your remote repository (from your local).
      1. $ git push origin master # git push origin BRANCH_NAME

    Q. How to clone and remote repository?
    Check:           
    $ git branch -r # to list all remote branches only.

    $ git remote -v # check list of all remote branches


    Origin: $ git clone https://git.company.com/andixit/mkp.git # this is automatically set as origin.
    Upstream: $ git remote add upstream https://git.company.com/equinix/mkp.git # this will add upstream branch.

    Q. List all branch Local or remote?
    $ git branch -a # to check all branches local or remote.

    Q. How to remove / delete a repository?
    A. there could be three kind of delete / remove repository path in GIT:

    /apps/opt/projects/marketplace/services/report-data-service>git push origin -d MKP-5.3

    1. Remote:
    $ git push origin --delete <branch_name>
    $ git branch -d <branch_name>
    > git push origin --delete <branch>  # Git version 1.7.0 or newer
    > git push origin :<branch>          # Git versions older than 1.7.0

    2. Local:
    $ git branch --delete <branch>
    $ git branch -d <branch> # Shorter version
    $ git branch -D <branch> # Force delete un-merged branches

    3. Deleting a local remote-tracking branch:
    $ git branch --delete --remotes <remote>/<branch>
    $ git branch -dr <remote>/<branch> # Shorter

    $ git fetch <remote> --prune # Delete multiple obsolete tracking branches
    $ git fetch <remote> -p      # Shorter


    Q. How to checkout a specific revision?

    $ git clone https://git.company.com/anupdixit/mkp.git
    $ git checkout usermanagment

    # checkout a particular revision

    $ git checkout <sha1>
    $ git checkout 17a5d87d31aab43e9e6b8eb51bf1516b13ec78c6
    Q. How to switch to already existing branch?
    $ git checkout anup-dev # switched to anup-dev # use this command if branch already created.

    Q. How to create a new feature specific branch?
    $ git checkout –b anup-dev # execute this command to create a new feature specifc branch from current checkout branch.
    or use following 2 commnad equivalent to above command:
    1. $ git branch anup-dev
    2. $ git checkout anup-dev


    Q. Copy code from one local branch to another local branch?

    Go to the target branch (git checkout target) and merge the code-having branch (git merge code-having). then, if needed, push the updated target branch to its remote.
    eg. feature specific code is checked in to anup-dev, now i want to move it to user’s remote master.
    $ git checkout master # first go to target branch
    $ git merge anup-dev # merge the changes from branch that have code.


    Q. Copy code from one Remote branch to another Remote branch?

    A. $ git push origin anup-dev:master # push changes to master from anup-dev in origin

    Q. How to tag your release?
    1. Checkout A Tag:

      $ git checkout -b <NEW_BRANCH_NAME> <TAG_NAME>
      $ git checkout -b MKP_R3.10_UAT_RC5 MKP_R3.10_UAT_RC4
    2. Tag A Release:
      $ git tag -a <TAG_NAME> -m <TAG_MESSAGE>
      $ git push origin <TAG_NAME>

      Eg. $ git push origin MKP_R4.0_RC5_23052012
      $ git push origin --tags
    eg:
      $ git tag -a MKP_R3.10_UAT_RC5 -m "RC5"
      $ git push origin MKP_R3.10_UAT_RC5

    Q. How to undo a git commit?

    There are two ways to "undo" your last commit, depending on whether or not you have already made your commit public (pushed to your remote repository):

    1. Undo from local commit: Lets say I committed locally, but now want to remove that commit.

    $ git log

       commit 101: bad commit    # latest commit, this would be called 'HEAD'
       commit 100: good commit   # second to last commit, this is the one we want

    To restore everything back to the way it was prior to the last commit, we need to reset to the commit before HEAD:
    $ git reset --soft HEAD^     # use --soft if you want to keep your changes
    $ git reset --hard HEAD^     # use --hard if you don't care about keeping the changes you made
    Now git log will show that our last commit has been removed.

    2. Undo a public commit: If you have already made your commits public, you will want to create a new commit which will "revert" the changes you made in your previous commit (current HEAD).
    $ git revert HEAD
    Your changes will now be reverted and ready for you to commit:
    $ git commit -m 'restoring the file I removed by accident
    $ git log
       commit 102: restoring the file I removed by accident
       commit 101: removing a file we dont need
       commit 100: adding a file that we need
    3. Undo last 5 commits: $ git reset --hard 5a7404742c85
    HEAD is now at 5a74047 Added one more page to catalogue
    $ git push origin master --force
    Total 0 (delta 0), reused 0 (delta 0)
    remote: bb/acl: neoneye is allowed. accepted payload.
    To git@github.org:thecompany/mkp.git
    + 09a6480...5a74047 master -> master (forced update)
    Q. Git Reset:
    $ git reset --hard # removes staged and working directory changes
    ## !! be very careful with these !! you may end up deleting what you don't want to read comments and manual. $ git clean -f -d # remove untracked $ git clean -f -x -d # CAUTION: as above but removes ignored files like config. $ git clean -fxd :/ # CAUTION: as above, but cleans untracked and ignored files through the entire repo
    (without :/, the operation affects only the current directory)

    Q. How to find difference between different branch?
    A. $ git diff MKP-5.3 master services\report-data-service

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - -
    $ git log -5 —oneline # check last 5 changes to repository

    https://github.com
    Username:
    First you need to tell git your name, so that it can properly label the commits you make.
    $ git config --global user.name “your name here”
    $ Sets the default name for git to use when you commit.

    Email: Git saves your email into the commits you make. We use the email address to associate your commits with your github account.
    $ git config --global user.email “your_email@example.com”
    $ sets the default email for git to use when you commit.

    $ git clone <url_from_github>
    # give password when required

    # no need to run init because it already been initialized.
    $ git remote -v # check git remote location
    $ git remote add origin <url_from_github>

    $ git status # to check status of new and modified file
    $ git add . # add everything in current directory.

    $ git commit -m “Committing file”
    $ git status # to confirm nothing else to commit.
    $ git log # to check everything is committed

    $ git push origin master # push master to origin (remote) - give password when required.

    Sync Fork with upstream require 2 operation:
    1. Fetch:  from remote to local
    2. Merge: merge changes and differences in local with others changes.
    3. Push: once satisfied push changes to remote repo. 

    $ git remote -v
    $ git remote add upstream <github url>
    $git remote -v
    $ git fetch upstream
    - - if required we can switch upstream and view changes ---
    $ git merge upstream/master
    $ git push origin master # give password if required

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - -

    Source Tree- GIT Client:

    With recent update of Source Tree v 1.9.8 we start seeing problem where it fail to clone with message "warning: templates not found /usr/local/git/share/git-core/templates" on mac osX.

    Following is the solution for this problem:
    1. Got to your home directory. $ cd ~
    2. open .gitconfig in vi (or your comfortable editor).
    3. Add this at beginning of file:
      1. [init]
        templatedir = /Applications/SourceTree.app/Contents/Resources/git_local/share/git-core/templates
    This will resolve the issue, if required restart your Source Tree or machine.

    GIT Hub /or GIT Lab Setting up SSH Keys

    SSH key allows you to establish a secure connection between your computer and GitLab. Before generating an SSH key, check if your system already has one by running cat ~/.ssh/id_rsa.pub If your see a long string starting with ssh-rsa or ssh-dsa, you can skip the ssh-keygen step.

    To generate a new SSH key just open your terminal and use code below. The ssh-keygen command prompts you for a location and filename to store the key pair and for a password. When prompted for the location and filename you can press enter to use the default. It is a best practice to use a password for an SSH key but it is not required and you can skip creating a password by pressing enter. Note that the password you choose here can't be altered or retrieved.

    $ ssh-keygen -t rsa -C "email@gmail.com"

    Use the code below to show your public key.
    cat ~/.ssh/id_rsa.pub
    ------------------------
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDncSVBPs0hg5YRZ0NYJHueGpouluJPeKDpHO7gRsFSwUfkjGL5fKg4BCgxJZjdrHQ8G0e9jmt0oXYJpilde5olbrnx5NSEbP1hv18Mq8jTYEd91VH2HsrYJ2TNTgQ79JXA6m1v2UYTd15UwPkhzJEcpP29Cuh/MSX1URBA/aQ3wEfIc6LF45Kyx7St/kiBfPQwJfmcyRsIDv6ly6TQp8GT2nNzWVsFe6JigHN6XKf2YzFXK8oBGJZhv5vBNXYEr86rg7t34E8xYI/yBSGg1k2V+nymEfwhSRbmRyB+zdcvCVKVTSsgg3ySXj89EgDGULc7mfucNnkq0lThLVL1ObyJ email@gmail.com
    ------------------------

    Copy-paste the key to the 'My SSH Keys' section under the 'SSH' tab in your user profile. Please copy the complete key starting with ssh- and ending with your username and host.

    References:

    GIT SCM, About, GitRef, Interactive Git Reference, Git 30 mins Crash Course

    Sunday, January 12, 2014

    How To Manually Install Oracle Java on Linux

    Introduction

    Java is a programming technology originally developed by Sun Microsystems and later acquired by Oracle. Oracle Java is a proprietary implementation for Java that is free to download and use for commercial use, but not to redistribute, therefore it is not included in a officially maintained repository.
    There are many reasons why you would want to install Oracle Java over OpenJDK. In this tutorial, we will not discuss the differences between the above mentioned implementations.

    Assumptions

    This tutorial assumes that you have an account with DigitalOcean, as well as a Droplet running Debian 7 or Ubuntu 12.04 or above. You will need root privileges (via sudo) to complete the tutorial.
    You will need to know whether you are running a 32 bit or a 64 bit OS:
    $ uname -m
    • x86_64: 64 bit kernel
    • i686: 32 bit kernel

    Downloading Oracle Java JDK

    Using your web browser, go to the Oracle Java SE (Standard Edition) website and decide which version you want to install:
    • JDK: Java Development Kit. Includes a complete JRE plus tools for developing, debugging, and monitoring Java applications.
    • Server JRE: Java Runtime Environment. For deploying Java applications on servers. Includes tools for JVM monitoring and tools commonly required for server applications.
    In this tutorial we will be installing the JDK Java SE Development Kit 8 x64 bits. Accept the license and copy the download link into your clipboard. Remember to choose the right tar.gz (64 or 32 bits). Use wget to download the archive into your server:
        $ wget --header "Cookie: oraclelicense=accept-securebackup-cookie" \
           http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz \
            --no-check-certificate 
     
    Oracle does not allow downloads without accepting their license, therefore we needed to modify the header of our request. Alternatively, you can just download the compressed file using your browser and manually upload it using a SFTP/FTP client.
    Always get the latest version from Oracle's website and modify the commands from this tutorial accordingly to your downloaded file.

    Installing Oracle JDK

    In this section, you will need sudo privileges:
        sudo su
    The /opt directory is reserved for all the software and add-on packages that are not part of the default installation. Create a directory for your JDK installation:
        mkdir /opt/jdk
    and extract java into the /opt/jdk directory:
        tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk
    Verify that the file has been extracted into the /opt/jdk directory.
        ls /opt/jdk

    Setting Oracle JDK as the default JVM

    In our case, the java executable is located under /opt/jdk/jdk1.8.0_05/bin/java . To set it as the default JVM in your machine run:
        update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100
    and
        update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

    Verify your installation

    Verify that java has been successfully configured by running:
        update-alternatives --display java
    and
        update-alternatives --display javac
    The output should look like this:
        java - auto mode
    link currently points to /opt/jdk/jdk1.8.0_05/bin/java
    /opt/jdk/jdk1.8.0_05/bin/java - priority 100
    Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/java'.

    javac - auto mode
    link currently points to /opt/jdk/jdk1.8.0_05/bin/javac
    /opt/jdk/jdk1.8.0_05/bin/javac - priority 100
    Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/javac'.
    Another easy way to check your installation is:
        java -version
    The output should look like this:
        java version "1.8.0_05"
    Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

    (Optional) Updating Java

    To update Java, simply download an updated version from Oracle's website and extract it under the /opt/jdk directory, then set it up as the default JVM with a higher priority number (in this case 110):
        update-alternatives --install /usr/bin/java java /opt/jdk/jdk.new.version/bin/java 110
    update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk.new.version/bin/javac 110
    You can keep the old version or delete it:
        update-alternatives --remove java /opt/jdk/jdk.old.version/bin/java
    update-alternatives --remove javac /opt/jdk/jdk.old.version/bin/javac

    rm -rf /opt/jdk/jdk.old.version

    Wednesday, November 20, 2013

    Installing Python 3 on CentOS/Redhat 5.x / 6.x From Source

    The latest release of the python scripting language is Python 3.4.0 However due to backwards incompatibilities with Python 2, it has not been adopted for CentOS / Redhat Linux 5. The primary reason for this, is because release of ‘yum’ (package management) used in EL5 requires Python 2. Because of this, Python cannot be upgraded in place to version 3 without breaking the package manager.

    Therefore to use Python 3, it will need to be installed outside of /usr.

    Installing

    Below is the list of command (with inline comments) on what is required to compile and install Python 3 from source. The installation will be done into the prefix /opt/python3. This will ensure the installation does not conflict with system software installed into /usr.
    - - - - - - - - - - - - #1 will install following- - - - - - - - - - - - - - - - - - 
    Installed:
      bzip2-devel.i386 0:1.0.3-6.el5_5                bzip2-devel.x86_64 0:1.0.3-6.el5_5                expat-devel.i386 0:1.95.8-11.el5_8
      expat-devel.x86_64 0:1.95.8-11.el5_8            gdbm-devel.i386 0:1.8.0-28.el5                    gdbm-devel.x86_64 0:1.8.0-28.el5
      openssl-devel.i386 0:0.9.8e-22.el5_8.4          openssl-devel.x86_64 0:0.9.8e-22.el5_8.4          readline-devel.i386 0:5.1-3.el5
      readline-devel.x86_64 0:5.1-3.el5               sqlite-devel.i386 0:3.3.6-6                       sqlite-devel.x86_64 0:3.3.6-6

    Dependency Installed:
      gdbm.i386 0:1.8.0-28.el5                         keyutils-libs-devel.x86_64 0:1.2-1.el5         krb5-devel.x86_64 0:1.6.1-70.el5
      libselinux-devel.x86_64 0:1.33.4-5.7.el5         libsepol-devel.x86_64 0:1.15.2-3.el5           libtermcap-devel.x86_64 0:2.0.8-46.1
      sqlite.i386 0:3.3.6-6

    Dependency Updated:
      expat.i386 0:1.95.8-11.el5_8                     expat.x86_64 0:1.95.8-11.el5_8             gdbm.x86_64 0:1.8.0-28.el5
      krb5-libs.i386 0:1.6.1-70.el5                    krb5-libs.x86_64 0:1.6.1-70.el5            krb5-workstation.x86_64 0:1.6.1-70.el5
      libselinux.i386 0:1.33.4-5.7.el5                 libselinux.x86_64 0:1.33.4-5.7.el5         libselinux-python.x86_64 0:1.33.4-5.7.el5
      libselinux-utils.x86_64 0:1.33.4-5.7.el5         libsepol.i386 0:1.15.2-3.el5               libsepol.x86_64 0:1.15.2-3.el5
      openssl.i686 0:0.9.8e-22.el5_8.4                 openssl.x86_64 0:0.9.8e-22.el5_8.4         sqlite.x86_64 0:3.3.6-6

    Complete!
    - - - - - - - - - - - - #1 will install above & if these are already installed we will see following- - - - - - - - - - - - - - 
    [root@bhmed-dt-2q ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
    Loaded plugins: logchanges, security
    Setting up Install Process
    Package openssl-devel-0.9.8e-22.el5_8.4.x86_64 already installed and latest version
    Package openssl-devel-0.9.8e-22.el5_8.4.i386 already installed and latest version
    Package bzip2-devel-1.0.3-6.el5_5.x86_64 already installed and latest version
    Package bzip2-devel-1.0.3-6.el5_5.i386 already installed and latest version
    Package expat-devel-1.95.8-11.el5_8.x86_64 already installed and latest version
    Package expat-devel-1.95.8-11.el5_8.i386 already installed and latest version
    Package gdbm-devel-1.8.0-28.el5.x86_64 already installed and latest version
    Package gdbm-devel-1.8.0-28.el5.i386 already installed and latest version
    Package readline-devel-5.1-3.el5.x86_64 already installed and latest version
    Package readline-devel-5.1-3.el5.i386 already installed and latest version
    Package sqlite-devel-3.3.6-6.x86_64 already installed and latest version
    Package sqlite-devel-3.3.6-6.i386 already installed and latest version
    Nothing to do
    [root@bhmed-dt-2q ~]#
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    1. # Install required build dependencies
      1. $ yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
    2. # Fetch and extract source. Please refer to http://www.python.org/download/releases to ensure the latest source is used.
      1. $ wget 
        1. https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz --no-check-certificate
        2. https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz --no-check-certificate
      2. $ tar -xjf Python-3.2.tar.bz2
      3. $ cd Python-3.2
    3. # Configure the build with a prefix (install dir) of /opt/python3, compile, and install.
      1. $ ./configure --prefix=/opt/python3
      2. $ make
      3. $ sudo make install
    4. #Python 3 will now be installed to /opt/python3.
      1. $ /opt/python3/bin/python3 -V
        1. Output: Python 3.2
    5. Ensure your python 3 scripts and applications query the correct interpreter.
      1. #!/opt/python3/bin/python3 Generally Work here is completed python3 can be accessed using this path.
    6. Now make sure you set your new PYTHON as in your PATH. try
      1. $which python: If this return a different version of python may be your system default then you might want to set your new python3.4 path or in the python3.4 directory try ./python that should open your new 3.4 python.
        1. echo $PATH
        2. export PATH=/YOUR/PYTHON/3.4_HOMEDIR/PATH:$PATH
        3. echo $PATH : (this is temporary, you can add to config files to make this export permanent) notice that i am adding it to the front so it gets picked before our system default.
    7. Now lets install some packages:
      1. # Create your virtual env: so this installation will not clash with system default python and/or you are not using the wrong python pip
        1. $ pyvenv-3.4 py3.4env
      2. # Activate it:
        1. $ source py3.4env/bin/activate
      3. # This should be pointing to the right pip in your new python 3.4 Home
        1. (py3.4env) $ which pip
      4. # This checks if your env is clean ..this would not return any  output
        1. (py3.4env) $ pip freeze
        2. (py3.4env) $ pip install numpy
        3. (py3.4env) $ pip install pytz

    Friday, October 18, 2013

    CENTOS v 6.4, GIT v 1.7.1 and JENKINS v 1.535 CONTINOUS INTEGRATION

    Having tuned our Agile process to release iteratively and often I decided it was time to spend some time looking at how we could introduce continuous integration into our PHP and Javascript BDD workflows. Given that Travis isn’t suitable for most of our work (your code must be open source), I chose Jenkins as our CI server and was able to get up and running fairly quickly. I  found a few resources that covered integrating Git with Jenkins but I ended up doing a bit of digging myself so thought I’d quickly share the steps I followed.

    Install Jenkins and Git

    I provisioned a fresh CENTOS v 6.4 box, which meant I was able to follow the official Jenkins docs without any problems. If you’re using anything other than Ubuntu/Debian or Redhat you may need to look elsewhere. The installation instructions outline simple Apache or Nginx vhost configurations that can be used to serve the Jenkins administration console. You’ll need to install git on the same box so that Jenkins can eventually pull down, or commit to, your git repositories. To install Git I simply ran $ sudo apt-get install git (debian) and $ yum install git (Centos).

    Install the Git Plugin

    Once you can access your Jenkins console,  goto `Manage Jenkins -> Manage Plugins` from the home screen.
    Open the ‘Available’ tab and find the plugin entitled Git Plugin.There is a filter box but it didn’t work particularly well for me, I ended up using Find in Chrome.

    Create ssh key pair

    Part of the installation process will create the user `jenkins` which will envoke all Jenkins processes, including all git commands. Therefore you’ll need to provision a keypair for this user then add the public key to your git repo. There’s a bit of trick to doing the former which I’ll cover now:

    1. Login to your box and switch to the Jenkins user. The installation process doesn’t create a password so you’ll need to have root/sudo permissions to do this. Run the command sudo su - jenkins. The ‘-’ specifies a login shell, and will switch you to jenkins’ home directory (for me this was /var/lib/jenkins’).
    2. Create a .ssh directory in the jenkins home directory.
    3. Create the public private key pair. There are many tutorials which cover using the ssh-keygen command to do this. The most important thing is not to set a password, otherwise the jenkins user will not be able to connect to the git repo in an automated way.
    4. Add the public key to your Git repo. We use bitbucket so this was fairly straightforward for me and I imagine anyone reading this will have performed similar actions for all their devs keys in the past.
    5. Set a git user and email address. This is also mentioned in the git plugin documentation. Run:cd /srv/jenkins/jobs/project/workspacegit config user.email "some@email.com"git config user.name "jenkins".
    Connect to the Git repo. This is a one time step which will dismiss that ‘Are you sure you want to connect’ ssh message, again jenkins won’t be able to deal with this. Just run ssh git@your_git_server_url info.

    Create a new Job in Jenkins

    The official docs provide a good level of detail on how to configure a basic Jenkins job, so I’d recommend following them here. The git-plugin docs also provide some useful info, so there’s not too much more for me to say other than list the steps I followed:

    1. Select Git in Source Code Management.
    2. Enter your git repository URL. This performs a asynchronous check and will give you an error if it can’t connect. Double check you followed the steps in #3 if you get an error.
    3. Select the branch to build. This is branch jenkins will pull from when a build is started so enter whatever is suitable. We are building from develop so I entered this here.

    Run a test Build

    Once you’ve saved the job it’s worth kicking off a build to check everything’s working OK. You can do this in the main dashboard. Have a look at the latest build, you should see the commit id that was pulled down. If you dig around in the docs you’ll find that the plugin will have fetched your branch (in my case develop) and pulled from the remote repo. The repo is checked out into the job’s `workspace` directory and during the build the Jenkins user is cd’d into this directory. By adding your makefiles and build scripts into your repository it’s then a straightforward case of configuring the Jenkins job to execute these upon build. Again, this is covered in good detail in the docs.

    Post Receive Hook

    Finally you’ll need to setup your Git repository to initialise a build each time you push to your repository. Github and bitbucket both have hooks ready to be used, but if you’re self hosted a good place to start is at the plugin documentation which specifies the HTTP endpoint which can be used to trigger the job.


    Wednesday, October 2, 2013

    Sealing Packages within a JAR File

    Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. You might want to seal a package, for example, to ensure version consistency among the classes in your software.
    You seal a package in a JAR file by adding the Sealed header in the manifest, which has the general form:
    Name: myCompany/myPackage/
    Sealed: true
    The value myCompany/myPackage/ is the name of the package to seal.
    Note that the package name must end with a "/".

    An Example

    We want to seal two packages firstPackage and secondPackage in the JAR file MyJar.jar.
    We first create a text file named Manifest.txt with the following contents:
    Name: myCompany/firstPackage/
    Sealed: true

    Name: myCompany/secondPackage/
    Sealed: true

    Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.

    We then create a JAR file named MyJar.jar by entering the following command:
    jar cmf MyJar.jar Manifest.txt MyPackage/*.class
    This creates the JAR file with a manifest with the following contents:
    Manifest-Version: 1.0
    Created-By: 1.7.0_06 (Oracle Corporation)
    Name: myCompany/firstPackage/
    Sealed: true
    Name: myCompany/secondPackage/
    Sealed: true

    Sealing JAR Files

    If you want to guarantee that all classes in a package come from the same code source, use JAR sealing. A sealed JAR specifies that all packages defined by that JAR are sealed unless overridden on a per-package basis.
    To seal a JAR file, use the Sealed manifest header with the value true. For example,
    Sealed: true
    specifies that all packages in this archive are sealed unless explicitly overridden for particular packages with the Sealed attribute in a manifest entry.

    Friday, September 27, 2013

    Viewing the Contents of a JAR File

    The basic format of the command for viewing the contents of a JAR file is:
    jar tf jar-file
    Let's look at the options and argument used in this command:
    • The t option indicates that you want to view the table of contents of the JAR file.
    • The f option indicates that the JAR file whose contents are to be viewed is specified on the command line.
    • The jar-file argument is the path and name of the JAR file whose contents you want to view.
    The t and f options can appear in either order, but there must not be any space between them.
    This command will display the JAR file's table of contents to stdout.
    You can optionally add the verbose option, v, to produce additional information about file sizes and last-modified dates in the output.

    An Example

    Let's use the Jar tool to list the contents of the TicTacToe.jar file we created in the previous section:
    jar tf TicTacToe.jar
    This command displays the contents of the JAR file to stdout:
    META-INF/MANIFEST.MF
    TicTacToe.class
    audio/
    audio/beep.au
    audio/ding.au
    audio/return.au
    audio/yahoo1.au
    audio/yahoo2.au
    images/
    images/cross.gif
    images/not.gif
    The JAR file contains the TicTacToe class file and the audio and images directory, as expected. The output also shows that JAR file contains a default manifest file, META-INF/MANIFEST.MF, which was automatically placed in the archive by the JAR tool.
    All pathnames are displayed with forward slashes, regardless of the platform or operating system you're using. Paths in JAR files are always relative; you'll never see a path beginning with C:, for example.
    The JAR tool will display additional information if you use the v option:
    jar tvf TicTacToe.jar
    For example, the verbose output for the TicTacToe JAR file would look similar to this:
        68 Thu Nov 01 20:00:40 PDT 2012 META-INF/MANIFEST.MF
    553 Mon Sep 24 21:57:48 PDT 2012 TicTacToe.class
    3708 Mon Sep 24 21:57:48 PDT 2012 TicTacToe.class
    9584 Mon Sep 24 21:57:48 PDT 2012 TicTacToe.java
    0 Mon Sep 24 21:57:48 PDT 2012 audio/
    4032 Mon Sep 24 21:57:48 PDT 2012 audio/beep.au
    2566 Mon Sep 24 21:57:48 PDT 2012 audio/ding.au
    6558 Mon Sep 24 21:57:48 PDT 2012 audio/return.au
    7834 Mon Sep 24 21:57:48 PDT 2012 audio/yahoo1.au
    7463 Mon Sep 24 21:57:48 PDT 2012 audio/yahoo2.au
    424 Mon Sep 24 21:57:48 PDT 2012 example1.html
    0 Mon Sep 24 21:57:48 PDT 2012 images/
    157 Mon Sep 24 21:57:48 PDT 2012 images/cross.gif
    158 Mon Sep 24 21:57:48 PDT 2012 images/not.gif

    Tuesday, July 30, 2013

    Markdown

    Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

    Markdown can be written in a basic text editor (don't use Word) like TextEdit for Mac (save as plain-text) or Notepad on Windows. It's an easy way to write text that easily translates into HTML. The web is written in HTML, so think of it like quick-start web development tool for content editors. When you write in Markdown, you save the document with the file extension .md. More often than not, you'll never need to save a Markdown document, because you'll be using an online tool.

    • Basic:
      • Italics: _surround by_
      • bold: **I will complete these lessons!**
      • Italics & bold: **_"Of course," she whispered. Then, she shouted: "All I need is a little moxie!"_**
      • part of phrase both bold and Italics: If you're thinking to yourself, **_This is unbelievable_**, you'd probably be right.
    • Headers: #   - You can't really make a header bold, but you can italicize certain words
      • # Header one
      • ##Header two
      • ###Header three
      • ####Header four
      • #####Header five
      • ######Header six
    • Links:
      • Inline Link: The first link style is called an inline link. To create an inline link, you wrap the link text in brackets ( [ ] ), and then you wrap the link in parenthesis ( ( ) ).
        •  For example, to create a hyperlink to www.github.com, with a link text that says, Visit GitHub!, you'd write this in Markdown:
          • [Visit GitHub!](www.github.com)
        • In the box below, make a link to www.google.com, with link text that says "Search for it."
          • [Search for it.](www.google.com)
        • You can add emphasis to link texts, if you like. In the box below, make the phrase "really, really" bold, and have the entire sentence link to www.dailykitten.com. You'll want to make sure that the bold phrasing occurs within the link text brackets.
          • [You're **really, really** going to want to see this.](www.dailykitten.com)
        • Although it might make for an awkward experience, you can make links within headings, too. For this next tutorial, make the text a heading four, and turn the phrase "the BBC" into a link to www.bbc.com/news:
          • ####The Latest News from [the BBC](www.bbc.com/news)
      • Reference Link: The other link type is called a reference link. As the name implies, the link is actually a reference to another place in the document. Here's an example of what we mean:
        • Here's [a link to something else][another place].
        • Here's [yet another link][another-link].
        • And now back to [the first link][another place].
        • [another place]: www.github.com
        • [another-link]: www.google.com
    • Images: The difference is that an image is prefaced with an exclamation point ( ! ), followed by the same two brackets, and a pair of parentheses containing the image URL. Within the image brackets, you can place some "alt text," which is a phrase or sentence that describes the image for the visually impaired.
      • Images also have two styles, just like links. To create an inline image, you'll use the same syntax as an inline link.
      • Q: In the box below, turn the link to an image, and fill out the alt text brackets to say "A representation of Octdrey Catburn":
        • ![A representation of Octdrey Catburn](http://octodex.github.com/images/octdrey-catburn.jpg)
      • Q: In the box below, we've started placing some reference images; you'll need to complete them, just like the last lesson. Call the first reference tag "First Father", and make it link to http://octodex.github.com/images/founding-father.jpg; make the second image link out to http://octodex.github.com/images/foundingfather_v2.png.
        • ![The first father][First Father]
        • ![The second first father][Second Father]
        • [First Father]: http://octodex.github.com/images/founding-father.jpg
        • [Second Father]: http://octodex.github.com/images/foundingfather_v2.png
    • Paragraph:
      • To create a block quote, all you have to do is preface a line with the "greater than" caret (>). You can also place a caret character on each line of the quote. This is particularly useful if your quote spans multiple paragraphs.
      • Hard Break: To move to next time : give a line break. (If you forcefully insert a new line, you end up breaking the togetherness). 
      • Soft Break: Soft Break: add 2 space at end of line.
    • List:
      • Unordered List: *<single space> word
        • * Flour
        • * Cheese
        • * Tomatoes
      • Ordered List:
        • 1. One
        • 2. Two
        • 3. Three
      • Sublist: Notice extra space before asterisk.
        • * Calculus
        •  * A professor
        •  * Has no hair
        •  * Often wears green
        • * Castafiore
        •  * An opera singer
        •  * Has white hair
        •  * Is possibly mentally unwell