How to Backup and Restore a MySQL database

April 29, 2008 · Filed Under MySql · 4 Comments 

I have seen a lot of people asking about a tutorial on how to backup and restore a MySQL database. Well, these are some very easy and quick steps that will walk you through this process.
Read more

How to Convert Pdf to Tiff

April 14, 2008 · Filed Under PHP · Comment 

If you are looking for an easy open source solution on how to convert a pdf to tiff and you are reading this article you may just got lucky today, because it tooks me more than four hours to get to this point.

There are many reasons to convert a pdf to a tiff format, in my case it was a simple conversion that will provide a specifics tiff format (Group 4) to be emailed (using PHP mail function) to a fax machine then faxed to the receptionists.

Read more

PHP: Automatic ellipsis for blocks of text

April 11, 2008 · Filed Under PHP · Comment 

This little function will help you truncate a string to a specified length when copying data to a place where you can only store or display a limited number of characters, then it will append “…” to it showing that some characters were removed from the original entry.

  1. function addEllipsis($string, $length, $end=‘…’)
  2. {
  3.   if (strlen($string) > $length)
  4.   {
  5.     $length -=  strlen($end);  // $length =  $length – strlen($end);
  6.     $string  = substr($string, 0, $length);
  7.     $string .= $end;  //  $string =  $string . $end;
  8.   }
  9.   return $string;
  10. }

Well this is very straightforward isn’t it? Anyways let’s explain how this works: The function take 3 arguments; the string to truncate, the maximum length allowed, and a default text, typically “…”.
We first start by checking the string length against the maximum length allowed. If it’s is greater than the max length then we have to trim the string to the specified length, otherwise we return it intact.

Trimming the string is very easy:
1- Recalculate the max length by subtracting the extra text length from it.
2- Truncate the string to the new length.
3- Append the extra text then return the new value.

You like short code, then you got it:

  1. function addEllipsis($string, $length, $end=‘…’)
  2. {
  3.   return (strlen($string) > $length) ? substr($string, 0, $lengthstrlen($end )) . $end : $string;
  4. }

I hope this will help :-)

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Conditional Statements in PHP

April 8, 2008 · Filed Under PHP · Comment 

Just like in any other development language, PHP make use of the conditional statements to perform different actions based on different conditions and situations.

PHP offers three types of conditional statements:

  • if…else statement,
  • elseif statement,
  • switch statement,
  1. if…else statement:
  2. This statement is used if we want to execute a set of code when a condition is true and another one or none if the condition is false

    1-1 Syntax
    1. if (condition) {
    2.   statements_1
    3. } [else {
    4.   statements_2
    5. }]

    if condition is true, statement_1 is executed. if the optional else clause is specified, statement_2 will take place if the condition is false.

    1-2 Example

    The following example reflect a “traffic light” scenario:

    1. if ($light == "green") {
    2.   echo "Go!";
    3. } else {
    4.   echo "Stop!";
    5. }

    the same scenario can be described as

    1. $msg = "Stop!";
    2. if ($light == "green")
    3.   $msg = "Go!";
    4. echo $msg;

    but I like to use the following short code instead

    1. <?php echo ($light == "green") ? "Go!" : "Stop!"; ?>

    the same as

    1. <?= ($light == "green") ? "Go!" : "Stop!"; ?>

    or

    1. $msg = ($light == "green") ? "Go!" : "Stop!";
    2. echo $msg;

    Note: Open and Close brackets are optional if the set of code to be executed is only one statements.

    1. if ($light == "green")
    2.    echo "Go!";
    3. else
    4.    echo "Stop!";

    When evaluating a boolean expression to true or false use the operator “===” or “!==” instead of “==” or “!=”

    1. if ($green_light === true) {
    2.    echo "Go!";
    3.    echo "I Said Go!";
    4. } else
    5.    echo "Stop!";

    Note: Try to combine as many conditions as you can using the logic operator || (or), && (and) etc… instead of breaking your code to multiple statements.

  3. elseif statement:
  4. This statement is used if the set of code to execute depend on a sequence of multiple conditions.
    2-1 Syntax

    1. if (condition_1) {
    2.    statement_1
    3. }
    4. [elseif (condition_2) {
    5.    statement_2
    6. }]
    7. [elseif (condition_n-1) {
    8.    statement_n-1
    9. }]
    10. [else {
    11.    statement_n
    12. }]
    2-2 Example

    In the previous “traffic light” example we had only two cases, either the light is green or unknown. We wanted the drivers to stop in all cases except when the light is green. but this is not what we see in a real life. Let’s change this light color to “white”, rotate it little bit and keep it for our pedestrians. In this example we will be dealing with a typical “traffic light”.

    1. if ($light == "green") {
    2.     echo "Go!";
    3. } elseif ($light == "yellow") {
    4.     if ($light == "flashing")
    5.          echo "Slow down and be especially alert!";
    6.     else
    7.         echo "Slow down and be prepared to Stop!";
    8. } else {
    9.      echo "Stop!"
    10. }
    2-3 The if(); elseif(); else; endif;`alternative’:
    1. if ($light == "green") :
    2.     echo "Go!";
    3. elseif ($light == "yellow") :
    4.     if ($light == "flashing") :
    5.          echo "Slow down and be especially alert!";
    6.     else :
    7.         echo "Slow down and be prepared to Stop!";
    8.     endif;
    9. else :
    10.     echo "Stop!";
    11. endif;
    12. }

    Obviously, there is more complex cases. Some “traffic light” have an orange color instead of yellow, a flashing red and a flashing green may be. anyways in this case using the previous conditional statement become ambiguous, very complex, and hard to maintain. As a best practice using the “switch” statement comes more handy in terms of readability than a sequence of if elses.

  5. switch statement:
  6. The “switch” statement have the same magic effect as a sequence of “if elses”, only that the switch statement provide a non-iterative choice between any number of set of code based on specified conditions. it compare an expression to a set of labels and select any matching ones. An optional default case is executed if no much was found.
    1-1 Syntax

    1. switch (expression) {
    2.    case label_1:
    3.       statements_1
    4.       [break;]
    5.    case label_2:
    6.       statements_2
    7.       [break;]
    8.    …
    9.    case label_n-1:
    10.       statements_n-1
    11.       [break;]
    12.    [default:
    13.      statements_n
    14.      [break;]]
    15. }
    3-2 Example

    Back to our “traffic light” example with “switch”:

    1. switch ($light) {
    2.    case "green":
    3.       echo "Go!";
    4.       break;
    5.    case "Orange":
    6.       echo "Slow down and be prepared to Stop!";
    7.       break;
    8.    case "yellow":
    9.       echo "Slow down and be prepared to Stop!";
    10.       break;
    11.   case "flashing":
    12.       echo "Slow down and be especially alert!";
    13.       break;
    14.    default:
    15.      echo "Stop!";
    16.      break;
    17. }

    You can imagine any scenario you want and make this example more accurate. the default statement will take place if the light is “red” or in any non specified case like when a light is broken or any other strange case that may occur.
    Note: The switch can be a little tricky, especially because you can easily forget to place the terminating colons, the break statement, or forget some conditions. I personally always use the optional “default” case, it’s like handling exceptions.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

F.R.C. 1383 S. Missouri Ave Clearwater, FL 33756-6500

April 8, 2008 · Filed Under Lifestyle · 14 Comments 

You have just received that wonderful little yellow card that was waiting in your mailbox today and you are so curious to know what is it about. Well you are so lucky because it’s 8:35 pm now and it’s a Friday…

Well if you picked up something similar from your mailbox today. You should be a little nervous, Yes You are!!!. Please think twice before confusing this mail with any other important information that you may just have been waiting for.

This mail is a 100% SCAM, The YELLOW card has you full name and your new address just like you credit card. It’s a scamming magazine and these people are trying to get your Visa, Master Card, or any other Bank Card info. Once they get it, they will hit your credit so badly, charging you for magazine that you may never receive.

They are using this web site as a cover http://familyreadingclub.com/index.php and changing names and phone number frequently, to avoid detection. names like FRC, CFC, A.C.I, or other names, and surely people like Michelle Barbaa, Debbie Peti, or Amanda Walters have never been in this world. So don’t expect any “GOOD NEWS” from them.

Before you made the call beware that the numbers they use are not toll free even if they looks like they are. These guys talk professionally and once they get nothing from you they change tones, their target are most likely people who have moved recently. Even as a scamer they are so lazy that they can’t do business at early morning, so you have to wait until 10am. They wish receiving calls nights and weekends but that will looks more suspicious, Ahah! So let keep things professional 8:30pm looks perfect. All right man! Always listen to your mom “Never talk to stranger”.

scam front

Scam Front

scam pack

Scam Back

Mail from Clearwater, Fl. it said ‘We are trying to reach you with Good News! It is really important that you call us. Call toll free 1-877-45-4020. Control # XXXXXXXX Thanks Michelle Barbaa Call 10 am to 8:30 pm EST Monday thru Friday’

N.B: If you receive a similar card, immediately report it to your local Postmaster.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

PHP RGB Color Class Make it Simple

April 7, 2008 · Filed Under PHP · Comment 

I have created this Class while working on a PHP/Ming project to simplify my coding experience. Now it’s time to share this experience with my visitors.
ColorRGB is a PHP base color class and a simple container for the pixel red, green, and blue values. All you have to do is instantiate it and enjoy your color manipulation.

  1. <?php
  2. /**
  3. * Class ColorRGB
  4. * Description: this is a rgb base color class
  5. * Author: Rachid Lamtabbet
  6. * Version: 1.0
  7. * Author URI: http://www.alfasky.com
  8. * please read the license
  9. */
  10. class ColorRGB {
  11.         private $RGB = array();
  12.         function __construct() {
  13.           $this->RGB=array(
  14.             ‘aliceblue’             => array(240, 248, 255),
  15.             ‘antiquewhite’          => array(250, 235, 215),
  16.             ‘aqua’                  => array(  0, 255, 255),
  17.             …
  18.             ‘yellow’                => array(255, 255,   0),
  19.             ‘yellowgreen’           => array(154, 205,  50)
  20.           );
  21.         }
  22.  
  23.         public function Color2RGB($color=‘black’) {
  24.            $this->$color= strtolower($color);
  25.            return $this->RGB[$this->$color];
  26.         }
  27. }
  28. ?>

The class is very easy to use, just create your instance,

  1. <?php
  2. $color = new ColorRGB();
  3. $this->black = $color->Color2RGB(‘black’);
  4. $this->lightgrey = $color->Color2RGB(‘lightgrey’);
  5. $this->snow = $color->Color2RGB(’snow’);
  6. $this->white = $color->Color2RGB(‘white’);
  7. ?>

the default color is black, no alpha is specified, this could be the subject of the next release. If you are using this class with the ming for a “Fill” color
know that your color object is an array(), use the index to separate your RGB values.

  1. <?php
  2. $shape->setLine($unit,  $this->snow[0], $this->snow[1], $this->snow[2]);
  3. ?>

You are free to use the class for any purpose just attribute the work by providing a link to AlfaSky and keep the author name and signature.
download

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Good bye Prototype I’m going jQuery!

April 7, 2008 · Filed Under Java Script · Comment 

I have been using Prototype in many projects but in two days and after inderstanding the philosophy behind jQuery, it looks like I’m not coming back. Yes I will never forget my past with Prototype and Scriptaculos, but I just can’t stop thinking about jQuery with its Interface plug-in for my next project.

I’m thinking of recoding some of my javascript work using jQuery and I will be posting some samples soon. There has to be someone to convince that I’ was wrong but I’m sure what I’m doing is right. Good by my dear Prototype…

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

My HP Customer Service Nightmare

April 7, 2008 · Filed Under Lifestyle · 2 Comments 

This is the second time that I had to call HP customer service, It’s really terrible, Yes they may have some nice and good looking products, but their customer and technical services are really the worst that I have ever had to deal with :(

Last time when I called them about a technical problem on my new laptop, I spent about 10 minutes listening to their boring operator machine listing me all the services of the world before asking me to press 82154887566511!.. :x . All right, that was only a machine, now that I heard a living human been, it was even worst. It took about another 10 to 15 min to get my information before the lady asked me the stupid question that I was hoping for since the beginning of our conversation, “How can I help you today?. Sir!” It took me about five minutes more to clarify my problem, and then she directs me to the technical service, of course she had to put me on hold, I agreed to enjoy this meaningless music, but the operating machine already missed me and came up with a new list of products, at that time, I putted my phone on speaker because I new that the list will be very long.

Finally and after 30 min of wasted time I got in touch with the technical support. What surprise me the most at that point is that I found my self answering the same questions again, I got made I said that I’m having a case number, why don’t you just take a look at it and help me instead of wasting my time. He said that is the requirement, I said: “ok let’s go for it”Â, well another 10 min is gone and I’m not yet talking about my problem, finally when we got to the point of talking about the problem he simply suggested that I took the laptop to the store and let them change it for me, believe me I was shocked and happy at the same time, I was shocked because I have to drive from Virginia to Maryland since I made my purchase their, and I was happy because I don’t have to deal with this nightmare again.

Lately I was trying to check, online, the status of the rebate that I got for my new HP laptop, and don’t ask me why I got the same brand, I didn’t got any feedback and I had to call them again, I had enough, I said let’s be very optimistic, I opened the window, got a cup of water and dialed the nightmare’s number. This time I’m very familiar with the list I was trying to impress the machine by reciting the list my self. Well I did great, it was more like a game, I got in touch with a guy, he tried to be nice, I said that I need to check the status of my rebate, He said: ”what kind of laptop do you want to purchase Sir?”

I tried to calm my self down, I said that I already own one and I’m calling to check the status of my rebate, he apologized and directed me the an other service, the operating machine was very nice too she knew that I was upset so she skipped the list and told me that some one will be with me shortly, 10 min of witting my call ended up with a message telling me that they are experiencing a problem at the moment and that I have to call laterÂ. Please advise me! Should I call them again or just wait, or what kind of medication should I take before dialing the number again?

Conclusion: if you are in rehab or in an anger management program, try HP Customer Service for free. Good luck!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]