Wednesday, December 16, 2015

Determining image file size in Javascript

After a lot of googling and searching, I realized the best way to do this is to create a service call to the backend witht he url of the image whose size needs to be figured out.

This service should make a HEAD call to the server to get the content - length. And pass it along as a response.

Not all servers support HEAD calls so as a fallback make a GET call to the get the request and determine the file size from the headers.

We need to set few headers for this to work universally. One of them is user-agent.

Code for the same is :

private void makeRequest(@FormParam("url") String url, Map response, String requestMethod) {
    try {
        HttpURLConnection urlCon =
                (HttpURLConnection) new URL(url).openConnection();
        urlCon.setRequestMethod(requestMethod);
        urlCon.setRequestProperty("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0");
        //urlCon.setDoOutput(true);        urlCon.setDoInput(true);
        urlCon.setUseCaches(false);
        urlCon.setDefaultUseCaches(false);
        urlCon.setConnectTimeout(2*60*1000); // 2 minute        urlCon.setReadTimeout(5*60*1000); // 5 minute
        if(urlCon.getResponseCode() == HttpURLConnection.HTTP_OK)
        {
            String contentLength =  urlCon.getContentLengthLong()+"";
            String contentType = urlCon.getContentType();
            response.put("content-length",contentLength);
            response.put("content-type",contentType);
            response.put("status","ok");
        }
        else        {
            response.put("status","nok");
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
        response.put("status","nok");
    }
}

Monday, December 14, 2015

Most expensive product on Amazon India By Category

Amazon India today has become the most visited e-commerce site in India. So, I decided to analyze the most expensive products that Amazon India Sells across various category.

So lets start.

Book worth Rs 53,46,000.00



This is quiet modest. I think its a must in every library!

DVD worth Rs 40,045.23



My kids are gonna die uneducated :(

A Flip Cover worth Rs 255,255.00




I would get around 40 actual Micromax Juice phone at the same price.

A pen worth Rs 1,700,000.00




"No doubt a pen is mightier (worthier) then a sword"

Telescope worth Rs 896,000.00



This might actually be a fair price. Should understand technical part of it to comment. Help!

Spoons worth Rs 2,183,731.00




I might by a house with a kitchen at the same price. Though each spoon would just cost you mere 33,000. Thats a relief!

A Game worth Rs 868,434.00



That might be correct again, with import duty on all. I don't know.

MultiGym worth Rs 2,950,000.00



Someone from gym community should comment on this

A bath cereal worth Rs 2,010,000.00



Just 20 lacs for it. I am not sure it would be most expensive breakfast ever or bath ever.

A pair of Socks worth Rs 200,997.98



Ahem! my feet feel warm.

A Shoe worth Rs 102,035.00 

(One of the variants with size 44)




Just for one variant price shoots up 5 times, can't a computer catch that.

A Bag worth Rs 90,000



I am not a fashionista. This might be fair.


So if you are feeling rich today then dare buy one of the above products. My favorite in the list is the flip cover.

Intent of the post is to show disparity in the pricing on the most visited E-Commerce site in India, and need for a AI based Anti-Spam engine on such e-commerce sites to keep a check spam pricing. Some people might actually end up ordering these by mistake. I hope not.
Jeff Bezos, are you listening!

Update 1: Amazon have responded to the query raised by this post. They have accepted that they do need a mechanism to detect price spam. Yoohoo! I love there Customer Service! Snippet of the response is below:



Fixing Deployment.AddInAlreadyInstalledException.



If you are building any VSTO for any of the office applications, then its quite common to run into this issue.


The error message would say that

"The customization cannot be installed because another version is currently installed and cannot be upgraded from this location. To install this version of the customization, first use Add or Remove Programs to uninstall this program: TestUpdatedVersion. Then install the new customization from the following location: file:///D:/Samples/TestUpdatedVersion/bin/Debug/TestUpdatedVersion.vsto ********** Exception Text ********** Microsoft.VisualStudio.Tools.Applications.Deployment.AddInAlreadyInstalledException: The customization cannot be installed because another version is currently installed and cannot be upgraded from this location. To install this version of the customization, first use Add or Remove Programs to uninstall this program: TestUpdatedVersion. Then install the new customization from the following location: file:///D:/Samples/TestUpdatedVersion/bin/Debug/TestUpdatedVersion.vsto at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.VerifySolutionCodebaseIsUnchanged(Uri uri, String subscriptionId, Boolean previouslyInstalled) at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()"


So let me explain a fool proof way to troubleshoot this. Would be quite useful for Support Engineers.


  1. Go to Control Panel and search for this application plugin. If its listed then try to uninstall this and then re run the set-up. If its not listed or re-running the setup.exe fails then continue with step 2.
  2. Try cleaning up registry and installed file list by using a "Fix it" package from Microsoft, available here https://support.microsoft.com/en-us/mats/program_install_and_uninstall
  3. Now most probably the application is uninstalled but it has left behind some registry. So let clear them. 
  4. Press Start+R. In run command prompt type regedit and press enter.
  5. Clear any application related keys from 
  6. In registry editor go HKEY_CURRENT_USER\Software\Microsoft\Office\/Addins/
  7. to HKEY_CURRENT_USER\Software\Microsoft\VSTO\SolutionMetadata\{GUID} and clean up the entry for the VSTO. Check on the right side of the screen to figure out the right registry entry.
  8. Then check if there is an entry for HKEY_CURRENT_USER\Software\Microsoft\VSTA\Solutions\{GUID}. If there exists an entry then clear this up too. 
  9. Now First you would have to install Visual Studio 2013 Community edition from here https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx,
  10. This should result in download of mage.exe with its dependencies. https://msdn.microsoft.com/en-us/library/acz3y3te(v=vs.110).aspx Then going to C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin you should see mage.exe there.
  11. Then cd into the location for mage.exe in commandprompt.
  12. Run the following command there: mage.exe -cc. It should produce an output "Application Cache Cleared"
  13. Now reinstall the VSTO by running the setup.exe. This time it should go through for sure. If it does not then please do leave a comment.

Wednesday, December 9, 2015

Buy Gobar Online on Amazon.

Ever wanted to gift someone Gobar? Now you can. Just follow the link below!





And suppose if you dont wanto buy Cow Dung Cake, then you can also get it in powder form here:

Tuesday, December 8, 2015

One Plus X invite Finder

Lots of people are looking for one plus X invite so I decided to write a crawler to scrape it. Use this buy link to test your invite. I would keep on updating new invites here and would request people to add invite in the comment section.



          Buy Here.




Another invite at https://invites.oneplus.net/claim/IN11-AD09-16B0-E083