Monday, April 29, 2013

GIT: Setting Up a Shared Repository

Shell commands for creating new git shared project:
$ mkdir /pub/my-repo.git
$ cd /pub/my-repo.git
$ git --bare init --shared
$ git --bare fetch /home/alice/myproject master:master
$ chgrp -R $group /pub/my-repo.git

Wednesday, April 24, 2013

Importing constants & methods from other java class

It a nice syntax feature:

Importing static variables:

import static com.xxxx.yyy.className.variableName;

Importing static methods:

import static org.junit.Assert.*;

Tuesday, April 23, 2013

Simulate user browser behaviour in java - forms

There are two major approaches:

  • use a browser library. There you define all actions you want to do.
  • parse the browser response manually and fill the forms by on low-level.

Saturday, April 20, 2013

Windcards in certificate "Common Name"

Nice feature of X.509 certificates are wind cards. For example:

Common name = *

Friday, April 19, 2013

How to become a Certified Ethical Hacker

TODO: add ethical hacker tools used

Installing root and intermediate certificates in java keystore

Issue faced:
java software could not validate that the server certificate is correct. This exception is thrown:
PKIX path building failed:
unable to find valid certification path to requested target

Issue in deep:
Default java validation mechanism:

Friday, April 12, 2013

HTTP Basic Authentication in Java - two different ways

We will see two different ways of authentication with java and . The connection is implemented with standard Sun/Oracle class

Solution 1: the more popular way, with Authenticator

            Authenticator.setDefault (new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
           String.format("Getting PasswordAuthentication with username %s and pass with lenght = %d", 

                    return new PasswordAuthentication ( 

Solution 2: the direct authentication injection, according http-basic standard:

import javax.xml.bind.DatatypeConverter; // standard class for Java 1.6, no additional jar needed

            String encryptedUserPass = DatatypeConverter.printBase64Binary( 
                        ( userStr +":" + passStr ).getBytes()
            connection.setRequestProperty  ("Authorization", "Basic " + encryptedUserPass );

Why the popular way is not fine?

  • it uses same authenticator for all connection. In multitheaded and multi-connectioned applications it could cause problems - same authentication for different servers. I could not found a way of setting an Authenticatotor just for my connection.
  • two requests for each my request. The first is initialised with no authentication, and when server says that it needs, the java library sends the second one, with user+pass; For debugging purposes it is not good.

Certificates with multiple valid hosts

The standard SSL certificate applies only to server in its CN (common name) field.

There is an extension Subject Alternative Name (, which allows the certificate to be valid for more than one host. It cold be very helpful in such complex server environments.

Note that the client software have to be aware of the Subject Alternative Name (, otherwise it would identify it as invalid. New browsers seem to be compatible.

Wednesday, April 10, 2013

Some git workflow

There are local commits.

git clone
Gets a Git repository from a remote source (makes a copy), so you could pull and push later.

Example with clones the repo with submodules:
git clone --recursive git://
Example, alternatively cloning submodules later this way:
git clone git://
cd bar
git submodule init
git submodule update
git clone

git identity - user name and email:
git config --global "Alexander Tomov"
git config --global
git show url
git config --get remote.origin.url 

git log origin/<branch>..HEAD
 - shows local commits

git diff origin/<branch>..HEAD
 - shows diff of local commits

git push

error: failed to push some refs to 'x'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.

git pull --rebase

git status
Shows you the status of files in the index versus the working directory. It will list out files that are untracked (only in your working directory), modified (tracked but not yet updated in your index), and staged (added to your index and ready for committing).

Example output:
# On branch xxxx
# Your branch is ahead of 'origin/xxxx' by 2 commits.

git push

git status
# On branch xxxx
# Changes not staged for commit:

Some important commands:

git branch -a
#    list remote branches

git pull --recurse-submodules
#    update all submodules (newer git clients)

git submodule foreach pull
#    update all submodules (for older git clients)

git add
Adds files changes in your working directory to your index.

Example: git add .

git rm
Removes files from your index and your working directory so they will not be tracked.

Example: git rm filename

git commit
Takes all of the changes written in the index, creates a new commit object pointing to it and sets the branch to point to that new commit.

Examples: git commit -m ‘committing added changes’
git commit -a -m ‘committing all changes, equals to git add and git commit’

git commit --amend
It does a fast-fix for your last commit. In other words it joins your current commit with your last commit.

git merge
Merges one or more branches into your current branch and automatically creates a new commit if there are no conflicts.

Example: git merge newbranchversion

git reset
Resets your index and working directory to the state of your last commit.

Example: git reset --hard HEAD

git stash
Temporarily saves changes that you don’t want to commit immediately. You can apply the changes later.

git stash
Saved working directory and index state "WIP on master: 84f241e first commit"
HEAD is now at 84f241e first commit
(To restore them type "git stash apply")

git stash apply
Revert the changes made by "git stash"

git fetch
Fetches all the objects from the remote repository that are not present in the local one.

Example: git fetch origin

git log
Shows a listing of commits on a branch including the corresponding details.

Example: git log
commit 84f241e8a0d768fb37ff7ad40e294b61a99a0abe
Author: User <>
Date:   Mon May 3 09:24:05 2010 +0300

    first commit

git show
git show <commit_id>
Shows information about a git object.

Example: git show
commit 84e341e8a0d768fb37ff7ad40e294b61a99a0abe
Author: User <>
Date:   Mon May 3 09:24:05 2010 +0300

    first commit

diff --git a/README b/README
new file mode 100644
index 0000000..e69de29

Example: git show 84e341e8a0d768fb37ff7ad40e294b61a99a0abeq
Applies diff on the commit

git grep
Lets you search through your trees of content for words and phrases.

Example: git grep "" -- *.php

git diff
Generates patch files or statistics of differences between paths or files in your git repository, or your index or your working directory.

Example: git diff
Example: git diff path/to/file.txt

git config -l
Show git config, my identity information (name, email) and remote repository info (url)

git checkout
Discard changes

Example: git checkout file.txt

To reset one file in your working directory to its committed state:

Example: git reset --hard
To reset every file in your working directory to its committed state:

git mv old_name.txt new_name.txt

Rename a file

git update-index --assume-unchanged

To temporarily ignore changes in a certain file, run:
git update-index --assume-unchanged <file>

Then when you want to track changes again:
git update-index --no-assume-unchanged <file>

Reverting to previous commit
git checkout 0923d7fc32...

Where HEX id is the hash value from git status. Additional info and workflows could be found in that thread.

Switching to another branch

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master

$ git checkout -b branch_to_switch remotes/origin/branch_to_switch

git checkout -b develop remotes/origin/develop

Showing only file names in commits
git log --name-only


Delete a Git tag
There are separate commands for deleting remote and local tags:
git push --delete origin tag_name
git branch -d the_local_branch

Show tags
git tag

Branches 'develop' and 'origin/develop' have diverged.
And branch 'develop' may be fast-forwarded.
git rebase origin/develop
Async-ed branch:
Symptom of async-ed develop branch:
# git remote show origin

  Local branch configured for 'git pull':
    master merges with remote master
(no develop here)
  Local refs configured for 'git push':

git branch --set-upstream develop origin/develop

git status
# On branch develop
# Your branch is ahead of 'origin/develop' by 1 commit.

# git remote show origin
  Local branches configured for 'git pull':
    develop merges with remote develop
    master  merges with remote master
# git checkout develop

Nice links:

Example workflow:

On undoing, fixing, or removing commits in git:

Tuesday, April 9, 2013

Linux command "find" in examples

find . -name *.rb
- search for all files with extension rb from current folder on.

Friday, April 5, 2013

Parsing XSD with floating elements

There is a way to create valid XSD definition with different order of the elements. This is important when the other party pulls text with different tag order or there are variantions of the received content.

The solution is <xsd:all> tag, described here. StackOverflow gives more practical problem, being solved by <xs:all>.