<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function openFull(theUrl) {
h = screen.height;
w = screen.width;
window.open(
theUrl,'','left=0,top=0,screenX=0,screenY=0,
height='+(h-100)+',width='+(w-10)+',
directories=no,location=no,menubar=no,
resizable=no,scrollbars=yes,status=no,
titlebar=yes,toolbar=no'
);
}
</SCRIPT>
</HEAD>
<BODY>
<a href="javascript:void(0);" onClick="openFull('full-screen.html');">Open Full Screen Window</a>
</HTML>
Friday, March 20, 2009
Open full screen window using Javascript
Here's a very interesting sample code that I found. I have been looking for the solution of this issue since long time...
Sunday, March 15, 2009
More swap with a swap file ...
There are situations when either you have a pre-installed Linux system or a new one, but forgot to set enough swap space for your needs or you recently have upgraded your hardware (like I have recently added an additional RAM on my machine :) ).
Now, to make the most of the hardware that you've got, you might consider to increase the swap space. What do you do now? Do you need to repartition and reinstall the system? Answer is NO! Linux offers you with fascinating swap utilities to make a real file and use it as swap space. The trick is to make a file and then tell the swapon program to use it.
Here's how to create, for example, a 64 megs swap file on your root partition (of course make sure you have at least 64 megs free):
dd if=/dev/zero of=/swapfile bs=1024 count=65536
This will make a 64 megs (about 67 millions bytes) file on your hard drive. You now need to initialize it:
mkswap /swapfile 65536
sync
And you can then add it to your swap pool:
swapon /swapfile
With that you have 64 megs of swap added. Don't forget to add the swapon command to your startup files so the command will be repeated at each reboot.
Now, to make the most of the hardware that you've got, you might consider to increase the swap space. What do you do now? Do you need to repartition and reinstall the system? Answer is NO! Linux offers you with fascinating swap utilities to make a real file and use it as swap space. The trick is to make a file and then tell the swapon program to use it.
Here's how to create, for example, a 64 megs swap file on your root partition (of course make sure you have at least 64 megs free):
dd if=/dev/zero of=/swapfile bs=1024 count=65536
This will make a 64 megs (about 67 millions bytes) file on your hard drive. You now need to initialize it:
mkswap /swapfile 65536
sync
And you can then add it to your swap pool:
swapon /swapfile
With that you have 64 megs of swap added. Don't forget to add the swapon command to your startup files so the command will be repeated at each reboot.
Tuesday, March 3, 2009
Adding emmuerated values to the spreadsheet column.
Most of the client interactions makes use of various spreadsheets. One of the common strategy for validating some spreadsheet column is to provide a list of allowed enumerated values to it.
For long time I wasn't aware of this myself. Thus once I came to know about it I felt like sharing how to achieve that.
Following are the steps for adding validation to a spreadsheet column:
1. For Open Office (OpenOffice SpreadSheet):
For long time I wasn't aware of this myself. Thus once I came to know about it I felt like sharing how to achieve that.
Following are the steps for adding validation to a spreadsheet column:
1. For Open Office (OpenOffice SpreadSheet):
- Select the spreadsheet cells for validating
- Click the menu: Data -> Validity. A popup dialog would appear.
- Select "List" option from the "Allow" drop-down.
- Add the comma-separated or tab-separated or newline-separated enumerated entries in the "Entry" text area.
- Click "Ok"
- Select the spreadsheet cells for validating
- Click the menu: Data -> Validation. A popup dialog would appear.
- Select "List" option from the "Allow" drop-down.
- Add the comma-separated enumerated entries in the "Source" textbox.
- Click "Ok"
Sunday, March 1, 2009
Creating transparent images using GIMP (GNU Image Manipulation Program) ...
INTRODUCTION:
GNU Image Manipulation Program (GIMP) is a very powerful image manipulation software available for Linux operating systems. While working on one of client project which is a Rich UI application, we felt the necessity of inventing customized icons of our own at lot of places. The key challenge was to find a tool for helping our cause. After scanning through a stack of softwares available free / commercial; we found GIMP to be the most interesting of them all.
Two of the prime requirements for creating icons are to have a control over exact icon size and the graphic transparency. Following are the steps for creating transparent images using GIMP:
STEPS:
1. Open GIMP application
2. Click File -> Open
3. Select and load the image from the disk.
4. Zoom into the image for better accuracy while making it transparent.
5. Click Layer -> Transparency -> Add Alpha Channel
6. Make sure to select the Fuzzy selection tool from the main window toolbar for GIMP
7. Selectively click the section that you want to make transparent
8. When you are sure that this section is highlighted properly, then click Edit -> Clear or simply hit 'delete' from keyboard.
9. Repeat steps 7 and 8 until all the sections are made transparent.
10. Finally save the image File -> Save.
Hope these steps will be very helpful to everyone, especially if the application demands heavy use of images and icons.
GNU Image Manipulation Program (GIMP) is a very powerful image manipulation software available for Linux operating systems. While working on one of client project which is a Rich UI application, we felt the necessity of inventing customized icons of our own at lot of places. The key challenge was to find a tool for helping our cause. After scanning through a stack of softwares available free / commercial; we found GIMP to be the most interesting of them all.
Two of the prime requirements for creating icons are to have a control over exact icon size and the graphic transparency. Following are the steps for creating transparent images using GIMP:
STEPS:
1. Open GIMP application
2. Click File -> Open
3. Select and load the image from the disk.
4. Zoom into the image for better accuracy while making it transparent.
5. Click Layer -> Transparency -> Add Alpha Channel
6. Make sure to select the Fuzzy selection tool from the main window toolbar for GIMP
7. Selectively click the section that you want to make transparent
8. When you are sure that this section is highlighted properly, then click Edit -> Clear or simply hit 'delete' from keyboard.
9. Repeat steps 7 and 8 until all the sections are made transparent.
10. Finally save the image File -> Save.
Hope these steps will be very helpful to everyone, especially if the application demands heavy use of images and icons.
Monday, February 16, 2009
Wednesday, July 9, 2008
Brusque shutdowns?? Hang on, using Java Shutdown Hooks!!
Every application that you build has some well defined and methodical steps for its closure. However, users usually come up with their own ways of shutting down your application. And not every time your cleanup code is given a chance to work.
Brusque shutdowns cause many nightmares to developers than anything else. Java once again provides yet another rescue - Java Shutdown Hooks!!
Essentially, a shutdown hook is used to guarantee that your cleanup code is given its chance to run, irrespective of how the user terminates the application. Very crudely defined the shutdown-hooks are the Java Threads associated or hooked up with the Runtime.
Historically there was a workaround; that if you pass the -Xrs flag to the JVM (1.3.1 and earlier) parameters while creating the JVM, then the shutdown hook will NOT be called. This might be because -Xrs reduces use of OS signals by Java/VM.
This is by far the better technique than to rely on ever reliable (pun intended) finalizers. Off-course it still won't work against the fatal `kill -9`.
In Java, the virtual machine shuts down itself in response to two types of events: first, when the application exits normally, by calling the System.exit method or when the last non-daemon thread exits. Second, when the user abruptly forces the virtual machine to terminate; for example, by typing Ctrl+C or logging off from the system before closing a running Java program.
Fortunately, the virtual machine follows this two-phase sequence when shutting down:
Creating a shutdown hook is simple:
Simple shutdown hooks can often be written as anonymous inner classes, as in this example:
Or more formal way as in the following example:
PS: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html
Brusque shutdowns cause many nightmares to developers than anything else. Java once again provides yet another rescue - Java Shutdown Hooks!!
Essentially, a shutdown hook is used to guarantee that your cleanup code is given its chance to run, irrespective of how the user terminates the application. Very crudely defined the shutdown-hooks are the Java Threads associated or hooked up with the Runtime.
Historically there was a workaround; that if you pass the -Xrs flag to the JVM (1.3.1 and earlier) parameters while creating the JVM, then the shutdown hook will NOT be called. This might be because -Xrs reduces use of OS signals by Java/VM.
This is by far the better technique than to rely on ever reliable (pun intended) finalizers. Off-course it still won't work against the fatal `kill -9`.
In Java, the virtual machine shuts down itself in response to two types of events: first, when the application exits normally, by calling the System.exit method or when the last non-daemon thread exits. Second, when the user abruptly forces the virtual machine to terminate; for example, by typing Ctrl+C or logging off from the system before closing a running Java program.
Fortunately, the virtual machine follows this two-phase sequence when shutting down:
- The virtual machine starts all registered shutdown hooks, if any. Shutdown hooks are threads registered with the Runtime. All shutdown hooks are run concurrently until they finish.
- The virtual machine calls all uninvoked finalizers, if appropriate.
Creating a shutdown hook is simple:
- Write a class extending the Thread class.
- Provide the implementation of your class' run method. This method is the code that needs to be run when the application is shut down, either normally or abruptly.
- In your application, instantiate your shutdown hook class.
- Register the shutdown hook with the current runtime's addShutdownHook method.
Simple shutdown hooks can often be written as anonymous inner classes, as in this example:
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() { database.close(); }
});
This idiom is fine as long as you'll never need to cancel the hook, in which case you'd need to save a reference to the hook when you create it.Or more formal way as in the following example:
package test;
public class ShutdownHookDemo {
public void start() {
System.out.println("Demo");
ShutdownHook shutdownHook = new ShutdownHook();
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
public static void main(String[] args) {
ShutdownHookDemo demo = new ShutdownHookDemo();
demo.start();
try {
System.in.read();
}
catch(Exception e) {
// Do nothing.
}
}
}
class ShutdownHook extends Thread {
public void run() {
System.out.println("Shutting down");
}
}
Last thing that I want to mention it here is that the shutdown hooks are with us since JSDK 1.3. So guys, start hanging out with Shutdown Hooks!!PS: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html
Labels:
brusque shutdowns,
Design Patterns,
Java,
shutdown hooks
Monday, January 7, 2008
Dependency Injections / Inversion Of Control
In order to reduce the amount of coupling between components, most programmers follow the “Program to an interface, not an implementation” principle. Dependency injection is one such pattern that builds on top of this principle.
Dependency injection is a term used to describe a separation between the implementation of an object and the construction of an object it depends on, and the ability for a container to resolve the dependency. In turn, the client program becomes independent of the specific implementation dependency.
Lets take an example for the explanation:
Suppose, one wants to trade some FooShares. Thus, “MyTrade” depends upon the “FooShares”.
Dependency:
To get the handle to the “FooShares” somebody must create it!!!!
Dependency Push or Injection:
Using the above principle, broadly there are three main styles of dependency injection: Constructor Injection, Setter Injection, and Interface Injection.
For more details refer following article by Martin Fowler:
http://www.martinfowler.com/articles/injection.html
Dependency injection is a term used to describe a separation between the implementation of an object and the construction of an object it depends on, and the ability for a container to resolve the dependency. In turn, the client program becomes independent of the specific implementation dependency.
Lets take an example for the explanation:
Suppose, one wants to trade some FooShares. Thus, “MyTrade” depends upon the “FooShares”.
Dependency:
public class FooShares { // some implementation }
public class MyTrade {
private FooShares foo_shares;
public MyTrade(FooShares foo_shares) {
this.foo_shares = foo_shares;
}
}
Dependency Pull:To get the handle to the “FooShares” somebody must create it!!!!
public class TheCreator {
public void performTrade() {
FooShares foo_shares = <b>new FooShares()</b>;
MyTrade myTrade = new MyTrade(this.foo_shares);
}
}
thus…..”MyTrade” will have to pull “FooShares” object.Dependency Push or Injection:
public class FooShares <b>implements Shares</b> { // some implementation }
public class SomeOtherShares <b>implements Shares</b> { // some other implementation }
public class MyTrade {
private Shares shares;
public MyTrade(<b>Shares shares</b>) {
this.shares = shares;
}
}
// Both are trueMyTrade myTrade = new MyTrade(this.some_other_shares); MyTrade myTrade = new MyTrade(this.foo_shares);thus…..creators can now push or inject their own implementations into MyTrade. “MyTrade” no longer is dependent upon “FooShares” implementation.
Using the above principle, broadly there are three main styles of dependency injection: Constructor Injection, Setter Injection, and Interface Injection.
For more details refer following article by Martin Fowler:
http://www.martinfowler.com/articles/injection.html
Subscribe to:
Posts (Atom)