Grunt configuration for chromeapp + Angular + Jasmine

I’ve spent the last couple of hours battling Grunt config to use Angular and Jasmine testing framework with Yeoman’s (yo) chromeapp a.k.a generator-chromeapp. Here’s how I did it:

  • Run yo chromeapp with the test-framework option
    yo chromeapp --test-framework=jasmine
  • Install Angular dependencies using bower
    bower install --save angular
    bower install --save-dev angular-mocks
    bower install --save angular-animate
    bower install --save angular-material #Optional

    If you plan to use bower, note that the generator puts the bower_components directory in the app folder. You can modify this by changing the “directory” in .bowerrc. I’ve chosen to keep it as-is

  • Create app.js in app/scripts and define your module
    angular.module('MyChromeApp', ['ngAnimate', 'ngMaterial']);
  • Modify your index.html
    <html ng-app = "MyChromeApp">
    <script src="bower_components/angular/angular.js"></script>
    <!-- Optional -->
    <script src="bower_components/angular-animate/angular-animate.js"></script>
    <script src="bower_components/angular-aria/angular-aria.js"></script>
    <script src="bower_components/angular-material/angular-material.js"></script>
    <script src="scripts/app.js"></script>
  • Modify the jasmine task in Gruntfile.js
    jasmine: {
     all: {
     src: ['app/scripts/{,*/}*.js',
     options: {
       specs: 'test/spec/{,*/}*.js',
       vendor: ['app/bower_components/angular/angular.js',
  • You’re done! Now you can create controllers and services using
    yo angular:controller Dashboard
    yo angular:service Storage
  • Run jasmine for unit-testing
    grunt test

Custom AngularJS search filter

I’m working on an Angular-based Chrome app at the moment and I needed to make a search box. The search filter example in the Angular docs shows how to search based on a single property of the array objects. It also shows the use of multiple input boxes to search in different properties.

The example data has “Julie 555-8765” and “Juliette 555-5678”. Wouldn’t it be nice if the search field could handle queries like “julie 555” and show both of them as search results?


In essence, the search filter would need to match “555” in the “phone” property and “julie” in the “name” property. It would have to break down the search query into parts (“555” and “julie”), make sure that each part matches one of the properties of the object and show it in the results only if all parts are found in the object. This can be done by combining the multiple properties of the object into a single string, checking if each query part is found as a substring of the object string, and doing an AND operation of the results of all query parts.

Here’s some sample code

A Plunker version of the same code is available here

Go ahead and type something like “555” and you’ll see two results, Jane Doe and Jane Smith. If you change that to “555 Doe”, the Jane Smith result is dropped.

Note that the filter function is rather intensive because it converts each object to a JSON string and tries to locate all query string parts in it. To prevent frequent execution of the filter function, this makes use of the relatively new ng-model-options (added in Angular 1.3) to delay the ng-model update by 400 milliseconds. You may want to tweak the delay amount.

Remotely accessing a PostgreSQL database through PgAdmin

I was trying to access a Postgres database on my WebFaction server using the PostgreSQL admin tool PgAdmin III. It took a little bit of Googling to figure it out, so here’s a quick guide for anyone in similar situations.

If your hosting provider, like mine, does not allow direct remote access to databases, you need to create an SSH tunnel so that accessing the default Postgres port, 5432, on your computer redirects to port 5432 on the server. For WebFaction accounts, that can be done like this

ssh -L 5432:

where webXX refers to your WebFaction server.

If you see “bind: Address already in use”, it means that the postgresql service running on your computer on port 5432 is preventing the SSH tunnel from being set up on the same port. To stop your local postgresql service, on Ubuntu, you can do this

sudo service postgresql stop

When the postgresql service has stopped, you can set up the SSH tunnel.


Use the “Add server” option and provide the following configuration

  • Host:
  • Port: 5432
  • Username: <remote Postgres username>
  • Password: <remote Postgres password>
  • Maintenance DB (only if you have trouble connecting to your server): <remote Postgres database name>

Play/pause music in Guayadeque through global keyboard shortcuts

I’ve tried a lot of music players on Linux, ranging from the desktop environment standards like Rhythmbox, Banshee and Amarok, to experimental ones like Tomahawk and Guayadeque. The latter has been my music player of choice for over a year now – its simple UI and small memory footprint works well for me.

One feature Guayadeque doesn’t seem to have is global keyboard shortcuts. Ctrl+Right/Left skips to the next/previous track, and Ctrl+Space plays/pauses the current track, but these shortcuts work only when the Guayadeque window has focus. Referring to this thread and this article, I went about writing a tiny shell script to play/pause music when Guayadeque is running, or launch Guayadeque and then perform the action. Here’s

dbus-send --type=method_call --dest=org.mpris.guayadeque /Player org.freedesktop.MediaPlayer.Pause
if [ $returnCode -ne 0 ];
  guayadeque &
  sleep 5
  dbus-send --type=method_call --dest=org.mpris.guayadeque /Player org.freedesktop.MediaPlayer.Pause

I replaced MediaPlayer.Pause in the above script with MediaPlayer.Next and MediaPlayer.Prev in separate scripts to handle skipping to the next or previous track. I mapped the shortcut Ctrl+F10 to launch, to use at times when I just want music to start playing!


Issues with upgrade to Ubuntu 13.04 [Raring Ringtail]

April just flew by, and that means it’s time to play with the new Ubuntu 13.04. I’ve been using Ubuntu as my main operating system since 8.10, and as with every new version release and the subsequent upgrade process, I hope that the upgrade will be seamless and not require troubleshooting. Of course, something always manages to go awry, and I end up spending a few hours reviving my system after every upgrade. This one was no different.

I upgraded using the dist-upgrade feature of update-manager. It took a while to fetch the packages [*hat tip to BSNL], and installed them. On the next reboot, however, I was greeted by the cold, silent command prompt.

General error mounting filesystems.
A maintenance shell will now be started.
CONTROL-D will terminate this shell and reboot the system


Given that my upgrade attempt was a day after the release, Google hadn’t yet caught up to the barrage of issues and AskUbuntu/UbuntuForums posts that follow every release. It took me a while to dig up the relevant information. What fixed it? Mounting the partition, and attempting to upgrade once again. Apparently, the upgrade process had not completed successfully.

mount /dev/sda1 /mnt
chroot /mnt
aptitude update
aptitude dist-upgrade

That wasn’t too bad. After logging in, I noticed that Unity did seem a lot lighter – The Dash started quickly [The initial delay of the Dash in processing search queries on the first launch was quite a bit in the 11.10 era. I had resorted to using Synapse as my Dash replacement] and the side menu generally stayed out of my way. So far, so good. I opened up Nautilus, and immediately wished I had the forensic “Crime zone. Do not cross” tape – At first glance, Nautilus looks beautiful and shiny, thanks to its new icon set and design, but it takes no more than a minute to realise that its sleekness is at the cost of functionality. What is with the bizarre obsession to dumb down software, to force everything to conform to the “simplistic and elegant, but barely functional” trend? I’m not a designer, nor do I claim to have an intuitive understanding of design, but that principle reminds me of the myth (?) of rib removal in the quest to be pretty. In the habit of hitting the backspace key to go to the previous directory? Too bad. Backspace does not work. The new key combinations are:

Alt + Left = Previous directory
Alt + Up = Parent directory

and there’s no way to change that. Used to hitting F3 to open up another pane within Nautilus to drag-drop files between two different locations? You’ll learn to open up a new window to do the same thing now. Also, the “Open with” menu item has been removed for directories. Forget about being able to add an entire directory to the VLC playlist directly, that’s wrong. File association is messed up, but it’s been the case for a while now.

Sigh. I dare-say Nautilus has jumped the gun, and it’s time to move to Nemo and/or Dolphin.

Talking of VLC, it had issues after the upgrade – it would not show video, instead playing just the audio track. Here’s the fix that resolved it:

VLC –> Tools –> Preferences [or Ctrl + P] –> Video
Uncheck “Accelerated Video Output (Overlay)” in the Display sub-section.

That’s not all – Occasionally, I would have no sound at all, in any app! “Sound settings” would show “Dummy output” as the only output in the input or output devices sections. It’s completely arbitrary – restarting would often fix the issue. I don’t seem to be the only one having this issue.

And that’s a wrap! Notwithstanding these minor hiccups in the transition to a new release, I do like the Ubuntu ecosystem, and don’t intend to move to another distro. This clearly is a maintenance release, with no new “media-bait” features or controversies [Amazon shopping lens, anyone?] and it’s surprising that the end-of-life is Jan 2014. Canonical is branching off into a lot of new ventures, and I believe there are interesting things to come from Ubuntu Phone and Android integration.

P.S: Am I the only one who’s not impressed by the version names? [Yup, some people can complain about ANYTHING]. The next release will be called Saucy Salamander. That is so…mainstream and so unlike the precedent established so far. You disappoint, Canonical!

Sri Lanka

[Disclaimer: This post is just my opinion and I don’t intend to disparage Sri Lanka or its culture. If, however, you feel you must let out your rage over something in this post, feel free to insult me in the comments section, or you could just pass this off as the views of a ‘smelly Indian’, if that helps :P]

I’ve just returned from a two-week backpacking getaway in Sri Lanka, and it’s a fascinating country. Here’s the breakdown

Continue reading →

Setting up a mail server: The n00b edition

One of the reasons why working at a startup excites me is the unpredictability of my future tasks. Case in point: I was recently asked to set up a mail server as a replacement for the Google Apps subscription currently in use. The requirements given to me specified that IMAP support and a web client are essential, as is the ability to send out emails not just to internal addresses, but also to other domains. After all, what good is a mail server if it can’t talk to the rest of the world? I decided to get started, but there was a tiny hold-up: I had no idea how to build a mail server! Continue reading →

Basic ActionBar action item tutorial

As requested by a reader, here’s a simple tutorial explaining the use of menu items in an ActionBar. Menu items shown in the ActionBar are called “action items”, and they’re just as easy to use as menu items. This demo app shows an appropriate Toast when action items are selected.

To start with, make sure to set the minimum SDK version as 11 (Android 3.0 Honeycomb) or greater. ActionBar was introduced in Honeycomb, and will not work on platform versions below that without the help of the Android support library and/or ActionBarSherlock (Setting up ActionBarSherlock is covered here).

Continue reading →

Shell script to attack a WPA/WPA2 network [Based on reaver and aircrack-ng]

I’ve spent the past few days playing around with the command line, and that is not something I do very often. It all began when I discovered this handy tool called Reaver which exploits vulnerabilities of the WPS standard. Naturally, I had to test it out on the numerous WPS-enabled wireless networks around me: I must say I have very, err, co-operative [and oblivious] neighbours!

I had previously tried in vain to learn to use the aircrack-ng suite of WiFi hacking. Since reaver is based on aircrack-ng, I had no choice but to give it another shot. This time, however, things made more sense, and I managed to use reaver successfully.

I made a small configurable shell script that will hopefully make the command line options seem a little less intimidating to the newcomer.

Continue reading →