Low Disk Space Warning Script

Have you ever experienced a full disk on a server or a desktop? Not fun. This script would normally be run as a cron job and would notify you by email if any drive's free disk space has passed below a certain threshold. The code could be better; I wrote this one a long time ago when I was a bit of a n00b and I was in a rush as well. I might make take a look at it again and see if I can make some improvements.

Topic: 

mp3 Sample Clip Creator With Fade-In/Out

This script will create mp3 sample clips. I created it to automatically create sample mp3 clips for a friend of mine's (Will Stroet) website. You can tweak the length of the clip and the fadeout. Unfortunately it can only create samples that start at the beginning, however, it could be easily modified to start anywhere. It depends on the quelcom library, lame, and mpg123.

Topic: 

Why I Chose Python Over C#

I was recently tasked with writing a sipmle UI and the choice of what language/framework to use quickly boiled down to two choices: C# or Python. I eventually chose Python and here's why:

XML

When I started sketching out a design for this project in C#, I ended up envisioning lots of XML configuration files, in place of compiled-in, hard-coded configuration. In Python, however, XML is rarely required. Instead you can use python modules and data structure to specify your configuration.

You can notice this difference clearly if you look at C# and Java web frameworks and compare them to Python web frameworks. Django (a Python web framework) has a few configuration files. One is settings.py which is basically just a list of key value pairs. Some of the values, however, are Python tuples (immutable lists). It looks like a hybrid between a .ini file and an xml file. The beauty of this is that you can actually run a program like pychecker or pylint on your program and if you are trying to access a key in your settings file that doesn't exist, it will complain! Try doing that in a compiled language. So Django and other programs just take advantage of the fact that since code isn't compiled, you can put all your config in code, and you can easily tweak it later without needed to re-compile anything.

In web frameworks and other projects for C#/.NET and Java, XML is a huge part of configuration. Spring, Hibernate, Ant, log4j/log4net all rely on either XML configuration or annotations (which just couple settings to your code and bake it into the build). So if you write your own applications in Java/C# you will find yourself also using XML for configuration and writing code to parse and possibly write XML as well. The only time I ever enjoyed using XML was when I was using the ElementTree library for Python, which is now a standard library in Python.

Less code

Python code is generally a lot shorter. This means it's quicker to write, quicker to read, quicker to debug, quicker to modify later. No braces, no semi-colons, terse data structures, list comprehensions.

No compiling

Being able to modify code in the field is huge. Many times we've modified Python code in the field using a text editor after getting some obscure error and then re-ran the script. No re-compilation necessary.

Libraries

I tried porting a simple python script to C# just to see how easy/hard it would be. The first step was porting the command-line options parsing. I used GNU getopt style parsing, which is included in python's getopt library. No such thing is included in .NET. There is a third-party library, CSharpOptParse. Having to download this was a bit of a turn off. Then I looked for an example of CSharpOptParse usage and I found one. Ugh. The python getopt example is much nicer. If you don't like getopt there is also optparse (apparently, "optparse is a more convenient, flexible, and powerful library for parsing command-line options than getopt". I'll have to give it a try!). It looks even simpler than getopt!

The next thing I to find was to look at how to call an external executable in C#/.NET and capture stdout and/or stderr. Talk about annoying. Python's new-ish subprocess library is awesome.

Finally my Python script does some path splitting using os.path.split and os.path.splitext. I did find .NET's Path class to be pretty convenient, although no better than python's os.path.

Documentation

The Python documentation is far better than anything I have seen in the .NET/C# world. Maybe it's because smart people use Python.

Conclusion

I've been a long-time Python user but I do like languages like C# and Java as well, but when I put Python and C# side-by-side for this simple little project, nothing competes with it.

Tags: 

How To Stop Chrome Thrashing to Disk

Google Chrome will thrash to disk a lot to disk, at least in version 0.2.149.27, build 1583 (the first publically available beta) in Windows XP. It is so bad that my entire computer locks up a bit and becomes unresponsive. Disabling phishing and malware protection seems to stop the thrashing:

  1. Click on the monkey-wrench icon to the right of the address bar.
  2. Choose "Options" from the menu.
  3. Click the "Under the Hood" tab
  4. Disable the "Enable phishing and malware protection" check-box

[img_assist|nid=321|title=Google Chrome Disable Malware and Phishing Protection|desc=|link=none|align=none|width=418|height=315]

According to procmon it is writing to this filename: <systemdriveletter>:\Documents and Settings\<username>\Local Settings\Application Data\Google\Chrome\User Data\Safe Browsing. There is only one other site where people are talking about this thrashing problem, at Ars Technica.

Tags: 

init.d Script for Trac on Ubuntu Linux

I modified an nginx init.d script and created an init.d script for trac.d. I run tracd and then forward traffic from trac.davidgrant.ca to trac's port (using nginx) rather than using cgi or fast-cgi. Please let me know if you have any problems with this scripts and I will fix it.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          tracd
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the tracd web server
# Description:       starts tracd using start-stop-daemon
### END INIT INFO
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/tracd
NAME=tracd
DESC=tracd
#DAEMON_OPTS="-s -r -d -p 8080 --basic-auth=*,/etc/tracd/tracusers,trac /trac"
DAEMON_OPTS="-s -d -p 8000 /home/david/trac --pidfile /var/run/$NAME.pid"
 
test -x $DAEMON || exit 0
 
# Include tracd defaults if available
if [ -f /etc/default/tracd ] ; then
        . /etc/default/tracd
fi
 
set -e
 
case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /var/run/$NAME.pid
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac
 
exit 0

After you create the script at /etc/init.d/tracd, don't forget to do the following:

sudo chmod +x /etc/init.d/tracd
sudo /usr/sbin/update-rc.d -f tracd defaults

to make the script executable and to make it run on startup.

Tags: 

Not Happy With TortoiseSVN

I don't use svn in Windows much but when I do I usually use TortoiseSVN. I haven't been very happy with it lately. With TortoiseSVN installed, Windows Explorer take 5-10 seconds to start and during that time I can't use the task bar because it's a part of explorer.exe. While I like the Explorer integration idea, I'm not sure if I like how everything in Tortoise involves at least a right-click on a folder. Also, sometimes it's nice to see all your working copies in one window, although the working copies may be spread out all over your hard drive.

So I have been giving RapidSVN a try and so far I like it. Not much to say about really, it looks like a pretty standard VCS client. Only downside is that it doesn't support subversion 1.5 yet and I was planning on upgrading my svn server pretty soon.

Tags: 

Cuil Sucks Big Time

I got all excited to try this new Cuil search engine today but was extremely disapointed. The only thing Cuil does well is sucking. The first thing I did was to search for my name to see where on the front page it would show up (on Google I am the first hit). I was a bit surprised when I did not see my home page on the first page, second page, or third page. Maybe my site is not indexed at all. So I decided to search for one of my most popular posts, my Latex Resume Template post. Not only did it not come up but this great resource on LaTeX resume templates was also missing.

Let's look a little deeper and see how shitty Cuil really is. Try searching for "latex resume template" (obviously, remove quotes). The same search for latex resume template on google is orders of magnitude better. It doesn't take very long at all to notice the differences...

Let's look at the hits that Cuil gave us:

Now let's compare with Google's first 10 hits:

There you have it. The funny thing is that Cuil returned slightly more hits than Google (67,900 results for Cuil vs. 63,000 for Google) but it doesn't make a difference when the top 10 are garbage in one and exactly-what-you-are-looking-for in the other. Google must be laughing their asses off right now. Apparently Dvorak thinks Cuil sucks too and he's pretty blunt about it.

Tags: 

Thumbs up to Tomato Firmware, Thumbs Down to X-Wrt

I have an old Linksys WRT-54G v3. I have ran various different firmwares over the years, but performance was never a big deal. I was mainly looking for something that allowed to me to access all of the devices features and a nicer frontend than the one that Linksys provides. At one point I was using different firmwares for QOS when we were sharing our connection with some other people in our building. Anyways, I had been using X-Wrt (white russian) for quite some time. It is basically a nice user-friendly version of OpenWrt.

Recently we purchased a Squeezebox Duet and even more recently we purchased a second Squeezebox Receiver. We finally have wirelessly-streamed music in pretty much every room of the house. We had been noticing gaps in the audio and I decided it was finally time to fix it. I discovered a diagnostics page (called "Server & Network Health", available via SqueezeCenter's Help page) and noticed that streaming rates I was getting were much lower than the 3000 kbps that I was expecting. In fact I was actually getting much lower than 1000 kps and had to change the scale of the measurement just to get a proper reading.

I decided to upgrade to Tomato firmware, which I had heard a lot of good things about. Immediately, I was getting about 3000+ kbps and the audio problems were gone. As an added bonus, we are now able to watch MythTV from a wirelessly-connected laptop, which were not able to do before (previously I had assumed that wireless streaming video was just too much for today's wireless networks to handle, or too much for MythTV to handle). I think I am going to make a donation to Tomato because it has made such a big difference for us. We can now enjoy listening to our mp3 library anywhere in the house (without gaps) and can watch recorded TV shows on our laptop.

Make Shared Folders Work in TinyXP as a Guest in VirtualBox

I gave TinyXP Rev 09 a try recently as a guest in VirtualBox. (I do have a legal license for Windows XP, so while that definitely doesn't make downloading TinyXP legal, I feel that morally speaking it's ok).

I wasn't able to browse for shared folders at \\vboxsvr as I expected. It is, however, possible to map these folders to drives using the "net use" command:

net use z: \\vboxsvr\david

That worked perfectly. Have fun!

VirtualBox USB with Windows XP guest in Ubuntu Hardy or Intrepid

[img_assist|nid=366|title=|desc=|link=none|align=right|width=145|height=150]
First of all, USB will not work in VirtualBox if you are using the Open Source Edition (OSE) of VirtualBox. Get the full closed-source edition of VirtualBox from their website. There are many differences between the open-source edition and the closed-source version and one of them is USB.

I finally got USB working with Windows XP running as a guest inside VirtualBox running on a Ubuntu Hardy host. First find out what the group id of the vboxusers group is:

$ grep vbox /etc/group
vboxusers:x:<gid>:david

Then, enable the deprecated /proc/bus/usb inteface:

$ sudo gedit /etc/init.d/mountkernfs.sh

Add the following line after /proc is mounted, at the end of the do_start() function.

#for hardy:
domount usbfs usbdevfs /proc/bus/usb -onoexec,nosuid,nodev,devgid=<gid>,devmode=664
#for intrepid:
domount usbfs "" /proc/bus/usb usbdevfs -onoexec,nosuid,nodev,devgid=<gid>,devmode=664

replacing <gid> with the <gid> you found in the first step. Make sure to reboot. This didn't work for me until I rebooted. There you have it. You shouldn't have to edit /etc/init.d/mountdevsubfs.sh or /etc/fstab as some other internet sources have suggested.

rsync --delete is dangerous!

I hosed my entire home directory on this server last night with an incorrect rsync command. I tried syncing my svn repository to the server like this:

rsync -az -e ssh --delete /var/svn/repos/ servername:/home/username/

The problem is that I had an extra slash on the end of "/var/svn/repos/". Without the extra slash, it would create a directory called repos inside servername:/home/username and sync it with /var/svn/repos. With the slash, it syncs the contents of "/var/svn/repos" with the contents of servername:/home/username, thus causing all files in servername:/home/username to be deleted because of the --deleted command.

What I could have done instead is create a directory on the remote server called repos and then rsync like this (actually you don't need to create repos first):

rsync -az -e ssh --delete /var/svn/repos/ servername:/home/username/repos

Or I could have done this:

rsync -az -e ssh --delete /var/svn/repos servername:/home/username

The last command will create a directory called repos in servername:/home/username and it will sync it but not delete anything in servername:/home/username. Add a trailing slah to /var/svn/repos and it will!

Luckily I had a nightly backup of my entire home directory on my local server's external backup drive. I was worried because although I make these nightly backups I haven't actually inspected them in a while. Fortunately everything was intact.

Tags: 

Stupid Tourists

About 99% of tourists piss me off. A while back we went to a non-all-inclusive and although those places usually attract somewhat different crowd, there are clearly not enough rooms in the all-inclusives to hold all the annoying ones. While reading the reviews of the place we were going to, one of the reviews was ok until the end until I read this:

Snorkel past Xcaret ... AWESOME REEF ... find someone on the beach in Playa to take you, there are people at booths along the way that will take you. Count your change, people try to rip you off. Bargain for everything including food, cab fare, snorkeling.

Obviously it was the "count your change, people try to rip you off" comment that pissed me off. I have never experienced someone trying to rip me off in Mexico, Cuba, or Peru. The last time someone short-changed me was at the hot dog stand at Granville and Broadway in Vancouver. I find these types of comments racist especially when stated in the form "people try to rip you off" rather than just stating "I was ripped off by $X at location Y." I've also had someone tell me, before travelling to Mexico, that "all Mexicans lie." Where do people come up with these ridiculous stereotypes?

The final part of the review, "bargain for everything including food, cab fare, snorkeling" is also one of my pet peeves. For the most part, I pay what I am told the price is and I always try to find out the price beforehand when paying for a service. If I am buying goods, the prices always seem reasonable in the first place and seem to reflect the value of the item. If I am not willing to pay the stated price for an item, I either a) don't buy it or b) will offer what I am willing to pay for it (but which still reflects what I think the item is actually worth, at least to me). But I never bargain just for the sake of bargaining, like so many tourists like to do.

Tags: 

Sorry Kubuntu, I've Switched to Ubuntu

I've used Kubuntu for a long time. In fact I had never used plain Ubuntu except for once a long time ago on an old laptop but then I promptly removed it because it caused the laptop to overheat badly (it was painful on the thighs) and so I went Gentoo, my bread-and-butter distribution. I never liked Gnome for some reason. I never had good experiences with Gnome in Debian or Gentoo. KDE always seemed to work a lot better out of the box. It might be because KDE is an all-in-one solution whereas Gnome is a bit more modular and made up of metacity, gnome-panel, nautilus and a bunch of applets. I remember trying out Gnome in gentoo and metacity wouldn't start, or it would crash spontaneously. Not Gnome's fault, but it's a problem that just would never have happened in KDE.

Ubuntu has fixed all that by focusing on Gnome and ignoring all other desktop systems and window managers and making it work great out-of-the-box. Gnome is nothing like I remember it being. Kubuntu allowed me to continue using KDE, which I was used to but unfortunately I think Kubuntu has fallen behind Ubuntu. The biggest factor here is probably Ubuntu's far larger user base. More users reporting bugs and more developers eating their own dogfood. 90% of all Ubuntu tips & tricks and how-tos on the web are for Ubuntu, not Kubuntu. A few things turned me off Kubuntu in the last while:

  • Totally broken X config in KDE Control Center (mangles xorg.conf file badly, had to use nvidia-config or "dpkg-reconfigure xorg-server".
  • Documentation on the web is almost always Ubuntu-specific and relied on going to menu items that just aren't present in Kubuntu (at least not out of the box).
  • Not easy to set up Compiz on Kubuntu Gutsy (at least if you upgrade from Edgy). It's easy to set up in Ubuntu Gutsy or Hardy.
  • Bad experience with KDE 4. I tried it a few times after it was released and it felt like a piece of alpha software. Was hoping for a better experience but it was buggy and I don't think Kubuntu has the resources behind it to perfect it like Ubuntu does with Gnome.
  • Auto-mounting had been good in Kubuntu but once in a while I have problems (not able to unmount, devices spontaneously unmounting themselves, etc.... I have never had a problem in Ubuntu so far and I enjoy the fact that I don't get that annoying pop-up after I plug something in in Kubuntu or Windows.

Cleaning out my RSS Reader

I love Google Reader and I love reading about the latest in technology, politics, you-name-it, but I have a ridiculous number of feeds and they are just too much of a time sink. I need some way to clean them out so I can have more time to do other more important things.

One idea is to borrow from a technique that I have used to get rid of new clothes: go into your closet hang all the hooks backwards. Whenever you wear a garmet hang it back up in the closet in the usual way. n months later, take the garmets that are still hung backwards and donate them to the local thrift store. I can't remember where I got this idea from, but I think it might have been from lifehacker.com (whose feed I am subscribed to).

For feeds, I was thinking maybe I could create a new label called "keeper". Whenever I read a item from a feed that feel I could not have lived without reading it, that feed gets labelled with the "keeper" label. n months later, I can toss out all the feeds that do not have the "keeper" label.

Alternatives to using feeds:

  • Go to the website for the feed and look at the most popular articles in the past week or month. This isn't always possible with all feeds.
  • When you need to know how to do something, just google it, rather than subscribing to a feed of how-tos (like lifehacker.com for instance). Pull rather than push.
  • Go to a site like reddit.com or digg.com when you have some free time, otherwise, don't worry about all the stuff you might have missed.
Tags: 

Pages

Subscribe to David Grant RSS