## Saturday, November 17, 2012

### The iPad and the Kindle

Like many people, I love to read, especially when traveling and going on vacation. Because travel space and carry-on weight are always at a premium, I am forced to get a small book that I can carry easily with me. The choice of book is a gamble: either it will be an enjoyable hit, or a disappointing miss. In the latter case all is not lost, since I can usually buy another book at the airport, or at a local bookstore where I am at.  I have always wondered how nice it would be to be able to carry my whole library with me, and read the book of my choosing and mood.

So when the Kindle came out, I was very excited, and bought one immediately. The promise of carrying my whole library in the digital device without incurring the weight was overwhelming. The Kindle did not disappoint: the screen was as easy on the eyes as the printed page, the battery life was fantastic, and the added bonus is that I could buy books all over the world and have them delivered wirelessly to the Kindle without incurring bandwidth charges.

The Kindle served me well for a long time, mostly for mainstream books--fiction and non-fiction. It was not good for technical books or PDF papers. The screen size was too small to be convenient for figures, charts, and programs. I searched for an alternative, and the Kindle application came to the rescue. I installed it on my laptop, and starting enjoying the technical books in electronic format.

As I read more technical books, I found my usage shifting to the Kindle application on my laptop. As an added bonus the fonts were better, and the application had more features than the stock Kindle device. However I missed the convenience of not having to carry my laptop with me everywhere.

So when the new iPad came out, I got one, and I believe I got the best of both worlds. The iPad is relatively light, and convenient to hold; the screen size is good; and the battery life is acceptable. Moreover, the text is easy to read in low light conditions, and in addition to reading,  I can surf the Internet, get my email, and stay connected to the world. At times I don't even need to bring my laptop with me.

Kudos to Amazon for building the Kindle application, and widening the distribution of their content beyond the hardware they design and sell.

## Tuesday, October 9, 2012

### Switching to Android

I have been an iPhone user for about 4 years now, but have recently been frustrated with the poor battery life on my phone especially with relatively moderate usage--I use the phone for the occasional phone-call or text message, and use it primarily for work emails. I grew tired of having to charge the phone multiple times per day, and started to look at other options.

My coworkers have been pleased with the battery life on the Samsung S3, so I decided to give it a try. I went to the AT&T store, and upgraded my phone. Before I did, I looked at the iPhone 5, and while it is a beautiful design, I thought its screen size is a big disadvantage compared to the Samsung.

My first impressions with the Samsung were not very positive: the usability is inferior to the iPhone, and things were not as intuitive or as consistent. However as I continued to use the phone, I discovered a lot of features that in my mind overshadowed the usability issues, and the phone started growing on me.

First there is the Swype keyboard, where you enter words by drawing a continuous line between the letters that form the word, and the predictive text engine figures out what you typed with very high accuracy. If you prefer to use the older way of tapping letters, there are subtle features in the keyboard, where if you linger over a letter, you see the capitalized form of it, and the numeral or special character that is associated with the letter, which makes it faster to enter special characters than using the symbol or shift keys.

Second, dictation is amazing, you can dicate sentences at a fast speed, and the software transcribes it with very high accuracy. Quite a keystroke saver. Dictation works everywhere, for google searches, typing letters, and calling and texting people. Similar to Siri on the iPhone but much faster and better accuracy.

Third and more importantly the battery life is great. With elevated usage I get about a day and a half worth of battery life.

And finally I think the call quality is much better, even in areas where I have bad reception. People can hear me better, and I can hear them better as well.

There are downsides though in addition to usability. First syncing music and transferring files using OSX Mountain Lion is not possible. All the programs including Samsung's do not work with the phone. Also there is an annoying issue with iMessages, where other people with iPhones can't send you text messages if they are using iMessages.

I'll give the phone a month, and see how I think about Android with more usage.

## Wednesday, June 20, 2012

### Stephen Hawking at the Flint Center

I have always enjoyed physics and astrophysics, and the epitome of that enjoyment was attending a live lecture by the famous by Dr Stephen Hawking at the Flint Center yesterday.

The event was roughly two hours, divided in three parts. First, Dr Hawking gave a fascinating exposition of black holes and the Hawking radiation, then his long time friend, Prof. Kip Thorne gave an excellent talk about his research on black holes. The sessions ended with a Q&A session dubbed: the best of Hawking.

The event was sold out, and the Flint Center was overflowing with patrons standing up on the side to listen to Dr. Hawking. It is not hard to understand why. Dr Hawking is a world renowned physicist who can explain complex topics in simple terms that everyone can understand and enjoy. Because of his deteriorating physical condition due to ALS, most of the lecture and Q&A session were prepared--later on Kip revealed the reason is that the technology that Dr. Hawking uses to communicate allows him to talk at the rate of about 3 words per minute, which is not suitable for live events.

Dr Hawking was both illuminating and entertaining; I specially enjoyed how he explained such a difficult topic as black holes using simple and humorous analogies. Take the Hawking radiation for example, where information could escape a black hole, but in a different form than that originally in the black hole. Dr Hawking compared the phenomena to an encyclopedia that has information, but when you burn it it turns into ashes and smoke. The information is still in the ashes and smoke, albeit not in an easy form to recover.

Incidentally Dr Hawking made a bet that nothing can escape a black hole earlier in his career, and when he proposed the Hawking radiation, he paid up the bet with an encyclopedia, albeit not a burnt one.

Dr. Thorne was next, and he talked in detail about his research. The two fascinating takes were it is hard to measure gravitational waves, that the equipment designed to do that is amazing: mirrors separated by 4km, to measure a perturbation on the order of magnitude of 1E-17 cm. Dr Thorne laughed that such a resolution is ridiculous, that he has spent half his career convincing people that it would work, that there are a lot of stations around the world that are setup to measure gravitational waves due to collisions of black holes.

Dr. Thorne then showed simulations of colliding black holes, and simulations of how their vortices would interact (clockwise/counter clockwise spins). The resulting patterns were breathtaking, and reminded me of the great Turkish pottery patterns and designs.

In the end Dr Hawking answered questions from his best of Hawking sessions. The answers were informative, and humorous, like the one about time travel, where Dr Hawking said he has experimental evidence it does not work: he once hosted a party for the travelers from the future, but did not send the invite until later. No one showed up.

He also had a great answer to the Landau physicist productivity scale, where Landau assigned Newton 1, Einstein a 0.5, and himself a 2. The question was where would Hawking rate himself, to which he answered: Landau was good, but not that good. And people who rate themselves are losers.

But perhaps his best answer was what does he miss due to his ALS condition. Dr Hawking was profound in his answer, listing the blessings he has in life: an excellent physics career, 3 children and many grand children, wonderful friends, and a fulfilling life.

What a treat it was to see Dr. Hawking in person, and to listen to him for a little bit of time.

## Wednesday, May 30, 2012

### Scala environment in Emacs

At work we have been doing most of our development in Java, and it has been serving us quite well. For a new project that we started, we looked at other JVM based languages, that would help us develop a little bit more efficiently, as well as leverage the big code base that we have.

Since a couple of people on the team knew Groovy and Grails, and have used it in the past to develop web applications, we went with that choice, and so far it has served us well. Development became a little bit more pleasurable, and we got rid of some of the Java boilerplate.

Out of curiosity I started experimenting with other JVM based languages, and since a lot of my friends at other company were singing praises for Scala, I decided to play with that.

The first step is setting up a Scala development environment, and with a couple of additions to my .emacs file, I got just that:

For Scala development in emacs, you need a couple of things:

1. scala-mode
2. ensime

Then move the directories under your elisp directory, and add the following lines to your .emacs file, changing the PATHTOELISP accordingly

;; scala support
(require 'scala-mode-auto)


After expanding the zipped tar archive, move the directory to your elisp directory, and add the following lines to your .emacs file

(add-to-list 'load-path "/PATHTOELISP/ensime_2.9.2/elisp")
(require 'ensime)


And now you have syntax highlighting, auto-completion, and a Scala REPL and debugger inside of Emacs.

## Thursday, May 17, 2012

### More mutt goodness

I have been using mutt for some time now as my primary email client, and have found that I have not missed using any of the more graphical interfaces like Mac Mail, or Gmail web interface. Not even to look at HTML emails, PDF documents, or Word documents. Thanks to a couple of open source utilities, I can convert these documents to text, and read them from within mutt, leading to a seamless experience, and a much more pleasant email workflow.

The following lines in your  ~/.mailcap config file configure the utilities and do the magic:

HTML emails

I use the links browser to do the conversion from HTML to text. There are many other options to use, such as Lynx, or w3m, but I like links because it formats the HTML tables better than Lynx or w3m, and handles utf8 characters better. You can also turn off the html numbered links easily if you choose to.

PDF files

application/pdf; pdftotext -layout /dev/stdin -; copiousoutput

I receive a lot of resumes, and hate to open them in Preview or Adobe Acrobat. For me, nothing beats looking at resumes in text mode where I can focus on the candidates' skills, and experience, without being distracted by formatting and colors.

For the conversion I use the pdftotext script which you can get by installing the poppler macport.

Word documents

application/msword;             antiword -f -s %s  2> /dev/null; copiousoutput
application/vnd.openxmlformats-officedocument.wordprocessingml.document; docx2txt.pl %s - 2> /dev/null; copiousoutput

There are two formats for word documents, the older DOC format, and the newer DOCX format. For the older format I use antiword, which you can install through macports, and for the newer format I use the perl script docx2txt, which you can download from the docx2txt sourceforge repository.

I have not had a need to convert powerpoint slides or excel spreadsheets to text so far, but if you know of any utilities that help, let me know.

## Saturday, April 21, 2012

### PiQL tech talk

Big Data has been gaining a lot of press lately, and NoSQL even more. A lot of new software development is moving to using NoSQL databases to alleviate the scaling pains of traditional RDBMS systems when the data size grows very large. The NoSQL databases usually expose a simple key value based API, where you can set, retrieve, and scan values based on the value of the keys you're interested in. The API is sufficient for most applications, but sometimes you want more than the simple retrieval API; you want SQL, where you can join keys, and have more complex filtering rules.

Here is where PiQL plays a role. Last week I attended a talk about PiQL by Michael Armbrust. In the talk, Michael introduced PiQL: a query system that runs on top of NoSQL key-value stores, and allows developers to write SQL queries that execute efficiently against the simple key-value retrieval API.

The system operates in two stages: the first is the static analysis stage, and the second is the execution stage. In the analysis stage, the optimizer analyzes all the SQL queries in the application offline. The analysis phase produces one of two results. If the queries can't be executed efficiently, the system warns the developer, and gets their explicit approval to serve the results of these queries.

However for the SQL queries that return bounded results, such as select ... limit 100 type queries, the system creates views and indexes in the key-value store, and translates the SQL queries into an execution plan over these views and indexes to make the execution efficient.

At run-time, the system uses the previously created views and indexes, with an efficient execution plan to transform SQL queries to simple key-value retrieval APIs, and serve the results. Michael brushed upon the transformation patterns for different SQL query types including joins and how PiQL creates views and indexes to serve these.

PiQL works well with read intensive systems. The issue with updates is that in addition to updating the data, the system also needs to update the views and indexes, and that could take a bit of time. When I asked Michael at the end of the talk he mentioned the updates typically take 150ms, but for some queries where the created views and indexes are a cross product of two keys, the updates take longer. If a read comes in during the update time, then you might miss the updated data. The updates are still bounded though, because the key spaces are bounded--a prerequisite for efficient execution in PiQL.

## Saturday, March 3, 2012

### Back to Mutt

For the last decade I have used web based email almost exclusively for work and personal use, and in due course have accumulated a rather large email archive. Lately I have been traveling a lot, and started missing offline email, especially since the flights don't have wifi in general, so I decided to augment my online email with an offline one.

My first choice was Apple Mail. The setup and mailbox imports were a breeze, and the interface is beautiful. However the mail client crumbled under the large number of messages that I have: color beach balls were a common sight, and the client seemed to leak memory--after an hour of use, the memory footprint was roughly 2.5GB which made matters worse.

I had a similar issue with other mail clients, and while talking to a colleague at work, I remembered that I did not experience these issues with a very old mail client that I used before: mutt.  So I went back to set it up.

Mutt is not for the faint of heart, but techies should feel at home setting it up and using it. The installation is a breeze on Mac OS X, thanks to the ports system:

sudo port install mutt-devel +compress +gnuregex +gpgme +headercache +imap +pop +sasl +sidebar +smtp +ssl +tokyocabinet

The configuration is a different story. Like most Unix programs, the installation requires editing configuration files. The first is .muttrc, that you put in your home directory. I have lost my older .muttrc, so I had to recreate it from scratch:

set realname="First Last"

set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"

set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates

set signature = "~/.signature
set editor = emacsclient"

set mail_check = 15
set timeout = 15
set imap_peek=no

set imap_keepalive = 900

auto_view text/html

set print_command = muttprint

Now Mutt is ready to use. There are a couple of conveniences though that would make life a lot easier. One is handling HTML emails that a lot of people tend to use these days. You can add the following to your .mailcap file in your home directory

text/html; lynx -dump %s ; nametemplate=%s.html; copiousoutput

which allows you convert HTML emails and display them as cleaned up text inside of mutt.

Lastly is adding color to mutt. While you can edit the color scheme manually, it is usually better to start from a designed scheme and customize it. I like using Solarized, and you can download the schemes directly from GitHub.

And now you're ready to roll, even with a large mailbox.

## Thursday, January 26, 2012

### Why good customer service matters?

I am not an Apple fan, but I do like their computers, and recommend them to colleagues and friends for a variety of reasons. They are well designed, and in addition to an excellent user interface, they run a flavor of Unix--which makes the life of computer programmers a lot easier. But most importantly, Apple's customer support is impeccable, that despite all the hardware issues I experienced in the past, I still recommend Apple computers. Let me explain why.

A year and a half ago, I bought a Mac Book Pro for work. At the time it was the first generation unibody laptop, that had an i7 processor, lots of memory, and lots of disk space. Alas, like first generation models everywhere, it also had a lot of hardware problems. The most annoying of which was the screen randomly turning dark, with the hard drive spinning out of control. The only way to get out of this state was by forcing a reboot by holding down the power button, and losing everything I have been working on.

At first I thought it was a software problem, but after searching the Internet, I found that a lot of people are experiencing similar issues with this generation macbook pro. On Apple's discussion boards there were threads 50 pages long of people having the same issues, with stories about faulty logic boards, bad graphics chips, and bad memory chips. I was furious that I got a lemon for an expensive laptop, and went raging to the apple site to file a complaint.

Unlike other sites, the support links were front and center. I selected my computer model, entered the serial number, and wrote in the problem description. The next screen asked for my contact information--phone number and email, but the third screen diffused my anger. It asked if Apple can call me now, and when I clicked yes, I immediately got a callback, and talked to a tech support engineer within 30 seconds. The tech was very helpful, he diagnosed the problem, and scheduled a same day appointment for me to the nearest Apple store. When I went there, the service was quick, and I got replacement parts the next day. Today nothing on my Macbook pro is original, apart from the unibody, keyboard, and LCD screen.

The whole experience was so delightful, that despite starting with a lemon laptop, I still recommend Apple products. And at my current company, I retell that story, to make sure we delight our customers with exceptional customer support.

## Wednesday, January 18, 2012

### On cyclomatic complexity

Not all of us are lucky to work with greenfield projects; the majority end up working with codebases that we inherit. These codebases have had their share of modifications that moved them away from the original elegant design: bug fixes, feature additions, and enhancements that were done in a hurry because of delivery pressure, without regard to code hygiene and future maintainability. The code then feels heavy, complex, hard to understand and more painful to maintain.

There are a lot of ways to characterize code complexity, but the one that jumps to mind is "cyclomatic complexity" described by the McCabe paper from 1976 http://www.literateprogramming.com/mccabe.pdf.  The paper describes how to measure the cyclomatic complexity of different program control paths, and recommends a bound of 10 for manageable code complexity. NIST also selects the same number http://hissa.nist.gov/HHRFdata/Artifacts/ITLdoc/235/chapter2.htm. The numbers, despite being arbitrary, provide a guideline to when to get out the scalpel, and start cleaning up the code.

I was curious about how our code fares, and luckily I found a lot of open source tools that help with that. For C/C++ programs "cccc" is good. If you're using the ports systems,

sudo port install cccc

does the trick. For Java code there are a lot of plugins for various IDEs, and for NetBeans, Simple Code Metrics is good. The plugin page shows that it is old and unmaintained, however it works perfectly in NetBeans 7.1. You choose a file or a package, and click the SCM icon, and it spits out metrics about the code including the cyclomatic complexity.

When I ran the tests, the results were an eye-opener. The good news is that most of the code has a complexity below 15, with the occasional function that is high up in the 30s. Not alarming, but definitely would need attention to keep the code hygiene high. The surprise came when I included some of the open source libraries that we use, and the numbers shot up as high as 206. When I talked to colleagues from other companies, the experiences were similar--most of the normal code hovers around 20, with the occasional function around 50, but no high alarming numbers like the 206 one.