Graph Databases by Ian Robinson, Jim Webber, Emil Eifrem; O’Reilly Media

Graph Databases

This books lays a solid foundation for understanding what Graph Databases are all about. Implementation details are all based on Neo4J, except for a fleeting reference to Twitter’s FlockDB when discussing scalability.

Chapters 1 and 2 provide an overview of Graph Databases, and compare them to Relational and NoSQL Databases. Appendix A provides a useful overview of different NoSQL databases.

Data modeling with Graph Databases is compared to relational databases in Chapter 3. It also discusses the creation of domain models using an example from the Systems Management domain, and Cypher to create and query the models. Cross-domain modeling and common modeling pitfalls are also discussed.

Chapter 4 discusses data modeling for Neo4J in further detail, and demonstrates when to use nodes or relationships. Neo4J can be embedded into applications or deployed in server mode, benefits of each mode are discussed. Test-driven data model development with ImpermanentGraphDatabase Java class is also discussed.

Chapter 5 provides common real-world use cases and examples. Domains covered in detail include social networking, authorization and access control, and geo/logistics.

Chapter 6 discusses native graph processing and storage, with topics such as index-free adjacency for better query performance, and programmatic access to Neo4J database provided by the Kernel, Core, and Traverser APIs. Non-functional characteristics such as transactions (ACID properties), recoverability, availability, scale (capacity; latency; throughput) are also discussed.

Graph algorithms such as depth- and breath-first search, Dijkstra’s algorithm, and A* algorithm are discussed in chapter 7. Analyses based on these algorithms, and techniques from graph theory and social sciences, can be used to gain new insights from a domain. Social graph properties such as Triadic Closures, Structural Balance, and Local Bridges can be used to gain new insights into a social network.

I found the book extremely useful to understand what Graph Databases are all about.

I thank O’Reilly Media for providing the book for review.

Getting started with Apache Cordova

Apache Cordova, or PhoneGap, is a cross-platform HTML5 app development framework. It allows creation of offline HTML5 and hybrid applications. This post recounts my brief experience getting started with Apache Cordova. It is relevant for Android and iOS, and assumes you are developing on a Mac.

Install Node

Grab the Node installer for Mac and install it. You’ll need it for installing Cordova. The cordova command line utility is based on Node.

Install Cordova

After Node has been installed, use npm to install Cordova

sudo npm -g install cordova

Use cordova --version to check the version of Cordova. In my case it’s currently


Create HTML5 app

A new Cordova HTML5 app can be created as follows

cordova create myapp com.mycompany.MyApp MyApp

A new folder called myapp is created, and the HTML5 resources are created under myapp/www.

Create platform-specific apps

An iOS app to build and deploy the HTML5 app can be created thus

cordova platform add ios

You’ll require Xcode, download it from the Mac App Store if you don’t have it installed. The command above does not work with the preview release of Xcode 5.0, I had no problem with Xcode 4.6. Cordova will create platform-specific files for iOS under myapp/platforms/ios, including a Xcode project to build and deploy the native application. The project opens and builds with the preview version of Xcode 5.

Cordova also copies the HTML5 app from myapp/www to platforms/ios/www. Remember to add the latter folder to .gitignore if you use Git for version control.

To create an application to deploy on Android

cordova platform add android

You’ll need to have Android SDK in PATH. Since I use Android Studio, here’s how I modified my PATH variable

export PATH=$PATH:/Applications/Android\\

The Android project structure under myapp/platforms/android does not work with Android Studio, but builds with ant. Eclipse ADT can be used to migrate the project to Gradle and Android Studio. A Gradle based build setup is under consideration but may not happen soon.

Build and test platform-specific apps

The iOS app can be built and deployed using the Xcode project under myapp/platforms/ios.

To build the android app run ant under myapp/platforms/android

ant debug

Deploy using adb

adb install -r bin/MyApp-debug.apk

Iterate and build

Every time you change the app in myapp/www, you’ll need to run

cordova prepare ios
cordova prepare android

Then, perform the platform-specific build steps described earlier.

The performance on iPhone 4S with iOS 7 is quite acceptable. It not as smooth on a Samsung Galaxy S3 (Android 4.2.2). Lesser Android Smartphones may struggle.

Handling TCP Keepalive

TCP Keepalives are useful for scenarios where one end of the connection disappears without closing the connection. This can happen when a NAT or firewall resets, or forcibly closes the connection. The following code in Python enables sending a Keepalive message when there is no data activity over a socket for 60 seconds. If it does not get a response, it sends Keepalive messages 4 times at intervals of 15 seconds. After that, the connection is closed. The code has been tested with Python 2.7.2 and Ubuntu 12.04.

To test, create a TCP listener/server using netcat on a different PC (or nc on a Mac)

netcat -l 8001

Now, disable the network connection, enable a firewall, or power off the router, to see Keepalive in action. Wireshark highlights Keepalive messages when TCP sequence number analysis is enabled.

You’ll see the following messages when the connection times out

Traceback (most recent call last):
  File "", line 39, in do_work
    req = sock.recv(10)
error: [Errno 110] Connection timed out
Other Socket err, exit and try creating socket again

On Mac and Windows you can enable Keepalive, but cannot set TCP_KEEPIDLE and other parameters, you’ll get the following error message (Python 2.7.2 with macports)

Traceback (most recent call last):
  File "", line 65, in <module>
  File "", line 19, in do_work
    sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 60)
AttributeError: 'module' object has no attribute 'TCP_KEEPIDLE'

MacBook Pro with Retina display

The 15 inch MackBook Pro with Retina display is the best laptop I have used. Here’s what I like about it

  • Mac OS X.
  • Beautiful 15 inch (220 pixel-per-inch) Retina display that allows you to read a PDF file two (side-by-side) pages at a time.
  • Parallels Desktop 8, and the ability to run Windows 8 seamlessly, and Linux.
  • The ability to build Android for a target device in 40 minutes.
  • The ability to run several virtual machines and not feel it.

I have one gripe. The battery doesn’t last as much as an iPad’s. Apple should be able to deliver better battery life in the next hardware and software refresh, with Intel fourth generation Haswell processors and Mac OS X Mavericks.

Cross-platform mobile app development frameworks

Development of applications for all the different mobile devices out there is becoming increasingly costly, especially for small teams. Reusing widespread knowledge of web app development to develop mobile apps is an attractive proposition. A quick survey of cross-platform mobile app development frameworks follows.

Cordova (Adobe PhoneGap)

  • App runs in embedded web browser i.e. you code in HTML5 and CSS3
  • Ability to create plug-ins to invoke native code, including UI
  • Code is developed and packaged using IDE of native platform, such as Android Studio and Xcode
  • Could become extinct after Web Applications are implemented by most browsers
  • See PhoneGap: a misunderstood hybrid framework for more

RhoMobile (Zebra)

  • Provides a Ruby on Rails like framework
  • UI views are written in HTML5
  • Controller and model written in Ruby
  • Ruby code executes in an embedded web server
  • Code is written in RhoStudio
  • Native extensions can be written for scenarios that require more performance or access to device specific features

Sencha Touch

  • Entirely HTML5 based
  • Lots of UI components
  • Applications can be served over the Internet
  • Ability to package apps for distribution through app stores
  • Mobile (touch) centric
  • Not very different from AngularJS, Bootstrap, Dojo Toolkit, jQuery Mobile etc

Titanium (Appcelerator/Axway)

  • Code that will be reused is written in JavaScript
  • JavaScript is evaluated at run-time, using V8 or Rhino, like Node.js
  • JavaScript code can call native code and vice-versa through proxy objects
  • Code can use native embedded browser to create hybrid apps
  • Code is developed in Titanium Studio, an Eclipse-based IDE
  • Also see Comparing Titanium and PhoneGap

Worklight (IBM)

  • End-to-end solution with server and client frameworks
  • Hybrid application coded using HTML5 and CSS3
  • Development environment based on Eclipse
  • Support for jQuery Mobile, Sencha Touch, and Dojo Mobile
  • Application can be prepared for deployment to several native platforms, without changing any code
  • Concept of a Shell app, which provides integration to the native platform by leveraging Apache Cordova
  • Hybrid inner apps run within the shell app and are managed by the server
  • Server can be used to preview and manage applications (app store)
  • Offerings for enterprise and consumer space

Xamarin (Microsoft)

  • Application has access to the Mono .NET runtime features, including its core class library for .NET
  • Wraps native UI of the device. UI views retain native look-and-feel but cannot be reused across different platforms
  • Core application logic can be reused
  • Apps are distributed as ARM binaries, with native performance
  • Code can be developed in Xamarin Studio or Visual Studio (paid version required)
  • Up front licensing cost justifiable if you are a Microsoft developer and can reuse most code except UI views

There are quite a few lesser-known cross-platform frameworks. To cite a few

  • Calatrava – from the folks at ThoughtWorks
  • Corona SDK – Lua-based framework
  • Icenium – now part of Telerik AppBuilder/Platform

Which of these to choose for your next project is quite a tough choice. I have been in hybrid app development situations and the truth is you always run into limitations. You will have to troubleshoot corner cases, performance issues, and go native when nothing else works. Do choose an approach that gives you that flexibility.

Android on BeagleBoard-xM

I just crossed paths with a BeagleBoard-xM and thought I’d try Android on it. I tried pre-built binary images for Android 4.0.3 from Texas Instruments (TI), and Android 4.1.1 Jelly Bean image from project rowboat. The source code is available from gitorious.


Beagle is a set of embedded development boards that can run Android. The original BeagleBoard uses an OMAP 3 processor, specifically OMAP3530 with an ARM Cortex-A8 core running at 720 MHz. The BeagleBoard-xM uses the TI Sitara AM37x running at 1 GHz. I have Rev C of that board. The BeagleBone and BeagleBone Black use the TI Sitara AM335x.

Android 4.0.3 (Ice Cream Sandwich)

I downloaded the pre-built binary image, a part of TI Android Developer Kit.

Next, I used an Ubuntu 12.04 VM running in Parallels on a MacBook, and a MicroUSB USB adaptor, to write the binary image to a MicroSD card. The binary image includes a bash script that does the job

sudo ./ /dev/sdb

Change /dev/sdb to whatever device appears in dmesg | tail after you plug in the MicroSD card.

Some cursory findings follow

  1. Graphics acceleration looks good. Sample video in Gallery app plays well, but without any sound from audio out jack.
  2. Ethernet interface seems to be supported as device usb0, didn’t test it though.
  3. The Gallery app has some nice images, and the slideshow option shows images with the Ken Burns effect.
  4. adb with USB OTG connector does not seem to work. In fact the board does not appear on my MacBook.

Android 4.1.1 (Jelly Bean)

The pre-built binary for Jelly Bean is available from rowboat.

Findings are similar to the ones above. Surprisingly there is no Ethernet configuration under settings, so Ethernet needs to be started from the serial port shell

screen /dev/cu.usbserial 115200
netcfg usb0 up

It may probably work automatically if the ethernet cable is plugged in before the board boots up.

BeagleBone and BeagleBone Black

Pre-built Jelly Bean images for BeagleBone are available from TI and rowboat. There are no pre-built images for BeagleBone Black yet.

tar with different owner and group

I needed to tar a folder and set all files and folders to owner/group 0/0. After a few man page perusals and internet searches, this is what worked

tar cvjf system.tar.bz2 --numeric-owner --owner=root --group=root  ./system

Here’s what tar tvjf system.tar.bz2 lists

drwxr-xr-x 0/0               0 2013-07-30 15:53 ./system/
drwxr-xr-x 0/0               0 2013-07-30 15:57 ./system/app/
-rw-r--r-- 0/0           29081 2013-07-30 15:53 ./system/app/ApplicationsProvider.apk
-rw-r--r-- 0/0          109577 2013-07-30 15:53 ./system/app/BackupRestoreConfirmation.apk
-rw-r--r-- 0/0           31705 2013-07-30 15:53 ./system/app/BasicDreams.apk
-rw-r--r-- 0/0          624562 2013-07-30 15:54 ./system/app/Bluetooth.apk
-rw-r--r-- 0/0         2852568 2013-07-30 15:57 ./system/app/Browser.apk
-rw-r--r-- 0/0          970646 2013-07-30 15:56 ./system/app/Calculator.apk
-rw-r--r-- 0/0         1786627 2013-07-30 15:56 ./system/app/Calendar.apk
-rw-r--r-- 0/0          771929 2013-07-30 15:54 ./system/app/CalendarProvider.apk
-rw-r--r-- 0/0          137476 2013-07-30 15:53 ./system/app/CertInstaller.apk