While developing apps for iPhone or iPad I often have to look into documentation. IMO the experience of browsing through documentation within XCode is not the best. Today I found this great Mac application which so far is the best way to browse through iOS documentation. The application I am talking about is called Dash. It is also a code snippet manager where you can put frequently used code snippets. This is a must have for iOS or Mac developers.

DashScreenshot.png

Dash can be found on iTunes. http://itunes.apple.com/app/dash/id458034879

Tagged with:
 

Once I was proud of my IT setup at home. All those desktops and laptops sharing bits-n-bytes with each other and participating in networking bliss made me proud. Year 2011 was somehow not too good to my computers. First catastrophe was the denise of my Sony VIAO laptop. This was the machine which build EverydayMobile.com.au. And I loved it. Next went the Netbook I got for attending TechEd 2009. Biggest disaster was a lightning strike which took away my power horse, my desktop which could put all other machines to shame. I still remember the day when this one went down and with it went the pride I had in my home network. This was also a machine which I assembled as I did all other desktops I’ve had. There was a special attachment.

The status now is that I have one laptop which is a Mac Book Pro. In all fairness this has been my main work machine for past 1.5 years. I am also using it as my main machine connected to a Dell 24″ monitor. Other than that there is a Windows machine connected to main TV set running XBMC. BTW: XMBC is the best media centre software out there. You must look at it.

Someone and I don’t know who said that “May the dreams of your past be the reality of your future”. With that in my mind I look forward to 2012 which shall be the year of revival for my home computing. But this time I am about to do things differently. After being influenced by Apple over last year and a half, I have decided to do without a desktop PC. So at some point in 2012 I plan to get a iMac. The model I am considering is the 27″. iMac is one of those machine which triggers love at first sight.

iMac

The configuration I have in mind is:

  • 27-inch screen
  • Intel Core i7 3.4GHz quad-core
  • 16GB RAM because I alway run Windows in VM

iMac has the ability to hook up another monitor so I will also use my Dell 24-inch monitor as a secondary screen. This will be the main work horse at home.

In terms of portable computing I am thinking another iPad. The one I have now has been permanently hijacked by boss at home. And my Mac Book Pro which serves well both for Windows and Mac development.

The question now is of funding. I have a plan up my sleeves which shall be revealed if it works.

Till then dreaming and thinking about my iMac…

Tagged with:
 

imageGoogle Shortener is a service provided by Google to create short URLs. Google Shortener has been available for some time now but only recently Google released a public API to access this service programmatically. Today I decided to try it out and wrote some C# code to work with the API. I will describe what I did in this post.

A bit about the API

Like other URL shorteners, Google API also takes in a long URL and gives you back a short one. When you click on the short URL, you end up at the same location on web as you did with your original long URL.

The API itself is implemented as a RESTful service and is very simple. You can read the overview and reference for API here.

.NET Wrapper

I wanted to use the API in my .NET application so I created a wrapper. I have made the source code available at code.google.com. Feel free to download and play with it.

There are three methods in Google Shortener API:

  1. url.insert – Shrinks a Url.
  2. url.get – Returns the long Url for a valid short url.
  3. url.list – Returns a list of Urls shortened by an authenticated user. Analytics data is also returned by this method.

If you want analytics for your Url then you must invoke the methods by passing in an API key. You can get your API key from Google API Console.

Enough talk. Let me show you the code. The main class in the wrapper is called Shortener which contains two methods: GetShortUrl() and GetLongUrl(). An API key can be passed in to the constructor of Shortener and the API key will be used for all subsequent requests for that instance.

public Reply GetShortUrl(string longUrl)
{
  string data = "{\"longUrl\":\"" + longUrl + "\"}";
  string postUrl = googleShortenerUrl;
  string response = HttpHelper.HttpPOST(postUrl, data);
  return DeserializeJSON(response);
}

public Reply GetLongUrl(string shortUrl)
{
  string getUrl = googleShortenerUrl + "&shortUrl=" + shortUrl;
  string response = HttpHelper.HttpGET(getUrl);
  return DeserializeJSON(response);
}

The response received from Google is deserialized into a Reply class.

public class Reply
{
  public string kind { get; set; }

  public string id { get; set; }

  public string longUrl { get; set; }

  public string status { get; set; }
}

GET and POST are done by using HttpHelper class. Download the code to see this class.

Conclusion

Google Shortener API is as simple as it gets. The API also let’s you retrieve analytics data for URLs. I have created a .NET wrapper for the API and have implemented functionality to get short URLs and long URLs. Next steps for this little project are to implement list method, implement authentication support and make the API a bit more rich by enhancing Reply class to support strongly typed members rather than all strings.

One final time. Link to code.

Tagged with:
 

ubuntuInstalling Oracle XE on Ubuntu was a breeze. I downloaded the package and executed it. Ubuntu Software Center kicked in and performed the installation. The issue I faced was when I started database. I got the following error:

"operation failed, deepak is not a member of dba group"

The solution is to make myself a member of dba group. This can be achieved by following command.

sudo usermod -a -G dba deepak

I could now run Oracle database without any problem.

Tagged with:
 

ubuntuAfter installing Blogilo through Synaptic Package Manager I got an error when I ran Blogilo. The error is "Cannot connect to database".

The way to resolve the issue is to install the libqt4-sql-sqlite package. The package can be installed from terminal using this command:

sudo apt-get install libqt4-sql-sqlite

I am writing this solution here for future reference. Hopefully it will help other Ubuntu users aswell.

Tagged with:
 

I installed Netbeans 6.9 on my machine and found that Javadoc is not installed. For example when invoking intellisense for a method in Calendar class I get the following message.

Javadoc not available

Javadoc is not installed with Netbeans by default but can easily be installed. This is how it’s done.

First download documentation from this link. Get the documentation zip file and copy it to a folder. Next go to Tools –> Java Platforms in Netbeans. This brings up Java Platform Manager. On this screen select the environment e.g. JDk 1.6 and then click on Javadoc tab. Browse to the zip file and click close on Java Platform Manager.

Netbeans-Java Platforms Manager

Javadoc will now be available.

Tagged with:
 

This example show you how to apply gzip compression to a file in Java.

Java supports both Zip and GZip compression out of the box. You do not need any third party components.

import java.io.*;
import java.util.zip.*;

public class GzipCompressor
{

	public void Compress(String inputFile, String outputFile)
	{
		try
		{
			BufferedReader reader =
				new BufferedReader(new FileReader(inputFile));

			BufferedOutputStream output =
				new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outputFile)));

			int b;
			while((b =reader.read()) != -1)
			{
				output.write(b);
			}

			reader.close();
			output.close();
		}
		catch(IOException e)
		{
			System.out.println(e.getMessage());
		}
	}
}
Tagged with:
 

Working through Force.com tutorials I came to the point where I wrote some Apex code. Instead of doing this via Browser based interface, I decided to use Force.com IDE which as you know is an Eclipse plugin. This post documents the steps I went through to get connectivity to the warehouse application created as part of the tutorial.

I created a new Force.com project in IDE and entered my username and password.

201012101021.jpg

Things did not go well and I got the following message.

201012101025.jpg

But I thought that I already have a security token. I’ve been logging into developer.force.com from this computer. However I decided to follow the suggestion in the message and logged into developer.force.com and went through the Reset Security Token process.

201012131251.jpg

I got the token emailed to me and used is as per the instructions on Reset Security Token page. The instruction is to append the token to the password.

And finally I was connected.

201012131248.jpg

I could now see my project in the project explorer.

201012101037.jpg

Tagged with:
 

When starting Eclipse on Windows 7 I came across this error “Failed to load the JNI shared library”. After many trials and errors the solution revealed itself. The problem was that I did not have 64 bit JVM on my machine. I had been running 32 bit JVM and that was the culprit. If you get this error then Install 64 bit JVM. Here is a link where you can find 64 bit JVM.

Tagged with:
 

I have been looking at some code from Microsoft and I found that in C# they keep curly braces on the same line. This is also the preferred style in Java. Since I also write Java code these days I decided to keep the same style for curly braces.

So how do you configure Visual Studio to place curly braces on the same line? It turns out that there are options which allow you to do this. In Visual Studio go to Tools –> Options –> Text Editor –> C# –> Formatting and toggle check boxes under New line options for braces.

image

This will not affect  existing code but any new code you write will honour these new settings.

Tagged with:
 

MTOM which stands for Message Transmission Optimization Mechanism is a W3C Recommendation which is mostly about reducing the size of binary data when transferred through SOAP web services.

Binary data can be sent through SOAP already. So what’s the need for MTOM? Well it turns out that binary data in SOAP messages is encoded as text by applying Base64 encoding. This increases the size of payload. MTOM recommends that binary data should be sent in its original form without applying any encoding. This is a good idea and can work well when transferring files via web services.

Service

I wanted to try it out in WCF which supports MTOM. So I built myself a service which gets a photo from local drive and provides an operation which can transfer the file to client. Below is the simple service contract I came up with.

[ServiceContract]
public interface IPhotoService
{
  [OperationContract]
  PhotoServiceResponse GetPhoto();
}

 


GetPhoto operation returns a PhotoServiceResponse which is defined below.

[MessageContract]
public class PhotoServiceResponse
{
  [MessageBodyMember]
  public Byte[] Photo { get; set; }
}

 

PhotoServiceResponse is a MessgeContract which has a member decorated as MessageBodyMember. This is absolutely required. Creating DataMembers as you would to describe the data to be included with a message will not work. So remember that for MTOM you must define a MessageContract which should have a MessageBodyMember.

The implementation of this service is simple.

public class PhotoService : IPhotoService
{
  public PhotoServiceResponse GetPhoto()
  {
    PhotoServiceResponse response = new PhotoServiceResponse();
    response.Photo = File.ReadAllBytes(@"c:\temp\queenstown.jpg");
    return response;
  }
}

For the config file for service I added a wsHttpBinding and specified messgeEncoding to be Mtom.

<wsHttpBinding>
  <binding name="WsHttpMtomBinding" messageEncoding="Mtom" />
</wsHttpBinding>

And the end point used the binding configuration.

<service name="WcfMTOMSample.PhotoService">
  <endpoint
    binding="wsHttpBinding"
    bindingConfiguration="WsHttpMtomBinding"
    contract="WcfMTOMSample.IPhotoService" />
</service>

Client

I created a Windows Forms client to render out the photo I’d receive from my service. GetPhoto opreation is called like any other service operation. A byte array is passed to GetPhoto method as a out parameter.

PhotoServiceClient client = new PhotoServiceClient();
byte[] photoBytes;
client.GetPhoto(out photoBytes);

 


 


Within the client config I created a wsHttpBinding and specified messgeEncoding as Mtom. I also specified good enough size to accommodate approx 2.5 mb data by setting a large value for maxReceivedMessageSize. Within readerQuotas setting the maxArrayLength attribute takes care of large arrays.

<wsHttpBinding>
  <binding
    name="IPhotoServiceBinding"
    maxReceivedMessageSize="2621440"
    messageEncoding="Mtom">
  <readerQuotas maxArrayLength="2621440"/>
  </binding>
</wsHttpBinding>

The client then used the binding configuration.

<client>
  <endpoint
    address="http://localhost:1669/PhotoService.svc"
    binding="wsHttpBinding"
    bindingConfiguration="IPhotoServiceBinding"
    contract="PhotoServiceReference.IPhotoService">
  </endpoint>
</client>

And finally I had my service return me a photo as binary data which I displayed on a form.

image

BTW: This photo is from my recent trip to Queenstown in New Zealand. A country I absolutely love and would visit again many times.

I hope you enjoyed the post.

Tagged with:
 

SQL Search by Red-Gate is a great tool for searching within database objects. It is invaluable on brown field projects where you work with existing databases. My recent experience was working with a database which had hundreds of Stored procedures, Views, Triggers etc. I had to find out all objects which used a particular table. SQL Search made this job a breeze. SQL Search does a text search across all database objects so you can also look for things like column names.

Taking an example of Northwind database. You could to search for all database objects which have the word “customer” in their text. Below is a screenshot showing the search results.

 image

The best thing is that SQL Search is free.

Tagged with: