Sunday, December 29, 2013

Google App Engine Project using Maven

Since folks from google have created the archetypes for Google App Engine Web projects it is takes seconds to actually create a sample web application and deploy it!
In the post I am going to show you how to do just that, read on..
#Create a maven project using app engine archetype 
mvn archetype:generate -Dfilter=com.google.appengine:

#Select an archetype of choice 
#At the time of writing this blog post, following are the options available
Choose archetype:
1: remote -> com.google.appengine.archetypes:appengine-skeleton-archetype (-)
2: remote -> com.google.appengine.archetypes:guestbook-archetype (-)
3: remote -> com.google.appengine.archetypes:skeleton-archetype (-)
4: remote -> com.google.appengine.demos:guestbook-archetype (-)

Note: Run the following maven commands inside the project directory where the .pom exists
#Verify the demo application
mvn verify

#Start the app engine devserver on your machine 
mvn appengine:devserver

#Test the demo application locally
http://localhost:8080

#Update the 'appengine-web.xml' with the following details
{appengine.app.id}
${appengine.app.version}

####### Deploy the application on app engine 
mvn appengine:update

#The END!
Now you will be able to use the app url and access the application default being
http://{appengine.app.id}.appspot.com
https://{appengine.app.id}.appspot.com


Thursday, November 28, 2013

HBase Query Results to File

1. Create a file hbase_query with all your HBase Queries
2. Run the following command
cat hbase_query | hbase shell > hbase_output

Sunday, November 24, 2013

How to type control characters into a file using Vi

Its simple.. For example if you need to write ^@ in a file in unix
1. Open the file in insert mode using vi
2. Use the keys in the order they have been listed
(ctrl+v) + (ctrl+@)
All it means is keep the ctrl key pressed and use v & @ in close succession

Thursday, November 21, 2013

Most frequently used Maven Plugins

maven-assembly-plugin
A plugin to package a runnable jar with all its dependencies.
'SkipAssembly' property when set to false packages the dependencies inside the jar!
false
'manifest' tag can be used to set the jar manifest entries
 
         com.bytemeagain.json.JsonPrettyPrinter
         com.bytemeagain.json

  
    maven-assembly-plugin
    
     
      jar-with-dependencies
      package
      
       single
      
      
       
        jar-with-dependencies
       
       false
       
        
         com.bytemeagain.json.JsonPrettyPrinter
         com.bytemeagain.json
        
        
         development
         https://github.com/homebrewcode/java
        
       
      
     
    
  


maven-javadoc-plugin
A plugin to create java-docs using the java-doc comments in your codebase
   
    org.apache.maven.plugins
    maven-javadoc-plugin
    
     
      attach-javadocs
      
       jar
      
     
    
   

Tuesday, November 19, 2013

Sunday, November 17, 2013

CSS 2.0

I thought CSS was simple, I underestimated the power of CSS
Only when I started evangelizing did I know how cool CSS is
Here are the slides to the CSS tutorial I came up in the process :)
http://www.slideshare.net/hbshashidhar/css-20

Saturday, October 26, 2013

Remote Debugging using Eclipse

   Your java application is running on a remote machine, something goes haywire and the only way to debug your application is through making changes to a piece of code at random and redeploying it multiple time rather than actually stepping through the code??
   Well here is a better solution to that problem. Remote Debugging using Eclipse.

1. Install the Remote System Explorer

2. Establish an ssh connection to the remote server using the Remote System Explorer plugin


3. Start the java application debug server in the remote location(say hostname.company.com) with -Xdebug, -Xrunjdwp VM argument
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -jar

3. Right click on the eclipse project that you would like to hook it to Remote Debugger as in the picture


4. Right click on the Remote Java Application and select 'new'


5. Configure the connection details as shown below


6. Run the debug!
Happy bugging :)
To understand more about how it works.. Head over to
Java Debug Architecture
and
http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp-spec.html

Thursday, October 24, 2013

Aspiring Software Architect!??

A good way to start is by reading about how huge systems are built.. So where do you start? Here is where.. http://aosabook.org/en/index.html

Dozer: Bean Mapper Toolkit!

Dozer is a Java Bean to Java Bean mapper
A neat tool to map the beans which uses XML based mapping!
http://dozer.sourceforge.net/

Wednesday, October 23, 2013

Flume-ng, Hello World Quickstarter Guide!

For a bare minimum flume implementation we need to have the following components
1. Client : Java Program : Generates event(s) based on the fluctuating source

2. Source : Java Program : Must extend 'AbstractSource'. It is used to interface with the client, where the source acts as a server which listens to the events generated by the client. Based on kind of behaviour expected the source can implement or extend one of the flume source's in the 'org.apache.flume.source.*' packages
 OutOfTheBox sources: Avro, Exec, NetCat, Sequence Generator, Syslog, Scribe

3. Channel : Java Program : Connects the Source and the Sink. Acts as an event conduit between Source and Sink. There are multiple implementations of the Channel that can be used out-of-the-box which could be found in 'org.apache.flume.channel'. Most common one is the 'memory' channel
 OutOfTheBox sources: Memory, JDBC, File

4. Sink : Java Program : Must extend 'AbstractSink'. It is used to collect the events coming out of a client and write it to file system Based on kind of behaviour expected the sink can implement or extend one of the flume sink's in the 'org.apache.flume.sink.*' packages
 OutOfTheBox sources: Avro, Logger, IRC, File, HBase

## To demonstrate how flume works. Following is the simplest example ##
##### flume-agent.conf #####
#Agent Definition
myagent.sources = mysource
myagent.channels = mychannel
myagent.sinks = mysink

#Channel Definition
myagent.channels.mychannel.type = memory
myagent.channels.mychannel.capactiy = 1000
myagent.channels.mychannel.transactionCapacity = 100

#Source Definition
myagent.sources.mysource.type = exec
myagent.sources.mysource.command = tail -F /user/shashi/Somefile.txt
myagent.sources.mysource.channels = mychannel

#Sink Definition
myagent.sinks.mysink.type = hdfs
myagent.sinks.mysink.hdfs.path =  /shashi
myagent.sinks.mysink.hdfs.fileType = DataStream
myagent.sinks.mysink.channel = mychannel
Flume command to get the agent started
##### flume command #####
#Command to start flume agent
flume-ng agent --conf-file flume-agent.conf --name myagent

Shell script to increment the file being tailed by the flume
max=100
for i in `seq 1 $max`
do
    echo "$i" >> /user/shashi/Somefile.txt
done

Want to know more about it? Head over to the flume wiki page! http://archive.cloudera.com/cdh4/cdh/4/flume-ng/FlumeUserGuide.html#configuration

Code link for custom flume components: http://goo.gl/u0M5Yj

Monday, October 21, 2013

Google Developer!

Every developer should compete in the dev challenge by Google at least once in a life time :)
https://developers.google.com/

https://developers.google.com/apis-explorer/#p/

Google Dictionary API

Power packed evening with the leaders of India Inc!


Apache TIKA: Content Analysis Toolkit

Apache TIKA - is a very powerful tool for analyzing documents of almost any format!
http://tika.apache.org/

Wednesday, September 25, 2013

Cassandra frequently used CQLs

Some of the commonly used Cassandra CQLs

1. List all the keyspaces in Cassandra
use system;
select * from schema_keyspaces;

2. List all the tables in a keyspace
use {keyspace_name};
describe tables;

3. How to dump CQL output on to a file
{cassandra_home}/bin/cqlsh -f cquery.txt > cquery.out

Link to an exhaustive list of CQL query examples
http://cassandra.apache.org/doc/cql/CQL.html

Below is the snip of how the CShell would look like

Tuesday, September 24, 2013

Load a resource file in Java

Read a resource file from a web application
new PropertyConfigurator().getClass().getClassLoader().getResourceAsStream("file.properties")

Sunday, September 15, 2013

Java Official Tutorial Page

Where to start learning about Java?
http://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html

Java Memory Management
http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf

Saturday, September 14, 2013

Java Interview!!

Couple of links that I came across to prep for the Java Interview
http://stackoverflow.com/questions/2114212/questions-every-good-java-java-ee-developer-should-be-able-to-answer
http://www.techinterviews.com/interview-questions/java
http://programmers.stackexchange.com/questions/58113/how-to-interview-a-j2ee-developer
http://javarevisited.blogspot.in/2011/09/servlet-interview-questions-answers.html
http://www.javagyan.com/preparing-for-an-interview/java-j2ee-interview-questions

java.util.String

What is the o/p of the code blocks below and why is the difference in o/p's?
  String helloWorld = "Hello, world!";
  if(helloWorld=="Hello, world!"){
   System.out.println("== is true");
  }else{
   System.out.println("== is false");
  }
  
  if(helloWorld.equals("Hello, world!")){
   System.out.println(".equals is true");
  }else{
   System.out.println(".equals is false");
  }

  String helloWorld = new String("Hello, world!");
  if(helloWorld=="Hello, world!"){
   System.out.println("== is true");
  }else{
   System.out.println("== is false");
  }
  
  if(helloWorld.equals("Hello, world!")){
   System.out.println(".equals is true");
  }else{
   System.out.println(".equals is false");
  }

Wednesday, September 11, 2013

Adding code syntax highlighter to your blog post!

Click me to know how to add code snippets to your blog like below!  
public class HelloWorld {
 public static void main(String[] args) {
  System.out.println("Hello, World!");
 }
}