Wednesday 6 July 2016

Java Date Validations and Various Regex Validators

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CheckDateFormat {
 public static void main(String... args) {
 
  Date date = checkDates("2016-01-01");
  System.out.println(date);
 
  date = checkDates("2016-13-01");
  System.out.println(date);   //returns null
 
  date = checkDates("03/22/1974");
  System.out.println(date);   //returns null
 
 
 
 }
 public static Date checkDates(String text) {
  // http://howtodoinjava.com/regex/java-regex-date-format-validation/
  // https://www.debuggex.com/r/7jAhBMayS28ezOAN/4
  SimpleDateFormat df = null;
  
 
  if (text != null) {
   if (text.matches("\\d{4}-[01]\\d-[0-3]\\d")) {
    //http://stackoverflow.com/questions/2149680/regex-date-format-validation-on-java
    df = new SimpleDateFormat("yyyy-MM-dd");
   
   } else if (text.matches("/^(0[1-9]|1[0-2])\\/(0[1-9]|1\\d|2\\d|3[01])\\/(19|20)\\d{2}$/")) {
    //http://stackoverflow.com/questions/15196451/regular-expression-to-validate-datetime-format-mm-dd-yyyy   
    df = new SimpleDateFormat("MM/DD/YYYY");
   
   } else if (text.matches("/^(\\d{1,2})-(\\d{1,2})-(\\d{4})$/")) {
    //http://stackoverflow.com/questions/8937408/regular-expression-for-date-format-dd-mm-yyyy-in-javascript
    df = new SimpleDateFormat("dd-mm-yyyy");
   
//   } else if (text.matches("0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d")) {
//    //http://stackoverflow.com/questions/8937408/regular-expression-for-date-format-dd-mm-yyyy-in-javascript
//    df = new SimpleDateFormat("dd/mm/yyyy");
   }
 
   if (df == null) return null;   // didnt match any regex parser
  
   df.setLenient(false);
   try {
    return df.parse(text);
   } catch (ParseException ex) {
    return null;
   }
  }
  return null;
 }
}
Share:

Tuesday 21 June 2016

Thursday 9 June 2016

Bitbucket or Git Commands Sequence

HOW TO REBASE USING COMMAND LINE
In this example you want to copy all the changes from branch release/v1.0.0 into your branch.
go to your branch then type this commands

git pull
git pull --rebase origin release/v1.0.0



HOW TO COMMIT SOME CODE
git pull

git add -A

git commit -m "your remarks"  

git push




Removing a file

git rm "Filename.txt"




Conflicts tools

git mergetool
Share:

Tuesday 31 May 2016

Monday 30 May 2016

Save A File Opened in VI As The Wrong User

This happens to me all the time. I login as a normal user and start editing a file using vim. After editing is done, when I try to save the file, I don't have enough permission to save the file. I have to close the file, login as root and start editing again. Below is the given error in vim:

Try the below command
:w !sudo tee %
Explanation
  • :w – write
  • !sudo – call shell sudo command
  • tee – the output of write (:w) command is redirected using tee
  • % – current file name


stackoverflow.com/questions/28635647/how-can-i-save-a-file-i-opened-in-vim-as-the-wrong-user
Share:

Unix Command To Run .sh File


chmod Command: Run Shell Script In Linux

Another recommend option is to set an executable permission using the chmod command as follows:
chmod +x file.sh
Now your can run your .sh file as follows
./file.sh


cyberciti.biz/faq/run-execute-sh-shell-script/
Share:

Unix Deleting Folder and Files

Deleting folder and files under it. Go to the folder you want to delete then issue this command.

 sudo rm -r deletingdir 

 sudo - changing the access as root owner or admin.
 deletingdir must be in the list when you issues this ls
Share:

Saturday 28 May 2016

JQuery Code To Delete A Row

JQuery Code to delete a row





JSP Code

Share:

How To Use Syntax Highlighter

Put this code before the </header> tag



Wrap your code in this tags




 change the html tag to these values 

actionscript3 bash, shell
c-sharp,
csharp
cpp,
c
css
 delphi,
pas,
pascal diff,
patch
groovy
 js, jscript,
javascript
java
jfx,
javafx
perl, pl
php
 plain,
text
ps,
powershell
 py,
python rails, ror, ruby
scala
sql
vb,
vbnet
xml,
xhtml,
xslt,
html,
xhtml
Share:

Friday 27 May 2016

Testing Syntaxhighlighter

Share:

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.