9 March 2015

Postcrossing Project

What is postcrossing?

Before I start to write articles about my received postcards, I would like to explain what postcrossing is. Postcrossing is a platform that allows you to send and receive postcards from other people. Postcrossing describes it as follow:
“send a postcard and receive a postcard back from a random person in the world!”. How does that work?
Rate of Airmail Postcard India Post
AIR MAIL POSTCARD TO ALL COUNTRIES AT RS.12 Postal Tickets.
SURFACE MAIL IS CLOSED BY MANY COUNTRIES.

Step 1: Make a profile
If you want to start postcrossing, you have to make a profile for yourself at postcrossing.com. You have to fill in an username, your address (to receive postcards), what languages you understand and you can choose to fill in a website and a little something about yourself.
Step 2: Request an address
When your profile is complete you can start sending postcards! When you are a new member you can have 5 postcards traveling at the same time. When more and more postcards you sent are registered, this number increases.
You can request the address by going to “Send a postcard” in the menu. There are some notes you have to read and then you are ready to click on the button to request an address. You will get the address from the person you have to send a postcard to. You will also be given a postcard-ID. It is very important to write this down on your postcard, because this is the number the receiver needs to fill in while registering the postcard.
Step 3: Write your postcard
If you have received the address and postcard-ID, you are ready to write the postcard! I always take a look at the profile of the receiver to see what their hobbies are and which postcard they like. This way I can try to send him/her the postcard of what I think will suit him/her. When the receiver hasn't put anything on his/her profile I send them a regular card of something from the India. you need to affix rs.12 Postal Ticket and write Airmail Postcard from india.
Step 4: Mail & wait
Did you write your card? Is the postcard-ID on it? Did you put enough stamps on it? Then it’s ready to be mailed! After mailing the hardest part starts… waiting for your card to arrive. When the card arrived at it’s destination your address is released, which means that from now on you can also expect your first postcard!
Hopefully I’ve given you a clear explanation of postcrossing. If you are convinced to start postcrossing yourself I can only say this: Happy Postcrossing! 

1 January 2015

Embedded Temp arduino with LM35 to Redhat Cloud

My First Embedded Device with ATmega328 Board + LM35 Temp Sensor+ 16x2 LCD Screen + Java port reading to Redhat Cloud Temp SYNC with JSON.


22 December 2014

Free postcard in India. Receive by poostcardin Facebook App

POSTCARD-IN Project! Free Postcard

This Project Will let you send Postcard to Your Loved ones for their Birthdays, Anniversary etc.
Postcard Project:
We will send free Greeting Postcard to your Address just Register with Service. This Project is carried out to go OFF the web and greet them through pen.
You Don't Have Much to Do. The Cost of Service is beared by us. You can also Donate to this project. Donate to porject
Login to the Project. you will Receive Postcard to your doorstep on the Month or Before the week of Your Special Day.




  • 1.Signup To Project
  •  
  • 2.Login to Project
  •  
  • 3.Add your Details
  •  
  • 4.Save it. Done.
  • 5.Postcard Sent on week Before Sheduled Date

18 December 2014

Fast Track Your Startup Google Lunch

Fast Track Your Startup

Startup Launch provides startups in all stages with the platform, resources, online content, mentorship and training they need to succeed. From first idea to successful implementation and growth, our mission is to help startups worldwide become successful on the Google Developers platform and open-source technologies.

1) Start 2)Build 3)Go

https://developers.google.com/startups/

17 December 2014

java test a condition stored into string variable


package com.nhc.personal;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class TestCondition {
   public static void main(String[] bag) throws Exception {
                  ScriptEngineManager factory = new ScriptEngineManager();
                  ScriptEngine engine = factory.getEngineByName(“JavaScript”);
                  String condition = “10==10 && 20==20?;
                  System.out.println(engine.eval(condition));
     }

java write logs to file


package com.nhc.personal;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
/*
 * Author : Niraj chauhan
 * */
class Base{
 
 private String path = null;
 
 Base(String path){
  this.path = path;
 }
 
 public boolean setStandardLogOutput() {
  
  if(path == null) {
   System.out.println("Sorry !! Path is null");
   return false;
  }
  
  File stdLogDirPath = new File(path);
  
  if(stdLogDirPath.exists()==false) {   
   System.out.println("Directory path "+path+ " does not exist. Creating the directory path.");
   if(stdLogDirPath.mkdirs() == false) {
    System.out.println("Could not create directory path : "+path); 
    return false;
   }else {
    System.out.println("Directory path created successfully : "+path);
   }   
  }
  
  if(stdLogDirPath.isDirectory()==false) {
   System.out.println(path +" is not a directory");
   return false;
  }
  
  File logFile = new File(path, "EngineLogs.log");
  if(logFile.exists()==false) {
   System.out.println("Log file "+logFile.getName()+ " does not exist");
   boolean isFileCreated = false;
   try {
    isFileCreated = logFile.createNewFile();
    if(isFileCreated == true) {
     System.out.println("Log file "+logFile.getName()+ " created at path : "+path);
     FileOutputStream fs = new FileOutputStream(logFile,true);
     PrintStream ps = new PrintStream(fs);
     System.setOut(ps);
     System.setErr(ps);
    }else {
     System.out.println("Error while creating file  ");
    }
   } catch (IOException e) {
    System.out.println("Exception while creating the logfile. Reason: "+e.getMessage());
    e.printStackTrace();
    return false;
   }
  }
  return true;
 }
}

public class Engine extends Base {
 
 Engine(String path){
  super(path);
 }
 
 public static void main(String[] args) {
  String ENGINE_HOME = System.getenv("ENGINE_HOME");
  System.out.println(ENGINE_HOME);
  Engine engine = new Engine(ENGINE_HOME);
  boolean flag = engine.setStandardLogOutput();
  if(flag == false) {
   System.out.println("Error while setting the Eninge stardard logs output in a EngineLogs.log file");
  }
  System.out.println("--Begin--");
  System.out.println("--Finish--");
 }
 
}

java BlockingQueue


package com.nhc.personal;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
class Consumer implements Runnable{

    protected BlockingQueue queue = null;

    public Consumer(BlockingQueue queue) {
        this.queue = queue;
    }

    public void run() {
        try {
            System.out.println("Taken:"+queue.take());
            System.out.println("Taken:"+queue.take());
            System.out.println("Taken:"+queue.take());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Producer implements Runnable{

    protected BlockingQueue queue = null;

    public Producer(BlockingQueue queue) {
        this.queue = queue;
    }

    public void run() {
        try {
            queue.put("1");
            System.out.println("Put:1");
            Thread.sleep(1000);
           
            System.out.println("Put:220");
            queue.put("220");
            Thread.sleep(1000);
           
            System.out.println("Put:38");
            queue.put("38");
            Thread.sleep(1000);           
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class BlockingQueueFlight {

    public static void main(String[] args) throws Exception {

        BlockingQueue queue = new ArrayBlockingQueue(1024);

        Producer producer = new Producer(queue);
        Consumer consumer = new Consumer(queue);

        new Thread(producer).start();
        new Thread(consumer).start();

        Thread.sleep(4000);
    }
}

Heap Memory

1) Heap is a run time data area from which memory for all class Instances and arrays is allocated

2) Heap is created at Virtual Machine Startup

3) Heap storage is reclaimed by the Garbage Collector

4) Heap may be of fixed size or may be expanded as required

5) Heap memory does not need to be Contiguous

6) If a program need More heap memory than the automatic memory management system provides then Java Virtual Machine throws OutOfMemoryError

java code of batch operation


package com.nhc.personal;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
 /**  
  *  
  * @author Niraj Chauhan  
  */
public class CommitWriteBatchTestFlight {
 
 public static void main(String[] dataTrays){
  System.out.println("--BEGIN--");
  String commitCommand = "COMMIT WORK WRITE BATCH";
  
  final String TBL_NAME = "PLAYERS";
  final String COL_ID = "ID";
  final String COL_NAME = "NAME";
  final String COL_TEAM = "TEAM";
  final String COL_TOTAL_RUNS = "TOTAL_RUNS";
  
  String createTableQuery =  "CREATE TABLE PLAYERS ( " +
          "ID INT, " +
          "NAME VARCHAR(255), " +
          "TEAM VARCHAR(255), " +
          "TOTAL_RUNS VARCHAR(255)" +
         ")";
  
  try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.8.87:1521:aaadb","netvertextrunk","netvertextrunk");
    
    Statement stmt = connection.createStatement();
    stmt.execute(createTableQuery);
    System.out.println("Table create Successfully");
    stmt.close();
    
    PreparedStatement commitPrepStmt = connection.prepareStatement(commitCommand);
    PreparedStatement prepStmt = connection.prepareStatement("INSERT INTO PLAYERS (ID, NAME, TEAM, TOTAL_RUNS) VALUES (?, ?, ?, ?)");
    
    long startTime = System.currentTimeMillis();
    
    for(int i=1; i<=11; i++){
     prepStmt.setInt(1, i);
     prepStmt.setString(2, "Player"+i);
     prepStmt.setString(3, "Team"+i);
     prepStmt.setString(4, "100"+i);
     prepStmt.executeUpdate();
    }
    prepStmt.close();
    
    //connection.commit();
    //System.out.println("Execution Time: "+(System.currentTimeMillis()-startTime)+" ms");
        
    commitPrepStmt.executeUpdate();
    System.out.println("Execution Time: "+(System.currentTimeMillis()-startTime)+" ms");
    
    connection.close();
    
  } catch (Exception e) {
   System.out.println("Error while executing preparedstatement, Reason: "+e.getMessage());
  }
  
  System.out.println("--END--");
 }
}

Project Jigsaw, Changes for use java development kit (JDK)

In Moving toward a modular java, It have impacts on both developers and users. The changes made for modular run-time images to java and now in JDK 9.Moving toward a modular Java, Oracle is ushering in changes that have "significant impact" on both developers and users, including breaking IDEs, a high-ranking Oracle Java official said.

Project Jigsaw modularity improvements had been intended for inclusion in Java 8, which was released in March. But Jigsaw has been deferred until the release of Java 9. With modularization, applications can use just the modules they need, offering performance improvements as well secure boundaries between components. The effort also is intended to make Java more scalable to smaller devices

Other changes in modularization include JRE (Java SE Runtime Environment) and JDK images having identical structures. Previously, a JDK image embedded the JRE in a jre subdirectory; now a JDK image is simply a runtime image that set of development tools and other items found in the JDK.User-editable configuration files that were located in the lib directory now are in the new conf directory. Also, internal file rt.jar, tools.jar and dt.jar have been removed, with the content stored in a more efficient format in implementation-private files in the lib directory.


A new built-in NIO file system provider can be used to access class and resource files stored in a run-time image. Tools previously reading rt.jar and other files directly need to be updated to this file system. 

9 December 2014

Google is building new Android compilers Jack and Jill

new compilers jack and jill could be due to the ongoing dispute with Oracle over the use of Java.

new compilers jack and Jill could be due to the ongoing dispute with Oracle over the use of Java.
What changes for developers yet defined, but part of an ongoing process to cut-down on compile times and optimize Android development process.


The internal process would be Jill adds a new pre-processing and caching step which "shields" Jack from standard .class Java bytecode, where needed, and convert it into .jayce intermediate bytecode instead. Jack then takes the Java source code, and the .jayce bytecode, and converts it into Dalvik bytecode. Removing Java bytecode means would have less of an argument. 

Ubuntu 15.04 Release Dates

Mark Shuttleworth posted a blog in which he announced the codename for the next version of Ubuntu, which will follow ubuntu 14.10 (Utopic).

Original Blog Post

"In my favourite places, the smartest thing around is a particular kind of monkey. Vexatious at times, volant and vogie at others, a vervet gets in anywhere and delights in teasing cats and dogs alike. As the upstart monkey in this business. I can think of no better mascot. And so let’s launch our vicenary cycle, our verist varlet, the Vivid Vervet!"

23-apr-2015 is the tentative release date being given for Ubuntu 15.04 ‘Vivid Vervet’. Ubuntu’s 14.04 LTS went live on 17-apr-2014. The starting alpha release will shortly available from 18th December.

How to install PHP in Ubuntu 14.10?

Step 1 : Install Apache

sudo apt-get update
sudo apt-get install apache2

Step 2: install MYSQL

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Step 3: install php


sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Step 4: Restart Apache

sudo service apache2 restart

you can find your web-server files in /var/www/html Directory

to check installation add index.php file with code

phpinfo();
?>

Check with Firefox http://localhost or http://127.0.01. 


31 August 2014

How to show a dialog to confirm that the user wishes to exit an Android Activity?

private Toast toast;
private long lastBackPressTime = 0;

@Override
public void onBackPressed() {
  if (this.lastBackPressTime < System.currentTimeMillis() - 4000) {
    toast = Toast.makeText(this, "Press back again to close this app", 4000);
    toast.show();
    this.lastBackPressTime = System.currentTimeMillis();
  } else {
    if (toast != null) {
    toast.cancel();
  }
  super.onBackPressed();
 }
}

3 May 2013

Solution Microsoft Acess ODBC 64-bit Driver


It's likely the shortcut for setting ODBC data sources is pointing to the 32bit data sources instead of 64bit.
Go to control panel -> administrative tools --> select data sources(ODBC) --> then right click on that file --> go to properties --> in the shortcut tab -> change the path from %windir%\System32\odbcad32.exe to
%windir%\SysWOW64\odbcad32.exeand make your connection. the driver for MS Access will work fine now.

23 March 2013

JAVA SERVLET CODE TO DOWNLOAD A .txt file

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import javax.servlet.ServletException;  
 import javax.servlet.http.HttpServlet;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpServletResponse;  
 /**  
  *  
  * @author Niraj Chauhan  
  */  
 public class DownloadFile extends HttpServlet {  
   protected synchronized void processRequest(  
       HttpServletRequest request,  
       HttpServletResponse response)  
   throws ServletException, IOException {  
     String filePath=request.getParameter("filePath");  
     System.out.println("filePath = "+filePath);  
     String fileName="file1";  
     if(filePath == null)return;  
     if(filePath.contains("/")){  
       String[] b = filePath.split("/");  
       fileName=b[b.length-1];  
     }          
     response.setHeader("Content-Length", String.valueOf(new File(filePath).length()));      
     response.setContentType( "application/octet-stream" );  
     //response.setContentType("application/vnd.ms-excel");  
         // System.out.println(".......response.getContentType() = "+response.getContentType());  
         response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");  
     FileInputStream inputStream = null;  
     try  
     {  
     inputStream = new FileInputStream(filePath);  
     System.out.println(" INPUTSTREAM CREATED");  
     byte[] buffer = new byte[1024];  
     int bytesRead = 0;  
     do{  
         bytesRead = inputStream.read(buffer, 0, buffer.length);  
         response.getOutputStream().write(buffer);  
     }while (bytesRead == buffer.length);  
     System.out.println(" END OF WHILE");  
     response.getOutputStream().flush();  
     System.out.println(" FLUSHING DONE");  
     }catch(Exception e){  
        System.out.println("Exception in DownloadFile.java ="+e);  
     }finally{  
     if(inputStream != null)  
         inputStream.close();  
     System.out.println(" INPUT STREAM CLOSED");  
     }  
   }  
   //   
   /**  
    * Handles the HTTP GET method.  
    * @param request servlet request  
    * @param response servlet response  
    * @throws ServletException if a servlet-specific error occurs  
    * @throws IOException if an I/O error occurs  
    */  
   @Override  
   protected void doGet(HttpServletRequest request, HttpServletResponse response)  
   throws ServletException, IOException {  
     processRequest(request, response);  
   }  
   /**  
    * Handles the HTTP POST method.  
    * @param request servlet request  
    * @param response servlet response  
    * @throws ServletException if a servlet-specific error occurs  
    * @throws IOException if an I/O error occurs  
    */  
   @Override  
   protected void doPost(HttpServletRequest request, HttpServletResponse response)  
   throws ServletException, IOException {  
     processRequest(request, response);  
   }  
   /**  
    * Returns a short description of the servlet.  
    * @return a String containing servlet description  
    */  
   @Override  
   public String getServletInfo() {  
     return "Short description";  
   }//   
 }  

19 March 2013

Convert JAVA DATE to MS SQL datetime format

 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
 Date javaDate=new Date();  
 System.out.println("Java Date : "+javaDate);  
 String msSqlDate=sdf.format(javaDate).trim();  
 System.out.println("Ms Sql Date : "+msSqlDate.replace(" ","T"));  
 insert into DATA (CREATED) values (convert(datetime,'"+msSqlDate+"'));  

JAVA CODE FOR LEFT SHIFT AND RIGHT SHIFT AND BITWISE OPERATOR

 public class Main {  
   /**  
    * @param args the command line arguments  
    */  
   public static void main(String[] rk) {  
     // range of int -2,147,483,648 to 2,147,483,647  
     // int is 32bit so below i have taken 32bits  
     int a=10; // a= 00000000 00000000 00000000 00001010 = 10 [ten]  
     a=a<<2; // left shift operator  
     //now a=00000000 00000000 00000000 00101000 = 40 [fourty]  
     System.out.println("a="+a);  
     // same way right shift operator  
     int b=2; // ..... 00000010  
     int c=2; // ..... 00000010  
     int d= c& b; //...00000010     
     System.out.println("[logican AND] c ="+c);  
     d=c|b;  
     System.out.println("[logical OR] c ="+c);  
     // same way change value of b=1 and c=2 then you could uderstand how it works bit by bit.  
   }  
 }  

java interfeces

JAVA :READ SOMETHING IMPORTANT ABOUT INTERFACE

i) All interface methods are implicitly public and abstract. In other words,
you do not need to actually type the public or abstract modifiers in the
method declaration, but the method is still always public and abstract.

ii) All variables defined in an interface must be public, static, and final—
in other words, interfaces can declare only constants, not instance variables

iii) Interface methods must not be static.

iv) Because interface methods are abstract, they cannot be marked final,
strictfp, or native.

v) An interface can extend one or more other interfaces.

vi) An interface cannot extend anything but another interface.

vii) An interface cannot implement another interface or class.

viii) An interface must be declared with the keyword interface.

ix) Interface types can be used polymorphically

Set CSS Using JavaScript

 function setSCC(){  
         var element=document.getElementById("add");        element.className='btn_disable';   
         element.style.height="100px";  
         element.style.width="200px";  
         element.disable=true;  
 }  
 Note : Above function can get the element having id="add". and it will set its css class to "btn_disable" and will set it height and width as specified , as well as it will disable the button.  
 u should have the css included in your page.  
 common.css  
 --------------------  
 .btn_disable  
 {  
    font-family: Arial;  
  font-size:10pt;  
  height:30px;  
     background-color:gray;  
    color:red;  
 }  

JAVA SCRIPT TO VALIDATE TIME IN "dd-mm-yyyy hh:mm:ss" FORMAT

 function validateStartTime() {  
  //This function will validte the datetimes of this format : dd-mm-yyyy hh:mm:ss  
  var date  = document.getElementById("startTime").value.trim();  
   var valid  = true;  
   var spaceIndex = date.indexOf(" ");  
   var onlyDate = date.substring(0,spaceIndex);  
   var dateData = onlyDate.split("-");   
   var onlyTime = date.substring(spaceIndex);   
   var timeData = onlyTime.split(":");    
   var day  = (dateData[0]);     
   var month  = (dateData[1]);    
   var year  = (dateData[2]);    
   var hour  = (timeData[0]);    
   var min  = (timeData[1]);    
   var sec  = (timeData[2]);      
   var regForDate = new RegExp("\\d{1,2}-\\d{1,2}-\\d{4}$");  
   var regForTime = new RegExp("\\d{1,2}:\\d{1,2}:\\d{1,2}$");  
   if(!regForDate.test(onlyDate)) valid =false;  
   else if(!regForTime.test(onlyTime)) valid =false;  
   else if((month < 1) || (month > 12)) valid = false;  
   else if((day < 1) || (day > 31)) valid = false;  
   else if(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && (day > 30)) valid = false;  
   else if((month == 2) && (((year % 400) == 0) || ((year % 4) == 0)) && ((year % 100) != 0) && (day > 29)) valid = false;  
   else if((month == 2) && ((year % 100) == 0) && (day > 29)) valid = false;  
   else if((hour < 0) || (hour > 24)) valid = false;  
   else if((min < 0) || (min > 59)) valid = false;  
   else if((sec < 0) || (sec > 59)) valid = false;       
  return valid;  
 }  

JAVA SCRIPT TO ALLOW ONE SPACE BETWEEN WORDS

 function removeExtraSpaces(){  
       var searchName = document.getElementById(“name”).value;  
       searchName = searchName.trim();  
       var words = searchName.split(” “);  
       var updatedName=”";  
       if(words.length>1){  
            for(var i=0; i                     if(words[i]!=”"){  
                                 updatedName += words[i]+” “;  
                      }  
            }  
            document.getElementById(“name”).value=updatedName;  
       }  
 }  

Java code to generate unique random key

 import java.util.Random;  
 public class RandomKeyGenerator {  
    public static String generateRandomKey() {   
 String allChars = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@$%^*()_”;   
     Random random = new Random();   
     int length = random.nextInt(5);   
     length+=7;  
     char[] chars = new char[length];   
     for (int i=0; i      chars[i] = allChars.charAt(random.nextInt(allChars.length()));   
      }   
     return new String(chars);   
   }   
 }  

9 March 2013

FAT DOG 64-bit Operating System.



Fatdog64 is a small yet versatile 64-bit multi-user Linux distribution. Originally created as a "fatter" (=more built-in applications) derivative of Puppy Linux, Fatdog has grown to become a completely separate, mature 64-bit distribution. Fatdog64 still embodies the Puppy Linux spirit, fast and efficient.
At around 200MB, Fatdog boots up to a complete desktop environment ready for use; most everyday application is already included.
  • Web browser (Seamonkey browser - which uses identical code base as Firefox)
  • Universal email client (Seamonkey Mail)
  • Versatile media player (VLC)
  • Bit torrent client (Transmission)
  • Word processing (Abiword)
  • Spreadsheet (Gnumeric)
  • PDF/PS/Djvu reader (Evince)
  • PDF annotation (Xournal)
  • Graphics editor (GIMP)
  • Scanning system (Xsane, Peasyscan)
  • Printing system (CUPS)
  • Video editor (avidemux)
  • Photo retouch (Fotoxx)
  • CD/DVD/Bluray burner (PBurn)
  • Remote connection clients (RDP, VNC, SSH)
  • File sharing servers (Samba, FTP, HTTP) 
  • Text editor - IDE (Geany)
  • HTML editor (Seamonkey Composer)
And many more included, with more in its package repositories.Fatdog is versatile: Use is at a Live CD (or Live USB), or install it. Installation requires *no* re-partitioning. Fatdog can store its settings in your existing partition: FAT, Ext2/3/4, NTFS partitions are supported, as well as CIFS shares and LVM and mdadm partitions; on your harddisk, USB flash drive, or DVD+RW. PXE-booting Fatdog is easy - only two files are required.
Fatdog ISO is a dual-isohybrid ISO:
  • burn it to CD/DVD to make a bootable CD, or
  • "dd" it to a USB flash drive to make a bootable flash drive
In either case, the resulting CD/DVD or USB flash drive will boot on standard systems, UEFI systems, and systems with Secure Boot enabled (Windows 8).Note: x86-64 CPU is required. Most Intel and AMD CPUs produced after 2008 supports 64-bit (including many Intel Atoms ).
Fatdog is created by kirk; and is currently maintained by kirk and james.


Site Link