Sunday, November 20, 2011

Calculating Code Toxicity

Are you dealing with legacy code and wondering how to calculate how toxic is your code ? Most importantly do you want to measure this on every checkin of your code using CI. There aren't many (as am aware of) tools which automates the toxicity calculation which you can hook up to CI. So decided I will write one as you might have guessed, am dealing with legacy code and obviously wanted to measure the toxicity of the code and how are we are tackling it over a period of time. You can find the code at github which has a detailed instructions on how to use the tool.

In short this tool is java based and works based on the checkstyle report of your code. It prints the aggregated toxicity for each of the checks on your console and generates a csv as an output which has toxicity values for all the files against each of the check.

Thanks to Erik's blog which helped me understand the toxicity calculation.

Sunday, August 28, 2011

Bookmarking folders in *nix environments (well its not 'alias')

Most of the time in our daily job we work on folders which are most frequently used. As a matter of fact, the first thing I do as soon as I open a terminal is to 'cd' to my project directory and few other directories which are project working directories and as you might have guessed it by now, I have always been using the wonderful tool called 'alias'. Today I came across a better tool than 'alias' to do the same job in much elegant way. 

Yes check out cdargs (http://www.skamphausen.de/cgi-bin/ska/CDargs) which is a folder bookmarking tool. I loved it as soon as I tried once. Its got two basic commands
  • mark <name> - Used to book mark the current folder  with a given name
  • cdb <name> - Used to navigate to the already bookmarked folders
You must be thinking what is so great about it, how is it any different from alias command. On well cdb does much more than just navigating to the bookmarked folder. If you run cdb command with out giving a argument, it opens a editor with a list of all bookmarked folders and you can just use your arrow keys to navigate and the feature I liked the most is you can even navigate to the sub folder of the bookmarked one and keep going as many levels as you want. 

Cool isn't it!!  Am loving it.

Sunday, July 10, 2011

Usage of DocumentReferences in ektorp for CouchDB

We are using ektorp as a java API for CouchDB and had a scenario of parent/child documents, though document based databases should not be used in the cases were there is a need for relational data, in practical world we end up having some sort of relationships between multiple documents (eg: parent/child etc). The primary reason being the choice of the document based database itself.
People go for databases like CouchDB not because there is a need for schema less data but for the other cool features these databases gives us like replication (master to master), conflict resolution etc., which can be leveraged to have a offline capability for applications. I think this itself is the smell, features like these should not drive one to use NoSQL databases, because the application domain needs the relational data.
Any ways the choice is made (yet to be challenged) and we had to figure out how to model our documents and persist in the database which has the parent/child relationship. CouchDB itself does not care how we store documents its up to the API to manage these relationships. Ektorp provides a way to achieve this (however its bit flaky, will cover the details at the end of this post)
Lets take an example which is quoted in the documentation of Ektorp itself, a BlogPost and a bunch of Comments. What if we want to store a BlogPost and Comment as different documents, can we add comments to the blog post and just by saving blog post does it save all the comments as individual documents ? the answer is yes, its is possible with @DocumentReferences annotation.
BlogPost.java

Comment.java

Blog post has a collection of comments, having a @DocumentReferences annotation on the collection comments will enable us to save a blog post by adding comment and the comment is saved as a separate document behind the scenes. However there is a trick to get this working.
1. The cascade property in the @DocumentReferences annotation, it has to be either set to ALL or SAVE_UPDATE to get this working.
2. Comment (which is a child in this case) should have a back reference to the parent with its id (blogPostId in this case) and the same has to be specified in the @DocumentRefernces annotation.
3. The most important thing is while adding a comment to the blogPost, this back reference in the comment has to be set manually. This means that before adding any children to the parent, the parent has to be persisted in the database before only then we will have the id generated for the parent which can be set as a back reference in the children. We expect typical ORM like hibernate to do this automatically for us in case of traditional RDBMS but in with ektorp we have to take care of all this manually.
Find the test below which demonstrates all the three points above.
BlogPost.java
BlogPostIntegrationTest.java


Notice that in the test, BlogPost if first created and persisted, post which a new comment is added to the blog post and just the blog post is updated this operation will create a comment as a separate document (behind the scenes). Like I mentioned before while adding a comment to the blogPost we should also set the blogPostId (backreference) in the comment explicitly.

Ektorp has documented the limitations of this usage but the example itself is not very clear hence this post :)

Monday, June 20, 2011

Have you enrolled for AADHAAR card ?

Surprisingly there isn't any notice be it in news papers or in local media about the enrollment for AADHAAR card in Bangalore. Yes Government of India started enrolling people in Bangalore. Got to know from one of my friend and was surprised by not having heard about it in the media.

All you have to do is go to the below address


Karvy Data Management Services,
"Skanda" No 59, Putana Road,
Basavanagudi,
Bangalore - 560 004.
Phone : 080 - 26621192/93

Ask for the UID form with the security guy outside office, its just one page form takes hardly couple of minutes to fill it. The security guy gives you a serial number and lets you in when your turn comes. The process takes hardly 10 mins but you gotta wait for at least an hour (may be few hours once the public announcement is done). So hurry up, go get enroll yourself. Office opens @ 0930 hrs and closes @ 1730 hrs.

And yeah dont forget to take photo copies of your age and address proof. For more information on what kind of proof is accepted go visit http://uidai.gov.in/

I was pretty impressed by the process, they let me sit next to them while entering details and did ask me to verify if all the details are correct at least thrice. And they are really fast in entering details unlike other government enrollments I have experienced so far. Once they capture the biometrics they gave me acknowledgment copy and seems they will take around 60 days for processing which include verification of details given and if all goes well they will dispatch card to your address (given in the form).

Only think I noticed bit weird was, there is a column in the form asking if I was ok to link my bank account with my AADHAAR card and I have given my consent for the same. I didn't check that option at all, but the data entry person took her liberty to tick it (I mean she gave a consent on behalf of me) but I wonder how with out giving my bank account details :P

Any ways hope it will be of some use and people wont ruin the process by registering multiple times and what not.

Wednesday, June 15, 2011

Applying git patch on svn repository


We are working on a project which uses svn repository as a central repository which has controlled checkins as patches, If someone wants to contribute to that repository they have to submit the svn patch.

But we wanted to use git as a repository for obvious reasons, so we have a mirror git repository for svn in github.
Its as simple as running the following command to generate a patch from git which is compatible with svn.

changes.patch can be applied on to svn repository with out any issues.
Origin of this command can be found @ https://gist.github.com/44537

Friday, June 10, 2011

Enabling colors for maven output

I was exploring how to enable color to the maven output and came across this link which explains how to patch the maven libraries to enable color coding, but didn't like patching maven and all to enable simple color output for maven. Then came across this wonderful shell script which uses sed to enable the color for the output generated by maven. You could also change the colors for each of the patterns like INFO, ERRORS and WARNING, for that matter any particular pattern you want because its using sed. 

Thursday, June 9, 2011

Cool VIMRC options

Have you just started using vi ? looking for all the nice options that you can set in your .vimrc which makes your experience with vi even better ? check this out https://github.com/nvie/vimrc

Just follow the instructions given under section "Installing this vimrc manually" you are all set to use vi in a much better settings.

Monday, May 2, 2011

WCF DataServices and JSON format

WCF data services by default uses the response type as XML in ATOM format. I thought there will be some configuration in web.config to change the response type to JSON. You really don't have to do anything in the web.config to change the response type. All you need to do is two things.

1. Set the response type to JSON on WEBGet method of your data service as shown below.

[WebGet(ResponseFormat = WebMessageFormat.Json)]
public IQueryable<Test> GetTests()
{
var tests = BuildTests();
return tests.AsQueryable();
}


2. On the client side while requesting a data service set the HTTP header "Accept" with a value "application/json"

Your data service will now returns JSON as a response to the request.

Sunday, May 1, 2011

Installing entity framework from Visual Studio

I was playing around with Entity Framework in .Net and when I created a project to use entity framework few library references were missing then I started looking @ if the installation was proper. This is when I discovered how to use the Package Manager in visual studio 2010 to install Entity Framework.

From within your Visual Studio 2010, go to Tools > Library Package Manager > Package Manager Console.

In the console, after the "PM>" prompt, type

install-package entityframework

you are all set to use entity framework.