Category Archives: Tips

Useful tool – Vista Battery Saver

Yesterday, I lectured on environmental technologies and had a chance to present, what I think is, one of the most useful ,open source downloads for people who use Vista on their laptop.

A few months ago, my friend Tamir Khason has released a super cool open source application called Vista Battery Saver.

"This tinny program will save up to 70% of your battery by disabling those nice, but greedy Vista features. Running in task bar with private workset of 5.5M and 0% CPU it will do all work for you, by enabling and disabling customizable features when power source changed or battery power fall under certain percent."

vista battery saver

Saving battery time does not only prolong the time you can use your laptop without recharging, it also reduces the total energy your computer uses. you might think it is nothing but this makes great difference if all of us use it (plus, it is free!).

Tip: Solving the browser caching problem of AJAX applications

Browser caching is generally a good thing, why download the same image again and again while you can download it once and save it on the browser? In some cases, however, this is not a wanted behavior.

The problem:
AJAX application tends to frequently ask the server for the same URL (a stock quote, application status and so forth). The AJAX application expect a response form the server while, in fact, after the first request the browser returns the cached page and the AJAX application does not work as expected. Clearing the browser cache or setting “no cache” parameters on the page does not always work.

The solution:
Add a pseudo-random parameter to the URL the AJAX application is requesting. Doing so will fool the browser to think this is a new page that has not yet been cached.

For example, this is how I would add a pseudo parameter to a URL in JavaScript :

var url = “http://mydomain?myParameters=myValues&pseudoParam= “+new Date().getTime();

The Date().getTime(); returns a new value every millisecond (or so), the browser thinks this is a new page that has not been cached and requests the URL form the server.

Tip: how to write an XML document with JSP for AJAX applications

AJAX applications usually connect to a server side application and request data in the form of XML. When the server side is written in JSP (Java Server Pages), for example a spring-framework web application with JSP views, writing the XML response is sometimes problematic.

The problem:

When using JSP to format the data in to XML and send it to the AJAX application, the XML is not recognized as XML (empty DOM object) and the AJAX application does not function properly.

The solution:

Add this to the beginning of the JSP
<%

response.setContentType(“text/xml”);
response.setHeader(“Cache-Control”, “no-cache”);
response.setHeader(“pragma”,”no-cache”);

%>

In addition, make sure there are no spaces between this addition and the root tag of the XML in the JSP, these spaces might create the same problem.

An example of this AJAX-JSP communication can be found in the Spring-dashboard code under the examples folder in this release (files: monitorData.jsp and monitor.jsp)

Another issue you might face with AJAX is client side caching. You can read more about this and how to solve this issue in this article – Solving the browser caching problem of AJAX applications

Removing the Ant Configuration Selection in eclipse

When I updated to eclipse 3.2 I found a new irritating feature:

The problem:
The first time when selecting the Run As-> Ant build… on any of the ant tasks (targets) you have in your build.xml file, you get a window called “modify attributes and launch.”

After that any time you try to run an ant task (with or without the build…) you get an annoying “Ant Configuration Selection” window that makes the ant running process a click longer.

The solution:
From the top menu select run->External Tools-> External Tools… which will bring you to “create, manage, and run configurations” window, there delete all the pre-defined tasks under ant build (on the left bar of the window) and click “close”…
I found this workaround here: http://dev.eclipse.org/newslists/news.eclipse.platform/msg20976.html

I hope eclipse will provide a different mechanism that will work around this problem in their next release.