Sunday, December 22, 2013

Android Studio: New Project Wizard Weird Blank Error Resolution

Recently I bought a new laptop and had to install all my software from scratch. Everything worked fine but I just couldn't get the Android Studio working. Whenever I tried to complete the New Project Wizard, it backed off throwing the following blank error message.


I tried re-installing the Studio, JDK, trying various setup configurations, typical restarts and whatnot but this was not going away. Surprisingly the samples which comes with SDK seem to load fine. Therefore I tried to copy one sample project folder to my working folder and thought of changing everything to suit my new project. Kaboom! The error came back!!!

Then only I checked whether my working folder path is to blame...


Zoomed...


Damn it! That single quotation mark is screwing things up all this time. Shame on you Android Studio. It's almost 2014 and still you cannot sanitize user inputs? So I changed my working directory and all went fine just like the old days :) Hope this post will help someone someday who is splitting hair across this stupid error. Peace out!


Saturday, September 21, 2013

How to run AutoCAD R14 in 64bit Windows 7

If you hate reading all the step-by-step crap about how I did it, just scroll to the bottom. The summary is there :)

 


First of all a bit of history on why I actually want to do this. My father is a surveyor. While I was doing my bachelors, I wrote a program to automate block plan drawing using AutoLISP. This was running on top of AutoCAD R14, and since then he was using it to do all his work. This was installed on Windows XP and was running on a desktop PC. Recently I upgraded my laptop and I wanted to give my old one to him and it was running a genuine Windows 7. Then I faced this problem on running AutoCAD R14 on 64bit Windows 7...

Before we start, I have to confess that I actually had a copy of the files which I got from the installed directory in Windows XP. If you want to do a fresh installation, then I am not sure how you can go about running the AutoCAD setup on Windows 7. Most probably you will have to set up a virtual box running Windows XP, install AutoCAD on it and then get the installed files copied to somewhere else. (The reason being the AutoCAD R14 setup does not run on Windows XP compatibility mode)

Ok, so let's assume you have a complete copy of AutoCAD folder from a Windows XP box. If you run the AutoCAD.exe directly in Windows 7, you get a message saying 'heidi3.dll' is not found. So first thing I did was to download it and copy it to the AutoCAD folder. You can download it here.

Now when you run AutoCAD, a different type of error message starts to appear. It's thrown from 'SmartHeap Library' and reveals nothing other than its enum value :D 'MEM_BAD_POINTER'. A bit of googling revealed that it is due to the 'sh31w32.dll' which is probably out of date when dealing with a 64bit OS. So I downloaded a more recent copy and replaced which was inside the AutoCAD directory. You can get it here.

And voila! AutoCAD splash screen came up! Hold on... that was just for a second. The main interface also got loaded and greeted me with another error message. I started loving it! This time it was more specific, just like the first one. It said now it cannot find 'gdifont3.hdi'. No worries, Internet to the rescue. So I downloaded the god damn file and copied it just like before. Get it here.

I was expecting a series of file missing error messages, but to my surprise, AutoCAD loaded fine and seemed to work just like it was freshly installed on Windows 7! Even my lisp program was running perfectly. So there you have it. AutoCAD R14 running on 64bit Windows 7 without skipping a beat!

Cheers!

Ok so here's what you need to do in a nutshell:
  1. You need a copy of working AutoCAD R14 files from another computer.
  2. Copy the following files into that folder. (Replace whatever necessary)
  3. Done!

Sunday, July 7, 2013

The Android+Azure Love Story

Once upon a time, there was this beautiful princess named ‘Android’. ‘Azure’ was the most powerful warrior at that time. One sunny day… Ok, let’s cut the crap and get down to business.

If you haven’t tried out Windows Azure yet, well then you’ve been missing out a lot. Windows Azure is amazing! If you’ve been living under a rock for the last couple of years, Azure is Microsoft’s flexible, open & rock solid cloud platform. And by any chance if you haven’t heard of Android, stop reading right now and go kill yourself!

With the introduction of the Mobile Services SDK for Android, Windows Azure supports developers with super easy access to structure data storage, authenticate and push notifications using GCM. Now you are going to learn how to get started.

Prerequisites:

Let’s build a simple ‘Contacts’ app which saves its content on the cloud. Sounds pretty lame, but we gotta start somewhere right?

Step 1: Create a new mobile service in Azure.


Step 2: Go to the DATA tab and create a new table named ‘Contact’. You do not need to create the columns. They are automatically generated when the data is inserted.


Step 3: Create a new Android project.

Step 4: Extract the .jar files in Mobile Services SDK to the project’s lib folder.

Step 5: Create a new class to hold the contact data.


The class name has to be the same name as of the table in mobile service database. Case doesn't matter.


Did you notice the annotations? They specify the mapping between the DTO fields and the back end Azure table columns. They even work with private fields.

Step 6: Modify onCreate method of your main activity to insert a random contact.


Client creation takes the mobile service URL and the application key, which can be found in the portal.

Note: `getRandomContact’ and  ‘showMessage’ method implementation details are omitted for brevity.

Step 7: Run the app couple of times.


Step 8: Browse the Contact table in Azure.


So there you have it. An Android app hookup up with an Azure backend in no time! And that’s not all; you can perform all your CRUD operations with ease. You can even intercept requests to the database using the ‘Script’ tab. This is particularly useful for hooking up push notifications for the GCM clients, like illustrated below.


The only thing you have to do is to enter your API key in the ‘Push’ tab. You can get your API key by registering the app in Google APIs console.

Also you can setup authentication for your app using Google, Facebook, Microsoft or Twitter accounts very easily. All you gotta do is add the credentials under the ‘Identity’ tab.

So, hopefully you figured how easy it is to use Azure mobile services with Android. Remember that you get 10 free mobile services with your free trial, so start experimenting now. I’m sure you are going to love it.

Inspired by a Colombo Mobile Developer Meetup session.

Tuesday, April 23, 2013

SLT Usage Meter - Firefox Add-on

Get the firefox add-on here.

I ported the Chrome extension to Firefox. Nothing new there. Just use :)

Here is a screenshot:


Get the firefox add-on here.

Sunday, February 17, 2013

SLT Usage Meter - Chrome Extension

Get the chrome extension here.


I previously wrote a small Windows application for checking the SLT ADSL usage for one of my colleagues.  (If you came looking for that, go here.) And now he has changed his laptop to a MacBook Pro and wanted to run it there. We tried installing it via Wine Bottler using .NET v2.0, but it didn't quite work out. Although we managed to get the UI, it looked like the HTTP requests are not going through. This limitation drove me to implement a more generic version of the same which would work practically on any OS. And a Chrome Extension seemed to be the way to go...

To be honest I have never written one. So went through the default developer tutorials and a hell of other stack overflow posts to get things rolling. Finally managed to get it working the way I wanted. And yes it DOES work on the Mac :)

 Here is the link to install the chrome extension:
Or else you can go to Chome Extensions home page and search for 'SLT Usage Meter'. Make sure you search under 'Extensions'. It will ask for your permission to access the website which you would normally check your usage. That's all your needs to do to get it working!

Here is a screenshots of the extension at work.



Try it out and let me know how it is. Comments are most welcome. And don't forget to rate and share it :) Thanks!

Get the chrome extension here.

PS: If you want the same for Firefox, its here.

Wednesday, November 21, 2012

Etisalat Post Pay Bill Viewer

Application Download Link: http://www.mediafire.com/?vq0zp3tdjn7746h

*** This does not work anymore. Etisalat guys have fixed this security hole within 24hrs since I released this! Impressive! So kudos to them :) And cheers to anyone who got lucky and had fun while it lasted ;) ***

Suddenly my Etisalat data package stopped working so I logged in using my other Airtel connection to check what's wrong. After bit of Googling, found this official portal which lets you view your current and previous bills. While on it, it appeared that their portal is easily vulnerable to exploit. Although you need authentication to view the bills, but once you know the bill URL and get the hang of how they are classified, getting the  customer data out is a piece of cake!

After checking few bills of random users, I thought of writing a utility which can be used to check the outstanding bill amount when a customer number is given. Customer number is printed as 'Customer No' in your actual bill. You can download the application  here. You can use it to view your previous bills too. But the best part is you can check details of other random users. Just for the kicks, I decided to reveal their name, address, post pay plan and the actual phone number. So have fun while it lasts ;)

The application has a simple interface. You will have to enter your customer number and choose the month and year of the bill which you want to see. When you click 'Get Bill Details' button, it will get busy for a while and display details if available. Check out the screenshot.


Do try out the app and comment if you need any improvements to be added in the later versions. Also comment if there are any bugs. Enjoy!

Application Download Link: http://www.mediafire.com/?vq0zp3tdjn7746h

Monday, November 19, 2012

C#: Handling the “The remote host closed the connection” exception in WCF REST

In a recent project, I was involved in developing WCF Restful services for mobile clients. There were some services where the clients send files as multi-part POST requests. In some cases the file data parsing on the server fails due to missing form data fields or missing file data but those scenarios ended up throwing exception on the server. It was the most common communication exception 'The remote host closed the connection'.

The WCF method signature looked like this:
public bool SaveImage(Stream stream)

And inside the method, there is absolutely nothing special I am doing when parsing fails. I am returning true when parsing failed and false otherwise. But when it fails, it throws this exception for no reason.
After much of Googling, I found that when client is no longer connected to the service this exception may occur on the server. And the solution was to check Response.IsClientConnected property and act accordingly if its false. When I checked it, to my surprise it was false even when the method itself gets called! That is only when the parsing failed. So my conclusion was that the WCF infrastructure takes care of those requests which are not legit at the very beginning of its pipeline and releases the client to free its connection pool. But I still wonder why it passes the context to the method, if it is not willing to listen for the response.
So to fix this I added this method to my base service class:
protected bool IsClientConnected
{
    get { return HttpContext.Current.Response.IsClientConnected; }
}
In every method which takes in a Stream, I call this method and make sure client is still listening and return the response. So what do I return when client is not connected? Just null. This gets rid of getting the nasty 'remote host' exception and you can save you logs from overflowing with that.
Happy coding!
PS: The downside of using this method is that you have to use HttpContext which forces you to use AspNetCompatibilityRequirementsMode.Required, in your service which will prevent you from self-hosting it. But then again I don think clients would be disconnected in this fashion unless in that case. So I guess it's fair enough :)

Arduino Line Following Robot: Cracking the shortest/fastest path on a grid with loops

I'm sure you've created a line following robot at some point, if you've been exposed to Arduino (or any other programmable elec...