Archive for the ‘Linux’ Category.

Switching from XEmacs to Emacs

My first editor in the *nix world was Emacs. When I started university, some friend showed me how to get started. I have never really become a power user with it, but it is the tool I use for random small editing tasks. At some point in time when I started using Linux on desktop more often I put some effort into making Emacs work well with my habits, and in the process I actually settled on XEmacs. At the time I believe it was more advanced than Emacs, more defaults worked out of the box, and the GUI actually had a button for copying text. This was important since I could never remember how to do that from the keyboard (I could only remember how to cut).

It is now 2009, and I think Emacs has long since eclipsed XEmacs in features etc. At least on Ubuntu, Emacs also comes with the important copy toolbar button ;). Besides, when I log in to remote systems they will almost certainly have Emacs but not XEmacs, meaning I can’t just upload my XEmacs customizations file and expect things to work. So I decided to see if I could make Emacs work at least as well as my XEmacs does.

Most of the settings were trivial; just copy to .emacs. Keyboard customization uses slightly different syntax in Emacs, but it was an easy conversion. The problematic things were font size and clipboard functionality. I wanted a bigger font size, and the best solution I found was to set the font face height explicitly (actual value will depend on your resolution and your likes), but the following gives me a nice 80×63 Emacs window that will use half horizontal and 100% vertical space:

;; With my resolution, dpi and fonts this let's me display 80x63 geometry
(set-face-attribute 'default nil :height 100)

The XEmacs clipboard worked out of the box with my X and Gnome settings, but Emacs needed some tweaks:

;; Make copy and paste work with other applications
(global-set-key [\C-z] 'undo)
(global-set-key [\C-x] 'clipboard-kill-region)
(global-set-key [\C-c] 'clipboard-kill-ring-save)
(global-set-key [\C-v] 'clipboard-yank)
(setq x-select-enable-primary nil) ; stops killing/yanking interacting with primary X11 selection 
(setq x-select-enable-clipboard t) ; makes killing/yanking interact with clipboard X11 selection

Incidentally, with those settings I have no problems with copying and pasting text since the key combinations are the same as in any other program I use. So I could even take out the toolbar, since I only needed it for copying.

Since I do most of my programming in Eclipse, I also wanted matching comment/uncomment region settings:

;; Comment/uncomment reqion similar to Eclipse: C-/ and C-? (control shift /)
(global-set-key [(control /)] 'comment-region)
(global-set-key [(control \?)] 'uncomment-region)

Probably my nicest customization (although not written by me) is to be able to cycle between buffers with Ctrl-tab and Ctrl-Shift-tab. They are kind of long, so see the links below.

I think I found the answers to most of my problems on EmacsWiki.

I have always found other people’s (X)Emacs customization files fascinating reads, so if you are like me, here you go: .emacs and .xemacs/custom.el.

Update: As was pointed out in the comments, binding C-x etc. breaks havoc with many Emacs bindings. However, I did this only after I was unable to get CUA mode to work properly (namely, copy and paste did not work between Emacs and other applications). But I gave it one more try, and it seems like adding these things to .emacs does indeed make copy and paste work like I want:

(cua-mode t)
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

Of course, remove the lines that bound C-z, C-x, C-c and C-v (since CUA mode does that).

Laptop Died

Today I came from work, lifted the lid of my Dell Latitude D820 expecting it to restore from suspend. Hum, after a few seconds the power light just went off. I thought the restore must have just failed, becoming slightly annoyed for having to wait for the OS to reboot and open all applications I had open. But I started getting worried when pressing the power button just caused the hard drive to spin for a few seconds, CD/DVD tray click and clack a few times, and then nothing but the power light on, nothing on display. I repeated the step a few times, but couldn’t get anything more promising.

Well, I figured maybe there is dust clogging places, so I dashed to buy some canned air, and thoroughly blasted everything I could reach without unscrewing anything. Plug the power on, power button… no change. I tried booting from an Ubuntu 8.04 LiveCD, but that didn’t work either (got nothing on display) which kind of leads me to suspect the CPU or motherboard being fried. But I have never really faced this situation before, so no ideas yet how to figure out what part is done for, or who could cheaply find out.

I then unscrewed the HD to compare it to the one I have in my work D830. Well, turns out they use different voltage, so I am not going to cross test. But I wonder if there was some way to read the data from the HD without using the D820 somehow.

Luckily my backups were just 5 days old, I have all my code in Subversion, and leave all my emails on the mail servers, so I didn’t lose much data. I use rsync for backup, so restoring on a different system was just a matter of copying files over. But I am actually getting a little ahead of myself.

I did some cleanup on my my Dell Inspiron 9300 and scraped enough space that I felt comfortable making small 15GB partition for Ubuntu 8.04 and a couple of gigabytes for swap, just to enable me to read email and manage my websites and maybe do a little bit of emergency coding. The 9300 feels much snappier under Ubuntu than it does with Windows XP, although having a slow disk and an old single core processor doesn’t really compare to the D820. After a couple of hours usage Ubuntu seems to be working fine except for sound, which is stuck at full volume and does not obey the controls. I haven’t spent any time troubleshooting or fine tuning the system, though.

If I can’t cheaply resurrect the system I guess I am in the market for a new laptop. The problem is I have become used to high resolution, fast disk, fast CPU and lots of RAM, meaning there are no cheap options for me. I have been using Dell computers for the past 8 years or so, and have been pretty happy, so taking a look there first… Bummer, the home systems seem to pretty universally have “weird” resolutions like 1440×900. I found 15 inch wide screen display and 1680×1050 resolution to be pretty optimal for me, but that does not seem to be available in the systems marketed for home users. The home systems also seem to come with glossy display which I have learned to hate. Price wise it seems like I might be able to get a system just under $1500 with reasonable configuration otherwise. On the small business side it seems like the Latitude D830 is available in the screen size and resolution I prefer, and surprisingly a decent combination comes out cheaper than in the home market. All in all a bit cheaper than I feared, but it is not fun due to the circumstances.

Upgraded D820 to Ubuntu 8.04

I had installed Ubuntu 8.04 LST (Hardy Heron) 64-bit on Dell Latitude D830 a while ago, but I was dragging my feet with my home laptop for a couple of reasons. My home system was running the 32 bit version of 7.10, and I was pretty happy with how it was working. It was basically rock solid, and I had everything I needed working correctly. But 8.10 is coming out soon, and I am actually interested in that version for my home system, although I haven’t yet decided if I’d want to do a clean install or an upgrade (what I just did with 8.04). I decided to keep things simple and my options open by upgrading to 8.04 now.

Basically the upgrade went smoother than I expected. I had a lot to download (over 1 GB), but nothing seemed to break on my system even though I have done some config changes to the system.

The upgrade process recommended uninstalling some software I had installed manually, like vmware-server, which I had converted to a deb with alien. I still need to reinstall vmware-server.

I’ve noticed a couple of annoying regressions regarding wireless support. The wireless light does not work at all, unless you install linux-backports-modules-hardy package, and even then the light is always on steadily while the wireless is on (regardless of if it is connected or not). But even more annoying is the really slow reconnection speed when coming from suspend; with 7.10 it was near instantaneous.

Ubuntu 8.04 LTS Experiences on D830

I finally wrote down a full matrix of how things are working with Ubuntu 8.04 LTS (Hardy Heron) 64bit on Dell Latitude D830. I had lots of problems originally when I installed from the beta, but the system works pretty smoothly now.

Once I get Java plugin working the computer will cover all the needs I have at work. Until then I am using the 32bit Java plugin in my home D820.

The final minor annoyances with the system are that the wireless is really slow to detect networks and connect to them. On my D820, coming from suspend, the system has reconnected to wireless before I have managed to type in my password. On the D830, I will have to wait a couple of minutes. The other remaining annoyance is that almost every time coming out of suspend or hibernation, the systems beeps to inform me something failed. However, I’ve never actually detected anything wrong (well, a couple of times when keyboard did not seem to be active, but closing the lid to suspend and opening again solved that problem).

Combine Two Files Line By Line on Command Line

Today I was faced with the task of combining two files which each had the same number of lines with matching order, but I needed a third file where each line should have each line from the other two files combined. So given file a.txt:


and file b.txt:


I needed a third file c.txt (the amount of whitespace on a line did not matter to me):

A 1
B 2
C 3

After a few false starts I stumbled onto the unlikely candidate ‘pr‘, whose description states it is used to convert text files for printing. However, it has just the right options to do the task I needed:

pr -tmJ a.txt b.txt > c.txt

Nice find for the series of simple command line utilities if I say so myself.

Update: After I learned about pr I also learned about other commands that can do this. For example paste is much more obvious choice than pr.

Eclipse 3.3 of 64-bit Ubuntu 8.04

I have been running 64-bit Ubuntu 8.04 for about two months now on a Dell Latitude D830. One of the broken pieces was Eclipse. There is a 3.2.x version in the repository, but I needed 3.3.x because Pydev requires 3.3. And besides, there always seem to be a lot of improvements in Eclipse even between minor versions.

Installing 3.3 on a 32-bit Ubuntu is trivial (you just download and unpack Eclipse in, say, $HOME/opt and create a little wrapper bash script in $HOME/bin to start eclipse). But trying this with 64-bit system just resulted in an Eclipse that died even if you looked at it wrong, or for no reason at all. I tried the sun-java6 in the repositories, the 32-bit version java in the repositories and even tried the 64-bit download from Sun. Nothing worked. It wasn’t until I stumbled onto a post where someone mentioned in a comment that they fixed this by installing IBM’s Java. I did not even know IBM has its own Java version.

So I installed IBM’s Java SE 6 64-bit AMD/Opteron/EM64T version, and changed my eclipse script to start with -vm argument that points to IBM’s Java, and now I finally have stable Eclipse.

Configuring PostgreSQL to Serve Hyperic on Ubuntu

I am thinking of basing my new work project on Hyperic which would use PostgreSQL as the database. I don’t have prior experience with either of these, though, so it is quite a steep learning curve. Hyperic offers several ways to get started, and I have already tried their VMWare appliance which worked without a hitch.

Next I wanted to try an actual install. Again, there are several options, some of which include everything you’ll need. I started by installing the postgresql Ubuntu package. I had already installed sun-java 1.6 to be able to run Eclipse, so I didn’t touch that although the Hyperic documentation says Java 1.4 or 1.5 is required. Then I downloaded and installed JBoss without any problems. Then I downloaded the Hyperic tarball without the extras. But the Hyperic installation instructions and the setup script weren’t really helpful in getting me past the errors…

The setup script failed to connect to PostgreSQL. Digging more deeply and doing some web searches it seems many people have problems with PostgreSQL on Debian-based systems. The first problem is authentication, and the Debian defaults which err on the side of safety while leaving new users unable to do anything. Read on how to get past FATAL: Ident authentication failed error. I added two lines for my Hyperic database user to be able to connect from localhost using TCP/IP and also using local sockets. After editing pg_hba.conf I needed to restart postgres, but sudo /etc/init.d/postgresql-8.3 restart failed because it could not read pg_dba.conf! This seems bizarre, and for now I just made the conf file world readable. A better way would be appreciated.

I was still kind of stumped, since I didn’t really know how to create databases or users, and I had no idea what the default password was. I got past that problem by finding the aptly named PostgreSQL on Ubuntu Linux – How To blog post, which informed me of the createdb command, and which SQL commands I need to run to create and edit users.

In retrospect I note that I should have read README.Debian.gz that came with the postgresql-8.3 package, as it would have saved me some headaches. It would have provided quick instructions on getting started if you followed it to the letter and created the database user with same name as your login name (which, frankly, I would probably never do).

The final piece that was hindering my Hyperic installation was that the setup script nor the instructions said anything about needing to create the database and the database user before running the setup script. I first created user “hq” and database “hq”, but it still didn’t work. Then I realized that the setup script error message said the database “HQ” did not exist. Creating all uppercase “HQ” database solved that problem.

Warning Hardy Early Adopters

I have been using 64-bit Ubuntu Hardy Heron pre-release on my new work laptop, a Dell Latitude D830. There have been a few glitches, and there are still a few bugs affecting the laptop, but it is usable. The two most annoying issues left are: CPU stuck on high speed coming from suspend, and wireless slow to reconnect after suspend (sometimes manual reconnect needed).

Today I noticed Firefox updates available, and decided to install. I’ve never had any dataloss issues with Firefox, and in fact the last time any Mozilla product lost my data was probably around Netscape 6 time. But now, after the installation of all the updates, and rebooting like it asked, my whole profile was gone. No bookmarks, no remembered passwords, no history, nothing. And of course I had not made backups, because I was thinking I will redo my setup once Hardy Heron is officially released. But after losing the complete profile I did realize I ended up losing some valuable bookmarks I may not be able to remember, even though I have just used the laptop a little while.

So, if you are using Hardy Heron and see a Firefox update, I recommend you back up your profile before proceeding.