Saturday, November 3, 2012

nice looking calendar



 http://www.dansshorts.com/skins/dansshorts/assets/images/calendar.png



 <style>


</style>




<div class="post-date">

nice font [ hand writting like ]

<style>


</style>

<h2 class=".post-title">
<a title="Permanent Link to Creating Snippets in Eclipse" rel="bookmark" href="/post/creating-snippets-in-eclipse">

Creating Snippets in Eclipse

</a>
</h2>

Friday, October 5, 2012

db executeUpdate , return boolean instead of int {smart code}

public boolean dbDelete(sql){
 return ( db.executeUpdate(sql) ) > 0 ;
}

timer task

final Timer timer = new Timer();
timer.schedule(new TimerTask(){
@override
 public void run(){
 // write your business here
timer.cancel();
}
},5000);

Saturday, June 9, 2012

how to write jquery plugin


   <script>

(function($){
    $.fn.extend({
        //plugin name - animatemenu
        animateMenu: function(options) {

            var defaults = {
                animatePadding: 60,
                defaultPadding: 10,
                evenColor: '#ccc',
                oddColor: '#eee',
            };
            
            var options = $.extend(defaults, options);
        
            return this.each(function() {
                  var o =options;
                  var obj = $(this);              
                  var items = $("li", obj);
                  
                  $("li:even", obj).css('background-color', o.evenColor);             
                  $("li:odd", obj).css('background-color', o.oddColor);                 
                  
                  items.mouseover(function() {
                      $(this).animate({paddingLeft: o.animatePadding}, 300);
                    
                  }).mouseout(function() {
                      $(this).animate({paddingLeft: o.defaultPadding}, 300);
                    
                  });
            });
        }
    });
})(jQuery);
    
    </script>
   
   
   
   
    <script type="text/javascript">
  
        $('#menu').animateMenu({animatePadding: 30, defaultPadding:10});

    </script>

Monday, April 2, 2012

ImageServlet

package com.mehconsulting.servlets;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// The following import just gives us an example image to use for this example:
import com.mehconsulting.samples.SampleImage;

public class ImageServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
   
    public ImageServlet() {
        super();
    }

    protected void doGet(
        HttpServletRequest request, HttpServletResponse response
        ) throws ServletExceptionIOException {
       
        // Not used in our simple example - see text.
        // String imageName = request.getParameter("imageName");
       
        // For this example, just create our input stream from our sample byte array:
        ByteArrayInputStream iStream = new ByteArrayInputStream(SampleImage.sampleImage);
       
        // Determine the length of the content data.
        // In our simple example, I can get the length from the hard-coded byte array.
        // If you're getting your imaqe from a database or file,
        // you'll need to adjust this code to do what is appropriate:
        int length = SampleImage.sampleImage.length;
       
        // Hard-coded for a GIF image - see text.
        response.setContentType("image/gif");
        response.setContentLength(length);
       
        // Get the output stream from our response object, so we
        // can write our image data to the client:
        ServletOutputStream oStream = response.getOutputStream();
       
        // Now, loop through buffer reads of our content, and send it to the client:
        byte [] buffer = new byte[1024];
        int len;
        while ((len = iStream.read(buffer)) != -1) {
            oStream.write(buffer, 0, len);
        }
       
        // Now that we've sent the image data to the client, close down all the resources:
        iStream.close();
       
        oStream.flush();
        oStream.close();

Monday, March 19, 2012

ThreadPoolExecutor


ThreadPoolExecutor

Introduced in Java 5, the ThreadPoolExecutor class provides a fairly flexible implementation of a Java thread pool as outlined in our introduction. In the simplest case, the class is used as follows:
  • we construct an instance of ThreadPoolExecutor somewhere fairly "early on" in our program's life cycle (e.g. when our server starts up), passing in parameters such as the numbe of threads;
  • when we need a job executing in another thread, we call the ThreadPoolExecutor's execute() method, passing in the Runnable which is the task to be executed.
For example, the pattern of a simple server that used one threaded job to handle each incoming connection would look as follows. Note that there are some details here that for simplicity we have omitted— such as how the thread pool is shut down or what to do if it is "overloaded"— but we'll come to these issues in a moment:
import java.util.concurrent.*;
...
ExecutorService exec = Executors.newFixedThreadPool(4);

private void runServer() {
  ServerSocket sock = new ServerSocket(portNo);
  while (!stopRequested) {
    Socket s = sock.accept();
    exec.execute(new ConnectionRunnable(s));
  }
}

private static class ConnectionRunnable implements Runnable {
  private final Socket s;
  ConnectionRunnable(Socket s) {
    this.s = s;
  }
  public void run() {
    // handle connection
  }
}

Constructing a ThreadPoolExecutor: the Executors helper class

In the first line, exec will in practice be a ThreadPoolExecutor or some subclass thereof. We could have called theThreadPoolExecutor constructor directly, but it has a number of parameters which can be a bit unwieldy in the simplest case. The Executors class is a placeholder for a number of static utility methods to facilitate construction and use of thread pools (and in principle, other types of executors— see below). Utility methods such asnewFixedThreadPool() in fact declare that they return an implementation of ExecutorService: an interface thatThreadPoolExecutor, and potentially other classes in the future, implements. So in practice, that is how we will refer to our thread pool. As you see, here we construct a thread pool that will always have exactly four threads, but we'll see thatThreadPoolExecutor and the Executors utility class are actually more versatile.
Our simple server then sits in a loop in some "main" thread (which calls runServer(), continually waiting for connections. Each time a connection comes in, it is passed to the thread pool to be executed in another thread when one is free to take on the job. Meanwhile, the main thread can immediately get back to accepting further incoming connections. At some point in the near future, and in one of the threads managed by the ThreadPoolExecutor, the run() method of the passed-in ConnectionRunnable will be executed.

Next: ThreadPoolExecutor options

This example shows a very simple case of using a ThreadPoolExecutor with default options. In some cases, we will need to set a few more options to make the thread pool behave in the desired way:

Sunday, January 1, 2012

div with glass skin

div {
   width: 100px;
   height: 100px;
   margin: 10px;
   padding: 0;
   border: 1px solid rgba(0,0,0,0.5);
   border-radius: 10px 10px 2px 2px;
   background: rgba(0,0,0,0.25);
   box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
   -o-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
   -webkit-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
   -moz-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
}
 
http://dev.opera.com/articles/view/beautiful-ui-styling-with-css3-text-shadow-box-shadow-and-border-radius/#glassbox