• Learning Chrome Extensions by accident

    05 Feb 2014

    So, twitter has revamped their look to be flatter and what not...It looks like apple now. This really means I was annoyed and wanted to get rid of things in the interface I did not like. Ok so how do we do that ? Write a chrome extension and that will be the permanent end of that!!


  • Learning Redis by accident

    While exploring the pub-sub mechanism in MongoDB, I came across Redis. Redis has this built in. This gave me the incentive to scratch a long time itch and try redis. Redis is eseentially an in-memory database. It is supposed to be fast (like really fast). So, I thought I would take it for a spin. Considering, I am on windows and it seems like there is no direct support for windows. Windows remains the poor second, but we will let it be for now. Microsoft provides the executable for 2.6 and we can download it from there.


  • Pub Sub with MongoDB

    In the spirit of trying out new thigns I wanted to create a pub0sub system with mongodb. Usually we would create a pub sub system with a message queue, but since we are a little crazy we will try and do it this way. Turns out it is quite simple. Before we begin we must understand somethings that are available uniquely in MongoDB.


  • MongoDb: Optimistic Concurrency

    Optimistic concurrency is one something that most of us need in our applications. What follows is a simple example on how to achieve it in MongoDB. First, a really simple document.

    Note : This post uses a lot of code that I have shown in previous posts, please look at them if there is any confusion. The principles remain simple and can be used without using the code shown below.


  • MongoDb: Querying the OpLog

    Back to MongoDB after some time. OpLog has always been a curious case for me. To know more about it let's start to our detective work.

    What is the OpLog?

    The mongodb website gives a rather long definition. I will quote that

    The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. MongoDB applies database operations on the primary and then records the operations on the primary’s oplog. The secondary members then copy and apply these operations in an asynchronous process. All replica set members contain a copy of the oplog, allowing them to maintain the current state of the database.

    To facilitate replication, all replica set members send heartbeats (pings) to all other members. Any member can import oplog entries from any other member. Whether applied once or multiple times to the target dataset, each operation in the oplog produces the same results, i.e. each operation in the oplog is idempotent. For proper replication operations, entries in the oplog must be idempotent:

    • initial sync
    • post-rollback catch-up
    • sharding chunk migrations


  • Up and Running with Asp.net MVC Mono and Monodevelop

    After 3 hours worth of work, I was finally able to run Asp.net MVC4 using monodevelop on mono. I will talk about installaing monodevelop later (that was a painful exercise). So, assuming you have monodevelop installed on windows and latest version of mono installed (mono-3.2.3)as well. Now, go file new solution Asp.net MVC project with razor. Run it and wait for the world to fall apart.


  • Tasks With Timeout On .net 4.5

    30 Dec 2013

    The previous two posts looked at creating tasks with timeouts on .net4. The code as expected took some heavy lifting to get going. Understanding the extension methods themselves took some time. Today, using .net 4.5 this can be made a lot easier. Can we do better ? Yes we can !!

        public static Task WithTimeout(this Task task, TimeSpan timeout)
            var delay = task.ContinueWith(t => { }, new CancellationTokenSource(timeout).Token);
            return Task.WhenAny(task, delay).Unwrap();
        public static Task<T> WithTimeout<T>(this Task<T> task, TimeSpan timeout)
            var delay = task.ContinueWith(t => t.Result, new CancellationTokenSource(timeout).Token);
            return Task.WhenAny(task, delay).Unwrap();


  • Tasks With Timeout Contd.

    24 Dec 2013

    As mentioned in the last post we can now have tasks with individual timeouts. The code looked a little heavy. Can we do better ? Yes we can !!

        var tasks = new List<Task>();
        //instead of checking for fault within the continutaion, 
        //we can just use a TaskContinuationOption to tell communicate the right semantics
        var t1 = Task.Factory.StartNew(_ => LongRunningTask(),TaskCreationOptions.AttachedToParent)
        .ContinueWith(t => SomethingUsefulWithTheResult(), 
        var t2 = Task.Factory.StartNew(_ => LongRunningTask(), TaskCreationOptions.AttachedToParent)
          .ContinueWith(t => SomethingUsefulWithTheResult());
        var t3 = Task.Factory.StartNew(_ => LongRunningTask("Entering task3"),
          .ContinueWith(t => SomethingUsefulWithTheResult());
        catch (Exception ex)
        Console.WriteLine("There was an exception");

    I will show in the next post how this wasn't all that better since this leaves a few gaps.


  • Tasks With Timeout

    23 Dec 2013

    So the task is to timeout a task. now, I never thought it would take me as long as it did. Turns out it is a really tricky problem problem. I was expecting something within the framework to make life easier, there isn't anything by default but msdn to the rescue Tasks With Timeouts


  • MongoDB-Sharding


    Mongodb sharding is based on shard key.

    K1 -> k2 on shard1 K2 -> k3 on shard2 etc..

    Each shard is then replicated for higher availability and DR etc..Sharding is therefore range based. Sharding is done per collections basis.Range based sharding helps it do range based queries.