Saturday, July 28, 2012

I love stackoverflow.com

I love stackoverlow.com. Easy to find a solution for my problem. Uncluttered user interface. I like their vote up button.

Saturday, July 7, 2012

Sencha's GPL3 licensing too restrictive

After reviewing Sencha's Open Source FAQ, I feel their interpretation of GPL3 licensing is too restrictive. Let us say, I am using Sencha ExtJs to build a public website, then my website source code will become a derived work. If I use the GPL3 license, then I have to distribute the entire source code of my website, including the back-end code. Another common scenario is using ExtJS in an intranet application. Here too, GPL3 license can not be used, as it excludes contractors from accessing the application. It seems like Sencha's GPL licensing will only work for open source projects. All others have go with their commercial license.

Reference

Fiddler Web Debugging Proxy

Today, I came to know about Fiddler. It is a great tool to inspect http requests and responses. I wanted to verify if a REST call is returning the json header  correctly or not. Fiddler came in  handy.
http://www.fiddler2.com/fiddler2/

Friday, July 6, 2012

Install Guice Module


  1. If using,  play 2.0.2, add  "com.typesafe" % "play-plugins-guice" % "2.0.3" to your build.scala file. For play 2.0.1, add  "com.typesafe" % "play-plugins-guice" % "2.0.2" to your build.scala file.
  2. Create a file called play.plugins in your app/conf directory
  3. Add 1500:com.typesafe.plugin.inject.GuicePlugin
  4. Re-run eclipsify command from the play prompt. Initially, I didn't know that I have to do this, and I was struggling for several hours.
  5. Then define Dependency class in module package and inject the service.  That's it

Dependencies.java

package module;
import com.google.inject.*;
import service.*;

public class Dependencies implements Module {
 public void configure(Binder binder) {
     binder.bind(Service.class).to(SomethingService.class);
  }  
}

Application.java


import javax.inject.*;
import service.*;
public class Application extends Controller {  
  @Inject static Service s;
  public static Result index() {
    return ok(index.render(s.demonstrate()));
  }  

Evaluating Logical Expressions

Today, I used Java 6 Scripting API to evaluate logical expressions. Here is an example:
import javax.script.*;
public class EvalScript {
    public static void main(String[] args) throws Exception {
        // create a script engine manager
        ScriptEngineManager factory = new ScriptEngineManager();
        // create a JavaScript engine
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        // evaluate JavaScript code from String
        Boolean result=(Boolean)engine.eval("'sometext'=='sometext'");
                      //result will be true
     }
  }


Reference


Getting Started with Play

Create a java project

  1. Download the latest play 2.0 zip from http://playframework.org
  2. Extract the zip file to a convenient location. Usually, I extract and put it in my c:\, so that it is easily accessible from the command prompt.
  3. Add the play framework path in your PATH environment variable.
  4. Open command prompt and 'cd' to your project folder.
  5. Enter 'play new learn-play' from your project folder (where learn-play is the name of your first project). 
  6. This will prompt for what language template. Pick option 2, which is 'simple java application'
  7. This will create a simple java application template. Look for  'OK, application learn-play is created. Have Fun!' message.

Run your application

  1. Open command prompt and 'cd' to your project folder. Then 'cd' to learn-play folder. 
  2. Run 'play' from the command prompt.
  3. This will show the '[learn-play]$' command prompt.
  4. Enter 'run'
  5. This will run the play application in development mode.
  6. From the browser enter 'http://localhost:9000' will run the application.

Create Eclipse Project

  1. From the play '$' prompt, enter command 'eclipsify'
  2. This will create an eclipse project.
  3. From eclipse, right click and choose Import->Existing Projects into Workspace and browse to your lean-play folder.
  4. This will open your learn-play project.
  5. Whenever you install a new module, you have to re-run the 'eclipsify' command

Reference