Archive for category Programming

Printing data table vertically..! Why? and How?

Last week one of my friend called me up as he got stuck when he has to print data table vertically. Yes vertical table, it means that you want your data to print from top to bottom and not left to write, which is standard conventional way to generate html table.

Vertical Table (Printing array data from top to bottom)

Vertical Table (Printing array data from top to bottom)

I took it as a challenge and wrapped that up in few minutes. But at that time I was so close to the problem that I could not see that PHP has some inbuilt functions which can help me do that and I did it other way around without using inbuilt PHP function. Here is the sample code for the same, which prints table vertically with the help of inbuilt PHP function array_chunk.

Array is the most powerful feature of PHP and playing with array is always been fun.

Sample code below uses array_chunk but I must say it was not a great help but it makes you less logic.!
// Function to print array data vertically
function print_vertical_table_sys($data_list, $rows)
{
	$columns = (count($data_list)/$rows);
	$data_list = array_chunk($data_list, $rows);
 
	echo '
<table border="1" style="border-collapse:collapse">';
	for($row_index = 0; $row_index < $rows; $row_index++)
	{
		echo '
<tr>' . "\r\n";
		for($column_index = 0; $column_index < $columns; $column_index++)
		{
			echo '
<td>' . $data_list[$column_index][$row_index] . '' . "\r\n";
		}
		$column_index = 0;
		echo '' . "\r\n";
	}
	echo '</table>
 
';
}
 
// Function Usage
$list = array();
for($i = 0; $i &lt;= 59; $i++)
{
	$list[] = $i+1;
}
//print_vertical_table_sys ($list, 10);

Now my question to you is how would you do that if you come across such requirement? Assume that you have list of array items starting from 1, 2, 3, ..... N and you want to print it with fixed length rows which starts like 1 and next cell will have 11 or something similar (similar to what you see in above image).

It's not that difficult but I would suggest give it a try and you will enjoy. Doesn't matter what technology you work with as the example which I will show you not will not use any functionality specific to PHP. Basically above code snippet is very close to that but I would suggest that before reading further more you give it a try. Come out of your regular work and make this fun exercise. Read the rest of this entry »

Tags: , , , ,

The perfect regular expression for email validation

Okey..! You are looking for "The perfect regular expression for email validation......" aaah..! That's great. I have come across an article as author has done lot of analysis to find out the perfect regular-expression and benchmark it against hundreds of test-cases.

My favorite is James Watts and Francisco Jose Martin Moreno's following one which uses preg_match:

/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i
Email Regular-Expression - Test-Case Run

Email Regular-Expression - Test-Case Run

Checkout this archived article here and let us know hat's your favorite regular-expression for email-validation?

Tags: , ,

Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found.

Couple of days back I got a complaint from one of the client who recently changed their deployment for one of the Portal we have been developing and the complaint was "Portal does not work in Internet Explorer." The same old great song.

I looked at the error, users were unable to download files from Portal over secure-HTTP (HTTPS). I tried it couple of times and found that it's not working really. Error was consistent from IE6 to IE8.

We have to fix this and to begin with I just googled-up with the error message I was getting. "Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later." Thankfully I got decent amount of Google search results and in first 2 or 3 I found a post from Mark Kolich sharing his similar experience with Internet Explorer and digging in more about that bug.

You can read more about this on Mark's post here on his website. But simple enough it was just a one line fix for the PHP guys. Yes, we have to add following line to get rid of the error message.

header("Pragma: ");

Simply just remove the Pragma headers from your force-download code and you're done.

Tags: , , ,

AG_E_PARSER_BAD_PROPERTY_VALUE

Error Reporting in Silverlight is really bad. One of the most common error you see whiled developing a Silverlight application
is AG_E_PARSER_BAD_PROPERTY_VALUE.
This error mostly occurs due to following,

Version Change in assemly while you are working in the same code (i.e. you used version x initially and later on you changed it to version x + y ). Some Assemblies in 3rd party control when upgraded do not support few older properties or methods.

Your XAML code is referring to some event which is not present in the code behind file. Make sure that all XAML code has relevant code in code behind file. (Remove any unnecessary Events from XAML and CS files)

Your XAML code has repeated the same code again, causing a clash.

Hope this helps

Tags:

A Mind Teaser – good one..!

To improve our programming skills and as a part of self-improvement exercise we are supposed to spend sometime every week as a part of Company Policy. Last fortnight my team has put their mind on test with one puzzle (passed on to us by other programming department) and it went quite well for everyone.

It was more about basic math rather than programming and it was good to see everyone refreshing their mind with roots of math/programming. I am sharing this puzzle/question on my blog and want my reader to put their mind and some of their time to crack this and put down their results as comments on this post.

Here we go: Read the rest of this entry »

Tags: ,

Paying the bills.!