Friday, January 30, 2009

Backup a Blogger Blog

I've decided to backup this blog because I'd hate to lose the stuff I've accumulated here.

The Google OS Blog suggests one of the following tips for blog backup:
  1. save the contents of the following link, together with images:

  2. save the contents of the following URLs (posts and comments) as XML files:
(replace blogname with your blog name, and N with the number of posts - or a really large number, say 10000).

While the second option seems to be more useful for machine consumption and has the benefit of saving the comments too, it does not provide a full backup - at least for this blog. I can't get all the posts from that URL. According to the readers' comments to the Google OS post, this seems to be a problem for others too.

Another comment pointed me to a relevant post on Lifehacker, which pointed me to HTTrack - the Website Copier.

The first step should be obvious - install it like this:
aptitude install httrack

A simple minded experiment
convinced me that this method needs some tweaking: HTTrack followed every link on the blog, saving the same files with different names over and over again. I stopped the mirroring process after more than 100 megabytes of data were downloaded...

After some more experimentation, I decided to start the mirroring process at the link provided in the first backup tip from Google OS, together with some filtering (I also disable HTTrack's animated progress messages, so that I can run this from a cron job):
httrack -%v0 --verbose --update "" \
-"" \
-"*widgetType=BlogArchive*" \
-"*" \
-"*_archive.html*" \
-"*" \
-"*.html?showComment=*" \
+"*.gif" \

This way I backup one page with all the posts, and one page per each post and its associated comments. This is good enough, as I don't really care about restoring the blog - I just want the contents saved.

Friday, January 23, 2009

Reinventing a Wheel: Status Bar Clock

I've said it before: freedom has its price. I use an unconventional Window Manager (WM) - awesome, and the price I pay for this choice is that I need, on occasion, to reinvent some wheels. Today's wheel is that innocent looking clock on the status bar (or panel, or taskbar, or whatever you call it).

The awesome (v2.3) status bar resides, by default, at the top of the screen, and it shows the list of tags, tiling mode, list of windows and the awesome logo.

One feature that's lacking from the statusbar, that I really need, is for the statusbar to display both the clock (date and time) and the load average. There are three steps to this:
  1. add the appropriate text fields to the awesome statusbar, by adding the following lines in the statusbar section in ~/.awesomerc (search for the string "mystatusbar" and put the following before the closing curly bracket):

    textbox uptime
    font = "mono 8"
    fg = "#999999"
    text = " 0.00 0.00 0.00"
    align = right
    text_align = right
    width = 0
    button = "1"
    command = "spawn"
    arg = "exec x-terminal-emulator -e htop"
    textbox clock
    font = "mono 8"
    text = " Day Mon 00, 00:00 "
    align = right
    text_align = left
    width = 0

    (this also demonstrates how to perform an action when the user clicks the uptime text box)
  2. write a script that continuously generates the text to be displayed and feeds that into awesome-client:

    while true
    if [ -S ~/.awesome_ctl.0 ]; then
    while true
    echo "0 widget_tell mystatusbar clock text `date +\"%a %b %d, %k:%M\"` "
    echo "0 widget_tell mystatusbar uptime text `uptime | sed 's/.*://; s/,//g'` "
    echo "" # an empty line flushes data inside awesome
    sleep 10
    done | awesome-client
    sleep 1
    (I prefer the 24-hour "military-style" format)
  3. modify ~/.xprofile to launch this script when the desktop is started, by adding the following lines:
        ps -C "" -o pid= | xargs /bin/kill -9 > /dev/null 2>&1
    ~/bin/ &
    (I put these scripts in ~/bin, you're obviously free to do something else).

The clock is now ticking...

(reference: the awesome wiki)

Friday, January 16, 2009

Expanding Tabs in Text Files

Text files that contain tab characters can be really annoying for programmers when switching editors or development environments. A tab character is displayed as several spaces, and the problem is that different editors have a different idea as to the number of spaces to substitute for each tab. This fact can, and does, mess up the indentation of source code.

As an emacs user (read: junkie) I always disable the "Indent Tabs Mode", to prevent indentation from inserting tabs into the code:
  1. type
    M-x customize-apropos <ENTER> indent-tabs-mode <ENTER>
    (on normal PC keyboards, the M-x stands for the key combination <ALT> x)
  2. toggle the value of this customization variable from "on" to "nil"
  3. press "Save for Future Sessions"

If you can't stand the fact that the code you're working with has tabs in it, and you don't mind causing all sorts of merge problems for your fellow developers, you can use the expand utility to expand the tabs, and replace them with spaces:
expand filename.ext > filename.ext.expanded
mv -f filename.ext.expanded filename.ext

(use the -t command line option if the default translation of one tab to eight spaces is not appropriate for the file in question).

Thursday, January 8, 2009

Adding a Titlebar to a Specific Window in Awesome

The default configuration file .~/.awesomerc for awesome 2.3 contains a rule for the Gimp, to force its windows to be floating:

rules {
rule { name = "Gimp" float = true }

This is fine, but the lack of title bars annoys me. And yet, I don't want to force title bars on all windows - it's a waste of screen real estate, especially on a 1024x768 laptop display.

The awesomerc man page is really worth reading. I found out that a titlebar section can be specified inside a rule, e.g.

name = "Gimp"
float = true
position = top
align = auto
text_align = left

This is both trivial and awesome...

Friday, January 2, 2009

UnDBX v0.12

After more than 2900 downloads of UnDBX v0.11, the only feedback I got was one 4-star review at and a thank-you email from a fellow who used UnDBX to rescue messages from bad DBX files.

Frankly, this is more than I expected, and it's really cool.

I wasn't going to release another version, because I'm quite happy with it as is. The reviewer I mentioned would've been happier if UnDBX had a Graphical User Interface, but I was never keen on providing one (I have more to say about it below).

The trigger for this release is the fact that v0.11 can't be compiled on Window$ as is. I wrote a very basic Makefile that allowed me to cross-build v0.11 for Window$ on my Debian/GNU Linux box at home, and I released a pre-compiled binary. I figured that anyone who really wants to compile it natively, would be able to do so by patching the Makefile.

But, as a user, I always get pissed off by packages with home grown build systems, that never seem to quite cut it. So, I've autoconfiscated UnDBX, such that you can now extract the source code archive, and, on many platforms, do this:
cd undbx-0.12
make install
and be done with it. On Window$ it means that you need to first install either Cygwin or MinGW (which is also a requirement for building the previous release).

I was a bit surprised at how easy it was to autoconfiscate UnDBX. Granted, UnDBX is almost trivial when compared to other free software projects. Furthermore, it was originally designed to run on both Window$ and Linux, so there was no need to modify it in the process. And yet, autoconf/automake with all that mass of machine generated convoluted shell scripts and makefiles, are quite intimidating beasts to the uninformed.

The source code package includes a lot more files now, but except for (16 line of code) and (5 lines), these are all machine generated. Actually, even was mostly machine generated and I just had to tweak it a bit. Most of the work went into reading about autoconf/automake.

My only gripe with autoconf/automake is that there doesn't seem to be any kind of support for binary distribution. I know that in the context of GNU it makes perfect sense, but it's a hassle nonetheless. Anyhow, I've added a little script to the source tree that handles this too.

This whole build system stuff is nice, but shouldn't a new release have some new user-visible features?!

Well, I just couldn't quite ignore that GUI issue. So I whipped up a launcher script that you can double-click. You'll be presented twice with a standard folder selection dialog in order to select both the input and output folders, and then undbx.exe will be launched on your behalf inside a console window. Not much, but it's better than nothing, I guess.

So there you have it - UnDBX v0.12

Happy new year!