Beautiful Themes for Sublime Text 3

I have been using ST3 for a while now on test drive and I have checked out some of the themes currently available for Sublime Text 3. All of these themes are available via Package Control. I am also going to link the screenshots to their respective github repo in case you don’t want to use Package Control for some (weird) reasons.

Soda Theme

Soda is probably the most popular theme for Sublime Text

Flatland Theme

Cobalt 2

Nexus Theme

Reminds me of Google Nexus.

Nexus Theme

Pseudo OSX theme

Mac / OS X users are going to love this one

Reeder Theme

Here’s another nice one

Phoenix Theme

And it’s cool


Which one did I miss?

So you know there’s a cool theme for ST3 that is not yet on this list? Please let me know in the comments, I shall add it.

Book Review: Instant Sublime Text Starter

Disclaimer: I received a copy of the book for review purposes.

The book Instant Sublime Text Starter is another nice title from Packtpub. The book gets an user started with the Sublime Text editor with very simple instructions. The book starts with installation and covers all major platforms. Having used the various operating systems over the year, I’ve found the instructions more than adequate for Windows, Linux and Mac OSX users.

The book highlights the common features of Sublime Text and provides a decent walk through. It also provides guidelines on where to go next to master the text editor. The book, as a starter is a very good one. If you’re into building software, Sublime Text could be a useful tool. And this book would certainly help you start instantly.

Tagging in Git: Why? How?

Why use Git tag?

Git tags are like milestones, markers or a specific point in the repo’s history marked as significant. Tags are usually used to mark stable releases or achievement of very important milestones.

Tags can help the users of the repo to easily navigate to the important parts of the code history like release points. For example, on Github, you can easily grab archive of “tags” in the current repo.

Dealing with Tags

List tags:

Search in tags:

That will display tags starting with “v1.” – use regex and your common sense to do complex queries. This can help you narrow down your query in case you have plenty of tags in the repo.

View a tag:

Note: The command doesn’t have “tag” in it. 🙂

Adding tags:

The “-a” denotes an annotated tag – means it’s stored as a full object in the git database where as a non annotated tag is just a pointer to a specific commit. Just drop the “-a” to create normal tags. The “-m” option is of course obvious, it allows you to add a message to the annotated tag.

Adding Tags later:

This will add the “v1.2” tag to the commit marked by “9fceb02”. “git log” will help you get the checksum of the commit.

Pushing Tags to remote branch:

PS: Git tags are not pushed automatically with generic “git push” command. You must push the tags separately.

Deleting a tag:

That will delete the tag v1.0.0.

These are the very common uses of Git tags. Look at the git manual for more complex stuff you can do with tagging 🙂

Doing magic with C# Method Extension

Say, we have a class defined in one of the assemblies shipped with a third party solution. It would be a great help if you could add a helper method to one of the objects. Unfortunately, we do not have the source code. 🙁 What do we do?

In such scenarios, .NET hasn’t left us alone in the desert 😀 The method extension technique will allow us to add our own methods to classes of our choice. Want to see an example? Take the List generics, every list of a generic type has some handy methods. Now we want to add one of ours. Printing each of the element in a list requires us to setup a foreach() loop every time. Why don’t we add an extension method named “Print()” which would print all the elements in a list – one by one? Let’s get our hands dirty!

Facts to remember:
— To extend a class and add method, we must declare a public static class with some name. The name doesn’t matter at all.
— We should define a method with our desired name in that class.
— The first parameter to the method will be “this < Object_we_want_to_extend > parameterName”. Do not forget the “this” keyword. It is the magic wand that does the magic.
— We can pass additional parameters.
— When calling the extended method from the original object, the first parameter is not required to pass. You can ignore it as if it were never there.
— For safety and security the extended method can not access private areas (fields, properties or methods).

So what do all these mean? Show me some codes! Okay, here you go:

The output shall be:

Cool, no? 😀 The code is commented as much as I thought necessary. Feel free to ask a question or submit any feedback you might come up with 🙂

Have fun implementing some extended methods on your own 🙂

Implementing the Observer Pattern in C#: Code Samples

I have been reading about data binding in windows phone 7 development and got curious about how .net implements the observer pattern. I spent some time understanding the flow and decided to write a blog post about it.

.NET platform offers IObserver and IObservable interfaces to quickly get up and running with the observer pattern. We know the theory – there is an independent subject, a observable aimed towards monitoring that subject and some observers which are very keen to receive updates whenever something interesting happens to the subject. The observers know that the observable monitors the subject, so they subscribe to the observable for notifications. The observable accepts all these subscriptions, keeps them in a safe place. Then he keeps watching and watching. When something interesting happens to the subject, he quickly gets to the list of subscribers and then notifies them one by one.

Compare this scenario to the day before Eid Ul Fitr. Tomorrow is Eid if we see the moon. Now, you have decided to go to the roof and keep waiting there until the moon pops up. Knowing this, some of your friends (who are so computer freak that they don’t even want to leave their PCs to watch the moon of Eid Ul Fitr) called you and asked you to notify them if you see the moon.

The Moon == Subject
You == Observable
Your nerd friends == Observers

Here the observable keeps watching for the subject, when the subject pops up in the sky, the observable calls the observers – that’s it, simply that’s the observer pattern.

To implement this pattern, we define a Subject object. It has a counter. Every time you view the counter, it gets increased by one. We are doing this little magic to track any changes in the subject.

Then we define the SubjectObservable object which implements the IObservable. It accepts a subject in it’s constructor. This is not mandatory but we did this to track the subject in a better fashion. It provides a Subscribe() method which is called by the observers to subscribe to the observers. The method must return an IDisposable object. We do a trick and create a custom object implementing the IDisposable interface. In the constructor we accept the list of observers recorded by the observable and the instance of the observer passed for subscription. In the Dispose() method we remove the observer from the observer list. So when the Dispose() method of the disposer is called, the observer is removed from the observer list. The observable will no longer send any notifications to the removed observer.

The SubjectObserver is pretty simple. It has OnNext(), OnCompleted() and OnError() methods. The OnNext() is called by the observable to send the current state of the subject. Besides the abstract methods, we also define a constructor to accept a unique name instance and an instance of an observable to follow. When the OnNext() is called, we print out the current counter value of the subject. We also define a Dispose() method which shall invoke the Dispose() method of the disposer, removing itself from the observer list of the observable.

Well, if all these theories seem too complex to you. Do read the codes below. I have tried to add relevant comments. If you have any feedback, please do make a comment.

Okay, so every time we read the value of the counter data, the value increases. The subject is inspected by the observable and the observable passes the subject to the observers. Each observer again prints the counter and increases the value by one. This continues. 🙂

Git: Automatically add all changes to staging area

I use Git heavily as a DVCS. The scenario I often come across is when I have manually deleted a whole bunch of files from here and there. It becomes a mess if I have to “git rm ” on them manually – one by one. Thanks to Git, there is an easy solution.

Issuing the above command automatically adds all changed files to the staging area. Cool, isn’t it?

Using Entity Framework: The CodeFirst Approach

When I started into the world of .NET based web development, I often encountered the term “Entity Framework Code First” or “EF Code First”. Where as I could no where find the option to create “Code First” entities in the visual studio. 🙁 How disappointing! 😛 I could create ADO.NET Entity Data Model but that would create .edmx files which looked all cryptic to me! I was just beginning .NET and my background is heavily based on PHP and Python where nothing is “Visual”, we do it all in codes.

And then after going through some of the resources online, I finally understood what’s going on. The ADO.NET Entity framework has two popular approaches – “Database first” and “Code first”. As the names suggest, in the first approach you write your models, generate databases, map the database with your models etc. Here database comes first. On the other hand, in the “code first” approach, you write plain classes which are identical to your database objects. Then following specific convention, you magically map the defined classes with the database. No need to write (I mean generate) complex xml maps or all those mess.

While I agree that both the approach have their own benefits, strengths and all those positive things, I found the code first approach easier to get started as a novice. So how does it work? Let’s see!

Say, we already have a table defined somewhere. For convenience, let’s use the following SQL script to generate a table:

I am not going to elaborate the process but the direction is to first create a database and then use the above sql codes to generate a table. It has one ID field that is auto incremented and the Name field. The simplest table structure I could think of! 😀

Now, in code first approach, convention is prioritized over configuration. Hence, we must define an identical class. Here it goes:

Remember those “virtual” identifiers are crucial. They have a lot to do with the magic that keeps things going. Another interesting thing to notice is that the Student object doesn’t derive from any other object.

Now, we need a database context. We shall define a class that will extend the “DbContext” class from the Entity Framework. The code should be like this:

One thing to notice is that we must pass a database connection string to the DbContext class. In this case, I have a connection string defined in my configuration file and I am passing the name of the connection to the DbContext class.

With this, we’re ready to use the Entities we have generated. So, how do we use them? Let’s see some codes:

The above codes will insert a entry in the database when run. Give it a try! 🙂

PS: I am just beginning .NET and C#. If you have any comments, suggestions or plain feedback, please do feel free to leave in the comments. I would appreciate your contribution to my personal development 🙂

Fixing Error 29506 while Installing SQL Server Management Studio

I was trying to get SQL Server Management Studio installed when I encountered the error 29506. Looking up on the internet revealed that it’s related to admin privilege. When I view the properties of the installer, under the compatibility tab, “Run as administrator” option is disabled.

So instead, from start menu, I ran command prompt in administrator mode. Changed directory to the folder where the installer was. Ran the installer from command line and it all worked 🙂

Fixing the Google+ Issue on Bangla Lion

For some reasons, many Bangla Lion users are randomly not being able to consume many static contents from Google+. They are also not being able to download any email attachments from Gmail. What’s happening? Google serves their content from Gmail attachments are also served from a sub-domain of this domain. For some unknown reasons we can not access that domain sometimes, sometimes we can.

Just a few moments ago, when I complained to Bangla Lion customer care, the customer manager helped me fix the problem. What we did?

1) First we set no proxies. On my Firefox 5, I had proxies set to system proxies. Bangla Lion’s customer manager suggested that I should set no proxy or automatic detection for proxies. I changed it to no proxy. For this, I went to Firefox Menu > Options > Options > Advanced > Network > Settings (I am using FF5).

2) Then I went to “Network and Sharing Center” > “Change Adapter Settings”. I right clicked on my Bangla Lion connection (I am using the indoor device, so mine is a wired network) and selected “Properties”. In the “Networking” tab, I double clicked on the TCP/IPv4 entry. The dialog box I got, it let me define how my IP address and DNS addresses are obtained. I manually set the DNS Servers to: & .

The customer manager also gave me another pair of DNS in case I still have an issue: &
This was supposedly a good sign of proper customer service, which I had read the other day on

3) I cleared my browser’s cache and everything was okay. To test things, I have restarted my router several times to see what happens when I am assigned to different IP address. Everything looks fine.

So, the description I gave so far is very specific to Windows 7 and Firefox. A general instruction for any OS and any browser should be:

1) Make sure you’re not using any proxies.

2) Change your network’s DNS to: & or &

3) Clear the cache and offline data.

I am satisfied with Bangla Lion’s customer care, at least they put some people who knows something. When GP started image optimization, it was a night mare. +1 to Bangla Lion for their informative customer care service.

Quick JSON Parsing with C#

It’s quite sad that Microsoft doesn’t ship a decent JSON parser with .NET, not even the latest .NET 4. If we look at the web, everyone uses JSON today. Without no out of the box support for JSON, I was having much troubles consuming different APIs Services. But just a few moments ago, I found the JSON.NET project on CodePlex. The library has cool Linq integration that makes JSON parsing easier.

For test purposes, I am outputting this JSON string on http://localhost/json.php :

After downloading the JSON.NET package, I added a reference to “Newtonsoft.Json.dll”. Then used the following code snippet (C#) to parse the data and print the values from a console app: