AngularJS interval example

One useful technique to keep content synced between client and server is doing continuous polling. Of course websockets are even better, but for this post, I’m going to just talk about the polling technique using AngularJS. AngularJS has an $interval service that can do this well. However, they do warn that you have to handle manually killing the interval service when you don’t want it to persist anymore like when you destroy a controller. This can be done with the following example code snippet.

var startedInterval;
$scope.startPing = function(num) {
    if (angular.isDefined(startedInterval)) {
        return;
    }

    startedInterval = $interval(function() {
        console.log("Ping " + num);
    }, 1000);
};

$scope.stopPing = function() {
    if (angular.isDefined(startedInterval)){
        $interval.cancel(startedInterval);
        startedInterval = undefined;
    }
};

$scope.$on('$destroy', function() {
    $scope.stopPing();
});

var num = Math.random();
$scope.startPing(num);

This is just a quick demonstration of this technique.

Bitbucket brightens my day from the github pricing gloom

I’ve been using github for a while now and honestly, it rocks. It really beats the heck out of the dinosaur, svn. However, the pricing for private repos on github is just something I had a hard time justifying. I have been running my own svn server for quite a while and it does not create additional cost to me. Plus, I can have unlimited number of private repos and of course because I can, I do. So in order to switch to github and shutdown my svn server, I would have to pay $50/month since I have more than 20 projects.

Alas, I have found what I’m looking for. Bitbucket. It is also git, although you can use mercurial too, but I just prefer git. It has all the niceties of github like integrated issue tracking, ease of collaboration, and of course all the good stuff of git. But the pricing is very different. They take the route that if you don’t have many contributors to a project, then it is too small charge. So they allow you to have private repos for free up to 5 users. After that, you need to start paying. That makes a lot more sense to me since after that, you are definitely running a legitimate business and should pull your weight. Before that, they are considered play projects or incubator projects. Oh, and you can have unlimited number of free private projects.

Time to say goodbye to my svn server.