Author Archives: cdadmin

Intercepting USSD calls in Android

Dialing a USSD code from a custom activity is straight forward using a DIAL or CALL intent, but listening to the returned result is not due to Android not having proper support for intercepting USSD calls within the platform, but partial though undocumented support exists within the native dialer application.

As a start, look at the PhoneUtils class in the Android source code. The link is for 4.0.3 but I believe this partial support has been present since 2.3.

Specifically, looking at line 217, an intent with the name “” is being composed. So what you need to do is implement your own service that responds to that intent. The service needs to be implemented according to the IExtendedNetworkService.aidl which is a part of the Android framework.

The aidl exposes several functions but the one we care about is the getUserMessage(text) function in that service. The text is the final value returned from the USSD call.


  • Since the service is binded on by PhoneUtils, then you need to start the service at phone boot up. It also means that any modification to the service will need a phone reboot.
  • Returning null from getUserMessage will suppress the dialer from showing the USSD result but there’s no way to completely hide the dialer.
  • You can also use the other functions to change the text shown while the call is in progress
  • This doesn’t seem to work on USSD prompts(menus), only on final results

Nothing explains code like a code sample, right? So I wrote a sample service and you can take a look at this link.

Inspiration for this post and code came from this Russian blog post.

Jack Compiler

There are 10 types of programmers in the world, those who have written a compiler and those who can’t read binary.

I’ve never written a compiler. At college, I had to drop the class because of a conflict and have always wanted to write one ever since. Even if just to say that I can.

The Elements of Computing Systems has a chapter focusing on building a compiler for the computer that is built throughout the book. The compiler is for an object oriented language called Jack.

Jack, the language, is designed to be simple enough to make the compilation process easier, but that doesn’t mean that it’s not an expressive language. In later chapters in the book, Jack is used to implement parts of the OS and other applications.

The grammar is easy enough and the author claims that it’s almost an LL(0) requiring only a look-ahead token in parsing expressions. The parser for it is a simple recursive descent parser.

I tried to conform to how the book does things, but preferred to do my own thing if it made more sense. It’s also still a work-in-progress and I’ll keep on working on it as time allows.

This is not a full compiler and is definitely no where near real compilers, but it’s a start. And I’d like to dedicate it to my muse without whom I would’ve given up a long time ago.

You can find the code over at my github repository at

Book Review: From Program To Product

Two years ago, I learned that you can be a brilliant programmer and write awesome code but if your code doesn’t help solve some problem or doesn’t ease someone’s pain, then you’re not really doing your part.

This is exactly the lesson that this book tries to drive home. It goes through the different aspects of creating a product from the programming and support to the licensing and legal side. The book also includes several interviews with people who have already done that. Personally, I found the interviews the most enjoyable part of it all.

The interesting part, to me, in all of this is the applications described in those interviews were really boring. As a programmer, they’re not exactly the kind of work that we love to do. I mean come on, a product to manage a stable? Tracking horses and lessons? Zzzzzz…. Not exactly the kind of work that would keep you up coding all night long. However, the applications were a success because they helped people to do their job better. They eased the pain of doing those things manually and, who knows, maybe gave someone less stress and more time to spend with their family. That is certainly what computers and programs are meant to do. To help us do what we’re supposed to do. And we’re all here to do what we’re all here to do.(The Matrix reference)

It took me a while to learn that lesson. I first noticed it when, as a freelancer, I had to work on a few jobs just to pay the bills. The tasks weren’t enjoyable to me as a programmer, I was just doing it for the money. And as a programmer, a lot of those tasks were very simple to do. Yet the people who I worked with were very grateful that I helped. And, as a business and a person, there’s nothing like a happy customer.

On the cons side of things, this wasn’t exactly a page-turner. Don’t get me wrong, the book is interesting. But recently I’ve been reading a lot of books about entrepreneurship and starting a business. And aside from the inspiration, once you’ve read one, you’ve read them all.

Overall, I give this book 3/5 stars. You can get the book from From Program to Product: Turning Your Code into a Saleable Product (Expert’s Voice).

Ugly code

Was writing some code today and ended up with “Dictionary<string, List<Dictionary<string, string>>> resultDictionary”

Does anyone else think that this is hideous? It’s a dictionary keyed by strings and holding lists of dictionaries keyed by strings and holding strings. And it is what you get when you have a statically typed language(C#) and no native dictionaries.

The code is trying to build a tree to encode as JSON to pass to javascript to represent as a tree widget…try saying that ten times.

I know what you’re thinking…and no, the code is no longer there, it only survived for a few mins before another iteration replaced it with something less icky..I tend to use evolutionary steps and refactor as i go.

Joining SpringerLink pdfs

My workplace has a subscription to SpringerLink. So I’ve been having a blast looking at the different books over there. I found lots of books that are on my Amazon wish list and so i was like a child at a candy store.

The problem is that the books are provided via separate pdf files for chapters. I am not sure why they do that, I think to make it tougher to pirate the files? Although that doesn’t really make any sense. Regardless, it is a bit annoying and I’d like to have the books as one pdf to transfer over to my trusty Sony Reader(more about it later) to read them while on the go.

So i hacked up a python script to rename the individual files by their chapter number making it easier to join. I then hacked up another script that reads these files and joins them in correct order into one file. Sadly, the scripts are only tested on Linux and will probably only run there. The first version used pyPDF and was probably cross-platform, but it had some problems with the pdfs so i reverted to using pdftotext that, as far as i know, only runs under a GNU Linux system.

This is what the code looks like for the script that does the renaming.

This is what the code looks like for the script that does the joining. pyPDF is needed for this to function.

You can download the scripts from the My Projects section. The code will be licensed under the GNU GPL.

You can check the code in its updated glory at my github account.

Note to publishers, you really should step into the 21st century. Especially for the technical books, I really don’t want to pay shipping costs that are more than the price of the book, the printing costs and all the other unneeded crap…I just want the content. This is especially true for technical books that get outdated very quickly such as books about frameworks.

#barcamp-lebanon Conclusion

BarCamp-Lebanon was great yesterday. Met some interesting people. Attended some interesting sessions(except for the 3rd one which was a waste of my time, notice no coverage) and was surprised at the abundance of geeks and geekets attending. And speaking of things that were good, that veggie pizza was great….

We also all agreed that we need more barcamps, more meet ups and more gatherings like this. To facilitate collaboration between entrepreneurs, hackers, and geeks in general. Very exciting indeed…

I feel like a 90 year old today and I’m paying the price of all of yesterday’s excitement. So forgive me my uploading speed….next up, the photos.

I’d like to thank the organizers of BarCamp-Lebanon, especially David and Sami. If you’d like to know more about the barcamp, you can visit the wiki page at BarCamp-Lebanon.

Session2 at #barcamp-lebanon, organizing hacker meetup

Just 4 people in attendance…oooh, not a lot of people want to meet up, what does that mean?
Would like to organize hacker meet ups for coding challenges, general coding….

Gathering ideas about this issue and getting feedback. Interesting. Presenter saying, “programming sucks”…really? I don’t think so.

Also talking that we should have meet ups for sharing knowledge…completely agree. Building up tech meet ups that are fun.

Somebody pitching something called lebgeeks in this session to get more feedback.
I am all in for it.

barcamp-lebanon session about IP Law and creative commons

Currently attending #barcamp-lebanon. Sitting in a session about IP law and creative commons. The main question is why don’t we promote creative commons as a way for brand recognition in this part of the world. This is specifically true for Arab media networks which are unknown in the western world.

Basically, since the cost of digital distribution is going down, we should use that to promote our brands, our knowledge and even our education.

Discussion moving on towards piracy and why is it widespread in this part of the world. Somebody noted that it is actually a much bigger problem in Asia and is a big problem throughout the world. General consensus is that media distribution that is in place is broken…Having a broken system promotes sharing and some people took it further towards piracy.

Speaker promoting using creative commons for digital content…for non-commercial use. I am not sure about that. I am not against commercial uses, just the way the content is distributed and sold.

Talk about collecting societies, interesting idea…never head about it before. Still not sure. What is being said doesn’t really chime with what i think. Maybe because i write software instead of producing digital media.

I feel like listening to a soft Richard Stallman, “sharing is good”….