Archive for the ‘Coding’ Category

Picking a GoogleVoice phone number

Monday, December 13th, 2010

screenshotI decided to use Google Voice service. The first problem I had was to select the phone number I wanted to use. This screen shot shows how one can pick a phone.

There is a rudimentary search, but if one wants to have a phone that spells a word or a phrase, then this search dialog is not really helpful. You are also given only five phone numbers at a time and you can not filter these numbers. For example, I would like to ask for phone numbers that does not contain 0 or 1 (which do not have letters associated with them).

The brute force approach was to look at the current five phones, select ones that do not have 0s or 1s and paste them into a website that tries to match a phone number with words (I used After repeating the process a few times I realized that it was way to slow…

screenshotSome time ago I cam across Sikuli and it seems that this was a job for this software. I quickly wrote a script (using their IDE) that found all radio buttons, selected phones next to them, copied them into Notepad, clicked “Next 5 >” button and repeated the procedure. Strangely enough, I did not see a direct way to copy/paste text in Sikuli, and that’s why I had to use keyboard shortcuts.

Once I got the phone numbers in the text file I wrote a trivial perl script to filter out ones that I wanted and create links to that would show what the numbers can spell. The list of links was opened in Firefox using Url lister plugin.

At this point all I had to do was to look at a web page with proposed words and if I did not like them I simply closed the tab, which presented me with the next opened tab. This way I was able to review many numbers quickly and pick the one that I liked.

Code commenting style

Sunday, April 4th, 2010

After programming for more than ten years I gradually refined my commenting style to a level that I am satisfied with, at least for now. Long story short, this is an example for C++:

// This is a comment.

Simple and precise. Let me explain why. The general format follows this pattern:

1. Comment character(s), such as /*, //, #, %.
2. Space.
3. Comment string, that starts with a capital letter (with rare exceptions).
4. Period.
5. Comment closing character, such as */, –>

1, 3, and possibly 5 must be present in any comment. Let’s focus on the parts that can be present or omitted. I include Space before the comment string to differentiate between a comment line and a commented out code:

// Use it as follows:
// exec(true);

In the example above, the first two lines are comments, because there is a single space before the comment string. The last line is a commented out line of code.

I use capital letter to start a comment and a period after a comment sentence for multiple reasons. First, it forces to make comments from well formed sentences, which can be easier to understand as compared to incomplete sentences. Second, it tells me where a comment sentence starts and ends. For example, if I see a comment line that does not end with a period, then I can assume the next comment line must continue the same sentence. For example:

// This is one
// comment sentence.

To recap. A space before helps separate at a glance comments from commented out code. Following a formal sentence structure (start with a capital letter and finish with a dot) helps to understand the comments better and provides information about where the comments start and end.

C++ logger class

Monday, February 8th, 2010

I was looking for a logger implementation for one of my projects. I needed a few features: simultaneous output to a console and a log file, efficiency, and ease of use. Quick google search revealed a few candidates: Apache log4cxx, and Pantheios. Do it yourself articles (example) about home made logging I ignored, because I have done enough of those (Boost Logging Library v2 is in the same category for me). Given that my primary platform is Windows, log4cxx was dropped, as windows was not directly supported.

Compiling a few examples for pantheios was not difficult, but getting it to do exactly what I planned, which is to have output to a console and a file at the same time, was a little more challenging. The solution was not obvious from the documentation, and sample name mx.1 did not stand out to me as meaning Mixing different back ends. But after searching in pantheios forums I have found the answer to my question.

At the end of the day Pantheios was my choice. We will see how happy I will be with it after I play with it for a while.

Find duplicate files using OpenOffice.Calc

Tuesday, October 13th, 2009

I had a problem of having a set of directories with some files duplicated in some of the directories. The search for a software to remove duplicate files did not reveal any free utilities to accomplish this task. So I decided to use OpenOffice.Calc to do the job.

  • First I got the list of all the files:
    dir /b/s >list.csv
  • Then, I opened list.csv in OpenOffice.Calc and used this formula to extract only the file name:
  • After that, I sorted the sheet by the file names and added a formula that detected duplicate file names:
  • Search for the string DUP (in values) quickly showed me where the duplicates are.

I know it was not as easy as running a specific program, but it was easier for me to do that than to find a free software.