Sunday, July 29, 2012

Colors in R console

Update 2: The colorout package has moved again and is now available on GitHub.

install.packages('devtools')
library(devtools)
install_github('jalvesaq/colorout')

Update: The colorout package on CRAN has not been updated to be compatible with R version 3.x.x yet. However, if you compile and install it yourself, it still works.

download.file("http://www.lepem.ufc.br/jaa/colorout_1.0-1.tar.gz", destfile = "colorout_1.0-1.tar.gz")
install.packages("colorout_1.0-1.tar.gz", type = "source", repos = NULL)

 R console


Let's face it, the R-console is one of the more uninviting things I have seen, perhaps second only to the Ocaml console which comes without readline.

This is what my (and probably your) R console looks like this:
R console without color
What I see on the console is a single color which, firstly, makes it a challenge to separate stderr, output, warnings and errors, and, secondly, is just boring. I did not know what I could do about it and I stuck with it because the only other option seemed to be moving to a GUI (JGR or Rstudio). This is not to say that there is something wrong with the GUIs, but I prefer working with only my keyboard and, hence, shun GUIs almost as a rule. (Eclipse for Java is an exception.)

But it changed when I discovered the package colorout on CRAN, which makes my console look like this:
R console with color (using colorout)
This makes it remarkably easier to differentiate different forms of output.
The coloring is not perfect (notice that the second '-' in the interval outputted for tmp30 is assumed to be a negative sign instead of being a separator), but I would choose it any given day over the drab single color.
I did need a little tweak to my .Rprofile file since I did not like the way the default settings display the error:

~
musically_ut

Monday, June 11, 2012

Book Review: Seabiscuit - An American legend

This book is about a horse and four people around it: the owner, the trainer and two riders.

To be honest, I did not start the book with high hopes. To begin with, it was non-fiction and then it was about a horse. About 10 pages deep, I had an inkling that Laura Hillenbrand was luring me into a trap. I distinctly remember thinking "This is not how one writes a historical account" but I could not figure out what was amiss. The facts were all there, the cross-references seemed to match up and I could find nothing wrong apart from some poetic exaggerations which brought forth gentle chuckles. I circumspectly read through the account of earthquake in San Francisco without realizing anything.

It was just after the first race in Tijuana that I realised what was wrong with the book: It wasn't boring!

Friday, May 25, 2012

Book review: The Museum of Innocence

The first 100 pages or so made me consider many times why I was reading the book at all (it came highly recommended) and why didn't Kemal bey just move-on. Why stay there? And moreover, why call it innocence when nothing could have been further away? Why color something purportedly black and white like carnal desires in shades of gray by waving brushes of grandeur on it? Why not just admit it for what it was, why not just smack the monkey, massage the seal, walk the cobra and then do something else?

However, by the time his first year of misery was over, I understood him better. His misery was not a choice. His misery was a way of life. His innocence was blindness and denial, but it still reeked of innocence. He lived in Turkey, he lived the life of a rich man, and though the poor there thought that wealth would cure them of their illnesses, he lived not very differently.

Wednesday, April 4, 2012

Umlauts and accents in Gnome 3

The extra characters can usually be typed with the help of a compose key. In Gnome, one can choose one of the keys on the keyboard to be a compose key in this way.

Monday, March 5, 2012

Rate songs in notifications with Rhythmbox

Update: Keeping in mind the feedback, I have enabled instant update of the notification once the ratings are changed in my new patch to the notification plugin of Rhythmbox.


When do you rate your songs?

I have a huge music library. Enough to keep me engaged for more than a month if I listen to each song in a row with no repeats. Hence, my preferred time for rating songs is while I am listening to it.


Currently, this process is somewhat complicated. I have to go to Rhythmbox's workspace, rate the song and then figure out which workspace did I just leave and then continue my previous work. This interrupts my work flow.

However, Gnome 3 allows actions in its notifications and one can already do the Previous, Play/Pause, Next actions from within the notification.

Saturday, December 31, 2011

Line segment intersection

It looks like an easy problem, it has a trove of information on it and Bryce Boe even has a two line solution for it. However, his program does not handle improper intersections, i.e. when one end of one of the segments lies on the other line. Since a point lying on the line does not make triangles with different orientations (since it has zero area), his program does not count it as an intersection.

The highest voted answer on the stack overflow question needs special care while handling vertical lines (And it is general outline for a solution, not actual code).

Now there are multiple methods of correcting these problems, and this is one of them:


Use this function to test the implementation:





Tuesday, December 20, 2011

Numerically stable standard deviation calculation and code perforation

How would you implement a class which has an append(double x) function to collect values, and a get_std_dev() function which returns the standard deviation of the values collected?

Sounds like an easy problem, here is my guess at what your code would look like:


This looks like an standard implementation, but it contains some subtle bugs. These bugs do not show up in regular usage, but they lie patiently in wait. Remember the tricky binary search implementation bug which escaped detection in the JDK for about a decade and is now staple fodder of all technical interviews?