Palindrome word checker.

This post is again for performance test (yes I like to play with this kind of stuff).
The task is to check if given word is palindrome?
I wrote isWordPalindrome and isWordPalindrome2 and both implementation can be seen below.

The test was to execute 1000000 times palindrome word checker and for words "neven", "nevven", "evven", "bib" and ipp".
I executed on brand new machine several times and I find out average result, which is:

isWordPalindrome   - executed for 1.535 seconds.
isWordPalindrome2 - executed for 4.974 seconds.
 
Read more

Two implementations of Game cards ordering written in PHP

This idea of this post is similar to my previous one. It's again for performance, but for a different task. This time, it's for cards ordering.
I wrote it in two different ways:

     1. Using a predefined array with other I want.
     2. Exploding cards value when I need to compare them.

Exploding cards value when I need to compare them.
You can find both implementations below, but just before then I want to share the significant performance difference between both ways based on the test I did.
The test was to execute 1000000 times ordering method with initial sets of cards order "4D", "4H", "4S", "4C", "10H" (after first iteration cards will be ordered and action will not change they order, but that is not the idea of the this post).
 
Read more

Reverse words order

Recently I needed to write function which order words in reversal. For example if we gave "AAA BBB CCC" it must return "CCC BBB AAA".
When I hear that in my mind occurred two implementation and I wrote both of them. In the end I decide to make performance test and the result was quite interesting.

I executed 1000000 times word_order_reverse1 and words_reverse2 with same input words "AAA BBB CCC".
Also I made it several times in brand new VPS to be sure it's not affected by my CPU load. The average result shows:

Time: 1.8467 Seconds (for word_order_reverse1)
Time: 3.3945 Seconds (for word_order_reverse2)
 
Read more

Docker image size reducer

Using a Docker give us great opportunity to move server instances from one machine to another in cloud or in bare metal servers, but sometimes it’s has some price like storage that Docker use. For example after moving one of my Docker instances with creating images it was using 3+GB so I figure out how to reduce this state to acceptable size of 670 MB.

The solution is export a Docker image and import it back. I wrote two bash functions which make those actions. The both functions are making same things. First one use containers as entry point and second one use already created images.

Warning: This will delete all previous versions of this Docker instance.
# Reduce docker image size by removing history of image
function docker-image-reduce-by-container() {
        DOCKER_CONTAINER_ID=$1
        DOCKER_NEW_IMAGE_NAME=$2
        if [ ${#DOCKER_CONTAINER_ID} == 0 ]; then
                echo "Current container id is required as first parameter."; exit
 
Read more

Install Selenium on Docker

I am gone to show how to run Selenium server and Selenium PHP client driver especially the Facebook version.
For more information about that driver you can get from here.

NOTE: If you don't want to through whole process and you have installed docker, just pull it from my docker hub repo at: https://registry.hub.docker.com/u/gzekiii/selenium-with-php-facebook/

For example:
 docker run -it -h selenium --name="selenium" -p=80:80 gzekiii/selenium-with-php-facebook /bin/sh -c "if [ -f /run.sh ]; then bash /run.sh; fi; exec /bin/bash"
 
Read more