Saturday, 1 June 2013

Multiple instances of MySQL with single installation in Windows

Specify options for each server in separate files and use --defaults-file when you install the services to tell each server what file to use. In this case, each file should list options using a [mysqld] group.
With this approach, to specify options for the 5.0.92 mysqld-nt, create a file C:\my-opts1.cnf that looks like this:
[mysqld]
basedir = C:/mysql-5.0.92
port = 3307
enable-named-pipe
socket = mypipe1
For the 5.1.71 mysqld, create a file C:\my-opts2.cnf that looks like this:
[mysqld]
basedir = C:/mysql-5.1.71
port = 3308
enable-named-pipe
socket = mypipe2

Install the services as follows (enter each command on a single line):
C:\> C:\mysql-5.0.92\bin\mysqld --install mysqld1 --defaults-file=C:\my-opts1.cnf
C:\> C:\mysql-5.1.71\bin\mysqld --install mysqld2 --defaults-file=C:\my-opts2.cnf

When you install a MySQL server as a service and use a --defaults-file option, the service name must precede the option.
After installing the services, start and stop them the same way as in the preceding example.

Thursday, 4 April 2013

Calling multiple Functions on single event in JQuery



$.firstfunc = function(cb) {
    alert("Function 1");
    return false;
}

$.secondfunc = function(){
    alert("Function 2");

    cb();
    return false;
}

$("#service_id").change(
  function() {
    $.firstfunc($.secondfunc);
});

Thursday, 7 March 2013

Using Static Variable in JavaScript

The following code snippet explains how we can use static variables
in JavaScript.  
 
function foo() {

    if( typeof foo.counter == 'undefined' ) {
        foo.counter = 0;
    }
    foo.counter++;
    document.write(foo.counter+"<br />");
}

POST Data without CURL in PHP

file_get_contents() and stream_context_create() can be used for making POST requests instead of CURL. Following code snippet explains how the data can be posted and retrieved.

$post = http_build_query(array(
    "username" => "postuser",
    "password" => "postpassword",
    "example" => "any data",
));

$context = stream_context_create(array("http"=>array(
     "method" => "POST",
     "header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
                 "Content-Length: ". strlen($post) . "\r\n",  
     "content" => $post,
))); 

$page = file_get_contents("http://example.com/login.php", false, $context);

The posted data can be retrieved at the other end i.e. login.php as a normal post
variable in the following fashion.
 
echo $_POST['username'];
echo $_POST['password'];
echo $_POST['example']; 

Wednesday, 9 January 2013

Sorting a Map by its keys in Java

 
The key is to use TreeMap or convert the HashMap to TreeMap as done below. 
 
Map<String, String> map = new HashMap<String, String>();        
Map<String, String> treeMap = new TreeMap<String, String>(map);

Thursday, 1 November 2012

Update a row in in the same table with the data of another row in MySQL

UPDATE biometric_image dt1, biometric_image dt2
SET dt1.cam_img = dt2.cam_img
WHERE  (dt1.comcaseno='775/2012' AND dt1.partytype='seller' AND dt1.partyserial='1') AND (dt2.comcaseno='775/2012' AND dt2.partytype='drafter' AND dt2.partyserial='1')

Tuesday, 16 October 2012

include JavaScript file in JSF

In JSF 2.0, you can use <h:outputScript /> tag in the <h:head> section to render a HTML “script” element, and link it to a js file. For example,

<h:outputScript library="js" name="common.js" />

It will generate following HTML output

<script type="text/javascript" 
   src="/JavaServerFaces/faces/javax.faces.resource/common.js?ln=js">
</script>

The directory hierarchy is as below.

Friday, 7 September 2012

Clean URL's and apache mod_rewrite

After a lot of brain storming and googling around I could fix the issue of Clean URLs which were not working even after having all the configurations right as per my post http://webtecblog.blogspot.in/2012/06/removing-indexphp-from-codeigniter-urls.html. The following modifications in httpd.conf saved my life.

The default settings were
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>


which I modified to

<Directory />
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>


And things started working for me. Hope this helps others as well.

Monday, 27 August 2012

Having a Date Time in a String in Java


  The following code snippet can be helpful in having a Date Time as a String in Java.

            Date dNow = new Date( );
            SimpleDateFormat ft = new SimpleDateFormat("dd:MM:yy HH:mm:ss");
            String date = ft.format(dNow.getTime());

  In the SimpleDateFormate constructor different date formats can be supplied as input.

Input from console in Java


Taking input values for console application can come out as a need at times. To take such inputs the following code snippet can be used.
 
        try {
            System.out.print("Enter input value: ");
            BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
   String in = bufferRead.readLine();
            System.out.println("The entered value is "+in);
         
        } catch (IOException ex) {
            Logger.getLogger(LogManager.class.getName()).log(Level.SEVERE, null, ex);
        }