Thursday 6 March 2014

Simple Date Formats and Converting a string to a particular date format wilth all the Date Format Definations in Java


SimpleDateFormat is a Java class that handles the date fromats. There are some basic rules followed in defining the custom date fromat.

E  - represents first 3 letters of the day of the week like (Ex: Sun, Mon, Tue etc..)

EEEE - represents the full name of the day (Ex: Sunday, Monday etc..)

yy - represents the last two digits of the year (Ex: 14 for 2014)

yyyy - represents the year (Ex: 2013,2014 etc..)

M - represents the month number (Ex: 1 for January, 2 for February, 11 for November etc..)

MM - represents the month in number with a preceded 0 (Ex: 01 for January, 02 fro February etc..)

MMM - represents the month in text with first 3 characters of the month (Ex: Jan, Feb, Mar Apr etc..)

MMMM or M's >3 - represents the full text of the month (Ex: January, February, March etc)

dd - represents the day in number with preceding zero for numbers less than 10. (Ex: 01, 02 etc..)
          (increasing each d will put a preceding 0 for example for ddd 1  becomes 001 which is not used as  the day are not more than 31 in a month)

H - represents the number of hour in 24 hours format (Ex: 1,2, 12 18, 24 etc..)

HH - represents the hour in 24 hours format with the preceding 0 (Ex: 01,02,03, 18,24 etc..)

h - represents the hour in 12 hours format ((Ex: 1,2, 12 etc..)

hh - represents the hour in 12 hours format with the preceding 0 (Ex: 01,02,03,12 etc..)

m - represents the minutes (Ex: 1, 2, 3, 59 etc..)

mm - represents the minutes with preceding 0. (Ex: 01, 02, 03, 59 etc..)

ss - for seconds withe preceding 0 (Ex: 01, 02, 03, 59 etc..)

a - represents the AM/PM.

z or zz or zzz - represents the 3 lettered Time Zone (Ex: CST, UST, IST etc..)

zzzz - represents the full Time Zone name (Ex: Central Standard Time, Indian Standard Time etc..)


Example:
Here is an example code for the Date formats.
The special characters are used for the user readable format users can put what they like most.

import java.text.SimpleDateFormat;
import java.util.Date;

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Simple Date Format test program");
       
        SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzzz");
        Date now =new Date(); //The object new will have the current date
       
        System.out.println(now);
        System.out.println(sd.format(now));
       
     }
}


How to disable mouse right click in HTML

Method 1:

Easiest way of disabling the mouse right click in the websites is by just adding the "oncontextmenu" attribute in  body tag.


Example:
<html>
<body  oncontextmenu="return false">
<h1>Disabling the Mouse Right Click in HTML.</h1>
<p>
This is a  test paragraph for to demonstrate the disabling of mouse right click.
<em color="red">Right Click on me.</em></p>
</body>
</html>

 Note:
If you don't want to disable the context menu on the whole page and if you want to disable a single element in html you need to write the oncontextmenu="return false" attribute in that particular tag.


Method 2:

Here is another way of disabling the mouse right click in the websites is by adding some javascript in the script tag. In this method you can give the alert to the user saying that the "Mouse right click is disabled in this page".

<html>
<head>
<script>
document.oncontextmenu = function() {
  alert('Mouse right click is disabled on this page!') ; 

}
</script>
</head>
<body>
<h1>Disabling the Mouse Right Click in HTML.</h1>
<p>
This is a  test paragraph for to demonstrate the disabling of mouse right click.
<em color="red">Right Click on me.</em></p>
</body>
</html>





Monday 24 February 2014

Short and Effective way to Sort a Set with its Key in Java

Many times we need to sort the data to represent in a particular order.
Here is a trick  to sort the data sets in Java. In this example i am using an unordered MapSet to demonstrate the sorting of MapSet with its key.


Map<String,String> maps_set=new Map<String,String>;

maps_set.put("Java","developed by SunMicroSystems");

 maps_set.put("CSHARP","developed by Microsoft");

 maps_set.put("PYTHON","Python Organization");



 SortedSet<string> keys=new TreeSet(maps_set.keySet());//Here the Keys were sorted by the TreeSet and placed in the keys object

  System.Out.Println("Key         Value");

 foreach (String key : keys) {
      System.Out.Println("Maps_Key:"+key+"  Map_Value:"+maps_set.get(key));
}


In the above example the I had put the 3 values into the maps_set and they are not in a alphabetical order 

Tuesday 11 February 2014

How to Know the list of processes run by a User with distribution status description from backend in Peoplesoft


By default the "Process Monitor Process List(PS_PMN_PRCSLIST)" table will not have the description of the Distribution status it will have the Fieldvalue (i.e the translate field value of the DISTSTATUS field) of the distribution status. The below Query will give you the Description of the process distribution status.

Here is the Query to know the Processes ran by a user with its distribution status description:

SQL Syntax:  
select * from PS_PMN_PRCSLIST P,PSXLATITEM X where OPRID='<operator id>  and P.DISTSTATUS=X.FIELDVALUE

Example for The processes Run By the VP1 user:

select OPRID,PRCSINSTANCE, PRCSTYPE, RUNSTATUSDESCR, DISTSTATUS, X.XLATSHORTNAME as DISTSTATUSDESCR from PS_PMN_PRCSLIST,PSXLATITEM X where  X.FIELDNAME='DISTSTATUS' and X.Fieldvalue=DISTSTATUS and  OPRID ='VP1';

Friday 7 February 2014

Effective and Faster String Building in Python

          Many times we use string building in many languages and also in python. Here is a tip for a fast string building in Python.

Commonly Used:

string1 = "Example" + " for "+ " String Building"   #Commonly used by regular developers

The above method of concatenation is not a best practice most of object oriented language will provide methods for such operations like "join" method in Python.


Best Practice:

string1 = "".join("Example"," for","String Building")   #Best practice for faster execution


 Using String Building in Python:

string1 = "%s %s %s" % ("Example","for","String Building") # Another Best Practice and very fast







Wednesday 5 February 2014

How To check the Report Distribution Node From Backend

Some times we may need to check the Report Distribution Node Details from the backend through any SQL Plus or Toad.

The table used for the Report Distribution Node is:  PS_CDM_DIST_NODE
The Query To Execute to know the distribution node details with its node name:

select * from PS_CDM_DIST_NODE where DISTNODENAME='<node_name>'

Replace the <node_name> withe node you want to search for.

Example for PROD node:  select * from PS_CDM_DIST_NODE where DISTNODENAME='PROD';





Thursday 30 January 2014

About Python and Google Appengine

Python is a light weight,easy and dynamic programming language that became popular in last couple of years.  Python can run on Windows, Linux/Unix and Mac OS and it is free to use for commercial also because of its Open Source License. You can find the License on Python's official website.


Google also supports its Python written web application top host on its most popular Google Appengine. The developer guide for Google appengine for python is available at this link.

As on the date of this post Google is providing the Python 2.7 for websites hosted on Google Appengine.
There are many web frameworks available for python language like Webapp2, Django.

You can download the latest version of Python form the Pythons Official website.



Useful Links: