Archive for the ‘Programming’ Category

Rackspace Cloud API

In an article here, Rackspace is announcing the availability of their beta web services api that can be used to jack into their cloud. Much like EC2, this should lead the way for projects like scaler, that dynamically grow a configuration as thresholds are reached.

Check out http://www.rackspacecloud.com/ for more info. I am going to sign up, I will let you know how it goes.

Stop the plesk adminstrator from recieving dr.web license failures

… And other things that might annoy him/her

There was a request that went around for months from a plesk administrator griping about the various messages that appear in his mailbox, such as the dr.web license notification. By default, messages to the root and postmaster accounts are sent to the plesk administrator. This is accomplished via qmail aliases.

# cd /var/qmail/alias/
# ls -al
total 28
drwxr-sr-x 2 alias qmail 4096 Mar 9 01:59 .
drwxr-xr-x 11 root qmail 4096 Sep 29 21:14 ..
-rw-r–r– 1 root qmail 26 Dec 10 2007 .qmail-mailer-daemon
-rw-r–r– 1 root qmail 16 Mar 9 01:57 .qmail-postmaster
-rw-r–r– 1 root qmail 16 Mar 9 01:57 .qmail-root

Typically these look something link this:
# cat .qmail-postmaster
&plesk_admin_address@foo.bar.com

To keep the customer happy, I made a slight amendment to the alias:

# cat .qmail-postmaster
|cat >/dev/null
# cat .qmail-root
|cat >/dev/null

Removing the aliases will cause all kinds of noise in the logs and actually break the server’s already fragile rfc compliance (rfc2821:4.5.1) . This allows the messages to be ‘handled’ silently. Since most plesk ‘administrators’ don’t care to know how many failed ssh attempts there were in a month, or how much disk space they are using, it is usually a working solution when you can’t get dr.web to stfu.

Learning python

I have started to rewrite some of my existing code in python in an earnest effort to master the language (I have been putting it off for a long while now). Anyway, I was working on a parser for a # commented file, this is how I stripped the comments from each line in C:


while(fgets(line, sizeof(line)-1, fp)) {
  char *hash; //ptr to hash mark denoting a comment
  if(line[0] == '#' || line[0] == '\n')
    continue;
  if((hash = strchr(line,'#')) != NULL)
  line[hash - line] = '\0'; //line + hash = memory location of hash
  printf("%s", line);
}

Now that I am beginning to get a handle on python, I am really starting to appreciate its elegance. This line of code accomplishes the same task:

line.strip()[:line.find("#")].strip()

I have not compared the performance of the above line to my c code , but I would assume using all the nested objects would incur a performance hit. I may test this later, but I am pretty sure my c code would be much faster.

Clearing the screen in C

A simple program that demonstrates one way to clear the screen using ANSI/VT100 terminal control escape sequences

clear.c:

#include <stdio.h>
int
main(){
printf("\x1b[2J\x1b[H");
return 0;
}

(ESC)[2J = Erase screen and set cursor to home

(ESC)[H = return cursor to home (seems redundant but is necessary for some VT’s)

Return top