Archive for May, 2008

Creating Dynamic image

Some website prompt you to enter dynamic number generated in the image , especially when you are filling registration form ….and usually found at the end of registration form. User must enter exactly same number or alphanumeric character found on the image , this is because to make sure that Human is using webapplication and keeping away from robots/sypwares or any hacking software’s to fill the form.

Below is simple java code for how to generate dynamic image .This is a sample servlet that dynamically generates JPEG images. Currently all image properties are hard-coded, but it should be trivial to provide a jsp form to collect them (e.g., color, font, dimensions, messages). The generated image contains dynamic data such as the appserver name, and OS name.

import com.sun.image.codec.jpeg.JPEGCodec;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;

public class ImageServlet extends HttpServlet {
private static final int WIDTH = 450;
private static final int HEIGHT = 200;
private static final Color BACKGROUND_COLOR = new Color(100,149,237);
private static final Color COLOR = new Color(0,0,139);
private static final Font FONT = new Font("Times New Roman", Font.BOLD, 46);
private static final Font FOOT_FONT = new Font("Courier", Font.ITALIC, 14);
private static final Color FOOT_COLOR = Color.BLACK;

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
   response.setContentType("image/jpg");
   ServletOutputStream out = response.getOutputStream();
   BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_BYTE_INDEXED);
   Graphics graphics = image.getGraphics();
   graphics.setColor(BACKGROUND_COLOR);
   graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
   graphics.setColor(COLOR);
   graphics.setFont(FONT);
   graphics.drawString("Hello World!", 10, HEIGHT/2); //insert String or any random number
   graphics.setFont(FOOT_FONT);
   graphics.setColor(FOOT_COLOR);
   graphics.drawString("Created by " + getServletContext().getServerInfo(), 10, HEIGHT - 30);
   graphics.drawString("for http://javahowto.blogspot.com/ on " + System.getProperty("os.name"), 10, HEIGHT - 10);
   JPEGCodec.createJPEGEncoder(out).encode(image);
}
}

The web.xml file is as simple as declaring and mapping a servlet:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
   <servlet-name>image</servlet-name>
   <servlet-class>ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
   <servlet-name>image</servlet-name>
   <url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

And i hope you know rest of the things to deploy the webapp ......

output...

1 comment May 21, 2008

Linux useful commands

Its been month i have logged into ubuntu … and the sad news is i forgot many commands … moreover i love to do lots of stuffs in console rather than choosing GUI … Whenever i forget some command , the best option for me search in google … But today i found something interesting , where i can stick some useful commands in my brain …or even you can stick to your wall too !!

fwunixrefshot.png

Click the image above to download a full PDF. Print it out, stick it on your wall, and pass it on. It’s licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported license, so feel free do distribute and modify it, even for commercial use!

3 comments May 18, 2008

Started something new, Google AJAX API!

Well its been long i have tried something new or learn something new …. Today i started with Google’s AJAX Search API . I started with simple local search using simple search and i learned how to embed samething in my blog see this example : http://madhucm.blogspot.com.

I would have included in this blog but i dont know how to edit <body> tag. And also it doesn’t allow you to do … well it doesn’t matter however.

The first thing i did was getting the JAX Search API key so that it is valid within a single directory on your web server. And after getting the key, i tweaked  my blog template , and finally included the script. Well if you know javascript it damn easy to create you own search.

ex: var localSearch = new google.search.LocalSearch();
searchControl.addSearcher(localSearch); // This is local search
searchControl.addSearcher(new google.search.WebSearch()); // search on web
searchControl.addSearcher(new google.search.VideoSearch()); // video search
searchControl.addSearcher(new google.search.BlogSearch()); // blog search….

You can also customize your view , like :- TABBED, LINEAR .

// create a drawOptions object
var drawOptions = new GdrawOptions();

// tell the searcher to draw itself in linear mode
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_LINEAR);
or
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
searchControl.draw(element, drawOptions);

more info:http://code.google.com/apis/ajaxsearch/

1 comment May 16, 2008

Logging GC activity how to

An easy low cost method to check the activity of the garbage collector in the JVM is to tell the JVM to create an activity log. This is achieved for Sun JVMs using the non-standard command line option “-Xloggc:file_name“. This will tell the JVM to create a log file with a content similar with this:

0.806: [GC 8064K->1211K(30912K), 0.0051670 secs]
1.363: [GC 9275K->1856K(30912K), 0.0061070 secs]
1.944: [GC 9920K->2602K(30912K), 0.0115890 secs]
2.351: [GC 10666K->3289K(38976K), 0.0083440 secs]
3.159: [GC 19417K->4316K(38976K), 0.0325310 secs]
3.948: [GC 20444K->5735K(56192K), 0.0083630 secs]
35.812: [GC 37671K->7896K(56512K), 0.0152040 secs]
525.368: [GC 39832K->8066K(89600K), 0.0082710 secs]

As one can guess the log entries show the time of the garbage collection activity, the memory before and after and the duration of the garbage collection. This can prove very useful when monitoring the activity of a server application for memory leaks and for memory activity.
If the information about the garbage collection activity is only needed at the console the “-XX:+PrintGC” and “-XX:+PrintGCDetails” options can be used. The last one will produce an output with more details lke this one:

[GC [PSYoungGen: 33584K->1312K(33600K)] 36545K->6656K(55104K), 0.0141310 secs]

Heap
PSYoungGen total 33920K, used 8802K [0×00002aaac91c0000, 0×00002aaacd790000, 0×00002aaad39c0000)
eden space 30976K, 19% used [0×00002aaac91c0000,0×00002aaac97840a8,0×00002aaacb000000)
from space 2944K, 98% used [0×00002aaacd4b0000,0×00002aaacd784978,0×00002aaacd790000)
to space 4096K, 0% used [0×00002aaaccf90000,0×00002aaaccf90000,0×00002aaacd390000)
PSOldGen total 21504K, used 5344K [0×00002aaab41c0000, 0×00002aaab56c0000, 0×00002aaac91c0000)
object space 21504K, 24% used [0×00002aaab41c0000,0×00002aaab46f8340,0×00002aaab56c0000)
PSPermGen total 21248K, used 19211K [0×00002aaaaedc0000, 0×00002aaab0280000, 0×00002aaab41c0000)
object space 21248K, 90% used [0×00002aaaaedc0000,0×00002aaab0082d50,0×00002aaab0280000)

The behavior of the logging option seems to produce identical results as “-XX:+PrintGC” even if personally I would’ve expect more details in the log file. Maybe this will change in a future version of Java.

4 comments May 15, 2008

wondering how to enable blocked chat in gmail ??

Block access to web based chat messengers and IM like gtalk , msn or yahoo in your office without blocking the whole site itself using the Hosts file.

imageFor example in iGoogle there is an option to add these messenger modules(gtalk,msn,hotmail & yahoo). And with this trick you can block only these Messengers but not the whole IGOOGLE itself.

First of all,Open the hosts file located in C:\windows\system32\drivers\etc with your notepad.Add these following lines in the hosts file and save it.

127.0.0.1 localhost

127.0.0.1 chatenabled.mail.google.com

127.0.0.1 httpcs.msg.yahoo.com

Bang you are done !!!

msn_messenger_blocked More messengers can be blocked by adding the server address of the messengers to this file.With this the Gtalk module in the Gmail page is also blocked.

2 comments May 12, 2008

Cool Virtual Desktop Managers for Windows

If you constantly find your desktop cluttered and overloaded with programs and browser windows then a virtual desktop manager might be for you. Virtual desktops are handy if you want to keep different tasks and programs separated. They are quite common on Mac and Linux computers.  It may take some time but once you get used to using them, they become an essential part of a productive workflow. So if you’re up for it, below are some of the better Windows desktop managers out there:

(1) Dexpot

Dexpot is an easy to use and fast desktop manager that makes managing multiple desktops very easy. It’s my favorite desktop manager and comes with plenty of useful features.

Dexpot- Virtual Desktop for Windows

When it comes to virtual desktops, the most important feature is the ease of switching between desktops. The easier and faster the switching, the better it is. Dexpot offers a number of ways to switch between desktops, including keyboard shortcuts Alt+1/2/3/4 or using the ‘Desktop Manager’ located on top of the Windows taskbar (picture above).

Dexpot - Virtual Desktop Manager

Another cool feature is the ability to quickly move or copy a particular window to one of the other desktops. To access these options, simply right-click on any of the program tabs in the menubar. There is also an option to copy certain windows to all desktops at the same time. Very useful.

Virtual Desktop Settings

You can also customize each of your multiple desktops further with its own wallpaper, desktop entry/exit sounds, screensaver, manager icon and so on.

source:http://www.makeuseof.com/tag/2-cool-virtual-desktop-managers-for-windows

1 comment May 5, 2008


Categories

AD

May 2008
M T W T F S S
« Apr   Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

1

Blog Stats

Talk To Me

Text