Wednesday, April 27, 2016

How to add git branch name to the command line

How many times you run the git branch command to find out which branch you in?

Following will help you to overcome above hassle and have a quick glance at your branch name.



1. Open /home/<USER>/.bashrc file.
2. Add following to the bashrc, save and exit.
parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt
3. Open a new terminal window and browse your git repo :)

Friday, April 22, 2016

First shot with the AF_Motor Library

I had to use an Arduino motor shield as a HAT on a uno board, powered by four 1.2V rechargeable batteries, to power-up two DC motors. ( Yes, juice provided by arduino is not enough to power two motors )

 
























Since this is my first library usage, I had to find out how to install a library in my workspace and decided to note the steps as a reference here.

Howto Install the Library-

1. Download the library, in my case AF_Motor from
https://github.com/adafruit/Adafruit-Motor-Shield-library/zipball/master.

2. Unzip and rename to motorsheild and copy in to the sketchbook libraries directory. (Create libaries directory, if not exists)
Eg:- /home/udara/sketchbook/libraries/ directory.

Why Rename: Default library name(adafruit-Adafruit-Motor-Shield-library-89a0973), contains hyphen(-) characters which causes library pickup issue during IDE startup.



3. Start/Restart IDE.

Hint: Browse File> Examples, you should see motorsheild sample sketches.

Sunday, April 3, 2016

how to resolve "M: bad interpreter" while working with bash scripts

This is a common problem if you try to port a script created in windows environment to unix,
 /bin/bash^M: bad interpreter: No such file or directory
How to solve this,

run dos2unix <BASH_SCRIPT>
Eg:- dos2unix run.sh

For further information: http://www.linuxcommand.org/man_pages/dos2unix1.html

Wednesday, March 2, 2016

Getting HTTP response back from a CURL POST request

CURL request:
curl -H "Content-Type: application/json" -H "Authorization: Basic <AUTH_VALUE>" -X POST -d '<BODY_CONTENT>' <EP_URL> -k -i

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hn6WUe7mxu6Va9bv0kww6xyBSPdOXOfyDz/CxDZLtUsnmi2Fi70tmSAz690jzgaoupH8X2O7JhzRX7v+EMow5xqXPZ3i3d2FcvBjssmFPZh10Y13+sSTRWn3ciYcfx2c+/a00c+bxMSFg0FWEtcpptY0tQkJhrGn+f49ARDk2wZoYEBLkE/KKnpvk1p6HFFwkJsHdslrtV5QDjzRVPGx5rIrt1Sp3qhOFAYHnAoxF6XcgTLx8+q2tUlft+XdTy61zo/So1/+n6VxawCwZIkn5UHzAfAL2BaYA4OaqMnTY97s6ILCip4e5+/CKzT7LbL14cAjVs6fI4lZ/9nsuSgpTPBqzhvSzKRx3Pjg4TllcjaFyq0/f6MAEnSSz2Ir2tL5ue0fLI29YSLDfa6+R2t0fKvqkklg3/KhMs4vWlr/g2oFVyCtZWIWXXtnzN/z8g86H9UJv5FAg0x2/p/TXF87g+gYLgMGDAGuMWCHH2D789EXrdOq/hNnFDqoYoO9OzqnFWktO3Hjg7cqGUEVHlIwNuDxabzeGsj5zW+72F8gODWFKV1O10I+zEmA4RMdXkBlUz515jt/w/Q/Sb8SazMqEgzhL4LPsV6bFX9pSN8nb9PiI/6sXq2sTGIdN/czqrRE7j/xBywhvcZXA9g+8yiUnZKwJ5YQkoAIKCySh0auw19/GqaU4bwt3TPBuomW3UTdHE=' https://localhost:9443/endpoints/PageLogEventReceiver -k -i

Sample response: 

HTTP/1.1 401 Unauthorized
Set-Cookie: JSESSIONID=B083D193C0722F2CA8021BA2021BA4F0; Path=/; Secure; HttpOnly
Content-Type: text/html;charset=UTF-8
Content-Length: 14
Date: Wed, 02 Mar 2016 16:30:48 GMT
Connection: close
Server: WSO2 Carbon Server

_AUTH_FAILURE_

Friday, February 19, 2016

WSO2 ESB Mutual SSL - Certificate exchange

We need to consider two scenarios here.

1. External system act as a client to ESB. 
     Eg:- SOAP UI invoking ESB proxy

2. External system is a server to ESB.
    EG:- ESB invoking external service

Following image depicts all certificate exchange steps to cater above scenarios.



Wednesday, February 17, 2016

how to import a private key in to JKS

Lets take following scenario where you implement an application based on asymmetric cipher (Eg:- RSA). Assume you are responsible for the decryption part, where you have to use the given private key to handle this.




Probably you will get only the private key or private key and the certificate. I'm going to take the first instance assuming you have only the private key.

Note :- assume name of the private key is private_key.pem

1. Create a certificate sign request using the given private key.
openssl req -new -key private_key.pem -out key_cert_r.csr
2. Get the certificate signed by an authorized party/self-sign.
Self-sign:
openssl x509 -req -days 365 -in key_cert_r.csr -signkey private_key.pem -out key_cert.crt
3. Generate a pkc12 key store using the private key and above certificate.
openssl pkcs12 -export -name alias -in key_cert.crt -inkey private_key.pem -out keystore.p12
4. Generate a java key-store using above pkc12 keystore.
keytool -importkeystore -destkeystore tmp_keystore.jks -srckeystore keystore.p12 -srcstoretype pkcs12 -alias alias

If you already have java key store configured within your application, let's merge above tmp_keystore.jks with the existing key store.
keytool -importkeystore -destkeystore existing_keystore.jks -srckeystore tmp_keystore.jks