Insert current time in an emacs buffer

A lot of text editors (way back to the days of Borland’s SideKick—wow, what a blast!) provided an easy way to insert the current date and time in the file you are editing. This is particularly useful for a notes/journal type of thing.

Emacs (the One True Text Editor) does not provide an “out of the box” way to do this, but a very simple piece of elisp can do it.

I put this (adapted from a suggestion found on the help-gnu-emacs list) in my .emacs:

(defun mr-insert-current-time ()
  (interactive)
  (insert (format-time-string "%F %T")))
(global-set-key (kbd "C-c d") 'mr-insert-current-time)

(defun mr-insert-current-time-block ()
  (interactive)
  (insert "n-------------------n")
  (insert (format-time-string "%F %T"))
  (insert "n-------------------n")
  )
(global-set-key (kbd "C-c C-d") 'mr-insert-current-time-block)

which allows me to press C-c d at any time to get the current date and time in my buffer (formatted the way I like). The second function puts it in a little block, good for seperating entries in a notes log.

PCMCIA and your custom RedHat 9 kernel

I recently wanted to compile a custom kernel for my RedHat 9 laptop. (For some reason, RedHat decided to omit NTFS support from their stock kernel, even though it includes just about every other module under the sun.) Much to my consternation, on reboot my PCMCIA cards no longer worked. :( The only change I made to the default kernel config was to add NTFS support, so I was rather perplexed.

Booting back to the stock kernel (ya gotta love grub!) revived my PCMCIA CardBus, but left me NTFS-less. (Please keep the “that’s a feature, not a bug” comments to yourself…) The release of a security patch for the 2.4.20 kernel just increased my desire to get a custom kernel going.

Further investigation determined that the problem was a missing socket driver (yenta_socket) module. When the ds module tried to load, it failed because it couldn’t find the socket driver. Manually loading yenta_socket then ds got everything working properly. But it didn’t work at boot time, only if I manually loaded the yenta module.

I still can’t figure out why this is the case, since my modules.conf and /etc/sysconfig/pcmcia files are the same with either kernel. But for what it’s worth, adding this line:

    pre-install ds modprobe yenta_socket

to modules.conf solved the problem.

If anyone can shed any light on this, I’d be glad to hear it.

Linux on a Compaq EVO N600c

There are several good resources for getting Linux running on a Compaq EVO laptop. A tip I haven’t found elsewhere: unless you disable glx (in /etc/X11/XF86Config), putting the machine in standby (with X running) will cause the screen to make very weird patterns.

An unsolved problem: standby mode still consumes significant battery power. Enough, in fact, to totally flatten the batteries after about 15 hours from a full charge. If anybody has seen this, and found a solution, I’d love to know.

My home network

At home, my main workstation is a 400Mhz AMD K6 running Debian (currently woody, but I can also boot into sid if I’m feeling daring). It also has FreeBSD, OpenBSD and an old unloved version of Debian GNU/Hurd installed.

We’ve also got a server running Debian (woody/stable), an Gateway Pentium Pro 200 MHz, which handles our email, databases and web developement, and other useful services like DNS and DHCP.

There’s also a couple of laptops (untethered courtesy of NetGear 802.11b cordless ethernet cards).

Connecting it all the outside world is a cable modem and a dedictated firewall/NAT gateway (OpenBSD on a Compaq Pentium 100 MHz). My heartless wife will not let me get more computers. :(

Printing from windows with samba and cups

The default debian (woody) config of cups didn’t quite allow this to work… make the following changes (to enable raw printing via the windows driver):

Uncomment line 83 in /etc/cups/mime.convs:

#application/octet-stream        application/vnd.cups-raw        0       -

and also uncomment line 152 in /etc/cups/mime.types:

#application/octet-stream

Also, we need to add the following (rarely mentioned) line to smb.conf (in the [Printers] section):

use client driver = yes

This will cause windows to successfully get the printers’ status.

How not to comment your code

Below is a piece of code I came across recently while reviewing somebody else’s work. It is a terrific example of how not to write comments.

//Create a vector
Vector seq = new Vector();

//Count the number of items in the sequence
int count = ms.itemCount();

//Loop through the sequence getting all the values
for( int i = 0; i < count; i++ ) {
    //Convert the item to an Instance
    MInstance mi = (MInstance)ms.getAt( i );

    //Convert the instance to a HashMap
    Map data = mInstanceToMap( mi );

    //Add this to the Vector
    seq.addElement( data );
}
//Return the vector
return seq;

Ignoring for the minute the infuriating habit of putting spaces around parameters (doesn’t anybody read the Java style guide any more?), these comments are completely useless.

There are plenty of places to learn how to write comments. A couple of references come to mind: Steve McConnell’s “Code Complete”, “The Pragmatic Programmer”, “Programming Pearls”.

In a nutshell… don’t write comments that say what the code is doing (you can safely assume that anyone likely to need to read your comments is at least borderline literate in the progamming language in question). Maybe explain why your code is doing it, and defintely document any assumptions. Please don’t tell me new Vector() creates a new Vector…