Wednesday, May 27, 2009

Desktop Launchers

One of the many great things about using the command line in a *nix environment is being able to access programs no matter what your current working directory is. Say for example I want to open a file to read, I just type 'less' then the file-name. I don't have to type the full directory path (/usr/bin/less) to get less to execute, this is because of the $PATH variable.

So when graphical desktop environments came along how did they handle finding programs? Well there seems to be two methods that are common among desktop environments, start menus and shortcuts. Neither of which are as fast as the command line because they both require mouse clicks to execute the program. (I know you can click the option button then arrow through the menus to find they application but the point is that it is slow.)

It takes me less then a second to type 4 or 5 letters. To move the mouse to the start menu, click, find the application in the list then click again to execute takes me 5 to 6 seconds and that's when I know where the application is at in the menu.

Solution: Launchers, a launcher is brought up with a keyboard shortcut usually (alt or command) + space bar. Then type the first few letters of the application, once you have found it hit enter and the application will open. Launches do much more then this but this is the most basic function of a launcher.

On my Mac I use Quicksilver, and on my Ubuntu Linux Desktop I use Gnome Do.

Launchers enable the best of both worlds, all the GUI goodness with the quick application access of the command line. Download one and try it out.

Friday, May 15, 2009

Google Operator Observation

I was writing a small Ruby program and with out thinking wrote:


Which of course produces a : :syntax error !! when executed. Duh, Ruby does not have pre/post increment/decrement operators.

I wanted to find more information about this, so I started with Google, typed in ruby ++ and hit search.

That's cool the suggestion for 'Ruby ++' is 'Ruby increment'. So Google recognises programming operators?, not exactly. I could not get the same suggestions for other operators.

Other words like 'test ++' did not give a 'test increment' suggestion. Other programming languages did produce this like 'perl ++' but others didn't like 'java ++'.

I couldn't find alot of information on the 'See results for' feature. My guess is that a 'programming language name' and '++' and 'increment' must show up together in alot of webpages and Google is not doing some cool operator interpretation, ... sad.

Thursday, February 26, 2009

MD5 hash, Java vs Ruby

I needed to create a small program that would create a MD5 hexadecimal hash for a password. First I implemented this using Java.

public class TestMD5 {
public static void main (String [] args) {
try {
String passwd = "password";
MessageDigest md =
byte[] hash = md.digest(passwd.getBytes());
StringBuffer hexstr = new StringBuffer();
for (int i = 0; i < hash.length; i++) {
String hex = Integer.toHexString(
hash[i] & 0xFF);
if (hex.length() == 1) {
} catch (Exception ex) {

Note: java.lang.Integer.toHexString does not add leading zeros. Without the length check after this function the hash string will not always be 32 charaters long.

Since I have started working with Ruby on Rails, I was curious to see how I would implement this in Ruby.

require 'digest/md5'
passwd = "password"
digest = Digest::MD5.hexdigest(passwd)
puts digest

In this case Ruby wins for having to write less code to get the same result.

Wednesday, February 11, 2009

iPhone Dev dreams

I have had my iPhone for several months, and one of my favorite aspects of the iPhone is the large number of applications available at the App Store in iTunes. As a developer I was excited to learn how to develop applications for the iPhone. I went to the iPhone DevCenter on the Apple Developer connection web site and started doing some research. After some reading and watching a few the dev videos I was eager to download the SDK and play around with the iPhone simulator.

Wait I can't download the SDK !!

I don't have Mac OS X 10.5 Leopard Nooooooooooo!!

Ok maybe not that bad but, I was disappointed. Looks like my iPhone dev days will have to wait until I get a new Mac or whenever I get around to installing OS X on my Ubuntu/XP computer.

Tuesday, February 10, 2009

Source Code in blog ... again

A few posts after I outlined how to post source code in Blogger, it stopped working. Syntaxhighlighter released a new version and I don't really have time to figure out how to get it to work again.

I found a post that outlines how to use VIM to export the code and highlighting to html. After adding the CSS to the Blogger template produces the result below which I am much happier with.

public class HelloWorld()
public static void main(String [] args) {
System.out.println("hello world!");

VIM command:
:runtime syntax/2html.vim

Add to $HOME/.vimrc
syntax on
" Conversion HTML (:help 2html.vim)

let g:html_use_css = 1
let g:html_use_encoding = "utf8"
let g:use_xhtml = 1

Tuesday, January 27, 2009

Mysql database welcomes its Subversion overlord

This post will describe how I versioned a Mysql database using Subversion(SVN). The database schema is an important part of the application and should be versioned just like your source code.

1. Setup SVN

In SVN create a `Databases` folder with a sub-folder for each database you wish to add to SVN. The Subversion client I use for this project is RapidSVN.

2. Add db_version table to databases

We will need to add a table to each database so we know what version of the database we are currently working with. This table will also serve as a log to track what schema changes have been made to the database.
create table db_version (
`id` int auto_increment,
`majorReleaseNumber` int,
`minorReleaseNumber` int,
`pointReleaseNumber` int,
`scriptName` varchar(50),
`dateApplied` datetime,

majorReleaseNumber - Major releases are significant changes to the database.
minorReleaseNumber - Minor releases are enhancements to the database that do not necessitate a major release.
pointReleaseNumber - A point release is usually a simple bug fix.
scriptName - The name of sql script that made the schema changes.
dateApplied - When the script was run on this database.

3. Create baseline scripts

I used mysqldump to generate a create script for existing databases. Be sure to include the --no-data option. SVN is used to keep track of the scripts that make schema changes to the database and is not intended to be used as backup tool for data of a particular instance of the application.
$ mysqldump -h localhost -u root -p db_1 --no-data > db_1.1.0.0.sql

The name of the sql script should contain the name of the database and the version of the database the script applies to.


At the end of the script be sure to add an insert statement for the db_version table.

4. Changing database schema

When you have a major, minor, or point release change to the database, the change script should be tested and then uploaded to the database folder in SVN. It is a good idea to backup the database before applying a change script. At the end of the change script should be an insert statement for the db_version table.

5. Sync database with SVN version

I am currently creating a small java application to query the SVN repository and compare it to what is in the db_version table. Then prompt the user to upgrade the database to a selected version. Below is an example out of how I see the application working.
$ dbsync check db_1
2 database versions avialiable

$ dbsync upgrade db_1
1.2.1 script applied
1.3.0 script applied
db_1 upgrade to 1.3.0 successful

Or if you only want to upgrade to a certain version
$ dbsync upgrade db_1 version 1.2.1
1.2.1 script applied
db_1 upgrade to 1.2.1 successful

I found a nice Java SVN api SVNKit that I am planning on using to create the dbsync application. I will have a future post about this when I am finished with the application.

Tuesday, January 13, 2009

Posting source code in blog

One of the main reasons I started my blog was for documentation. With documentation comes posting source code, but I had a hard time finding an easy way I could post code with spacing and syntax highlighting. I found syntaxhighlighter written in JavaScript that I could add to the existing blogger template.

public class HelloWorld()
public static void main(String [] args) {
System.out.println("hello world!");

I added all of the SyntaxHighlighter.css to the head section of the blogger template. Then under that I add links to the JavaScript files I needed.

The last step is to add the following at the end of the template before the end of the body tag.

All the following around the code to post.