Saturday, October 26, 2013

Tips for High Performance Web Site

I am enjoying my new book "High Performance WebSite". Few awesome tips for making your website better..

1) Make fewer HTTP request
2) Use a Content Delivery Network
3) Add Expires Header
4) GZip Components
5) Put Stylesheets at the top
6) Put Scripts at the bottom
7) Avoid CSS Expressions
8) Make Javascript and CSS external
9) Minify Javascript
10) Avoid Redirection
11) Make Ajax Cacheable
12) Remove Duplicate Scripts
13) Use Image Spites for CSS
14) Versioning Static Assets

We all know most of the stuff but it's always nice to revise :)

Cheers!
Manisha

Tuesday, October 22, 2013

Updating existing Playframework project from 2.1 to 2.2

It is very trivial but got few minutes wasted for not reading the play migration documentation...

I had my old project in 2.1 and wanted to updated to newer version 2.2.0.

So here I am after downloading latest version of Playframework. Subsequent to downloading, I updated the class path to latest version and changed the version in my plugins.sbt file. Dreaming it will work :(.

First Error
-------------
unresolved dependency: play#sbt-plugin;2.2.0: not found
-------------

Simple enough to understand that some plugin name has been changes. Previous plugin name was play but now it's com.typesafe.play. Hence the new line looks something like below.

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

After updating this I was confident that I will be able to work on my project now but NOPE... Same old exception. After a while realized that new version of Play comes with new SBT version. So had to update build.properties file to 0.13.0

Update line in build.properties file
-------------------------------------------
sbt.version=0.13.0

This time I was super confident that I will feel the taste of success but same error greeted me with smile. I had to come out of play prompt and did "play clean-all" and then started the play console again. 

BOOM!! Could compile it with new version..

-Manisha



Wednesday, October 9, 2013

Byte Code Enhancement: Eliminates noise for you

In one of our pairing session, I wrote couple of Model classes and public fields. You guessed it right my pair started lecturing me on encapsulation and why it's important to hide the internal representation of an object.  :D 

I am not going into the details of why and what was wrong with exposing the public field. We all know it and pretty much following the javaBean specification all the while for a reason. In gist, we want to save our internal state and don't want anybody to destroy it unintentionally or on purpose.

I assured him that Playframework will takecare of his concerns and will replace the public fields reference with getters and setters right after your original code is compiled by slightly rewriting the byte code.

Playframework helps you eliminate all these boilerplate code where you’d normally write a simple getter and setter, and allows you to just use public fields whenever you DON'T require special logic in a getter and/or setter.

You don’t have to use it, if you don’t want to, you can just create your own getters and setters and Playframework won’t touch your classes.

I would recommend to think little longer if you decide to export or re-use your class outside your application because Playframework does it's magic after class is complied therefore if you ever change your mind to use setters and getters, you have to rewrite your client code. 

Have fun
Manisha

Monday, September 9, 2013

main.scala.html fails to load with end tags

I encountered very interesting issues today when I was adding twitter bootstrap to our project. I downloaded the bootstap and added the files into my public directory. Subsequently I added below lines into our main template since I need the styles on all the pages.


href="@routes.Assets.at("bootstrap/css/bootstrap.min.css")" rel="stylesheet" media="screen">
<script src="@routes.Assets.at("bootstrap/js/bootstrap.min.js")" type="text/javascript" />

After adding I refreshed my page and it was getting rendered as blank. None of the contents were getting displayed on the page though I could see them using view source. 

I started playing around and replaced the "/>" with proper ending tag. i.e.

<link href="@routes.Assets.at("bootstrap/css/bootstrap.min.css")" rel="stylesheet" media="screen">

<script src="@routes.Assets.at("bootstrap/js/bootstrap.min.js")" type="text/javascript"></script>

Everything started working as expected. So not sure why it did not work without proper end tag. I will debug the playframwork code soon when I will have some time.

Cheers!
Manisha




Friday, May 31, 2013

Using Developer License for iPhone development

I should say my start was bumpy. I was hoping to be up and running in an hour and it took me entire morning. Yes I am dumb and agree English is my third language but stumbled upon provisioning was no fun.

So started with applying the developer license and activating it. I was pretty happy to think I am all set to develop.

1) Downloaded and installed latest version of XCode 4.6.2.
2) Upgraded to latest version iOS 6.
3) Downloaded and Installed PhoneGap latest API for iOS.

Using below command created my HelloWorld application.

./phonegap-2.7.0/lib/ios/bin/create ~/Documents/toyspace/HelloWorld com.toy.HelloWorld HelloWorld

Install iOS Simulator components by choosing. XCode -> preferences -> Downloads -> Components.

Double click on HelloWorld.xcodeproj project to open and try running it using Simulator. Should run without any hassle.

Now I wanted to deploy the same HelloWorld application on my iPhone. Very simple desire of mine. Boom encountered

"No iOS Development certificate was found. However, there is already a certificate request pending. An Agent or Admin must approve this request before you can download your certificate."

Searched the error on google and found couple of useful links. Then I realized just activating the license which was issues to me is not enough.

One should create following things to get started.
1) Login to https://developer.apple.com using your apple id.

2) Choose -> iOS-> Development -> Certificates, Identifiers & Profiles. Create a new certificate using your mac Keychain store and register it under Certificates -> Development options.
 
3) Create a App ID for the package name of your application. Otherwise you will encounter
 "Code Sign error: The identity 'iPhone Developer: x Xxxxx' doesn't match any identity in any profile" error. i.e. in our case it will be com.toy.HelloWorld.

Once you have done above things on developer website. Come back to XCODE and open the Organizer to setup your device.  On XCODE menu options choose Windows - > Organizer.

Click on Add icon on Provisioning Profile option. Provide a profile name , select the App Id which we created and select the device where you want it to be deployed and choose the certificate to register your device with XCODE.

Now select the device as target and run the application again. Hopefully you should not see any error.


Cheers!
Manisha

Saturday, May 25, 2013

Another reason to use Java 7 - Tiered Compilation


I had my Ahhhaaa moment last week when I was reading about Tiered compilation, which was introduced in Java SE 7. It combines the goodness of client and server startup. In short client startup speeds to the server VM. 

Check below graph. 



Isn't this awesome performance benefit? For more details read this documentation. So start using java 7 if you haven't already done it. Or I would say go for java 8. I know lots of big companies where java 6 is still de facto standard. Question is how can we make these companies adapt quickly. May not be appropriate for this blog post. I need another blog for my all my rants ;).

Take a look and let me know your thoughts.

Will share more
Manisha 

Thursday, March 7, 2013

File not found issue with tomcat: URL Encoding

I have to admit, today was lot better than yesterday. My struggle started when I was asked to quickly ( I mean it, in 10 minutes or so..) deploy a POC application on amazon ec2 instance. It is a windows 2008 server, so installed tomcat as service under "Program Files" and installed java 7. Hoping my 5 pages application will fly in no time that's when I noticed an error stack on the tomcat console :(. Main root cause was:

"Caused by: java.io.FileNotFoundException: File 'C:\Program%20Files\apache-tomcat-7.0.29\webapps\xyz\WEB-INF\classes\createData.sql' does not exist"

I could see the file under WEB-INF\classes and that's when I realized that my URL is getting encoded, hence all spaces are getting replaced with %20.

I had below line of code which was causing the issues since there is no folder with name "Program%20Files" in the system.

String path = FileUtils.class.getClassLoader().getResource("createData.sql").getPath();
List readLines = FileUtils.readLines(new File(path));
I wrapped it using URI and BOOM problem went away.

String path = FileUtils.class.getClassLoader().getResource("createData.sql").getPath();
List readLines = FileUtils.readLines(new File(new URI(path).getPath()));

as usual I happy soul again.
Manisha                

Wednesday, February 6, 2013

Install applications without admin permission on windows machine


Off late I am living under processes and restriction world. Got confused correct? I am consulting at a place where I don't have any permission on my own laptop. I am not complaining about installing stuff but coping under certain directory and changing the environment varibales are restricted too.
Being a developer I live in code and wants full access to environment where I am living.  I found out that if you don't have Admin access to your machine you can still do things like administrator.
Create a "Temp" directory under c:\ drive. create a wintv directory under it and copy the cmd.exe underneath it. Boom now you can do anything on your machine. Copy any exe here and you can run them, install them. To change the environment variable just open the command prompt from c:\Temp\wintv directory and open Windows\System32\sysdm.cpl file. BOOM BOOM!!
You are unstoppable again :) Manisha

"." to open the home directory in windowns


Yesterday I was tweaking with my setting.xml which resides under ~\.m2\conf directory.

I was opening my explorer and then was making hundreds of click to reach there :O. A friend (Sachin) who was standing next to me showed me a nice shortcut to open home directory with one click.
Start -> Run -> Type just "." and hit enter.. Tadaaaa it will open your home directory. Thank you for showing Sachin.   I will remember, it now. Manisha

Maven: Could not calculate build plan: Failure to transfer

Last day a very simple thing took little while for us to resolve. I was trying to setup a new project on a machine and did not have all my environment variables setup properly.


I was trying both the command line and eclipse options interchangibly. Initially I had the wrong repository settins in settings.xml so it could not download any jars and I ended up having *.lastUpdated files all over.

Eclipse maven plugin seems to stop downloading the dependencies if it seems *.lastUpdated files. I had to remove the all the *.lastUpdated file and plugin starts to work agian.
I read same clean up can be done using mvn -U clean too.   happy reading Manisha