Sync up Docker container time with Host’s

I’ve had some issues with my application’s user session being expired as soon as it got created. After further investigation, it was due to the fact that docker container’s time was far behind the current PDT(which is where I am and a default timezone for all my servers).

Easiest solution was to mount these two files from host to any containers:

After the two lines of docker volume, viola. Time synced between host and container.

Bye bye data-only container! Hello named volume!

Persistent data practice that I’ve been using with Docker has been the host volume although I knew that data-only container pattern existed.

So this time around, I was going to start utilizing data-only container pattern for some of db containers. However, I got to know that after docker version 1.9.0.

For example with data-only container pattern, we would have a docker-compose file like this:

However, a better approach would be:

merging two git repos with history

I needed to merge two repos with history so that the target repo has merging repo’s history. This answer at stackoverflow had solved my issue.

So that was to merge project-a into project-b.

One thing I need to note is that project-b and project-a have to be git-cloned already, so prerequisite for the above the order of execution was as follows:

Also, don’t forget to commit your changes after the merge.

Simple Http Server on Mac

While working on html/css/js, it’s convenient to view those pages from http server. However, I don’t want to use MAMP or Virtual machine to set up nginx/apache.

I found this pro tip from this.

So I ended up with adding an alias to my .bash_profile file as follows:

Note that port number below 1024 cannot be bound as a normal user. This is meant to simply run a http server for development purpose. Do not use it to run your web application.

in Tips | 98 Words

Simple way to convert NodeList into Array in javascript

So what is going on with the above statement? Here’s what’s going on:

  1. getElementsByTagName does not return Array object. Instead it returns NodeList (You can easily test it out on the developer tools. i.e. document.getElementsByTagName(‘li’).constructor)
  2. NodeList does not have array methods. Prototype type chain is not connecting to array prototype at all. (NodeList.prototype.__proto__.constructor == Object)
  3. slice returns a new array object so using slice against NodeList converts NodeList into Array

VirtualBox and VBoxVmService for browser testing

When it comes to browser testing, I had struggled to keep an user session open for testing box when Jenkins initiated a browser testing job. So my solution for that was to run VirtualBox and VBoxVmService so that each virtual box runs as a windows service and it worked out very nicely for my purpose.

I used VirtualBox 4.2.18 and some settings are:

  • Network settings
    • Adapter 1 for NAT(for outbound)
    • Adapter 2 for Host-only (for inbound)


  • Download
  • It makes a virtualbox machine run as a window service in headless mode
  • When Virtualbox machines run as a window service, VirtualBox should not be run. They cannot run simultaneously.
  • Add a list of VBox machines in VBoxVmService.ini file as seen below:

in Tips | 149 Words

vmware fusion and shared directory on a host machine

I’m using vmware fusion to create many development environments so that I have completely isolated ubuntu for client A, windows 2008 server R2 for client B, centos for client C, and so on.

Actually it was several months ago, but I was bothered to find a solution to this weird bug couple days.

On vm ubuntu, every time I use *composer* to update PHP project dependencies I end up with php parse error. They look something like this:

  • PHP Parse error: syntax error, unexpected ‘)’ in …
  • PHP Parse error: syntax error, unexpected ‘F’ in …
  • PHP Parse error: syntax error, unexpected $end
  • and so on…

BTW the temporary solution was to open a file, save, and then quit vim.

To fix the issue better than the temporary solution was:

  1. sudo (on the vm ubuntu)
  2. sudo apt-get install open-vm-tools

Since then I have not had the same issue before. Some reported that the solution that I took steps stopped working for them, but it wasn’t the case for me.

Jenkins for php project on centos 6.2

After setting up Jenkins for use in my work place, I had to document how to set up in the past couple days. I thought I would share it here.

OS: CentOS release 6.2 (Final)
[—— ~]$ cat /proc/version
Linux version 2.6.32-220.23.1.el6.x86_64 ( (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Mon Jun 18 18:58:52 BST 2012
[—— ~]$ uname -a
Linux jenkins.sometrics 2.6.32-220.23.1.el6.x86_64 #1 SMP Mon Jun 18 18:58:52 BST 2012 x86_64 x86_64 x86_64 GNU/Linux

Prerequisites prior to Jenkins

java-1.6.0-openjdk.x86_64 (64bits) - as of Jun 27, 2012
1. sudo yum install java-1.6.0-openjdk(this will pull these dependencies)
- giflib
- jline
- jpackage-utils
- rhino
- tzdata-java
2. actual version is 1:
Apache Ant 1.7.1 - as of Jun 27, 2012
1. sudo yum install ant (this will install these dependencies)
- java-1.5.0-gcj
- java-1.6.0-openjdk-devel
- java_cup
- libgcj
- sinjdoc
- xerces-j2
- xml-commons-api
- xml-commons-resolver
2. actual version is 1.7.1-13.el6

1. sudo rpm -Uvh
2. sudo yum install php54w php54w-cli php54w-common php54-dba php54-devel php54-gd php54-intl php54-mbstring php54-mysql php54-odbc php54-pdo php54-pear php54-process php54-xml (this will install these dependencies)
- autoconf
- automake
- libXpm
- libicu
- unixODBC

1. sudo pear upgrade PEAR
2. sudo pear channel-discover
3. sudo pear channel-discover
4. sudo pear channel-discover
5. sudo pear channel-discover
6. sudo pear channel-discover
7. sudo pear install --alldeps phpunit/PHPUnit
8. sudo pear install phpunit/DbUnit
9. sudo pear install phpunit/phpcpd
10. sudo yum install ImageMagick-devel (This will install these dependencies)
- bzip2-devel
- ghostscript-devel
- jasper-devel
- lcms-devel
- libICE-devel
- libSM-devel
- libX11-devel
- libXau-devel
- libXdmcp-devel
- libXext-devel
- libXt-devel
- libgomp
- libjpeg-devel
- libtiff-devel
- libwmf-lite
- libxcb-devel
- xorg-x11-proto-devel
- zlib-devel
11. sudo pear install --alldeps pdepend/PHP_Depend
12. sudo pear install theseer/phpDox-0.4.0 (note: this can take a while. Be patient)
13. sudo pear install PHP_CodeSniffer
14. sudo pear install --alldeps phpunit/PHP_CodeBrowser
15. pear channel-discover (it’s not working currently...)
16. sudo pear install phpmd/PHP_PMD (this will fail.... maybe server is down as of now and will be back up tomorrow perhaps? For now skip it.)

To install Jenkins through yum
1. sudo wget -O /etc/yum.repos.d/jenkins.repo
2. sudo rpm --import
3. sudo yum install jenkins
4. sudo service jenkins start/stop/restart

Jenkins should be accessible through port 8080
Make sure iptable opens the port 8080 from outside

Install Jenkins Plugins
1. go to http://{}:8080
2. Click on “Manage Jenkins” link from side menu
3. Click on “Manage Plugins” link from the page
4. Click on “Available” Tab
5. Check these plugins (Some might be missing because they could be already installed)
- External Monitor Job Type Plugin
- ant
- Static Code Analysis Plug-ins
- Subversion Plugin
- HTML Publisher plugin
- Jenkins Translation Assistance plugin
- Jenkins SSH Slaves plugin
- PMD Plugin
- Jenkins Clover PHP plugin
- Publish Over SSH
- Green Balls
- Jenkins Violations plugin
- Plot plugin
- Measurement Plots
- xUnit plugin
- Hudson SCP publisher plugin
- Checkstyle Plugin
- DRY Plugin
- Jenkins JDepend Plugin
6. Click on “Download now and install after restart”

There gotta be something I missed, but this instruction should be a good start to set up jenkins on centos 6.2 for any PHP development work.

Happy CI'ing! :)

mysqldump tip

mysqldump is a command line tool for exporting mysql data.
This tool also can be used to generate seed xml files for php dbunit.
And this is how you can achieve that.

mysqldump -u {user} -t –xml –databases {dbname} –tables {tablename} > filename.xml

The above command will generate a xml file that PHP DBUnit understands.

And then inside phpunit class file, you would be using it like this:

protected function getDataSet()

$seed = $this->createMySQLXMLDataSet(dirname(__FILE__).’/filename.xml’);
$datesets = array($seed);

$compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet($seed);

return $compositeDs;