Mon, 19 Jun 2006
Make Emacs take the full screen height
I’ve been on a rather serious Emacs kick lately. One of the things that always frustrated me a little bit about EMACS is that the X11 variant wouldn’t make itself the full size of the monitor at start up without help from the window manager. This is fine and all; after all, I could always make the window manager do the right thing. At least until now.
Now, I use Carbon Emacs most of the time, and MacOS X doesn’t let you muck around with the window manager. However, after a bit of digging, I figured out how to make Emacs re-size the initial window (in emacs-speak, the initial frame):
; Put initial frame at the top left of the screen and make it full
; height, assuming we're not in a terminal.
(if window-system
(set 'initial-frame-alist
; Check out the elisp documentation on Backquote to
; understand the `( ,() ) construct.
`((left . 0) (top . 0)
; This attempts to automatically determine the emacs frame
; height by computing it from the screen resolution. We
; subtract 3 chars to account for the minibuffer and window
; decorations.
(height . ,(- (/ (x-display-pixel-height) (frame-char-height))
3)))))
There you have it. That only took me 4 hours to figure out. The tricky part was understanding the backquote notation (it lets you have a quoted lisp structure that you can “un-quote” parts of in order to have them be evaluated). Now that I have shared this information, of course, I feel better about spending the time on it. Besides, I get happy every time my emacs starts up and then makes itself the right size, as if by magic!
Fri, 27 May 2005
Personal Antispam Config
I wanted to make a couple of notes about my current anti-spam setup so I wouldn’t forget the various pieces.
The core of the system is SpamAssassin. I dump mail into spamd from
procmail via the spamc client. SpamAssassin is configured to whitelist
everyone in my mutt addressbook (automatically via a script currently,
although Rand is working on some kind of master sync tool that will sync
up with the Mac Address Book which I will probably switch to if he
finishes it). So far, so good. SpamAssassin is scanning my incoming email
stream for icky-badness.
procmail is configured to throw away any mail with a spam score of higher
than 7, and dumps anything with a score higher than 5 into the .spam folder.
Better; procmail is now throwing away everything that is certainly
icky-badness, and is filing off to the side the stuff that is only probably
icky-badness.
This is great and all, but I think that Bayesian Filtering will help even more; however, that requires training the filter, which I don’t want to spend a lot of time doing.
I have mutt configured with two hotkeys; S copies the current message into a
folder called .spam and deletes it, and H copies the current message into a
folder called .ham and deletes it. From my .muttrc:
# These copy messages into .ham/.spam depending on what I think they are.
# A cronjob then runs sa-learn on these mailboxes once/hour to add them into
# my Bayes token database.
macro index H "<copy-message>=.ham<enter><enter><delete-message>"
macro pager H "<copy-message>=.ham<enter><enter><delete-message>"
macro index S "<copy-message>=.spam<enter><enter><delete-message>"
macro pager S "<copy-message>=.spam<enter><enter><delete-message>"
I then have the following in my personal crontab:
42 * * * * (sa-learn —ham —mbox /mail/.ham && sa-learn —spam —mbox /mail/.spam) > /dev/null
which trains the Bayes database every hour. I don’t automatically purge the .ham and .spam folders because occasionally I get a false positive spam and I want to be able to re-train the Bayes database in that case.
Fri, 01 Oct 2004
syslog(3) and chroot(2)
Here’s a little bit of Unix esoterica that I just figured out. I’ve been
working on a patch to portmap to let it chroot itself, similar to what
BIND 9 does. It seemed to work perfectly, except that once it chrooted,
it wouldn’t syslog(3) anymore.
Now, the standard solution to this is to force the poor admin to make a logging
socked in $CHROOT/dev/log, and configure their syslogd to listen on that
socket. This is annoying, and adds to the reasons why admins don’t use chroot
as much as they could. I noticed that BIND 9 didn’t have this bug, and so
after poking around a bit, found the solution.
Turns out that openlog(3) doesn’t actually open the /dev/log file by
default. Instead, the file gets opened on first syslog(3). So, in order to
keep syslog(3) working after the chroot(2), the code should look something
like this:
openlog("foobard", LOG_CONS|LOG_PID|LOG_NDELAY, LOG_DAEMON);
...
chroot(chroot_dir);
...
syslog(LOG_ERR, "We're hozed!");
Tue, 03 Aug 2004
Setting hostname
I didn’t want to forget this hack later. To get the DNS provided hostname from a Linux box, you need to do something like this:
host $(ifconfig eth0 | grep inet | sed -e 's/.*addr:(.*) Bcast.*/\1/') |
sed -e 's/.* pointer (.*)/\1/' |
cut -f 1 -d .
This is because dnsdomainname doesn’t actually query DNS, or even get the IP of
the machine from any of the network interfaces. Also, hostname -i doesn’t
really print the IP of the machine; it prints the PTR for the hostname that the
machine thinks it’s on.