Author: sjan

Job Hunting

Code samples!?

Due to a RIF I find myself back in the job hunting game. And I just had an awful realization: I have no recent code samples for those who ask. At least none that are complete, professional quality, and not property of my (soon to be ex) employer. I have a few unfinished projects laying around, as well as some quick and dirty snippets for one-off tasks, but nothing like any serious code. I’m not sure how I will deal with this, but I had better think of something soon!

WordPress

WordPress 2.7 SVN headaches

When upgrading my blog to WordPress 2.7 using my favorite method (svn sw) I ran into the same problem plenty others were seeing from standard ftp upgrades. Namely: Fatal error: Call to undefined function: wp_remote_request() in /... path to blog .../blog/wp-includes/update.php on line 58. (See more about it here: http://wordpress.org/support/topic/224102?replies=36) I tried all sorts of craziness, including deleting everything but my uploads, my images and my custom theme, and then doing an svn up. Still no good. So finally, I got desparate. I did a fresh svn checkout of the 2.7 tag, copied my config, themes, uploads, images and plugins from the old version over, and all was good.

You can imagine, I am sure, that I was not really happy about the thought of going through the whole ordeal again for my wife’s blog. As fate would have it, svn sw worked like a charm on hers. Go figure.

Gentoo

Gentoo emerge error: Can’t locate Module/Build.pm

When trying to do my regular emerge today I ran into minor snag. When emerge tried to build dev-perl/IO-Socket-INET6-2.56 emerge failed with the following error:

Can't locate Module/Build.pm in @INC (@INC contains: /etc/perl /usr/lib/perl5/vendor_perl/5.8.8/i686-linux /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/site_perl/5.8.8/i686-linux /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/5.8.8/i686-linux /usr/lib/perl5/5.8.8 /usr/local/lib/site_perl .) at Build.PL line 3.
BEGIN failed--compilation aborted at Build.PL line 3.

I did some searching and didn’t come across anything directly related to IO-Socket-INET6, but I did see references to other Perl libraries failing to build with the same error, and remark in one of the threads that the only work-around was to emerge the Perl Build module. So, I did an emerge Module-Build and followed it up with my usual emerge -auvD world and IO-Socket-INET6 built just fine.

It seems that there may be a few Perl libraries in Portage that are relying on the Build module but aren’t adding it as a requirement in their ebuild. If you have lots of Perl libraries installed that you manage via Portage you may want to save yourself some hassle and emerge Module-Build now.

Gentoo

Parallels 4: first impressions

I upgraded to Parallels 4 the other day, and hadn’t really had time prior to today to do anything more than open my old VMs and upgrade them to the new version. So today I decided to put it through some paces. I have a massive Gentoo Server VM built in VMWare (one that I built for work) and decided to see if I couldn’t use the Parallels Transporter to convert it for use on my MBP. I first tried to import the whole Virtual Machine and it failed most unceremoniously and quickly. Whether this is due to the disks being broken into 2GB chunks or due to the OS being Gentoo I’m not sure. So, on with plan 2. Use the Transporter to import the disks and then plug those into a new image. While it took a long (long) time, Parallels did successfully import the 2 disks from the VMWare image. I then created a new Virtual Machine and pointed the VM’s first hard disk at the first image, and added a second hard disk pointed at the second image I imported. Although when I imported the first disk image I set it to be a “Bootable Disk” Parallels complained and said there was no OS on the disk and it would not be bootable. I continued anyway, and good thing I did.

After setting up the VM I started it up and sure enough, it booted fine. I did have to change the setting in /etc/fstab as the second hard disk showed up in Parallels as /dev/hdc rather than /dev/hdb.

A little tinkering with network settings (changing from eth0 to eth2) and all was running swimmingly. Since the servers on the VM rely on shared folders being available in /mnt/hgfs/ (the VMWare Workstation & VMWare Player host shared folder mount point) and Parallels will not share folders except with a Windows VM (due to the need to install Windows-specific tools) I added some configuration to /etc/fstab to use samba to mount shares from the host. (Of course, it helps to remember to turn on Windows file sharing in the OS X host too!)

EDIT: Parallels Tools for Linux Guests does, indeed, share out OS X host folders! Thanks to Vasily Averin, developer of the shared folders driver for Linux guests for pointing that out. It puts the folders in /mnt/psf which means a couple symlinks and I was on my way. Thanks!

In addition to all this tinkering to bring in a VMWare image, I ran some updates on the other Gentoo Linux image I upgraded from Parallels 3, and tried out the new “Modality” view while portage was runnning a bunch of updates. If you haven’t seen it yet, it makes a tiny semi-transparent window of the VM which stays on top of all your other apps. You can pull it down somewhere out of your way and keep an eye on how your updates are coming along. Actually pretty handy for things like attended installs and such.

Coherence in Windows seems to run even smoother than previously and I noticed that my machine wasn’t heating up nearly so bad as it used to. When you are working on a laptop this is a very good thing, indeed.

There was a lot of talk in the upgrade information about an iPhone app to controll your VMs but it doesn’t seem to be out yet. I will keep watching the app store for it though.

Browsers

Minefield: I came, I saw, I couldn’t use it

I decided I would be brave and download Minefield (the latest “trunk build” from Firefox) and try it out. I have been reading several reviews about how fast it is, and wanted to see for myself.

I was not, however, able to use it at all. First, my current setup. I am running OS X 10.5 on a 17″ MBP with 4GB RAM. (I have the older mobo however, and the system only actually uses 3GB.) I also have Parallels 3.0 installed with a Windows XP VM (this is important) and two Linux VMs (a Gentoo server and an Ubuntu desktop).

When attempting to start Minefield on OS X (Parallels not running), as Minefield starts Parallels attempts to start an installer on Win XP. The VM cannot be shut down until Minefield is shut down and the only way to do that is via Force Quit. Otherwise the installer continues to attempt to run on Win XP in Parallels. I did not download the Windows installer, nor did I wish to, however, there is something that is triggering a “Firefox Installer” on Win XP whenever Minefield attempts to open on OS X.

Needless to say, while Minefield will not start until it has finished “installing” on XP, and since it is trying (I guess) to install the OS X version on XP, I end up with a hung Minefield and an endless loop of Windows error messages (“The application Firefox Installer has performed and illegal operation etc etc”) followed by the “Firefox Installer” on Windows dying and respawning. Maybe I’ll try again in a week or two, since these are trunk builds and fixes and updates are coming in pretty regularly at this point.

Gentoo

Doing it the hard way, rather than the really hard way

When I shut down the server, prior to moving, I installed an extra hard drive I had laying around before packing it up to be shipped. With the move, and all the work and busy running about since then, I managed to forget that there was a 40GB drive, just waiting to be used.

The other day, I noticed in my daily email from the emerge –sync that cron runs, that it was unable to complete because there was not enough space on the disk. I logged on and df -h showed me that, yes, the drive was full. I did some cleanup and maintenance on the drive and managed to clear out about 1GB of space. This is important, because I needed to increase the size of my boot partition. When I first built this server (using Gentoo 2006.0) I had been having terrific results with a tiny little 32MB boot partition. Now I was having problems, because the boot partition didn’t have enough room to build the initrd for 2.6.27-gentoo-r1. I’m not sure why, but for some reason every kernel I have tried to compile after 2.6.25-gentoo-r1 (including r2, r3, r4, and r5 of the same kernel branch) would create an initrd that was in the 25MB range. Well, that plus a kernel and the configs and you have a no-go on a 32MB boot partition.

Anyway, after cleaning up the drive I was going to use parted to shrink the root partition and grow the boot partition. But parted requires that ext2 and ext3 partitions always start from the same block. Not a problem, the plan was to shrink the root partition, move the swap partition there and then grow the boot partition. Then the really hard part would have come – finding another drive (since this one was too small) and taking the entire server down for a rebuild. Ugh.

So I fired up parted and did a print all to see the block numbers for my partitions, and there it was, 40GB of unused space on another drive. (You probably heard the facepalm from wherever you are and wondered what that noise was.)

So, using good old cfdisk I created 3 partitions on the new drive, a 19GB ext3 partition, a 20GB ext3 partition and a 1GB swap partition. I copied the contents of /usr to the first, and the contents of /var to the second and used a little command chaining to put those where they belonged. (If you are curious, it went something like mv /usr /usr.old && mkdir /usr && mount /dev/hdd1 /usr followed by the same sort of chain for /var and then restarting a few services that point to files in var or usr).

I then did a swapon /dev/hdd3 swapoff /dev/hda2 and then edited fstab to match the new layout. Now for the fun part. Since I didn’t see a way in parted to delete a partition I shrunk the old swap partition down to 1MB, and then resized the boot partition to fill the new space. I did run into an issue where parted gave the error “Error: Filesystem has an incompatible feature enabled.” I found the fix for that to be using tune2fs to turn off resize_inode. That means no online resizing, but since this is not on an LVM that is not an issue. So, run tune2fs -O^resize_inode /dev/hda1 and then run parted and whoosh! A larger boot partition that will fit the massively fat initrd I am trying to stuff in there, and things are better. And with /usr and /var split off onto the new disk the root file system disk now has 11GB of space available.

And, in the spirit of doing things the hard way, I am posting this from my iPhone while laying about waiting for the stomach cramps to subside enough to sleep. (I hate this flu.)

Development

Learning Python

I was asked today “How do I learn python?” (I’m not making this up, that is a direct quote lifted right out of the chat log!)

Of course my first response was “start at python.org” (as it would be.) That is all well and good, but I started thinking about what specific things helped me? So, here are some specifics that might work well for you if, like me, you learn about half and half from reading (theory) and doing (practice.)

The first step, of course, is to download Python. You don’t need a fancy IDE to develop in Python, although if you have one you are comfortable with and use all the time, chances are that it has a Python plugin. (I know Eclipse does, and I believe NetBeans does, and jEdit has a Python client plugin that lets you run Python code right in the editor.) If you don’t want to muck about with an IDE, though, Python comes with it’s own lightweight editor, IDLE. Open it up, play around a bit.

Ok, so you’re looking at IDLE thinking “well, there isn’t much here is there?” You’re right – time for step two. Head over to the beginner’s guide and go for it! There are tutorials aimed at people who are new to Python and to programming in general, and people who are new to Python but not to programming. There is even a list of Python courses you can buy, and a fairly large list of introductory Python books for those who learn best that way. There isn’t much I can say that isn’t there already. I kind of wish that I had started there myself. When I started playing with Python I skipped over this and went straight for the documentation and googling for specific answers, as I was trying to build a script that I needed at the time to parse 1 -2 GB log files. Java was too much tool for the job, I didn’t have access to a beefy enough Linux box to do it in Bash and PHP was doing nothing but running out of memory. It made for a bit of a rough entry into Python, but I kind of like that sort of challenge.

Which brings us to step three – build something. No, not a “Hello World” app, but something useful, in the immediate sense. Something that will make you smile, or make your life simpler, or even something that will allow you to tick off an item on your to-do list.

So what (besides the end of my rambling in parenthetical asides) are you waiting for?

Community

World Day Against Software Patents – 24 September

Whether you think that software patents are a BAD THINGTM (as do I) or you think they are a good idea, it is important to know what it happening around this issue. Today is World Day Against Software Patents. Organized by the Foundation for a Free Information Infrastructure the day is meant to draw attention world-wide to the issue of software patents and encourage active participation in the fight to stop the practice. There are links to articles, a draft of their petition to stop software patents worldwide which you can sign and/or comment on, and way more information than you are likely to be able to get through today. Check it out.

Development

Learning things the hard way

These are some things I learned the hard way over the past few weeks. Ignore at your peril!

  • When your setup requires a different database layout (meaning differently named and/or organized databases and/or servers) for development than for live deployment, you would do well to try to mimick the live layout in your development environment before beginning. (This one hurt, bad.) In fact, when you find a need for your application to test for current environment (development vs production), you may want to be extra certain that you really need to set up your development structure that differently.
  • When your test & deployment environment calls for a server external to the existing systems and database servers, make sure that you:
    1. Have a clear understanding of what packages/versions that server will need.
    2. Have a clear understanding of how long it will take to get the hardware in place.
    3. Have a working copy in a VM on the same OS that the server will be deployed on before you say ok to anything.
    4. Ask, beg, plead, whatever, for a copy of that server (even on desktop hardware) to be set up for the testing. If you cannot test against real machines in a real environment for any kind of multi-server deployment, all bets are off. (Um, yeah, again, ouch.)
  • While the occasional 12+ hour day for developers is inevitable, too many of them in a row will result in more mistakes and coding errors of the most simplistic sort.
  • When you discover that you need to add functionality to an integral part of the software (like, say, the primary db connection class) do everything within your power to ensure that it still “works the same” – that is, add any modifications in such a way that they do not break existing code. This is not always easy to tell, but usually a simple trip around the application will tell you quickly if you have broken something as basic as this. (No, I didn’t break it, at least not anywhere other than locally. I actually took this step, many times and saved myself great embarrassment.)
  • Finally, when switching between languages (PHP, Java, Bash, Javascript, etc etc) you may find yourself looking at code that should work, but doesn’t. Chaining calls in PHP seems to be iffy at best. For example:
    • This does not work, although it seems it should. The $db is an instance of a legacy database connection class used for the project, do_query returns an array of results, and do_query with a second argument sets the value of the field named as the key for each row:list($account) = array_keys($db->do_query(“SELECT account_id FROM reports WHERE store_db=’$store’ LIMIT 1”, ‘account_id’));
    • while this does, using the same class and method:$data = $db->do_query(“SELECT account_id FROM reports WHERE store_db=’$store’ LIMIT 1”, ‘account_id’);
      list($account) = array_keys($data);
      // this also works:
      // $account = $data[0][‘account_id’];
    • Really, sometimes an extra line is worth not having the headache.
PHP

MVCFDH: One way to do MVC in PHP

Aaron Saray, over at 102Degrees, put up an interesting article today on MVCFDH, what he calls his way of building MVC architecture in PHP.

The short version is Model-View-Controller (which we are all familiar with) and adding the ‘Front Controller,’ ‘Dataobject’ and ‘Helper’ pieces. I won’t go into details here about what all this means, you can read it over there. The interesting thing is, without really having given it that kind of thought, that is pretty much the way I have always pieced together any kind of MVC work I have done, regardless of the language.

I think there might be a minor difference, though, at least in what we call things. I tend to think of them as ‘Dispatcher’ (don’t jump my case for calling it that, it works in my head!) rather than ‘Front Controller’, ‘Libs’ rather than ‘Helpers’ and ‘Dataobjects?’ I call them ‘Data Objects.’ :P