Category Archives: Programming

Activating Missing Ant Plugin in PDT Eclipse

ant-with-eclipse-header

Did you ever wonder why there is no Ant support in your Eclipse installation?

If you are working with Eclipse as your standard IDE for PHP Projects you will probably use the PDT Eclipse environment which doesn’t include much of the Java project tools. Ant is one of the very handy ones.


What is Ant?

With Ant you can write simple and as well sophisticated batch jobs for compiling and deploying your code or any other task you could think of. For an example, I’m using Ant to compress and obfuscate my Javascript and CSS files.


How does it work?

Tasks you would like to be processed with Ant you put in a build.xml file.
Here is a simple example:

1
2
3
4
5
6
7
8
9
10
11
12
 <target name="myTarget" depends="myTarget.check" if="myTarget.run">
     <echo>Files foo.txt and bar.txt are present.</echo>
 </target>
 
 <target name="myTarget.check">
     <condition property="myTarget.run">
         <and>
             <available file="foo.txt"/>
             <available file="bar.txt"/>
         </and>
     </condition>
 </target>

To learn how to write your own build files checkout the Ant Manual.


Activating Ant in Eclipse

  1. In Eclipse go to Help -> Software Updates -> Available Software
  2. Select Java Development Tools and install it
  3. Restart Eclipse

Now you should be able to see Ant in your Eclipse Preferences and when you right-click on a build.xml file in your project you can run it via Run As -> Ant Build.


Let’s make the Web faster – Google’s new Code Section “Speed”

google-speed-code-header

I can still remember the first days of the web when I we were using Mosaic and later Netscape as browsers. Although websites consisted mostly of simple  text and a sometimes even some images, the speed was terrible. Sometimes it took minutes to load entire pages. Nowadays we have tons of images on every single page plus animations, flash and other media types. The web got way faster in the last 10 years. Big companies started to invest money into infrastructure and ISPs evolved with their services.

Let’s take Google as an example. They can provide search results within a fraction of a second though there are quadrillions of data to be parsed an processed. Google can do that trick only because of their enormous server farms and highly streamlined websites. But Google wants to go to the next level: surfing the web should be as instantaneous as “flipping through the pages of a glossy magazine”.

Let’s make the Web faster

Google introduced a new Code section called Speed. You can find there many useful articles on how to optimize the performance of your website and web server. And if you have some ideas about improving the speed of the web you can post it there too. It’s definitely a good resource for beginners and professionals.

Here is a short introduction video made by some guys at Google:

[youtube]IWWBnJEsUtU[/youtube]


Reloading an IFrame via Ajax Request in Firefox and IE

iframe-ajax-reload-header

Recently I was working on a web project where I needed to show a preview window which was basically an IFrame. As the whole page navigation was based on Ajax calls I was looking for a bulletproof method for reloading an IFrame.

The first solution (only Firefox)

IFrame code:

1
<iframe id="preview_content" src="preview.php"></iframe>

Ajax code:

1
2
var iframe = document.getElementById("preview_content");
iframe.contentDocument.location.reload(true);

Well, this solution was working quite nice with Firefox but IE wouldn’t reload the page at all.


The proper solution

Ajax code:

1
2
var iframe = document.getElementById("preview_content");
iframe.src = "preview.php?x="+Math.round(Math.random());

The additional parameter x (a random number) will cause IE to reload the IFrame properly without using the cache.


Free Cheat Sheets for Developers on DZone

free-cheat-sheets-developer

I found today a superb resource for Cheat Sheets (also known as reference cards) on DZone.

Whenever I find a cheat sheet in a book store I need to buy it.  Looking up information on the Internet is way faster but sometimes you don’t have a connection and these short e-books can be of good help.

Here is a short list of Cheat Sheets I found on DZone:

You will find on http://refcardz.dzone.com more the 50 of these sheets.