Skip to content
April 12, 2015 / Samer Baydoun

Baby Step TDD

At one of the Softwareskammer’s sessions in Munich, we were introduced to a new practice of Test Driven Development called Baby Steps.

The Baby Step TDD came up as a solution for the problem of TDD when sometimes you write a test which forces you to implement too many changes in one step to make the test pass.

As known, the main cycle in the TDD is described as follow:

  1. Start
  2. Write a failing test
  3. Write code to make test pass (then goto 2, or if can’t think of more tests, refactor)
  4. Stop

With the Baby Step we had to do the same cycle but with an extra constraint that it must be done in 2 minutes. So at the end of each cycle the test must be “green” (test passes).

Now, the most painful condition was that if you finish on red you have to roll back your changes to the last “green” state.

We had to write Java code printing diamond, as described in Seb Rose’s post, and use git for committing the “green” code at the end of each cycle or rolling back “git reset –hard HEAD” when it is “red”.

From my point of view, in spite of the fact that the rolling back after each red cycle drove me crazy, I think the method is good in a way that it forces me to divide the problem to small problems and write more cohesive chunks of code while trying to keep the test passing in 2 minutes.

Putting this practice in production, once understood correctly, will guaranty a better code quality on the long run; however, it may not seem a good idea for some developers, as it presents a relatively slow process.

September 19, 2011 / Samer Baydoun

Why Trim function saves money

The answer simply: because it saves developer’s time.

In one of the php/Mysql websites I faced a problem with the sort order of some multilingual data. Usually when someone sort order such column, they get the English text first then the other languages like Arabic:

English text 1

English text 2

نص عربي 1

نص عربي 2

But what I have got was something like:

نص عربي 2

English text 2

English text 1

نص عربي 1

Actually some previous transportation processes of the database as well the high distortion of the sorted data made me thought that I have an encoding problem.

After 3 hours of work, trying to check the original encoding of data, I suddenly found that the web admin enters white spaces at the beginning of the entry very frequently. Although this made me smiling, as it saved me from falling in the hell of double-encoding problems, it pushed me to put a new ‘Must’ on my programming practices rules list.

The rule is the use of trim() function wherever the user has to enter data.

January 22, 2011 / Samer Baydoun

Fixing CPanel problem in redirecting domains to a URL friendly website

On one of the websites on an Apache server, I wanted to redirect two additional domain names to the main one, while using rewriting engine for URL friendly feature. I tried to use for that  the Redirect tool of CPanel with the Wild Card Redirect check. But like anything in a developer’s working life, it doesn’t work as one needs. The two domains didn’t work, with a “Server Not Found” error.

Back to the .htaccess file that the Cpanel modified I have found that the redirecting code is inserted after my friendly URL code:

RewriteEngine on
#URL Friendly
RewriteRule ^js/ - [L]
RewriteRule !\.(js|css|htm|gif|jpg|png)$ index.php

#Redirecting first domain
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$ "http\:\/\/www\.targetDomain\.com$1" [R=301,L]

#Redirecting second domain
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$ "http\:\/\/www\.targetDomain\.com$1" [R=301,L]

Putting the URL friendly code after the redirecting code solved the problem. But wait, it still gives the “Server Not found” error when referring to a sub-directory at one of the redirected domains. To fix this I just needed to add \/? at the beginning of the redirecting RewriteRule so that it redirects the sub-directory to the root directory of the target domain.

But what if I need to redirect a sub-directory of the redirected domain to the same path at the target domain. To do it, I replaced $1 with %{REQUEST_URI} at the end of the same line. And with some refinement, I’ve got the code working properly:

RewriteEngine on

#Redirecting domains
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^\/?(.*)$ "http\:\/\/www\.targetDomain\.com%{REQUEST_URI}" [R=301,L]

#URL Friendly
RewriteRule ^js/ - [L]
RewriteRule !\.(js|css|htm|gif|jpg|png)$ index.php
July 17, 2010 / Samer Baydoun

RSS Feeds in Zend Framework

This example shows how to output an RSS feed using Zend_Feed component. The example supposes that you have a News class that extends Zend_Db_Table class in your models and you included the Zend_Feed component in your Zend Framework library.

class NewsController extends Zend_Controller_Action

function rssAction()

$table = new News();
//Get the last 10 news.
$rows = $table->fetchAll(null,”sort_order”,10);
//Create an array for our feed
$rss = array();

//Seting up the head information of the rss feed
$rss[‘title’]      = “RSS Title Here”;
$rss[‘link’]       = ‘’;
$rss[‘published’]     = time(); //Set the published date to now
$rss[‘charset’]       = ‘utf-8’;
$rss[‘language’]     = ‘ar-sa’; //for Arabic language
$rss[‘logo’] = “http://path/to/logo.gif”;
$rss[‘entries’]       = array();//Which holds the actual news items

//Looping through the news to add them to the ‘entries’ array.

foreach($rows as $row){

$entry = array(); //Container for the entry before we add it on
$entry[‘title’]     = $row->news_title; //The title of the news
$entry[‘link’]         = “http://url/of/the/news/details/page”;
$entry[‘description’]     = $row->news_brief; //a brief of the news
$entry[‘content’]     = $row->news_details; //details of the news

$rss[‘entries’][]     = $entry;


$rssFeedFromArray = Zend_Feed::importBuilder(new Zend_Feed_Builder($rss), ‘rss’);

//disabling the layout

//printing the rss feed to standard output
print $rssFeedFromArray->saveXML();

//sending the HTTP headers and output the rss feed



March 28, 2010 / Samer Baydoun

What to call Twishort Twitter Service, Microblogging or Blogging?

Before closing my laptop to go bed, I’ve got a mention on twitter says “@samer_baydoun use new service when 140 characters just isn’t enough. 😉. I hurried to try it.

I found a twitter service that’s all about cuting the long post to the allowed limit and automatically posting it to Twitter with a link.  Following that link will show the whole post at Twishort page.

On Twishort website they present the service as:

“We really love Twitter for the limit of 140 characters. But sometimes there is a need to give a long answer, clarify challenging question, quote somebody’s words, etc. There are good thoughts, but not as meaningful for the blog, or just thoughts, for which 140 characters is not enough.”

But this way Twitter will play the role of chat/IM, which is away from its concept. So is Twishort seeing twitter as an IM client that needs help?

From another perspective, Twishort is trying to make micro posts longer while blogging is trending more towards microblogging, so what kind of trend is it? are we getting to milliblogging?

I am wondering about the future of this twitter service, and will be wondering more if it succeeded.

March 24, 2010 / Samer Baydoun

Statistics of Internet Usage in the Arab World (MENA Region)

For whom having questions like “what are the number of internet users in the Arab world”, “Who is the biggest online market in the MENA region?”, I tried to find answers. I collected the following information from the Internet World Stats website.

List of Internet Usage  statistics in the Arabic Countries

Here is a list of the Arabic countries with their internet usage statistics ordered from the highest usage to the lowest (by the latest data):

Population (2009 Est.) Usage, in Dec/2000 Internet Usage, Latest Data (2009) % Population (Penetration) User Growth (2000-2009) (%) of Table
1 Egypt 78,866,635 450,000 12,568,900 15.9% 2693.1% 18.7%
2 Morocco 31,285,174 100,000 10,300,000 32.9% 10200.0% 15.3%
3 Saudi Arabia 28,686,633 200,000 7,700,000 26.8% 3750.0% 13.4%
4 Sudan 41,087,825 30,000 4,200,000 10.2% 13900.0% 6.2%
5 Algeria 34,178,188 50,000 4,100,000 12.0% 8100.0% 6.1%
6 Syria 21,762,978 30,000 3,565,000 16.4% 11783.3% 6.2%
7 United Arab Emirates 4,798,491 735,000 2,922,000 60.9% 297.6% 5.1%
8 Tunisia 10,486,339 100,000 2,800,000 26.7% 2700.0% 4.2%
9 Jordan 6,269,285 127,300 1,500,500 23.9% 1078.7% 2.6%
10 Kuwait 2,692,526 150,000 1,000,000 37.1% 566.7% 1.7%
11 Lebanon 4,017,095 300,000 945,000 23.5% 215.0% 1.6%
12 Oman 3,418,085 90,000 465,000 13.6% 416.7% 0.8%
13 Qatar 833,285 30,000 436,000 52.3% 1353.3% 0.8%
14 Bahrain 728,709 40,000 402,900 55.3% 907.3% 0.7%
15 Yemen 22,858,238 15,000 370,000 1.6% 2366.7% 0.6%
16 Palestine(West Bk.) 2,461,267 35,000 355,500 14.4% 915.7% 0.6%
17 Libya 6,324,357 10,000 323,000 5.1% 3130.0% 0.5%
18 Iraq 28,945,569 12,500 300,000 1.0% 2300.0% 0.5%
19 Eritrea 5,647,168 5,000 200,000 3.5% 3900.0% 0.3%
20 Somalia 9,832,017 200 102,000 1.0% 50900.0% 0.2%
21 Mauritania 3,129,486 5,000 60,000 1.9% 1100.0% 0.1%
22 Gaza Strip 1,551,859 n/a n/a n/a n/a n/a
TOTAL 349,861,209 2,515,000 54,615,800 20.8% 5836.9%

The biggest Market

Egypt’s Internet users are the highest number with 12,568,900 users which is 18.7% of the total Arab Internet users, followed by Morocco and Saudi Arabia.

Statistics of internet usage in Arab world - Arabic users number

Statistics of internet usage in Arab world - Arabic users number

Internet Usage Penetration

The following chart shows that the UAE has the highest percentage of population in using Internet, followed by Bahrain and Qatar:

Statistics of internet users nubmers penetration in Arab countries (percentage of population)

Statistics of internet users numbers penetration in Arab countries (percentage of population)

The highest growth online

Even being at the bottom of the Penetration list, Somalia has the highest growth by achieving 50,900% (from 200 users to 100,000 in about 9 years), followed by Sudan and Syria:

Statistics of Internet usage growth in Arab countries

Statistics of Internet usage growth in Arab countries

Still wondering how much these numbers are accurate, but it may give an overview of the situation in our Arab world.

January 20, 2010 / Samer Baydoun

Twitter is over capacity

Twitter is over capacity at 12:01 pm GMT on Wednesday 20th January 2010 🙂
Wondering why??
Twitter is over capacity