Preload multiple images on a webpage

In order to speed up a web page with a lot of images, you can use JavaScript to plug on that page. In the <head> tag, use the following script:

function preload_images(){
var Img = new Array();
Img[0]= “ser_remodeling_pop.jpg”;
Img[1]= “ser_indoor_pop.jpg”;
Img[2]= “ser_outdoor_pop.jpg”;
Img[3]= “ser_newconstruction_pop.jpg”;
Img[4]= “ser_additions_pop.jpg”;
Img[5]= “ser_breakerpanel_pop.jpg”;
Img[6]= “ser_electricityupgrades_pop.jpg”;
Img[7]= “ser_conversion_pop.jpg”;
Img[8]= “ser_codecompliance_pop.jpg”;
Img[9]= “ser_troubleshooting_pop.jpg”;

var imageObj = new Image(250,167);

for(var i=0; i<10; i++){ imageObj.src = “images/”+Img[i]; } }

Then in the <body> tag, you have to call the javascript function to load all images above to the page. If you don’t have this function call on the <body> tag, images won’t load as expected.

<body onload=”preload_images()”>

Remember to put parentheses () at the end of a function call, otherwise it won’t work.

Using Switch() function

Back in the old day when I first know how to program in php, I always used if-else statement. Sometimes, it gets so long that I couldn’t even keep track of how many if or else, and where the else supposed to be closed. I have no idea. It’s like a jungle of if else in my file. Since I started using switch() function, my codes are much cleaner when I need multiple conditions applied on one variable. I love it. If you only have 1 condition, it’s not worth using this function.

This was my if-else statements before I used switch function:

You will see how switch function can save you a lot of typing and it looks much cleaner on you page.

I have a habit of writing open and close php tag when I start my php codes. If you don’t need the <?php tag, you can just ignore it.

Linux Set Date and Time From a Shell Command Prompt

Q. The time on my server set back 1 hour and all my cron jobs are running 1 hour off. How can I set the server date and time from the shell command prompt? I can only login over ssh session using Putty. Please advice?

A. You will use date command to display the current date and time or set the system date / time over ssh session.

This is useful if the Linux server date and/or time is wrong, you need to set it to new values from the shell command. You must log in as root user to input date command.

Linux Date Help command

You must know specific date command to perform date/time adjustment on your server. Use this command to display a list of date/time commands:

$ date –h


$ date –help

Linux Set Date

Use the following syntax to set new data and time:
date set=”DATE STRING”

For example, to set new date to March 22 2010 15:00:00, type the following command:

$ date +%Y%m%d -s “20100322”

Linux Set Time

Use the following syntax to set time for your server:

$ date +%T -s “05:15:15”


  • 05: Hour (hh)
  • 15: Minute (mm)
  • 15: Second (ss)

Use %p locale’s equivalent of either AM or PM, enter the following syntax w/o space in the time string:

$ date +%T%p -s “8:20:50AM”
$ date +%T%p -s “01:40:30PM”

An easy way to build data Session for a form

You wonder how data of each field on a form can be refilled after you submit a page. This post will show you how to build an array of sessions that capture the input data of a user after they submit a form.

If an anonymous arrive on your web form from the street, there’s no session until they enter some values and hit Submit button to process the form.

First, you have to have a form to collect data on your website. When customer submit the form, you loop through all the $_POST variables. To make it easy, you should build an array of all field names, so you can build SESSION names using foreach loop.

 'First Name',
   'lastname' => 'Last Name',
   'companyname' => 'Company Name',
   'address' => 'Address',
   'address2' => ' Address2',
   'city' => 'City',
   'state' => 'State',
   'zip' => 'Zip/Postal Code',
   'phone' => 'Phone',
   'ext' => 'Phone Ext',
   'fax' => 'FAX',
   'email' => 'EMail Address',);

   foreach ( $fields as $name => $value ) {
      $_SESSION[$name] = $_POST[$name];

Then if for any reason the form can’t be processed and customer is forced to go back to the form, all data on the form is still there. You can destroy the session anytime after the form is processed successfully. Just use the codes below to reset all SESSION variables.

Let’s draw a shape to replace pushpin on Virtual Earth Map.

Let me show you how to draw a shape to replace pushpin on Virtual Earth Map. If you develop a map for marketing/sales analysis by using geo codes and place pin points on a map, you may consider to use your customized points. First, it will represent your business professionally. Second, you can define the size you desire.

Let’s draw together a shape of a blue ball for example. Open Adobe Photoshop software, you can use any size and any shape such as rectangle or square. I will start with a 40×40 image space with a transparent background. This will not cover your map in the back if you save the file in .png or .gif format. If you save the file in .jpg format, the background won’t look cool on a map.

Select ellipse tool and use fixed size of 38×38 to start drawing a blue circle. Remember to check “Anti-alias” checkbox, so the circle will have a sharpened edge. Now, you can modify the layer by double click on layer. Check the Stroke box and select 1px for the border of the blue circle. Then select a darker blue color to draw the border.

To make the ball looks like 3D image, you can add lighting effect to it by the menu Filter->Render->Lighting Effects. Select any direction of light on the object. Now you have a great image but it’s only in .psd format. We got to save it for the web in .png or .gif format. Click on File->Save for Web & Devices. Select GIF or PNG-24 in the preset drop down box. Save the file to the server.

Then you can use the function provided by Microsoft Virtual Earth API to add this image to a map. The sample codes are below:

var image = “<img src=’images/icons/BlueBall.png’ style=’background:transparent;’/>”;

You can download the .png image here:

The screenshot below is one of the applications we built applying Virtual Earth Map. We need to define geo codes longitude and latitude for each property and embed the ball image for each location on the map.