FreeBSD on Asus EeePC 1000HE

May 13th, 2009

For my birthday this year I was given a brand new Asus EeePC 1000HE, one of those fancy new netbooks.  It came pre-loaded with Windows XP which didn’t last too long.  I was aware going into it that OpenBSD wouldn’t recognize the wireless card so I thought I’d give FreeBSD a shot.

The challenge to getting FreeBSD on this system is that it doesn’t have an optical drive and FreeBSD doesn’t have a really easy way to load the system from a USB disk.  You’ll need to bootstrap your own following instructions you find at the FreeBSD EeePC Wiki.

I installed FreeBSD 7.2 from the bootonly image.  The ethernet device was recognized but not marked ‘Up’ for some reason so I had to use the emergency shell to bring it up but after that I was able to perform a network install and then upgrade to CURRENT.

It looks as though the Atheros 9280 is supported pretty well, though you need to follow the man pages for creating the wlan0 device to be able to use it, I’m also using WPA2 on my home wireless network.  powerd also works, here’s my rc.conf that, along with wpa_supplicant will bring up the wireless device and enable powerd.

wlans_ath0="wlan0"
ifconfig_wlan0="WPA DHCP"
powerd_enable="YES"

and the relevant entries in /boot/loader.conf:

snd_hda_load="YES"
acpi_asus_load="YES"
acpi_video_load="YES"
hw.acpi.reset_video="1"
hw.acpi.sleep_button_state="S3"
hw.psm.synaptics_support="1"

There are a few things that I have not tested… like the camera, and I can confirm that as of right now suspend does not work.   Power usage is fantastic, however.

It did take a little configuring to get Xorg to work but it does nicely, with direct rendering here is my xorg:

xorg.freebsd.eeepc.conf

And my dmesg:

dmesg.eeepc.freebsd

mat FreeBSD ,

Splicing Internet Radio Streams with Python

April 20th, 2009

During the day I like to listen to various audio streams so I find myself switching back and forth between music and news.  Wouldn’t it be nice if you could play streams for a given amount of time?  I couldn’t find anything that did it automatically so I wrote this quick Python program to do it (requires pymad):

Musplice Project Page

You can download the latest version here:

http://git.matburt.net/cgi-bin/gitweb.cgi?p=musplice.git;a=snapshot;h=HEAD;sf=tgz

It’s pretty simple and straightforward setup script that installs the module, a musplice bin launcher, and a config file in /etc.  The example script plays Groove Salad for an hour and then switches over to WUNC, a public radio station in Raleigh, NC for 15 minutes.  You can add as many sections as you want to play different streams at different times.  If there is a stream that is a fixed length and you want to play all of it just set it’s time to: all

If /dev/dsp is not your sound device then you should set it in the ‘device’ section.  My sound device in OpenBSD is /dev/sound.  There is some initial ALSA support that doesn’t play to well if you set the device to: alsa

There is a simple cli interface, that takes a few commands… see the README for more details.

It’s a pretty simple 200 line program that I’ll probably enhance as I see fit since I tend to use it pretty frequently.

mat Code, Projects, python , ,

Bad Server

March 18th, 2009

So I realized today that my database has been down for two days without me realizing it. It appears that it just shut itself down at some point and never came back.

I’ve decided to give Monit a try for monitoring and notification of bad things like this happening. Do you use something similar with good results? If so let me know.

mat Site

An interesting problem in Python

February 10th, 2009

I like to tell stories about poorly written code.  As a programmer you come across it all the time, and good programmers work really hard to make sure everything they write is both clean and as free from bugs as you can make it.  There is a reason, though, that we spend so much time fixing bugs and that’s because it can be extremely difficult to write bug free code.  This problem that I encountered recently at work is one of those bugs that just sneaks up on you and punches you in the face… see if you can find the bug:

def createProc(acmd):
    dn = open("/dev/null")
    return subprocess.call(acmd, stdout=dn, stderr=dn)

I honestly did not see it at first and debugging it was a real pain, but if you study it and maybe take a quick refresh of the Python documentation you’ll see it.   In this case the program being spawned was crashing infrequently, and it would only fail if the program it was calling had an error.  Here’s how this function should have been written:

def createProc(acmd):
    dn = open("/dev/null", "w")
    return subprocess.call(acmd, stdout=dn, stderr=dn)

By now it should be obvious.  Python’s default open() mode is “r”ead.  This program was normally silent, but whenever it had a problem it would write an error message stderr and then quit.   The first time it tried to write to stderr it would throw an exception within the subprocess context, without being raised into the calling process.  If you tried to just open a file in Python without setting “w”rite mode and write to it the interpreter would throw an IOError telling you that the file handle is invalid but because of the call to fork() you would never see that exception in the calling function… just a return code of 1.

I actually found this problem while trying to track down another issue:

def createProc_bad(acmd):
    return subprocess.call(acmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)

This also seems rather benign.  Well, as benign as something can be when you are forking another process but in this case the process would hang!   This time the problem was a little easier to track down.   I’ve done a lot of work on pipes and I know enough about Python’s implementation to know that it was probably blocking on the pipe because we were never reading from it.  Once that pipe buffer fills up the process will block waiting to write to it and the application wouldn’t be able to make progress.   Here’s a good solution if you may need the data that would be written to those pipes and don’t want to worry about reading from it as the process progresses:

def createProc_better(acmd):
    proc = subprocess.Popen(acmd, stdout=PIPE, stderr=PIPE)
    (sout, serr) = proc.communicate()
    rc = proc.wait()
    return (rc, (sout, serr))

One has to be careful with this implementation, though.   Python will store this information in heap and it will quickly blow up the interpreter’s memory usage.   If you didn’t care about the output you could just redirect it to /dev/null as shown above.

mat Code, python ,

XMonad: A tiling window manager written in Haskell

February 8th, 2009

For a very long time I have been floating back and forth between a handfull of windows managers trying to find something that I like and doesn’t get in my way.  The one I have always gravitated to is Window Maker, simply because it is minimal and has a ridiculously small footprint.  I’ve also used Gnome and KDE from time to time but they just try to do too much and I need something that will support my terminal driven usage habbits.

Since I’ve been doing a lot of functional programming lately, a lot of which being in Haskell, I thought it was time to re-evaluate my window manager situation.  This is where xmonad comes in.

To be honest, I’ve never given much though to tiling window managers and I’m not sure why.  I’ve been using xmonad for the last 6 months and it is simply beautiful.  It can be driven entirely from the keyboard with some dead simple keybindings that are customizable.  I found myself changing the meta key used in most keybindings to the silly windows key on the keyboard… for a long time this key was worthless to me but xmonad likes to use Alt by default for most commands which conflicts with Emacs in some situations.  Configuration can be a little difficult for anyone who is not familiar with Haskell but there are plenty of examples and the code itself doesn’t require any advanced programming skill.

Another thing that impresses me is how well it handles multiple displays and multiple desktops.  Each screen’s desktop is capable of displaying any one of my 10 virtual desktops and they can be selected independently.  This may seem very rudimentary but the way that xmonad handles this is very elegant.  Per-desktop layouts are also excellent, and it’s a quick keystroke to switch between layouts.

It almost goes without saying that the aim of the project is to provide a crash free experience and I can back this up.  Since I have been using it it has crashed exactly zero times.  It also has a massive extension library that includes dozens of layouts, support for docks, panels, prompts and more.   It even has extensions to use it with Gnome and KDE.

The only problem I could imagine someone having is in writing a configuration file.  Luckily there is an archive of user submitted configuration files demonstrating pretty much everything that it can possibly do.  As is the case for the Haskell community in general there is also a wonderful user base to support it and any one who wants to use it.

mat Haskell ,

Switching Hosts (Again)

January 25th, 2009

I’ve been using VPSLink for almost a year now, and from a hosting standpoint they have been fantastic. Having my own Linux VPS has been nice but what I really wanted was one that would let me run FreeBSD and after a year of searching I finally found one: RootBSD

I have fully switched everything over and migration and set up was painless so we shall see how well everything runs.

Another nicety, for me anyway, is that they are actually local to me, one city over in Cary, NC

mat Site ,

ProcAn 0.8

March 8th, 2008

I haven’t written about procan in a while but I have been quietly working on it in the background.   This release brings UI improvements, namely an ncurses interface as well as some other small performance improvements and optimizations.  If you are not aware of it, ProcAn is an adaptive process analysis tool meant to provide a cleaner and more interesting view of current system activities and users.   You can find more information about it along with the download link here: ProcAn project page

A lot of the algorithm improvements are still a work in progress and planned for version 0.9.

mat Projects , , ,

The Evolution of the Imperative Programmer

February 11th, 2008

Today I thought I would write a little about Haskell.  This year I decided to learn this language and revisit the world of functional programming.   After spending a month with it there are things that I understand much better, but I’d be lying if I said it was easy.

In order to learn Haskell, and functional programming in general, you really have to change the way you think about programming.   One thing that has been especially hard on me has been the type system where, in a non-strict language, types really can take on a whole new meaning.   Non-strict languages tend to have a little uncertainty about when expressions are evaluated so you end up defining functions which end up being totally different types than you expected take the problem of the IO() monad:

getAFile theFile = do
li <- readFile theFile
return (words li)

this function opens a file, breaks the file into a list of words and returns the list.   You might ask yourself why I didn’t do this:

getAFile theFile = words (readFile theFile)

afterall, it seems like the evaluation of readFile would happen immediately and it would return a String no?  Not quite… see, it actually has the type IO String.  As mentioned above, IO is a monad and monads extend the normal type system as well as storing function results and side-effects.   In light of this, however, the words function does not know how to evaluate.  but by doing this:

li <- readFile theFile

li will have the type that we really expact because it will contain the result of the evaluation. You should also know that return doesn’t do what you expect either… it has the net effect of converting the list of words into type: IO [String] which I do here because the next function that I will call will take this particular type.  return is a common and very useful thing to have when performing operations involving monads.

So as you can see… for an imperative programmer this can get pretty hairy.   I get the feeling that this will come a little easier as I understand more about the language.    I don’t want to give the impression that I don’t like Haskell, quite the contrary I think it is incredibly useful.  I set about thinking to use it as a prototyping tool for algorithms but  now I think it has a strong place in my repetoir.   Here’s a good example:

Computing the sum of a Geometric Series at a given itteration:  

Here’s something in C, just to have to compare against:

double gseries(double c, double r, int max)
{
int n;
double res = 0.0;
for (n = 0; n < max; n++)
{ res += (c * pow(r,n)); }
return res;
}

and now in Haskell:

gseries c r n = sum ( [(c*r^x) | x <- [0..n] ] )

Now lets look at something you can’t do in C:

gseries_inf c r = [(c*r^x) | x <- [0..] ]

This is basically an infinite list.   This is allowed because of Lazy Evaluation Haskell will only evaluate what it needs in order to give you the information:

*Main> (gseries_inf 1 1.9) !! 100
7.505162419825193e27
*Main> (gseries_inf 1 1.9) !! 1000
5.6702336219128545e278
*Main> (gseries_inf 5 1.9) !! 1000
2.8351168109564274e279

Haskell is well suited for a wide variety of tasks and has earned its own place in my toolbox.

mat Code, Haskell ,

Switching Hosts

February 2nd, 2008

I signed up for Dreamhost a little over a year ago.  When doing my initial research on value hosts this was, hands down, the best one.   I realized this last week while trying to set up a web interface to my Git repositories that I had outgrown them so I began looking for a new one.  One thing that I knew I wanted was to move from Shared Hosting to a VPS Host and the one I settled on was VPSLink.

I have been using them for a week now and my site responds noticably faster than with Dreamhost, which was sluggish at best… even during off-peak times.  The flexibility of managing my own server (albeit, a virtual one) is nice and I decided to offload mailhandling responsibilities to Google for my domain… which was also very easy.

The one thing you have to be carefull about with VPS Hosts is making sure you get enough memory for you needs.   I bought a plan with 256M of real memory and 512M of Swap.  After some tweaking of MySQL, Apache and a few other services my server has been running for a week without touching swap or coming close to exhausting the physical memory.

With an Ubuntu 7.10 Xen client I also ran into problems after upgrading and the system refusing to install the new libc6-xen.   If you experience this problem (some applications exhausting CPU resources and running at 100% inside of Xen client) you’ll need to download the libc6-xen package install it via dpkg…. hopefully this will be fixed soon, but it caused me several hours of headache.

mat Site

Warfish.net

January 24th, 2008

Warfish.net is like a web-based version of Risk.  Completely turn based with email notifiers.   This is a shameless plug for this site… I don’t know the guy who runs it but it’s a hell of a lot of fun to play with friends.   If you’d like to try a game check out my recruitment page so I can invite you to a game:  http://warfish.net/networks/matburt

mat Games, Life