Unexpected default values in MySQL after ALTER TABLE

So I had just done a test in my development environment where I:

  1. ran a script to set NULL values in column X to something appropriate
  2. altered the table to make column X be NOT NULL and give it a sensible default

After I moved these changes to production, I suddenly realized that I had accidentally done (2) before (1), meaning that column X would have no NULLs and therefore my script would not have done its important work. But oddly, the production DB matched the correct values in my dev DB.

I then spent an hour discovering a “feature” of MySQL. Given a query like this:

ALTER TABLE `Foo` CHANGE `X` `X` INT(11) NOT NULL DEFAULT '69';

MySQL (5.0.26, in my case) will not set NULL values in column X to 69, instead it will convert the NULLs to 0. My script treated both 0 and NULL as “empty”, so it ran as I had intended.

On one hand, I’m not sure that I see the logic in doing a NULL-to-INT conversion on existing NULLs rather than setting them to the default I specified. On the other hand, at least I don’t have to clean up my database now. But on my third, invisible Gil-the-Arm hand, I probably spent the same amount of time trying to figure out why this worked out as I would have fixing the DB.

Posted in Rants | Leave a comment

CRT monitor recycling and disposal in Gainesville, FL

Problem: you have upgraded your computer monitors to LCDs and want to get rid of your old CRTs in a way that won’t dump a bunch of lead into the environment. Also, you live in Gainesville, FL where there is no recycling center that takes such things.

Solution: bring them to the Hazardous Waste Collection Center. You may need to pay a fee depending on the number of monitors.

Research: I only skimmed The Importance of Comprehensive Policy to Promote Safe CRT Recycling, but there are some interesting things in there. The difficulties with CRT recycling are about what you’d expect; quoting from the paper:

A CRT product is bulky and heavy to transport, it contains a high amount of toxic materials, and most of its weight is in low valued materials for recycling (leaded glass and plastics).

Other options: I wouldn’t put much stock in these options, but they might give you some ideas.

  • Thrift stores (e.g. Goodwill, Salvation Army) – at one point the Salvation Army took six (6) CRTs off my hands. However, I went there the other day and was told they they’ve got about 150 of them sitting in storage and weren’t going to take any more.
  • Dignity Project – talking on the phone to them, I was told they’ll take 17″ CRTs, but nothing larger than that.
Posted in HOW-TOs | 2 Comments

How to copy email to DreamHost with imapsync

I recently had need to move my email from a VPS to my DreamHost account. I thought I could simply use Thunderbird to copy the folders, but that process didn’t work very well. The DreamHost wiki has an article about importing email, but I wanted to jot down the specific steps. The key was to use imapsync.

# SSH into your DreamHost shell
wget http://www.linux-france.org/prj/imapsync/dist/imapsync-1.255.tgz
tar zxf imapsync-1.255.tgz
cd imapsync-1.255
./imapsync --host1 mail.oldserver.com --user1 theoden --host2 mail.newserver.com --user2 'theoden@newserver.com'
# rerun the above command if the process dies (had to do this like 10 times)
# you'll know it's complete when you see a table beginning with "++++ Statistics ++++"

A few notes about this process:

  • In my case I was moving mail to the same domain name (i.e., mail.example.com to mail.example.com). Obviously mail.example.com only points to one place, so I used an alias for the old mail domain; an IP address would probably work as well.
  • Note that with DreamHost you need to specify the full email address as the username.
  • You may have to subscribe to the sync’ed folders before they’ll show up.
  • Thunderbird seemed to lose track of my Sent folder after I sync’ed. The Sent folder was present and explorable, but did not have a special icon associated with and sending mail would result in an error about being unable to copy to the sent folder. The problem seems to have gone away once I set the “Maximum number of server connections to cache” to 1.
Posted in HOW-TOs, Linux | Leave a comment

Geek podcast roundup

Just a list of some geeky podcasts I’ve stumbled upon in my travels. Listening to these in the car is a great way to fill a commute…

Penny Arcade Podcast (rss): All geeks know about Penny Arcade; the podcast provides an entertaining view of the Mike and Jerry’s creative process. The two brainstorm, discuss current events, and joke around while they iterate toward their next comic. This one is a lot of fun and always feels like a special treat when it pops up on my feed reader.

Software Engineering Radio: The Podcast for Professional Developers. This is a solidly produced podcast that centers around interviews with engineers and researchers in the IT field. The topics are generally interesting, though listening to Germans talking to other Germans in English about abstract programming concepts can cause one’s eyes to glaze over; I recall one episode about the Java Spring framework that was just abysmal. Still, the podcast really shines when the guest is a native English speaker and especially when Markus Völter is doing the interviewing.

The WordPress Podcast: The #1 podcast for WordPress-related news, tips and information. One wonders if they are the only WordPress podcast, but that is besides the point. In this relaxed podcast, Charles Stricklin and “color commentator” Jonathan Bailey discuss all things WordPress in their chummy Louisianian drawls. As a user of WordPress who has submitted a few patches, I enjoy listening to the discussion, interviews, and insights into the blogging community.

P3 (php|architect’s PHP Podcast): A bi-weekly radio-style program full of news, punditry and plenty of rambling. The personable Paul Reinheimer and knowledgeable Sean Coates talk about PHP and related issues in their so-called “ramblecast”. Being a heavy PHP user, I like being kept up-to-date on what is happening with the language. Tips about web development creep into the podcast, and the rambling often runs far afield of P3’s focus. The conversational nature and lack of cohesiveness here can result in some tedious listening, but P3 does have its moments.

Dungeons & Dragons Podcast (rss): Go inside the world of Dungeons & Dragons for insights, interviews, and much more. My primary reason for listening to this was to hear the Penny Arcade guys and Scott Kurtz of PvP playing the new 4th Edition. Apparently Wizards of Coast sent out a high-quality DM or two to run a little campaign with these guys and recorded the result. I don’t even play D&D, but the aforementioned podcasts are really entertaining. In addition to the Penny Arcade podcasts, you’ll also find stuff about D&D news/events. These are somewhat interesting, though the real meat is listening to Mike, Jerry, and Scott crack jokes as they dungeon crawl.

Posted in Podcasts | 2 Comments

Downloading files over SSL with IE7

Problem

I have a script, call it download.php, that pulls files from a database and serves them up to the user. For example, download.php?fileId=69 might return some headers and data that cause the user’s browser to download a PDF and prompt the user if they want to open it in Acrobat or something.

This works fine in Opera and Firefox, but when dealing with IE7 over SSL, the browser throws an error message saying that it can’t download the file download.php. I tried playing with various header() calls, but eventually wound up with a solution that is “good enough”.

Solution

In IE7, do the following:

  1. Go to Tools -> Internet Options
  2. Click the Advanced tab
  3. Under the Security section, check Do not save encrypted pages to disk
  4. Click the Apply button

And there you go. For me this is fine because I’ve convinced most of my users to use Firefox. If you have a large userbase that is still using IE, then telling each one to muck around in their browser settings might not be the cleanest solution.

Posted in HOW-TOs, Micro$oft | Leave a comment

The Hyperion Cantos by Dan Simmons

When Hyperion arrived in the mail, I instantly had a good feeling about Dan Simmons’ 1990 Hugo award winner. My intuition proved correct and I ended up consuming all four books in the Hyperion Cantos. As a fan of science fiction – hell, as a fan of literature – you will find these books astounding.

After reading over 2000 rich pages full of expertly crafted characters and exotic worlds, I am at a loss to summarize the story. The four books are divided into two couplets: Hyperion and The Fall of Hyperion describe the Shrike Pilgrimage, a journey to the Time Tombs undertaken by seven diverse pilgrims under the watch of the murderous Shrike creature; Endymion and The Rise of Endymion tell an epic love story as humanity fights for and against its ultimate evolution. There, that’s the best I could do in terms of a quick summary – hardly scratches the surface of the tetralogy’s depth.

To rattle off a few literary themes, the books explore:

  • Religion, in a surprising number of forms
  • Love, also in a surprising number of forms
  • The evolution and motivation of artificial intelligence
  • Likewise, the evolution and motivation of humanity
  • The sanctity and splendor of nature
  • Poetry, especially that of John Keats

And I’m sure there is more that I’m not remembering at the moment. Switching to the topic of pure science fiction, this is definitely in the realm of “high” sci-fi, but there is good internal consistency and enough realism to not wander too far into the fields of fantasy. You have FTL, beam weapons, a mechanism for instantaneous travel, better-than-sentient AI, nanotech on the periphery, and “doc-in-the-box” devices that can heal pretty much anything. The books are full of interesting gadgets/technology and you will generally not suffer from sci-fi withdrawal.

To give a few criticisms, I found the second and fourth books to have some areas where you tend to get bogged down as a reader. Whereas I tore through Hyperion and Endymion, I found myself taking more breaks with the other two; The Fall of Hyperion had some slow political sections and The Rise of Endymion had me dragging my feet through the world of T’ien Shan where the author is hurling all these Chinese/Tibetan names/landmarks/structures at you.

As a computer geek, I found some of the AI/metaverse stuff to be a little silly. Simmons uses a Neuromancer sort of mechanic – even making a reference to William Gibson – which I found unfortunate because I hate the representation of hacking as flying around some 3D digital environment. Still, the whole AI theme and execution is pretty cool, even if you aren’t treated to a Vernor Vinge sort of plausibility.

But my gripes are small compared with the overall majesty of this series. The Hyperion Cantos has definitely jumped to the top of my sci-fi favorites, not just for providing compelling science fiction, but also for its exploration of so many vibrant aspects of the soul. I’m going to have to take a brief literary break to let these books sink in before I hit up the Hugos and Nebulas again.

Posted in Books | 1 Comment

On the Rain-Slick Precipice of Darkness: Episode One

After getting the game running on 64-bit Linux, I plowed through the first episode of On the Rain-Slick Precipice of Darkness in about 6-8 hours of play. One could probably beat the game much faster than that, but obviously you are supposed to stop and smell the roses. The game is full of Penny Arcade humor and I found myself clicking everywhere I could to absorb all the tasty content.

If I had to describe the game, I would say that it’s like a Penny Arcade-themed episode of Curse of Monkey Island with a somewhat real-time RPG combat system. The constant jokes, the satirical drama, the quality voice acting, the rich cartoon backdrops, and the atmospheric music – all reminded me deeply of the Curse of Monkey Island series. This is fine of course, and it would be hard to think of a better format for a PA game.

I described the combat system as having a “somewhat real-time RPG” style. You could think of it as a compromise between FFX and FFXII. The combatants are lined up like a classic RPG, but the clock is ticking and you have to make decisions in real-time. Additionally, there is a Paper Mario aspect where you can time a spacebar press to block/counterattack your enemies, as well as do extra damage on the special attacks. This made for some hectic battles as you hastily try to give orders to your party while keeping an eye out for enemy onslaughts.

In some ways I wish they had gone with traditional RPG combat, but I don’t think their system was deep enough to make such a thing engaging. As it was, the combat was fun and contained numerous satirical aspects that I found amusing (when I actually had time to read them). Some of the battles were actually challenging, though the game is quite forgiving of mistakes. Death of the party didn’t seem to incur any penalty, you are automatically healed after each battle, and enemies do not respawn.

On the subject of forgiving nature, Precipice of Darkness is nice to you in other ways. Traveling through the different areas is very quick and there are easy shortcuts so that you almost never have to hoof it very far to your destination. Items are found in various containers that do respawn and it’s easy to fill out your inventory. Though I must say that mindlessly smashing stuff to get items did get repetitive after awhile.

Continuing along the complaint vein, the game’s path-finding logic seemed a little bit off. The character would tend to get stuck behind things and you’d have to sort of guide them around sometimes. The minigames in the Pelican Bay area were… well, a real piece of crap, actually. The names of the games were hilarious, but the implementation of them was pretty shoddy – especially the ski ball game. Another issue in Pelican Bay was that all of sudden you were facing pretty strong opponents. I had a stretch when I was leveling up after almost every battle – seemed like there should have been one more stage in between.

In the end, the game is well worth the $20 for a Penny Arcade fan. References to comic strips abound, the off-color, irreverent humor is there in abundance, and Tycho’s rich writing and imagination leave a very distinctive mark. The game had me laughing out loud numerous times and I’ll definitely be purchasing the next episode.

Oh, and the final boss has an attack called “Music of the Spheres”. A deep bow to the architect of this Johannes Kepler (or Hyperion Cantos) reference.

Posted in Video Games | Leave a comment

Precipice of Darkness and 64-bit Ubuntu 8.04

I was very excited to see that Penny Arcade‘s new game, On the Rain-Slick Precipice of Darkness (Episode One), was available for Linux. My excitement blossomed further when I found that the game came with an innovative mini-game. The mini-game is called: Get This Working Under a 64-bit OS. I never get tired of this game, and have enjoyed playing it with Adobe’s Flash and the Opera web browser.

Apparently I had most of the necessary packages already installed (I think you need ia32-libs and lib32asound2). The game was actually starting up, but immediately flashed a message about not being able to find a sound driver. Googling around, the solution appeared to be use package alsa-oss. Apparently the game uses the Open Sound System (OSS) instead of ALSA; thus you need to use the aoss command which performs an OSS -> ALSA translation.

The problem then becomes that alsa-oss gives you 64-bit libraries on your 64-bit system. The solution is to use a 32-bit alsa-oss which you can find in this thread. I was a little hesitant to download and install a package from a URL containing the text “deletebox”, but it appears to be provided by an upstanding user. Here is a direct link. Once I had installed that, I can run the game just fine with:

aoss ./RainSlickEp1

One of my cores is completely pegged even with the game on pause, but so far Precipice of Darkness has performed great. Hopefully the next episode will have a 64-bit version…

Posted in HOW-TOs, Linux, Video Games | 2 Comments

Flash with 64-bit Firefox on openSUSE 10.3

I wrote about how I got Flash working with 64-bit Firefox on openSUSE 10.2, but I had to briefly struggle with it again on openSUSE 10.3. In this version of the distribution, I was pleased to find that nspluginwrapper was included in the package manager, installed by default, and automatically recognized by Firefox.

Unfortunately, I still had to take the less-than-user-friendly step of registering the Flash plugin with nspluginwrapper:

nspluginwrapper -i /usr/lib/browser-plugins/libflashplayer.so

A simple little command, but obviously not one that Aunt Tillie is going to stumble upon.

As a side note, I tried clicking the “Install missing plugins…” button even though it never, ever works. Maybe that thing works on Windows, but they should just disable it for Linux. The distributions tend to provide the major plugins in their package repositories anyway. Okay, back to programming on my (mostly-supported) 64-bit workstation.

Posted in HOW-TOs, Linux | 1 Comment

How to check if a variable exists in PHP

Go ahead, look at the PHP type comparison tables and snicker over how the language is a cobbled-together hack. I still love it, but I did run into a little bit of confusion today. Here is the basic issue:

$a = null;
//$b = 42;

Simple enough; $a is set to null and $b is commented out and therefore does not exist. The problem is that I could not find an easy way to differentiate between those two states. Sadly, isset() returns false when a variable has been set to null. I scanned over the function list and googled around some, but could not find the sort of exists() or is_defined() function that I wanted.

Amusingly, is_null() returns true for both $a and $b, but PHP will spit out a notice about an “undefined variable” when you do is_null($b) (depending on your error_reporting configuration). So PHP knows the difference between a null’ed variable and one that has never been set… but how do I get access to that knowledge?

The best way I could find was to use get_defined_vars(). For example:

$a = null;
//$b = 42;
$arr = get_defined_vars();
if (array_key_exists('a', $arr)) echo "Yes, \$a exists!\n";
if (array_key_exists('b', $arr)) echo "This will not print.\n";

If anyone knows of a better way to do this, I’d love to hear it.

Posted in HOW-TOs, Programming | Leave a comment