A switch on String idiom for Java

May 4, 2009 by Bozhidar

I’ve always been frustrated with the inability to write a switch on String in Java.  However the enum type introduced in Java 5.0 somewhat diminishes the issue. Read this excellent article on the subject.

Generating X Logical Font Descriptions(XLFD) for Emacs with xfontsel

May 2, 2009 by Bozhidar

Emacs prior to version 23 was unable to use TTF fonts. The type1 fonts that it uses are described by a XLFD line containing all the info about the font – its family, slant, weight and stuff like that. Guessing all of these while trying to find the perfect font for Emacs is boring and the process can the eased substantially with the help of the xfontsel application, which is generally available by default on most Linux installations with X.

The xfontsel application provides a simple way  to  display  the  fonts
known  to  your  X  server, examine samples of each, and retrieve the X
Logical Font Description (“XLFD”) full name for a font.

In other words you simply fire it up, select the properties of the font you need, see a preview of you selection and receice  XLFD line that you can pass to an Emacs Lisp function set-default-font for instance.

I myself am a fan of the terminus font and the XLDF line that I generated with xfontsel looks like that:

“-*-terminus-medium-r-*-*-20-*-*-*-*-*-*-*”

Ubuntu 9.04

May 1, 2009 by Bozhidar

As most of you probably know I generally use Arch Linux, at least at home. Recently the Arch Linux developers decided to drop the support for the ATI Catalyst proprietary video driver and I happen to own a RadeonHD 2900PRO so I was not very happy about this decision. So I thought I might give Ubuntu another try and installed the latest and greatest version 9.04 hot off the press. Here are some quick thoughts of mine about that release.

The installer was very polished. No issues, no complaints. I’d like however to see someday the option to select packages in the default installer.

The boot time was fantastic. Great job, Ubuntu team. I was pleasantly surprised by it. The new artwork looked great as well. Especially the New Wave theme which I simply love(except the issues it has with non-native GTK applications such as firefox, thunderbird). I found the new OSD notifications system good, although it seemed pretty much stolen from OSX :) As Pablo Picasso once said – “Good artists create, great artists simply steal”

The default software selection was decent enough. And there are the rich Ubuntu repos in which you can find almost everything. No worries here.

PulseAudio with OSS is still problematic, but I guess this is to be expected since probably only X-Fi owners use OSS. Flash performance is terrible on the 64 bit version at least. Skype 64bit is buggy as well. This is no fault of the Ubuntu team however. Video performance was satisfactory with Catalyst, though Desktop Effects are still almost unusable with it in the long run.

The overall experience with the system has  been overwhelmingly positive so far. I hope it’ll remain in the same general area. Stay tuned for further updates.

Ruby 1.9.1 is finally here

January 31, 2009 by Bozhidar

Hot off the press read the release announcement for Ruby 1.9.1(the first stable version from the 1.9 series) here.

The best way to implement the Singleton pattern in Java and Ruby

September 29, 2008 by Bozhidar

I haven’t posted anything lately, but I just received my brand new “Das Keyboard” and now I simply can’t stop typing. Recently I’ve been going through some effective technics to implement popular design patterns and I was surprised to see how few people where aware of them. For example since Java 5 the best way to implement the Singleton pattern is simply to use an enum like this:


public enum SomeClass {

INSTANCE;

}

This is possible due to the fact that in Java(unlike in C++ and C#) enums are full-blown classes(although they do not support features like inheritance for example). You get an added bonus when using an enum class – you do not have to worry about serialization – this is handled for you behind the scenes.

And this is how one should implement the Singleton pattern in Ruby:


require 'singleton'

class Some

  include Singleton

end

Through the magic of Ruby’s mix-ins you get a private constructor for your class and an ‘instance‘ method with which you can obtain a reference to the single instance of the class. And best of all – because this library has undergone a substantial degree of testing it is pretty much bulletproof. Things hardly get simpler than that.

The most valuable guides and articles about Git

August 18, 2008 by Bozhidar

Although Git is gaining a lot of momentum these days there are still obstacles to its adoption. One of the most often cited is the lack of good documentation. I agree that there are a lot of resources out there that can seriously confuse people beginning with git, so I want to share here a list of the guides and articles I have found most helpful in my git explorations. So here we go:

The Git Community Book – my personal favourite. A nicely written book, with succinct, but very helpful chapters. The book has one drawback though – it’s not finished yet.

Git QuickStart – if you’re really in a hurry to pick up a trick or two about Git check the QuickStart.

Git Cheat Sheet – the cheat sheet is also a source of highly compressed knowledge about git.

My Git Workflow – a bit more advanced, but extremely enlightening article about the mighty git.

I hope you’ll enjoy these articles and find them helpful.

A nice simple prompt for zsh

July 27, 2008 by Bozhidar

Recently I switched to zsh, after being a bash user for almost 5 years. I was in love with everything in zsh from day one, except one thing – the default prompt. Although zsh ships with several prompt themes, I didn’t like any of them so I looked around a little bit and constructed my own humble prompt. Here it goes:

PROMPT=’[%n@%m %~]$ ‘

In case you’re wondering what this gibberish means:

%n stands for your username(e.g. bozhidar)

%m stands for the first part of your machine’s hostname(you can use %M for the fully qualified name)

%~ stands for the current directory path with your home dir aliased with an ‘~’ (if you want to see the path in its natural form use %d instead)

All of this strange looking character combinations are called “escape sequences” and they have special significance to zsh. The rest of the characters in the prompt definition are represented literally in the resulting prompt. It looks like this(on my machine):

[bozhidar@drow ~/store]$

If you like it simply put the prompt definition like in your .zshrc file. You may want to put a little bit different version of the prompt in the root user’s .zshrc(if you use root at all that is):

PROMPT=’[%n@%m %~]# ‘

This follows the well established pattern that a normal shell and a root shell should be easily distinguished visually.

Using Emacs for Rails development – The perfect setup

July 19, 2008 by Bozhidar

Lately, I’ve started digging more and more into Rails, preparing for the start of a Rails powered project. Although there are some IDEs offering decent Rails support(namely NetBeans, Komodo and Aptana Studio) I have always preferred the comfort of Emacs for various reasons. So naturally I embarked on a quest to setup a suitable environment for Rails development in Emacs. After a couple of days of searching and evaluating possible solutions I finally set up a wordy environment. It consists of a couple of components – ruby-mode, ruby-electric, nxhtml-mode and rinari.

As you probably have guessed by now ruby-mode provides support for editing ruby source files. The mode is pretty feature complete and under active development, headed by none other than Matz himself. You can get it from the ruby svn repository. ruby-electric provides auto insertion of closing braces, quotes, ends, etc. It can also the found in the ruby repo. Instructions how to setup both modes can be found here. Although many people recommend adding pabbrev(a mode which provides auto-completion) to the setup, I don’t recommend it – I find the mode mostly annoying and stick to the old school dumb auto-completion with M-/ .

nxhtml-mode is a pretty comprehensive package for web development in general. We need it for its excellent support for erubis templates(.rhtml, .erb.html) and of course xhtml and css.

rinari is a mode for Rails development – it contains rich functionality such as the ability to easily navigate between models, views and controllers in a Rails application amongst other features. Instructions how to set up rinari together with nxhtml-mode can be found on rinari’s home page.

It’s always a good idea to add ecb(the Emacs code browser) to the mix, though this is entirely optional.

I hope you enjoy this setup and it helps boost your Rails productivity in Emacs!

Back to Arch Linux

June 26, 2008 by Bozhidar

After a very long period of waiting the new Arch Linux 06.2008 “Overlord” finally hit the shelves a couple of days ago. As some of you know Arch has always been my favourite distro, but recently I was using primarily Ubuntu(at least at home). Since today this is no longer the case – my desktop PC runs Arch now and I’m very pleased by that fact.

Don’t get me wrong – I enjoyed my exprience with Ubuntu a lot, but I’m one of those guys that always wants to tinker at things and Ubuntu simply isn’t built for tinkering…

Das Keyboard 3

June 16, 2008 by Bozhidar

Every professional developer knows how important to the development process the keyboard is, so it is only natural to be on the look for some quality piece of hardware. After a long research in the area of good keyboards I decided to upgrade my current rig to the recently released “Das Keyboard 3″. I have long heard stories about its quality and comfort and I hope I’ll experience them myself soon. So what are waiting for – research the market yourselves and make your pick, your hands deserve a quality keyboard!