31 May 2020

Geeky way to copy data between laptops which are in same network

Guys

Recently, I had a requirement to copy data from a laptop with disabled USB ports to a laptop which was normal 😉.
Since , I could not have used a pen drive to transfer data, so, I wrote a simple java socket program which served my purpose beautifully. Of-course, already available FTP client/server apps would have proven handy but what's fun in that!

PS: I hope it is self-explanatory that I didn't have the privileges to change the WORK-GROUP/DOMAIN of a laptop whose USB ports were disabled 

In case you tick any of the below criteria , then , you could use my code

1. USB ports are disabled on a laptop.
2. You are not a great admirer of FTP protocol 😄
3. You recently lost a pen drive
4. You can't change the WORK-GROUP/DOMAIN of a laptop.
5. You want to learn java socket programming
6. You are curious
7. You want to submit it as your semester project assignment.

Click here to get the deliverable.

In case , you want to see source code , DM me.









Delicious add to del.icio.us saved by 0 users

07 March 2014

Getting introduced to Spring...where to start..

For an introduction to Spring...please refer to this url...
http://docs.spring.io/docs/Spring-MVC-step-by-step/

Pom file example to download spring dependencies in Maven 
pom_spring




Delicious add to del.icio.us saved by 0 users

06 January 2013

All about oracle Jobs

This is how a basic job is written :

BEGIN
  DBMS_SCHEDULER.create_job (
    job_name        => 'myJob', 
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN procedure_name ; END;',
    start_date      => SYSTIMESTAMP,
    repeat_interval => 'freq=hourly; byminute=0; bysecond=0;',
    end_date        => NULL,
    enabled         => TRUE,
    comments        => 'Job defined entirely by the CREATE JOB procedure.');
END;

Note :  Other types of repeat_interval 
repeat_interval => 'freq=weekly; BYDAY=sun; byhour=8; byminute=0',
repeat_interval  =>  'FREQ=SECONDLY;INTERVAL=10',



This is how job details can be seen :

SELECT * FROM dba_scheduler_jobs;
 
Stopping job :
 
BEGIN
DBMS_SCHEDULER.STOP_JOB('procedure_name,job_class');  
END;
  
Job class can been seen from "dba_scheduler_jobs"  table.

For dropping job use  => DBMS_SCHEDULER.DROP_JOB('procedure_name,job_class');

For disabling job use => DBMS_SCHEDULER.DISABLE('procedure_name,job_class');
For enabling job use => DBMS_SCHEDULER.ENABLE ('procedure_name,job_class'); 





for more info use links : 

Link1
Link2




Delicious add to del.icio.us saved by 0 users

30 November 2012

code to check if the string contains all digits or not

Long checkDataType(String s){

char c[]=s.toCharArray();
boolean isnum=true;

for(int i=0;i
     if(!Character.isDigit(c[i])){

    isnum=false;

    break;

  }

}

if(isnum)

return (Long.parseLong(s));

else

return null;

}




Delicious add to del.icio.us saved by 0 users

06 November 2012

All about XPath

this is the sample xml.


DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse("C:/templates.xml");

 XPath xpath=XPathFactory.newInstance().newXPath();
 XPathExpression expr=xpath.compile("//templates/template[1]/label/text()");
 NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);

 for(int i=0;i    {
        System.out.println(ns.item(i).getNodeValue());

 }

here the output will be the value of the label of 1st template tag.



XPathExpression expr=xpath.compile("//templates/template/label/text()");
  NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);

here the output will be the value of all the labels present in all the template tags


XPathExpression expr=xpath.compile("//templates/template/@name");
NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);

here the output will be the values of attribute name of all the template tags



 XPathExpression expr=xpath.compile("//templates/template");
 NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);
    for(int i=0;i       NamedNodeMap la=ns.item(i).getAttributes();
    System.out.println(la.getNamedItem("name").getNodeValue());

}

if a tag has more than 1 attribute, then , values of the attributes can be fetched like this.


  XPathExpression expr=xpath.compile("//templates/template/@name");
    NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);
    for(int i=0;i         ns.item(i).setNodeValue("this is test");
         Transformer xformer = TransformerFactory.newInstance().newTransformer();
         xformer.transform(new DOMSource(dom), new StreamResult(new File("C:/templates.xml")));
    }


This code is changing the value of the specified attribute,here the attribute name is 'name' and saving in the xml





Delicious add to del.icio.us saved by 0 users

02 November 2012

calling procedure and functon from java code

calling stored procedure :

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


String s;
 String stmt="{call test(?)}";
 System.out.println(stmt);
 CallableStatement cs=con.prepareCall(stmt);
 System.out.println("enter the name of the employee");
 s=br.readLine();
 cs.setString(1,s);
 cs.execute();


calling function:

String stmt="{?=call test_fn(?)}";

String stmt="select test_fn('abc') from dual";
CallableStatement cs=con.prepareCall(stmt);
System.out.println("enter the name of the employee");
s=br.readLine();
cs.registerOutParameter(1,java.sql.Types.INTEGER);
cs.setString(2,s);
cs.execute();


to retrieve value
cs.getInt(1) ,so, in general , cs.get(Type)(index)


also instead of  "java.sql.Types.INTEGER", "oracle.jdbc.driver.OracleTypes.INTEGER" can be used.




Delicious add to del.icio.us saved by 0 users

30 October 2012

dom parser

package check;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;



public class DOM_Demo {

Document dom;

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

new DOM_Demo().go();

}


void ret(Node d){

NodeList n=d.getChildNodes();

{
System.out.println(d.getNodeName());
for@(int i=0;i{
    if(n.item(i).getNodeType()==1)  // 1 IS THE VALUE FOR TAG

ret(n.item(i));

}
else

{

if(n.item(i).getNodeValue().trim().length()!=0)
System.out.println("val : "+n.item(i).getNodeValue());
}

}


}

}

void go() throws Exception

{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//Using factory get an instance of document builder

DocumentBuilder db = dbf.newDocumentBuilder();
//parse using builder to get DOM representation of the XML file

dom = db.parse("C:/Users/shasharm/Desktop/ibf/NS_ABIS_IRP_IP_E1.xml");

Element d = dom.getDocumentElement();

ret(d);

}

}





Delicious add to del.icio.us saved by 0 users

sax parser



import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;

public class SAXParserExample extends DefaultHandler{

    List myEmpls;
   
    private String tempVal;
   
    //to maintain context
    private Employee tempEmp;
   
   
    public SAXParserExample(){
        myEmpls = new ArrayList();
    }
   
    public void runExample() {
        parseDocument();
        printData();
    }

    private void parseDocument() {
       
        //get a factory
        SAXParserFactory spf = SAXParserFactory.newInstance();
        try {
       
            //get a new instance of parser
            SAXParser sp = spf.newSAXParser();
           
            //parse the file and also register this class for call backs
            sp.parse("employees.xml", this);
           
        }catch(SAXException se) {
            se.printStackTrace();
        }catch(ParserConfigurationException pce) {
            pce.printStackTrace();
        }catch (IOException ie) {
            ie.printStackTrace();
        }
    }

    /**
     * Iterate through the list and print
     * the contents
     */
    private void printData(){
       
        System.out.println("No of Employees '" + myEmpls.size() + "'.");
       
        Iterator it = myEmpls.iterator();
        while(it.hasNext()) {
            System.out.println(it.next().toString());
        }
    }
   

    //Event Handlers
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        //reset
        tempVal = "";
        if(qName.equalsIgnoreCase("Employee")) {
            //create a new instance of employee
            tempEmp = new Employee();
            tempEmp.setType(attributes.getValue("type"));
        }
    }
   

    public void characters(char[] ch, int start, int length) throws SAXException {
        tempVal = new String(ch,start,length);
    }
   
    public void endElement(String uri, String localName, String qName) throws SAXException {

        if(qName.equalsIgnoreCase("Employee")) {
            //add it to the list
            myEmpls.add(tempEmp);
           
        }else if (qName.equalsIgnoreCase("Name")) {
            tempEmp.setName(tempVal);
        }else if (qName.equalsIgnoreCase("Id")) {
            tempEmp.setId(Integer.parseInt(tempVal));
        }else if (qName.equalsIgnoreCase("Age")) {
            tempEmp.setAge(Integer.parseInt(tempVal));
        }
       
    }
   
    public static void main(String[] args){
        SAXParserExample spe = new SAXParserExample();
        spe.runExample();
    }
   
}








Delicious add to del.icio.us saved by 0 users

17 October 2012

jdbc connection with oracle 10 g

try{


String driverName = "oracle.jdbc.driver.OracleDriver";

Class.forName(driverName);



// Create a connection to the database

String serverName = "127.0.0.1";

String portNumber = "1521";

String sid = "xe";

String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + "/" + sid;

String username = "system";

String password = "9868626216";

Connection connection = DriverManager.getConnection(url, username, password);



String query="select * from employee";

Statement st= connection.createStatement();

ResultSet rs=st.executeQuery(query);

System.out.println(rs);

//while(rs.next())

//{



//System.out.println("not 1 empty");

//}











} catch (Exception e) {

// Could not find the database driver

e.printStackTrace();

}




Delicious add to del.icio.us saved by 0 users

08 October 2012

japplet fundamental

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class test extends JApplet  {

    public void go() {
       
       
        this.setSize(500,500);
        this.setVisible(true);
   
        this.setLayout(new FlowLayout());
        System.out.println("in go");
        JButton jb=new JButton("click me");
        this.add(jb);
       jb.addActionListener(new ActionListener()
       {
             public void actionPerformed(ActionEvent ae)
             {
                  JOptionPane.showMessageDialog(null,"japplet example");
                
                 }
           }
           );
    }
   
    public void init()
    {
        System.out.println("in init");
        try{
            SwingUtilities.invokeAndWait(new Runnable(){
                public void run()
                {
                    go();
                   
                    }
            });
        }
         catch(Exception e){
            
               e.printStackTrace();
             }
        
    }
   
   public void paint(Graphics g)
   {
          //g.drawString("hi shailesh",10,10);
       }
}




Delicious add to del.icio.us saved by 0 users

07 October 2012

creating object from string in java

import java.io.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


   
   

class test{
   
   
    static void display()
    {
        System.out.println("this is display");
        }
   
    public static void main(String args[]) throws Exception
    {
       
    String s="test";
   
    ((test)Class.forName(s).newInstance()).display();
       
    }
       
    }   




Delicious add to del.icio.us saved by 0 users

code to execute .exe in java

import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;


public class test {
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {

Process pp=run.exec("progs");    // for cmd commands use=> run.exec("cmd /c dir");  where dir is a command. another eg=>run.exec("cmd /c javac x.java")
BufferedReader in =new BufferedReader(new InputStreamReader(pp.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}


//run.exec("cmd /c start");  for opening cmd




Delicious add to del.icio.us saved by 0 users

22 February 2012

Amdocs's placement experience


In this post , I want to share my experience of cracking Amdocs which was a combined product of god's grace and mutual cooperation ;-) .
Before Amdocs came in the campus , I already had the offer from GroupSoft , so , I was not fretting but yes,was wishing to crack it. 

Abstract details:
·         Total rounds- 3(online test, technical and hr interview)
·         Online test is conducted by MeriTrac and duration is 2 hours
·         There is no negative marking
·         The online test consist of different sections and to the best of my knowledge, there is a sectional cut-off.
·         The domain of the question paper are :
Ø  English comprehension (level was quite good )
Ø  Logical questions (level was good)
Ø  Quantitative questions (rs aggarwal is sufficient)
Ø  c/c++/java questions (You have to choose 1 language. I chose c language and I believe “Test your c skills” is more than enough to crack this section. Questions were mainly from pointers, bit-wise operators and outputs)
Ø  SQL (seriously very tough)
Ø  Unix (commands only. You can bank upon  Sambita Das unix book)

Tips for online exam:
As I have already mentioned that most probably there is a sectional cut off , so friends you can’t compromise with any section.
I had a group of three and we had different forte (I had very primitive knowledge of unix still I cleared the section …don’t think need to tell how ;-) )
If possible, try to crack it in a group (plz note that favorable ambience is not guaranteed always. May be a strict invigilator come at your time. So hope for the best and prepare for the worst)
Questions are same for all, just their order is changed, so be attentive.

 Technical interview:
Only 1 person was there. The questions were:                                                                                             
 Ã˜Explanation of  final year B.Tech project(Questions from it)
 Ã˜Current thesis work in M.Tech(Questions from it)
    Ã˜ The challenges I faced in the projects and how I dealt with them
 Ã˜A code -> to arrange the no.s in descending order(yes I guess I was lucky that day J)
 Ã˜Some simple SQL queries.

Note :  I was lucky that my technical interviewer didn’t ask any question from unix but another interviewer who was taking interviews in another room, was asking unix questions also(commands and shell scripts)


HR interview:
Two people were there.

ØThe 1st and basic question->Describe yourself. I mentioned about my +ve traits only,so,they asked if I have any –ve point also and what I am doing to tackle it?

ØWhy Amdocs?

ØThey mainly asked questions from what I had described about myself

ØHR was mainly an interaction session,they were briefing about the company and opportunities there.

ØAt last they asked me if I want to ask any question from them,so, be prepared for it too…(imp)


 All the best guys…J












Delicious add to del.icio.us saved by 0 users

01 February 2011

case 39

"Why all the bad things happen with good people?" , this movie made me ponder over this. Has the Lucifer and his army grown so powerful that even the almighty is finding it hard to confine them? Although in the end, "light conquers the darkness","good defeats the bad", but at the cost of so much sacrifices and trouble:-(. Hey guys, no more adages ;-). This movie is fine. If you have flair for ghostly movies,then you can bang on it.

tada...



Delicious add to del.icio.us saved by 0 users

24 January 2011

She's out of my league

Hilarious romantic love story. This was my second movie of Jay Baruchel and I am really impressed with this fluke ;-)(a lanky creature having galore acting skills).

The genre is not novel, its the same dork gets the diva, but the presentation is really refreshing.

I recommend it for cynical singles, friends don't despair:-)



Delicious add to del.icio.us saved by 0 users

20 January 2011

chat application in java

I recently created a chat application in java which is based on client-server interaction model.

The server can't handle too much load(at max 50) as I am not using any database.

Following features of java are exploited :

*MultiThreading
*Sockets
*ArrayList

The server application is running on the IIITA server(atleast 23*6 if not 24*7)

I am attaching the link to download the "client application"

click me

Its not a big project but just the basic one which is playing with sockets and threads. If any one needs its source code, let me know.

see ya in the chat box ;)



Delicious add to del.icio.us saved by 0 users

29 December 2010

Devil(2010)

 

















If you love to see supernatural activities on screen, then its indispensable for you to watch it. Five people with not so clean social backgrounds, stuck in a lift and began to feel precarious about each other as they were creeping towards their end by...(hehehehe). Unveil it yourself. This movie deserves more rating from IMDb, don't know how this site rates
NOTE OF CAUTION: THIS IS NOT A GHOSTLY MOVIE.



Delicious add to del.icio.us saved by 0 users

24 December 2010

Tees Mar Khan(TMK)


A complete entertainer. I want to frame it like this " A good meal without sumptuous dessert". Yes Akki was loud, Katrina was doing over-acting, ending was weak still you could find a big natural smile on your face throughout the movie. Farah is good in spoofing and this time she has taken SRK to the task. And for the detractors , I want to say , in this world the toughest job is to bring smile on others' face, if you people are looking for some logic, then go and attend some science conclaves , this movie is for bollywood lovers who know that they have to left their brain at home while rushing the multiplexes.
SOME MIGHT NOT AGREE WITH ME REGARDING TMK, I CANNOT HELP THEM AFTER ALL THEY ARE BORN IN A DEMOCRACY TOO, THEY CAN ALSO SPEAK ANYTHING, NO MATTER IF ITS LOGICAL OR NOT ;-)



Delicious add to del.icio.us saved by 0 users

10 November 2010

powerset program in java

The program was to find the power set of the given set . It was given to us as a lab work, i guess it might be useful for others as software community should always look for "REUSABILITY"



import java.io.*;

class powerset
{
   
    public static void main(String args[]) throws Exception
    {
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));   
       int i;char buff[]=new char[30];
       String str[]=new String[1024];
   
       str[0]="phi";
   
    System.out.print("Enter the no. of elements in the set : ");
    int x=Integer.parseInt(br.readLine());
    System.out.println();
    double n=Math.pow(2,x);
   
        for(i=0;i<x;i++)
        {
        System.out.print("Enter the "+(i+1)+" element of the set : ");
        String s=br.readLine();
        buff[i]=s.charAt(0);
        System.out.println();
        }
   
       
    for(i=1;i<n;i++)
    {
       
    str[i]=Integer.toString(i,2);
    int z=str[i].length();
    for(int j=0;j<x-z;j++)
    str[i]="0"+str[i];       
       
    }
       
        System.out.println("THE POWER SET IS : ");   
        System.out.println(str[0]);
       
        for(i=1;i<n;i++)
        {
            for(int j=0;j<x;j++)
            {
            char chk=str[i].charAt(j);
            if(chk=='1')
            System.out.print(buff[j]);
               
               
            }
           
        System.out.println();
           
           
           
           
      }
       
       
       
       
       
       
       
       
       
       
        }
   
   
    }



Delicious add to del.icio.us saved by 0 users

19 August 2010

postfix evaluation and checking the balance of the parenthesis

here r the codes for 2 famous problems of programming lab (for 1st yr btech students although i did it in my mtech).The language used here is c++.


1. POSTFIX EVALUATION (I got this problem in the entrance exam of IIIT-A)

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>


float a[30],top=-1;
void push(int val)
{
 if(top==29)
 cout<<"\nOVERFLOW";
 else
 {
  top++;
  a[top]=val;
 }

}

void pop(char c)
{ float temp;
switch(c)
{

case '+':  temp=a[top-1]+a[top];top--;a[top]=temp;break;
case '-':   temp=a[top-1]-a[top];top--;a[top]=temp;break;
case '*':   temp=a[top-1]*a[top];top--;a[top]=temp;break;
case '/':   temp=a[top-1]/a[top];top--;a[top]=temp;break;

}

}


void main()
{  char *p=NULL; int i,s=0; char opt;
do
{ top=-1;
clrscr();
cout<<"\nENTER THE POSTFIX NOTATION(separate operator and operand by a space) : ";
gets(p);
for(i=0;p[i]!=NULL;i++)
{

if(p[i]==' ')
continue;

else if(isdigit(p[i]))
{    while(isdigit(p[i]))
{
  s=s*10+p[i]-'0';
  i++;
}
push(s);
s=0;
}
else
pop(p[i]);
}
cout<<"\nANS IS : "<<a[0];
cout<<"\n\nDO YOU WANT TO CONTINUE(y/n) : ";
cin>>opt;

}while(opt=='y'||opt=='Y');
getch();
}





2. CHECKING THE BALANCE OF THE PARENTHESIS  (I got this problem as a lab test)


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
 

int top=-1; char a[30];
 void push(char p)
 {
 if(top==29)
 cout<<"overflow";
 else
 {top++;
 a[top]=p;
 }

 }

     pop(char p)
{
     switch(p)
     {

     case ')' : if(a[top]=='('){top--;return 1;}
     case '}' : if(a[top]=='{'){top--;return 1;}
     case ']' : if(a[top]=='['){top--;return 1;}


     }
     return 0;

}

void main()
{  char *p=NULL;int i,valid=1;char opt='y';


do
{top=-1;    clrscr();     valid=1;
cout<<"\n\nENTER THE INFIX EXPRESSION : ";
gets(p);
for(i=0;p[i]!=NULL;i++)
{

if(p[i]=='('||p[i]=='{'||p[i]=='[')
push(p[i]);
else if(p[i]==')'||p[i]=='}'||p[i]==']')
{
int chk=pop(p[i]);
if(chk==0)
{valid=0;break;}

}
else
continue;
}

 if(valid==1 && top==-1)
 cout<<"\nbrackets are balanced" ;
 else
 cout<<"\nbrackets are not balanced";
cout<<"\n\ndo you wan to test more(y/n) : ";
cin>>opt;

}while(opt=='y'||opt=='Y');
 getch();
}



NOTE: IF YOU WANT TO DISCUSS ANYTHING RELATED TO C,C++,JAVA(CORE),.NET(C#),DATA STRUCTURE,SQL THEN YOU ARE AT THE CORRECT DOOR....JUST KNOCK IT:)



Delicious add to del.icio.us saved by 0 users