Saturday, April 12, 2014

5 must have unique and useful Android apps part 2

I like products and apps that make it easier to do daily things. Mobiles have become our necessity at any given time. Below is the second part of 5 useful android apps that will help you execute your daily activities easily:


Pushbullet bridges the gap between your desktop/laptop and your mobile device doing 2 things, first it mirror the notification on your mobile to your laptop screen. Second you can send links, files, photos etc between the desktop/laptop and the mobile device. It is great to know who just sent you a text message while your phone is being charged and your are working on your laptop.


Shush is a very simple app, it lets your keep your phone in the silent mode for a given amount of time. Lets say you are going to a meeting that will take 1 hour then your keep your phone in silent, shush time selector appears which you can configure to 1 hour and you are done. After 1 hour your phone will come back to ringer/sound enabled mode. Website Remote turns your Android phone into a remote for Youtube, Soundcloud, Pandora and other online media playing services. It is super handy when you want to go on the 'couch mode' and watch those videos on Youtube. 


Spendee helps you track your expenses in an easy and visually enticing way. You can add your expenses on categories like Home, Utilities, Car etc and get a graph of your expenditure. It is very useful to know 'where your money goes' and manage your expenditure.


Feedly is the Google reader replacement where you can read all your RSS feeds at the same place. It is configurable and you can slide through the content, skim through and read important ones. Its integration with Pocket makes it a jiffy to read anything later if you like it.

I hope these apps make it easier and smoother to do your daily activities.

Read More

Friday, February 7, 2014

Ingredients of a great front end application with AngularJs

In the past 12 months the popularity of AngularJs has exploded, which clearly hints that applications are being built following the multi-tire architecture. A good back-end API with a front end consumer application surely makes a capable duo that can handle any requirements of the application. If you have a multi-tire architecture then you don't need to rebuild the back-end for serving data for other applications like a mobile application or any data requirement.

Popularity of Angular JS, source Google Trends

Why Front-end applications?

Front end applications with java-script run on the user's browser, when the data interaction is moved to models and services supported by a framework it makes the front end application very powerful. This also enables the concept of Single Page Application (SPA). Below are the 7 ingredients of a great front end application with Angularjs being the main ingredient.


AngularJs is a "Superheroic JavaScript MVW Framework" by Google which lets the developers abstract out the model view controller on front end (user browser) level. Its amazing features include two way data binding, routing and directives to name some. Angular with its features and flexibility might be your safest bet if you want to develop a front end application consuming data from a back-end API service.


Yeoman is a scaffolding which provides generators that can speed up the application development process. It supports Angular, when combined with other great applications it helps you build your front end application with ease. It does the heavy lifting for you so that you can focus on the code better. As mentioned:
Yeoman is a robust and opinionated client-side stack, comprising tools and frameworks that can help developers quickly build beautiful web applications. We take care of providing everything needed to get started without any of the normal headaches associated with a manual setup.


Bower is a package manager for javascript projects. Composer is the main dependency and package manger for PHP, similarly bower is the dependency manager for Javascript. It has a lot of packages which can be used for your project and managing the dependencies is matter of just one bower.json file on your project. You just do a bower install and all the dependencies are downloaded for you.


Grunt is a javascript task runner, it can automate tasks so that you can focus more on the development. In relation with AngularJs it can be used to start the server, check file changes to compile with the new changes and perform auto reload, check for JSLint, run your tests etc. You can configure the tasks in a grunt file and utilize its powerful API to create your own tasks.


Now you have a good separation of your front and and you are coding some javascript model, services and controller. How would you manage the view/template part of the application. There are many options like Handelbars, Swig (similar to Twig in php) but using Jade might be easier. Jade is like a compressed version of HTML which makes writing templates much easier and faster. Jade files can be compiled to output as HTML with a grunt task.

Compass CSS

Compass is a open source CSS authoring framework that use Sass to make writing CSS logical, easy and painless. It is like making CSS programmable with variables, nesting styles and other features which helps on making CSS code reusable and maintainable. Easy to install and easier to get started with Compass will change the way you write CSS. 


Now you have great java-script code a well managed front end with Jade and Compass, how about some testing. JasmineJs is a behavior driven development framework for testing javascirpt code. Test suites describe the tests and match the output. You can even use a custom solution with other libraries like PhantomJs. Still Jasmine can be a very good option for testing AngularJs application.


Using the right tools and technology to do your job will always benefit you, it will save time and effort maximizing productivity. A good mix and match of all the ingredients would yield desired results, I hope these you will use these tools when you think of developing a new front end application.
Read More

Saturday, February 1, 2014

Using PHPUnit data provider for less code and greater coverage

Writing testable code is a harder target to achieve than just writing tests for the code written. You cannot write comprehensive tests that covers many function each of 200 or more lines and classes that measure 1000s of lines of code (LOC). Writing testable code is always important if you want to be able to test/unit test your code and be confident that nothing will break.

Tests also help a lot when you re-factor some code or write new features. If all the tests are passing you are quite sure that nothing is breaking. Seeing all tests come out green is a very good sight for us software engineer.

Testing in PHP with PHPUnit

Unit testing and testing as a whole is not a new thing in PHP,  PHPUnit the de facto unit testing framework in PHP started in 2001, The chart below shows that popularity of PHPUnit has really grown over the past years in comparison to Simple Test another PHP testing framework.

Source: Google Trends
PHPUnit is a great unit testing framework that can automate testing and help in getting optimal output. As they state in the documentation:
The difference between a good programmer and a bad programmer is that the good programmer uses tests to detect mistakes as soon as possible. The sooner you test for a mistake the greater your chance of finding it and the less it will cost to find and fix.
It is true the sooner the problem is detected and fixed the better it is, same goes when some code is re-factored, a new feature is added or a bug resolved.

Data Provider in PHPUnit

There are may features of PHPUnit, which can help in writing comprehensive unit testing and moving toward the direction of test driven development (TDD). Among them, data providers provide arbitrary arguments to a test function so that same code can be used to test multiple scenarios and possible cases. In this very simple example I will use a part of checkout. The logic is very simple:
  1. If the payment method is  "Cash", apply a cash on delivery fee of 5.0
  2. If the payment method is "Credit Card", do not apply a cash on delivery fee. 

The part of the checkout class is given below:

Source: Github repository

The test for the above checkout class is given below:

Source: Github repository

What makes using data provider in this example relevant and optimal?

  • As the test needs to be run for both "Cash" and "Credit Card" the only thing it changes here is the addition of cash on delivery fee.
  • There is just one test with the payment method being passed as a parameter, saving us from writing X no of tests for X no. of payment methods. So less code and more coverage.
  • The test is clear concise and understandable.

Things to consider in the code:

  • The test runs the as many times as the data set provided by the provider function.
  • @dataProvider annotation is necessary in the test to get the data sets from the provider function.
  • When writing the provider function, its better to comment who is using the provided data sets and the order of variables (check the comment of  paymentMethodProvider method).
Both the above files with composer.json is available as a public git repository for your reference, you can check the read me file to know how to run the tests.


Whenever you write tests and think, "Why am I writing a new test for the similar thing. I guess there can be a way to write less test/code and cover all my test cases." Then is time to use data providers in PHPUnit. You save on time and effort to cover the cases, a new case is just another array in the provider function, even in case of new test cases being added its a one line change given the tests pass. I hope this helps you to write less test code and achieve more coverage.

Read More

Saturday, January 11, 2014

Most popular brands, people on Facebook in Nepal as of 2013 Q4 [Infographic]

From the last time I blogged it has not changed much for the most popular brands and people on Facebook. Age group of 18-24 account for almost 50% of Nepali Facebook users and 67.7% of all users are men so only 1/3 users are female. The top 3 brands in Nepal on Facebook are the same as 6 months before still Australian Education & Career Consultants has overtaken to come to No. 2 position and NCell came out at top as the last time.

This kind of analysis should have been done by a social media analyst company, but I doubt if there are any online marketing companies in Nepal which do such analysis. Anyways, Sajha Sawal and BBC Nepali have emerged as the most liked Facebook pages for entertainment and media category respectively. Looks like BBC is very popular in Nepal. Below the infographic will reveal all the details:

Link to the infographic page. You can use this infographic, please give credits.

Some other facts about what Nepalis like (local fans) on Facebook (source : :

  1. Gagan Thapa is the most popular in politics category in Nepal with 150722 fans, it could be the after effects of the second Constituent Assembly elections.
  2. Only Hari Bansha Aacharya (312697 likes) and Malvika Subba (250628 likes) are two Nepali celebrities in the 10 liked celebrities in Nepal.
  3. CricNepal is the only Nepali page which made it in top 10 sports pages with 155819 likes at number 3.
  4. Thamel is the most popular place for checking in with 11017 check-ins.
  5. Except of Sajah Sawal at number 1 with 267509 likes, there is no Nepali page or film or artist in entertainment category top 10.
The Facebook likes by Nepali people are similar to what it was 6 months back, its better to see Nepali people liking more Nepali media and personalities than foreign ones.
Read More

Friday, January 10, 2014

5 PHP development improvements rediscovered in 2013

Love it or hate it, the fact is 80% of the web is PHP and its usage has been in an increasing trend since 2010. Be informed that PHP is much better than you think as per Fabien Potencier. As a team, we have worked a lot on PHP this year, specifically on Symfony 2 mainly for our back-end APIs. It has really strengthen our multi-application SOA platform and enabled us to build responsive front ends on top of it.

In this process of having a robust back-end API, we have rediscovered and utilized some technologies inline with PHP development and improved on them in the past year. Here is a summary of these PHP related technologies/methods/best practices that will help all PHP developers:

PHP Specification Request - PSR

PSR (0-3) PHP Specification Request is a set of standards devised by the PHP Framework Interoperability Group (FIG) to standardize auto-loading, coding standard, coding style and logger interface. PHP-FIG members include big names like Zend, Symfony, Drupal to name some. We follow a slightly modified version of PSR-2 as our coding standards.

Writing clean code is always helpful and if you follow a widely accepted coding standard it makes it easier to open source the code. To make the process better you can use PHP code sniffer and integrate it with your IDE for code evaluation while you type.

Composer and Packagist

Composer is dependency management tool in PHP which lets you define libraries that your project is dependent on. Composer uses simple JSON declaration of dependent project in composer.json files and downloads the related libraries in the vendor folder. Getting started in easy with compser and all the opensource packages are listed in packagist, where you can search for packages you need.

Lets say if you want to work on Paypal and think someone might have submitted a wrapper library for Paypal Rest API, you can search and find the library that suits your need. You can even submit your library/package to be open source and used by others. Composer really makes working with dependency and managing version of the dependent library an easy task.

Virtual Development Environment - Vagrant

Vagrant is a virtual development environment which works as a virtual machine on your main machine with all needed software stack as config. Basically it creates a reproducible and portable development machine which is shared by all the developers, that in turn eliminates "Works on my machine" syndrome.

Another thing it greatly helps is the time to set up a machine and get running. In our case, it came down from around 2 days to install all the software stack and configure all environments to mere 5 hours including the download of all needed software. If you want your developer to start coding on the first day, this is your best bet as s/he does not need to install the correct version of PHP, MYSQL, X-Debug and all other software.

Debugging with X-Debug

Debugging in PHP used to be that elusive creature that you see sometimes and it just hides when you want to see it. On the contrary if you setup X-Debug correctly on your machine (or your vagrant) you can run the debugger and inspect how your code executes line by line. Beware that its a correct mix of X-Debug, a client on your browser like easy Xdebug for firefox and a good IDE that supports debugging like NetBeans or PHPStorm. Know well how to set it up.

In our case, X-Debug is installed on the vagrant machine so each developer does not need to manually install it. Just set up the preferred client on the browser and run the debugger on the IDE, then you can get new insights on how your code executes.

Automated Testing with PHPUnit

When your code is tested and all tests pass (they are green! yehh) you are confident that things will not break on the production environment. Writing test verify what the code is supposed do and it serves as animated documentation of the code. Not only does it help save the development time on the long run, you are already aware of the related things that break due the the changes you made when you coded a feature/fix. We use PHPUnit to test on our PHP code so that we know all our features are performing how it should.

I would not call our way of testing Test Driven Development (TDD) or core Unit Testing of each class. Rather its our own way of ensuring that the feature works as intended. We code the feature first and then write the test to verify if it meets the requirements. We generally ensure that before sending a pull request on git hub all the test pass.

All in all 2013 has been a great year with lots of things to learn and explore, we experimented with many things as we raised our technical know how to a different level in terms of the tools we use. We went from a cron that runs every minute to Rabbit MQ messaging queue that can be a different blog post :).

Now we follow continuous integration with Travis CI which runs the test we wrote with PHPUnit taking the code from Git Hub. I would like to thank our VP - Technology Alex (@_Odino_) for his vision and implementation of  above mentioned technologies. Lets hope we see more advancement in 2014.
Read More