[GIT] How to apply Pull Request

I use "Fetch and Merge" approach to apply Pull request from a forked repo to main repo. What is actually done in this approach is to fetch changes from the forked repo in main repo working copy and merge the changes. Once changes from forked repo are merged in main repo working copy, push it to remote main repo as usual.

This process is achieved in these steps:

1- CD to main.git repo working directory
$ git checkout master

2- Add forked repo forked.git in remotes
$ git remote add <forked> <forked.git>


3- Fetch changes from forked.git
$ git fetch forked

4- Merge into master branch
$ git merge <forked>/<master>

5- Push the merged changes to main.git
$ git push origin master 

How to List Users and Groups in OSX (Mac-Lion)

To list the users :
dscl . -list /Users
To list the groups:
dscl . -list /Groups 

How to Stop a Jenkins Server

Simply, unload the jenkins from Launch daemon using:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

How did I setup SSL with HTTPClient-4.1.2

I've been struggling to get this working for about 2 days now. I was able to POST a request directly from sockets, but it took me a while to see it working with HTTPClient-4.1.2. There are different variants out there in google for legacy HTTPClient and less than 4.1.x.
The key was to specify TrustManager and KeyManager while initializing SSLContext.

Step-1: First, you have to initialize SSLContext like this:

SSLContext ctx = SSLContext.getInstance("TLS");

Step-2: Getting TrustManager. Java look into its trust managers to check against authorized Certification Authorities(CA). Default trust store in Java is "jks". This is how you can get trust manager:
TrustManager[] getTrustManagers(String trustStoreType, InputStream trustStoreFile, String trustStorePassword) throws Exception {
KeyStore trustStore = KeyStore.getInstance(trustStoreType);
trustStore.load(trustStoreFile, trustStorePassword.toCharArray());
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmfactory.init(trustStore);
return tmfactory.getTrustManagers();
}

It should be called as:
TrustManager[] trustManagers = getTrustManagers("jks", new FileInputStream(new File("/Library/Java/Home/lib/security/cacerts")), "changeit");

/Library/Java/Home/lib/security/cacerts is the default path to trust managers in Mac OSX

Step-3: Getting KeyManager: This is where your client certificates are stored. KeyManager in the code can be retrieved as :
KeyManager[] keyManagers = getKeyManagers("pkcs12", new FileInputStream(new File("clientCertificate.p12")), "password");

You have to get KeyManagers using KeyManagerFactory like this:

KeyManager[] getKeyManagers(String keyStoreType, InputStream keyStoreFile, String keyStorePassword) throws Exception {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(keyStoreFile, keyStorePassword.toCharArray());
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmfactory init(keyStore, keyStorePassword.toCharArray());
return kmfactory.getKeyManagers();
}

Step-4: Once you have TrustManager and KeyManager ready, pass them in SSLContext:
ctx.init(keyManagers, trustManagers, new SecureRandom());

Step-5: Now create a SSLSocketFactory object using SSLContext object:
SSLSocketFactory sf = new SSLSocketFactory(ctx, new StrictHostnameVerifier());

Step-6: Assign Scheme to the HttpClient:
DefaultHttpClient httpclient = new DefaultHttpClient();
ClientConnectionManager manager = httpclient.getConnectionManager();
manager.getSchemeRegistry().register(new Scheme("https", 443, sf));

Done !
Now use this httpclient in HttpPost, HttpGet ….

My take on setting up Jenkins for PHP project on Mac OSX

I've found many good articles on setting up Jenkins for PHP projects. But couldn't get one which is targeted to Mac OSX. Here is the one, I followed to setup Jenkins for myself. I took following steps to setup one on Mac OS:

1- Installing php5 and pear using mac-ports: sudo port install php5 +pear
Enable libphp5.so module in apache configuration file: /etc/apache2/httpd.conf

2- Installing/configuring xdebug using macports:
command: sudo ports install php5-xdebug
Macports automatically put xdebug.so in /opt/local/lib/php/extensions/no-debug-non-zts-20090626

Copy xdebug config in /etc/php.ini
[xdebug]
zend_extension="/opt/local/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

Check debug installtion:
php -r 'var_dump(extension_loaded("xdebug"));'

3-Install ant using macports
sudo port install apache-ant
Macports installs ant in : /opt/local/bin/ant

4- Follow this tutorial for creating demo project and other steps:
http://edorian.posterous.com/setting-up-jenkins-for-php-projects

I had trouble in installing phpunit. I had to do install following packages as well in addition to the packages mentioned in above tutorial:
sudo pear install -f Net_URL2-0.3.1
sudo pear install HTTP_Request2-2.0.0RC1
and then
sudo pear install --alldeps phpunit/PHPUnit

5- Jenkins jobs folderis located at: /Users/Shared/Jenkins/Home/jobs/
6- Restart jenkins using : java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart
7- Reloading jenkins configuration: java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration
8- Checkout php-template job from this tutorial and reload configuration
9- You are Done !
10- Play around the Jenkins :-)

Linux command to find file names for matching pattern

Here is command to get files which contains the given pattern. For example, if you are trying to find "Got my text" in current directory and its sub directories, then following command will give line numbers along with file names that contains that text:

grep "Got my text" -nr ./*

Installing git-svn on Mac

git-svn can be installed on Mac using macports. Just this will do:
sudo port install git-core +svn

Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .