Aayush Tuladhar

April 12, 2013

Using Jython with Eclipse – LinkShare

Filed under: Link Share — Tags: , — ART @ 9:55 AM

Using Jython with Eclipse

 

April 8, 2013

Installing Python Packages

Filed under: Programming — Tags: — ART @ 12:27 PM

python

You know Python’s great. It gets the job done in less amount of time but the rich community and packages available for Python makes the Python even better.
You can download the zip file and install using default python setup install but finding the right package can be hassle most of time hence I would like to give a walkthrough on some of the package management tools for Python.
1. Install Setup Tools
>> Windows <<
Install the exe for the SetupTools which can be download from

https://pypi.python.org/pypi/setuptools#using-setuptools-and-easyinstall
or for Debian System use,
sudo apt-get install python-setuptools
Within the setuptools, you can use EasyInstall which lets you automatically download, build, install and manage Python Packages.

 

2. Install Pip [[ 
https://pypi.python.org/pypi/pip
 ]]
Pip is a another tool for installing and managing Python packages. It’s better than EasyInstall
easy_install pip
Not you can use pip to install various packages
pip install <package name>

January 17, 2013

8 Keys of success

Filed under: Link Share, Productivity — Tags: — ART @ 9:21 PM

8 Keys of success

  • Passion
  • Work
  • Good
  • Focus
  • Push
  • Serve
  • Ideas
  • Persistence

December 31, 2012

Adding GWT to Tomcat using Eclipse Pluggin

Filed under: Programming — Tags: , , — ART @ 7:32 PM

Google Web Toolkit is an open source set of tools for Front End support of your web applications.  It provides great features such as Dynamic and reusable User Interface components, Remote Procedure Calls (RPC), Browser history management etc. It is licensed under Apache License 2.0.

GWT on development mode runs on Jetty Server. But you can configure GWT to run on Tomcat container. Here’s a brief walkthrough the process:

[Make sure you have GWT Eclipse Plugging installed]


https://developers.google.com/eclipse/

  • Start with creating Dynamic Web Project.

Dynamic_Web_Project.jpg

  • Create a HTML file and run on the Tomcat Server to make sure your Tomcat is running properly.
  • Once you your dynamic web project is ready; Under Java Resources, Add new Source Folder [Right Click on Java Resources > New > Source Folder]
    1. Browser for the current working Project Name
    2. Add Folder name “gwt”

Note : Adding separate source folder is helpful to manage your GWT code base.

  • Once you have the “gwt” folder. Create Sample GWT Project using Eclipse Plugging. This will help to copy the same file framework as default GWT project format.

image.png

  • Check “Use Google Web Toolkit” and “Generate project sample code
  • Drag all the contents of src package from the GWT Web Application to gwt in Dynamic Web Project. Rename the filename as necessary.
  • Right Click on the Tomcat Project > Google > Web Application and On WebToolkit section, Check Use Google Web Toolkit. And in web application section, change War directory to: Web Content and Check “Launch and Deploy from this directory”.

image.png

image.png

  • At this point since no GWT code is generated. Refresh the Project and Run As > Web Application (running on external server) oint HTML file to the previous HTML we have created. And once the files are generated, add JavaScript reference to the nocache.js file

image.png

<script type="text/javascript" language="javascript" src="DRExplorer/DRExplorer.nocache.js"></script>

Now Your project is ready for using GWT plugging.

Make sure you have your entry point class ready and onModuleLoad method setup properly with respect to the HTML file.

I always try with Window.alert(“Hello World”); on the entry point just to make sure GWT pluggin is loaded property before moving forward.

December 29, 2012

Adding Google Signin feature with GWT and GAE

Filed under: Programming — Tags: , , — ART @ 1:45 PM

SignOn features using Google Web Services is easy and efficient way to authenticate users. It’s pretty common these days to have authentication via Google UserServices. Google App Engine provides UserServiceFactory api for this purpose. I tried implementing this API within Google Web Toolkit and here’s the code snippet for reference.

The code is divided to Server Side Code and Client Side Code. Server side code provides the implementation of the actual API call while the Client side code provides interface to those RPC calls and you can make asynchronous call to the server side api. Deeper understanding of RPC call can be found in my previous weblogs.

December 20, 2012

Apache Commons DBCP

Filed under: Miscellaneous — Tags: , — ART @ 5:25 PM

Image

Connection Pooling provides efficient way of using database connections. It uses shared pool of connections to perform database activities. With a connection pool, user doesn’t need to get a connection by itself, use a shared pool of connection.

Apache Commons DBCP provide efficient way to perform this task. his Commons package provides an opportunity to coordinate the efforts required to create and maintain an efficient, feature-rich package under the ASF license.

Apache commons provides framework for connection pooling code base, which makes it really easy to manage the pool.


http://commons.apache.org/dbcp/

 

December 16, 2012

JMX 101

Filed under: Programming — Tags: , — ART @ 1:17 PM
Add -Dcom.sun.management.jmxremote as VM Arguments

Sample Code :

December 1, 2012

log4j

Filed under: Programming — Tags: , , — ART @ 8:56 PM

log4j Hello World Example
Hello World Example of log4j. This instantiates a log4j logger class and logs with ERROR level on the logger class.

To run this you need log4j.jar which can be downloaded from


http://logging.apache.org/log4j/1.2/download.html

And Add log4j jar to the Java Class Path ( Eclipse : Right Click on Project > Bulid Path > Add External Archives … )


package com.aayush.logging;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class Intro1 {

public static Logger logger = Logger.getLogger(Intro1.class);

public static void main(String[] args) {
System.out.println("Hello World, Sorry I would be using log4j");
BasicConfigurator.configure();

logger.error("Hello log4j");

}

}

Using log4j.xml to add appenders to the logging configuration.
You can see that three types of appenders are used

  • File Appender – org.apache.log4j.FileAppender
  • Rolling File Appender – org.apache.log4j.RollingFileAppender
  • Console Appender – org.apache.log4j.ConsoleAppender

As name specifies, the rolling file appender have features to rolling file based on certain criteria. In this following log4j.xml we setup has file roling based on 10KB and limit the Backup Index to 5.

Similarly we can use org.apache.log4j.DailyRollingFileAppender to roll logs on daily basis as well. Log4j has various appenders support, and you can also create your own appenders as well.

Besides that in RollingFileAppender, filter is also being used to filter LevelMin and LevelMax we want to filter in the appender.


package com.aayush.logging;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class Intro1 {

	public static Logger logger = Logger.getLogger(Intro1.class);
	
	
	public static void main(String[] args) {
		System.out.println("Hello World, Sorry I would be using log4j");
		DOMConfigurator.configure("src/log4j.xml");
		for ( int i=0; i <= 1000; i++ )  {
			logger.error("Hello log4j");
			logger.debug("Hello log4j");
		}
		

	}

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
	<appender name="file" class="org.apache.log4j.FileAppender">
		<param name="file" value="log.out" />
		<param name="immediateFlush" value="true" />
		<param name="threshold" value="debug" />
		<param name="append" value="false" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
		</layout>
	</appender>

	<appender name="debugfile" class="org.apache.log4j.RollingFileAppender">
		<param name="maxFileSize" value="10KB" />
		<param name="maxBackupIndex" value="5" />
		<param name="File" value="debug.log" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
		</layout>
		<filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="LevelMin" value="debug" />
			<param name="LevelMax" value="debug" />
		</filter>
	</appender>

		<appender name="console" class="org.apache.log4j.ConsoleAppender">
			<param name="Target" value="System.out" />
			<layout class="org.apache.log4j.PatternLayout">
				<param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
			</layout>
		</appender>

                <appender name="mail" class="org.apache.log4j.net.SMTPAppender">
	               <param name="SMTPHost" value="relay.int.westgroup.com" />
	               <param name="From" value="aayush.tuladhar@gmail.com	" />
	               <param name="To" value="aayush.tuladhar@gmail.com" />
	               <param name="Subject" value="[LOG] ..." />
	               <param name="BufferSize" value="1" />
	               <param name="threshold" value="error" />
	               <layout class="org.apache.log4j.PatternLayout">
		             <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
	               </layout>
              </appender>

		<root>
			<priority value="all"></priority>
			<appender-ref ref="console"/>
			<appender-ref ref="debugfile" />
			<appender-ref ref="file" />
			
		</root>
	</log4j:configuration>

September 24, 2012

Greatest Misery

Filed under: Quote Bank — ART @ 9:11 AM

Distraction is the only thing that consoles us for our miseries, and yet it is itself the greatest of our miseries.

Blaise Pascal

September 18, 2012

Apache Derby

Filed under: Miscellaneous — ART @ 1:50 PM

Apache Derby

Opensouce lightweight RMDBS based on Java.

Older Posts »

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 54 other followers

%d bloggers like this: