Archive for April, 2012

Obtaining/Redeeming App Store Promo Codes

April 26th, 2012 No comments

My new iPhone app JEE Interview Questions went on sale today.

JEE Interview Questions App

I needed to get some promo codes and thought it would be a good idea to log the process of obtaining and redeeming promo codes. Before we get any further it is important to remember that Apple only gives out fifty codes for each application. These codes are strictly for non-commercial use only and will expire in 28 days.

Obtaining Promo Codes

In order to obtain the promo code for your app, start by logging into iTunes Connect. Then hit Manage Your Applications.
Manage Apps

On the Application Details page, click the “View Details” button for the version you are interested in.
App Details

The ensuing Page click the “Promo Codes” button.
Promo Codes Link

Then, enter the number of codes you would like and hit Continue. You will be asked to accept Apple’s contract.

The next page will contain a Download button that will allow you to download the promo codes in a text file.
Download Promo Codes

Redeeming Promo Codes

To redeem a promo code, you need to launch the iTunes application on your Mac or Windows. On the top right corner of the iTunes Store, click the “Redeem” link.
Redeem Code

On the next screen, enter the promo code. You might be asked to login. Then, you will see a success screen and your app will get automatically downloaded.
Redeem Success

One way to get the app is to launch the App Store app on your iPhone. Go to Updates -> Purchased -> “Not On This iPhone” and you will see your app waiting to be installed.
JEE Interview Questions - Not Purchased

Categories: iPhone, Solutions Log Tags: , ,

Custom JSR 303 Constraints

April 24th, 2012 No comments

In my previous blog post I talked about validating Spring Web applications using JSR 303 annotations. In that post, we used the out of the box JSR 303 constraints such as @NotEmpty and @Size. These out of the box constraints should be sufficient for most cases. However, there will be situations where you want to develop custom constraints. In this post, we will look at creating a custom constraint
that validates the ISBN number of a book in our Online Bookstore Admin application.

Each JSR 303 validation constraint consists of two parts. The first part is the constraint annotation itself.


import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;

public @interface Isbn 
	String message() default "{Isbn.message}";

	Class[] groups() default {};

	Class[] payload() default {};

The JSR 303 specification requires each constraint annotation to define the following three attributes:

  • message – The error message that gets returned upon validation failure. Here we have defined the default value Isbn.message that acts as a resource bundle key. It is possible to just hard code a message by simply omitting the braces.
  • groups – This defines the constraint groups that this annotation needs to be associated with. Here we will use the default group.
  • Payload – This holds the additional metadata information that can be supplied by validation clients. Here we are using the default empty array.

The @Target, @Retention and @Documented annotations are needed for the annotation declaration. The @Constraint annotation declares the validator that we will be using to validate elements annotated with @Isbn constraint.

The next step in creating the custom constraint is defining the validator.


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.validator.routines.ISBNValidator;

public class IsbnValidator implements ConstraintValidator
	public void initialize(Isbn isbn) { }

	public boolean isValid(String value, ConstraintValidatorContext validatorContext) 
		if(value == null || "".equals(value))
			return true;
			return ISBNValidator.getInstance().isValid(value);


Every constraint validator needs to implement the ConstraintValidator interface. The actual implementation of the IsbnValidator is straightforward. According to the specification, if the annotated element’s value is null or empty the validation should succeed. If you don’t want a null value, the element should be annotated with @NotNull annotation. The actual validation of the ISBN value is delegated to the Apache Validation API.

Now that we have the constraint defined, the next step is to use it in our Book Store application. To do that, we start out by creating a new property in the Book domain class and annotated it with @Isbn annotation. Here is the modified book class:


import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;


public class Book
	private String name;
	@Size(min=1, max=50)
	private String description;
	private String isbn;
	public String getIsbn() {
		return isbn;
	public void setIsbn(String isbn) {
		this.isbn = isbn;
	public String getName()
		return name;
	public void setName(String name)
	{ = name;
	public String getDescription()
		return description;
	public void setDescription(String description)
		this.description = description;
	public String toString()
		return "Name: " + name + ", Description: " + description + ", ISBN: " + isbn;

Then we need to modify the form.jsp file to add the ISBN form field.

 		<form:form method="post" action="book.html" commandName="book">
							<td>Name:</td> <td><form:input path="name" /></td> <td><form:errors path="name" /></td>
							<td>Description:</td> <td><form:textarea path="description"/></td> <td><form:errors path="description" /></td>
							<td>ISBN:</td> <td><form:input path="isbn" /></td> <td><form:errors path="isbn" /></td>
					<input type="submit" value="Create" />

The final step in this process is to add a new validation key/value to the file. Here is the new file: is a required field must be between 1 and 50 characters enter a valid ISBN

Now, when you submit the form with an invalid ISBN value, you will see a validation error.

Getting Started With Git and GitHub

April 22nd, 2012 No comments

For the last two years, I have been using Git on a windows machine. Recently, I had to install Git on my Mac and connect to Github. Since I have not blogged for such a long time, I thought of jotting down my notes here.

Setting Up Git Locally

1. The first step in this process is to download and install Git locally. The easiest way to do is to download the Git OS X installer from The recent version at the time of writing is

Once the download is complete, just run the installer. Upon successful installation, run the following command:

2. The next step is to configure Git. To do this, run the following commands from the command line:

git config –global “YOUR_NAME”
git config –global “YOUR_EMAIL”

3. Now we are ready to create a Git repository. To do that, create a new directory where you want to store your project files. For this blog, I have created a new folder called “hellogit” and moved to the folder in the terminal.

To create a new repository, simply run the following command in the project folder:

4. Now we are ready to add files to our repository. Assume that we have two files in our project test.html and test2.html. Move the files into the hellogit project folder.

Now run the git status command to know the latest status of our repository:

Git comes back saying that we have two untracked files. Git does not automatically track the files in our repository. Instead we need to explicitly add them.

5. To add files to Git, simply run the following command:

If you are new to Git, you might be wondering about the lack of feedback from Git about the add command. Just remember that upon a successful command execution, Git typically does not give you any feedback.

Let’s run the status command to see what happened:

From the above image, you can see that Git added our two files. It also mentions that we have a OS specific file DS_Store that needs to be tracked. We will address that in a minute.

6. When we are done making changes to our project files, we can check them in. To do that, simply run the following command:

In the above command, I have given a commit message “Initial Commit”.

7. Often we will end up with project and OS specific files (DS_Store) in our project folder that we don’t want to check in to Git. We can tell Git to ignore certain files and never track them. To do that, we simply create a .gitignore file that has the name(s) of the file that needs to be ignored.

Now, when the .gitignore file is in place, run the status command and you will see that the .DS_Store file is no longer tracked.

Preparing For Github

Before you can start using Github remote repository, you need to setup SSH keys. These keys are needed to establish secure connection between your computer and Github. To do that follow these steps:
1. Run the following command:

The No such file or directory indicates that you don’t have any SSH keys. Sometimes, the folder might exist but it might not have the id_rsa* SSH key files.

2. The next step is to create a new SSH key. Run the following command:

Hit enter to accept the default location. You will be asked to enter a passphrase. Enter a pass phrase and make a note of it as we will need it again.

Connecting To Github

1. Before we can push our code to a github repository, we need to create an account. Go to and create a new account.

2. Once you have created and logged into your account, you need to give github your SSH key. In order to do that, go to your account settings page and click the SSH Keys Navigation Item:

3. Copy the SSH key you created above. To do that, simply go to the .ssh folder and type the following command:

4. Click the Add SSH Key button and enter the key as well as a title.

5. Go back to the terminal and try to connect to github using this command:

When you accept Yes, you will be asked to enter the passphrase:

Check the “Remember Password in keychain” and hit Ok.

6. Now, we are ready to start pushing code to Github. Before we do that we need to create a remote repository on Github. To do that, click the New Repository button:

Enter the following information for the new repository:

Make sure you leave all the fields in their default state.

7. Once the repository has been created on Github, move to your terminal and cd.. into the hellogit project. Then run the following two commands (replace bava with your username):

Now, go back to your Github repository and you will see that the files have been pushed.

Categories: Git, Solutions Log Tags: ,