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} ^firstDomaing.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.firstDomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.targetDomain\.com$1" [R=301,L]

#Redirecting second domain
RewriteCond %{HTTP_HOST} ^secondDomain.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondDomain.net$
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} ^firstDomaing.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.firstDomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^secondDomain.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondDomain.net$
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’]       = ‘http://www.my-domain.com’;
$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
$this->getHelper(‘layout’)->disableLayout();

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

//sending the HTTP headers and output the rss feed
$rssFeedFromArray->send();

}

}

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 http://twishort.com 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

December 25, 2009 / Samer Baydoun

OOP in PHP and Performance issues

When began with PHP, I used to write quick scripts, procedural, which served very well the small projects. But when uses OOP designs with PHP, I noticed the BIG difference in performance which went bad with the OOP.

PHP was not designed to be an Object Oriented Programming language, although there are very respectable attempts to make it so. I just thought about the future of the Object Oriented Design with the PHP, which is narrow in my opinion.

So why programmers should use PHP for OO designs while there are other languages such as Java?

November 24, 2009 / Samer Baydoun

Credibility of followers number on Twitter

As checking my twitter account I went through a post of a friend says “I just become a member of this AWESOME site that gets you TONS of followers: http://tinyurl.com/yzl59f7“. The site was billionfollowers.com. For a while I rushed to login, it’s a brilliant service that I could get. Before I click login button I noticed the “By logging in you agree with the T.O.S” check box checked. Reading the T.O.S was enough to make me think twice about my privacy, I decided to keep away from this.

But when reviewing the idea of this site (or any other similar sites) I wondered about the credibility of twitter account followers number, does the number of followers reflect the activity, trends or knowledge of the account owner?

October 22, 2009 / Samer Baydoun

Arabic right-to-left multi-level dropdown menu

I have developed an Arabic (right to left) multi-level dropdown menu based on “jQuery Multi Level CSS Menu #1” posted by Dynamic Drive.

HTML code

<DIV id=myjquerymenu class=jquerycssmenu>
<UL>
<LI><A href="#">بند رئيسي</A></LI>
<LI><A href="#">بند رئيسي</A></LI>
<LI><A href="#">بند رئيسي</A>
<UL>
<LI><A href="#">بند فرعي</A></LI>
<LI><A href="#">بند فرعي</A></LI>
<LI><A href="#">بند فرعي</A></LI>
<LI><A href="#">بند فرعي</A></LI>
</UL>
</LI>
<LI><A href="#">بند رئيسي</A> </LI>
<LI><A href="#">بند رئيسي</A>
<UL>
<LI><A href="#">بند فرعي</A> </LI>
<LI><A href="#">بند فرعي</A>
<UL>
<LI><A href="#">بند فرعي</A> </LI>
<LI><A href="#">بند فرعي</A> </LI>
<LI><A href="#">بند فرعي</A>
<UL>
<LI><A href="#">بند فرعي</A> </LI>
<LI><A href="#">بند فرعي</A> </LI>
</UL>
</LI>
<LI><A href="#">بند فرعي</A></LI>
</UL></LI>
</UL>
</LI>
<LI><A href="#">بند رئيسي</A> </LI>
<LI><A href="#">بند رئيسي</A> </LI>
</UL><BR style="CLEAR: left"></DIV>

CSS Code:

.jquerycssmenu {
	BORDER-BOTTOM: black 1px solid; PADDING-LEFT: 15px; FONT: bold 12px Verdana
}
.jquerycssmenu UL {
	PADDING-BOTTOM: 0px; LIST-STYLE-TYPE: none; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px
}
.jquerycssmenu UL LI {
	POSITION: relative; DISPLAY: inline; FLOAT: left
}
.jquerycssmenu UL LI A {
	BORDER-BOTTOM: #778 0px solid; BORDER-LEFT: #778 1px solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 7px; PADDING-RIGHT: 7px; DISPLAY: block;
DIRECTION: rtl; BACKGROUND: url(tintblue.gif) white repeat-x center top; COLOR: #2d2b2b; BORDER-TOP: #778 1px solid; MARGIN-RIGHT: 3px;
BORDER-RIGHT: #778 1px solid; TEXT-DECORATION: none; PADDING-TOP: 5px
}
.jquerycssmenu UL LI A:hover {
	BACKGROUND-IMAGE: url(tintbluedark.gif)
}
.jquerycssmenu UL LI UL {
	POSITION: absolute; DISPLAY: block; VISIBILITY: hidden; BORDER-TOP: black 1px solid; LEFT: 0px
}
.jquerycssmenu UL LI UL LI {
	DISPLAY: list-item; FLOAT: none
}
.jquerycssmenu UL LI UL LI UL {
	TOP: 0px
}
.jquerycssmenu UL LI UL LI A {
	BORDER-BOTTOM: black 1px solid; PADDING-BOTTOM: 4px; MARGIN: 0px; PADDING-LEFT: 5px;
WIDTH: 160px; PADDING-RIGHT: 5px;
FONT: 13px Verdana; DIRECTION: rtl; BACKGROUND: white;
BORDER-TOP-WIDTH: 0px; COLOR: black;
PADDING-TOP: 4px
}
.jquerycssmenu UL LI UL LI A:hover {
	BACKGROUND: #eff9ff; COLOR: black
}
.downarrowclass {
	POSITION: absolute; TOP: 7px; LEFT: 5px
}
.rightarrowclass {
	POSITION: absolute; TOP: 5px; LEFT: 5px
}

JavaScript Code:

var arrowimages={down:[‘downarrowclass’, ‘arrow-down.gif’, 25], right:[‘rightarrowclass’, ‘arrow-right.gif’]}

var jquerycssmenu={

fadesettings: {overduration: 350, outduration: 100}, //duration of fade in/ out animation, in milliseconds

isRTL : true, //For arabic (or right-to-left) templates set it to True;

buildmenu:function(menuid, arrowsvar){

jQuery(document).ready(function($){

var $mainmenu=$(“#”+menuid+”>ul”)

var $headers=$mainmenu.find(“ul”).parent()

$headers.each(function(i){

var $curobj=$(this)

var $subul=$(this).find(‘ul:eq(0)’)

this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}

this.istopheader=$curobj.parents(“ul”).length==1? true : false

$subul.css({top:this.istopheader? this._dimensions.h+”px” : 0})

$curobj.children(“a:eq(0)”).css(this.istopheader? {paddingLeft: arrowsvar.down[2]} : {}).append(

‘<img src=”‘+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])

+'” class=”‘ + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])

+ ‘” style=”border:0;” />’

)

$curobj.hover(

function(e){

var $targetul=$(this).children(“ul:eq(0)”)

this._offsets={left:$(this).offset().left, top:$(this).offset().top}

var menuleft=this.istopheader? this._dimensions.subulw – this._dimensions.w -15 : this._dimensions.w

if(jquerycssmenu.isRTL)

menuleft=(this._offsets.left<this._dimensions.subulw)? (this.istopheader? -(this._dimensions.subulw – this._dimensions.w) : this._dimensions.subulw ) : -menuleft

else

menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuleft

$targetul.css({left:menuleft+”px”}).fadeIn(jquerycssmenu.fadesettings.overduration)

},

function(e){

$(this).children(“ul:eq(0)”).fadeOut(jquerycssmenu.fadesettings.outduration)

}

) //end hover

}) //end $headers.each()

$mainmenu.find(“ul”).css({display:’none’, visibility:’visible’})

}) //end document.ready

}

}

//build menu with ID=”myjquerymenu” on page:

jquerycssmenu.buildmenu(“myjquerymenu”, arrowimages)

 

Files

Click here to download all files.

<DIV id=myjquerymenu class=jquerycssmenu>

<UL>

<LI><A href=”#”>بند رئيسي</A></LI>

<LI><A href=”#”>بند رئيسي</A></LI>

<LI><A href=”#”>بند رئيسي</A>

<UL>

<LI><A href=”#”>بند فرعي</A></LI>

<LI><A href=”#”>بند فرعي</A></LI>

<LI><A href=”#”>بند فرعي</A></LI>

<LI><A href=”#”>بند فرعي</A></LI>

</UL>

</LI>

<LI><A href=”#”>بند رئيسي</A> </LI>

<LI><A href=”#”>بند رئيسي</A>

<UL>

<LI><A href=”#”>بند فرعي</A> </LI>

<LI><A href=”#”>بند فرعي</A>

<UL>

<LI><A href=”#”>بند فرعي</A> </LI>

<LI><A href=”#”>بند فرعي</A> </LI>

<LI><A href=”#”>بند فرعي</A>

<UL>

<LI><A href=”#”>بند فرعي</A> </LI>

<LI><A href=”#”>بند فرعي</A> </LI>

</UL>

</LI>

<LI><A href=”#”>بند فرعي</A></LI>

</UL></LI>

</UL>

</LI>

<LI><A href=”#”>بند رئيسي</A> </LI>

<LI><A href=”#”>بند رئيسي</A> </LI>

</UL><BR style=”CLEAR: left”></DIV>