Ramblings of General Geekery

Abandoning Remember The Milk

The milkify.com domain recently expired, and I didn’t really feel like renewing it. If you look at the (absence of) recent commits in either IronCow or Milkify, it’s easy to understand why: I’m not really working on those projects anymore. And that’s because I’m not using Remember The Milk anymore either.

To be fair, IronCow is pretty stable already – most of the latest changes were configuration management stuff and upgrades to Visual Studio 2010 – so it’s still usable. I’ll be available for bug fixes, of course, but if the guys at Remember The Milk add new features, I would probably not know about it and it wouldn’t be ported to IronCow unless somebody forks the project and submits a patch.

Milkify, however, won’t see any improvements unless somebody picks it up. It’s just not worth it to work on a tool I’m not using myself.

This means I get more time to focus on my new home projects like PieCrust and a couple of other bigger ones in progress.


Simple workaround for the iPad’s smart cover’s design flaws

I recently got an iPad (more on this later), and with it I got the much hyped smart cover.

IMG_4353.jpg

I loved the simplicity of it, and how quickly you can take it off and put it back on again… However, I quickly realized that I probably had more dust on the screen while using that thing than if I didn’t have any cover at all. Among the problems I had the infamous “dust lines” – those three lines you get on the screen at exactly the same spot as the cover’s folds.

The problem was pretty obvious: the natural way to fold the cover, and the way Apple advertises it, is as follows:

IMG_4357.jpg

But this results in the following situation:

IMG_4354.jpg

The iPad rests on the folded cover as expected, but the outer faces of that triangular stand are the faces that go against the screen when the cover is closed! They would therefore pick up dust and other particle directly from the table and all around, and put them back onto your screen as soon as you walk away… I don’t know where Steve Jobs used to go with his iPad, but my house is not always spotless clean, and neither are any restaurant tables or office desks that I want to put my iPad on.

An easy workaround for this problem is to fold the cover the other way:

IMG_4355.jpg

This way, the faces that go against the screen are actually inside the triangular stand, where they’re very unlikely to pick up any dust. This way of folding is a lot less intuitive, but once you get the hang of it, you can actually close and open it as fast as before. I haven’t had much dust on my screen ever since I started using this technique.

There’s just one big caveat to this workaround: it doesn’t work with the “stand up” mode.

IMG_4358.jpg

If you look closely at the picture above, you’ll notice what’s wrong: gravity alone can unfold the cover and make your iPad fall down on the table. In my case, the magnetic strength of the cover is barely enough to counteract the iPad’s weight and make it stand on its own, but the slightest touch can make it crumble down like a house of a couple of very expensive cards. However, I don’t care because I’ve never felt the need to use that position so far.


Article drafts in PieCrust

A common feature of a blog engine is to let the user work on an article for a while before actually publishing it. Thanks to pagination filtering, it’s pretty easy to do in PieCrust.

All you have to do is add the following to your blog’s home page’s configuration header:

posts_filters:
    not:
        has_tags: draft

This will skip any post that has the draft tag.

You will probably need to add some similar filtering to other pages such as the _tag or _category pages.

Edit: as Keilaron mentioned in the comment, you can’t modify the filters on a tag or category listing page, because their filters are preset to, well, filtering posts with a specific tag or category. This means that, unfortunately, you should not actually tag/categorize your drafts.

Edit 2: as of PieCrust 1.0, it’s possible to use a posts_filters on the _tag or _category pages, so it’s all good!


Fresh PieCrust available

I just pushed version 0.1.2 of PieCrust, the lovely static website generator that powers this blog, and most of my other websites.

Pie, anyone?

Yep, the version was bumped from 0.0.4 to 0.1.2. The main reason is that I very heavily refactored the code to make it a lot more readable and maintanable. This also means a whole new batch of bugs are lurking in the dark!

The main change for users is that there’s no _chef directory anymore. It’s all a lot cleaner, with everything living in _piecrust. Just be sure to delete your old directories before getting the new ones, so you don’t have old junk lying around. This also means that you need to (slightly) change your bootstraping code for running PieCrust. If you didn’t customize anything, you can just grab the new index.php from the sample website and overwrite your own. If not, you may want to check out the updated documentation on PieCrust bootstraping.

Among the new features, you’ll find:

If you want to see what’s planned in the future, there’s also a brand new public
Trello project board
.

Finally, check out the slightly redesigned and reorganized PieCrust website!


PHP is fucked up

You may be shocked by what I’m about to say but here it is: PHP is fucked up.

Well, duh

Oh, no. Wait. No you’re not shocked. You already knew it.

Today’s topic: namespaces.

PHP’s namespace implementation is fucked up. There’s really no way to say it nicely, and you will realize it 5 minutes after starting to use them, when most of your code breaks and you need to litter the beginning of your files with use statements and you really wonder what you gained in the process. It really comes down to the impossibility to import a whole namespace, and PHP’s inability to look into parent namespaces when a class is not found in the current one. Sure, I understand the first feature is actually very tricky in a dynamic language, and the second one may have been rejected because of performance reasons, but with that many downsides you have to wonder why namespaces were implemented at all. Pornel gives a good list of all those downsides in his article on PHP namespaces.

Sure, namespaces let us get rid of the PEAR naming conventions, and they work nicely with spl_autoload_register, but they also gave me my biggest WTF moment in recent history.

Consider the following code:

namespace Foo;

class BarException extends Exception
{
}

class Bar
{
	public function trySomethingSafe()
	{
		try
		{
			throw new BarException("Catch this!");
		}
		catch (Exception $e)
		{
			echo "Caught exception: ".$e->getMessage();
		}
	}
}

It defines a new exception type (FooException), and a class (Bar) that does something safe by wrapping the code of the function inside a try/catch statement.

Now run this from another file:

require_once 'foobar.php';

$b = new FooBar();
try
{
    $b->trySomethingSafe();
}
catch (Exception $e)
{
    echo "This should never show up, right?";
}

Well, guess what you get in your output window? Yep:

This should never show up, right?

It’s like the first try/catch block is not catching the exception! Surely it can’t be a bug in the PHP runtime, right?

Well, of course not. It’s the user’s fault. And that’s because PHP’s namespaces suck ass.

Look at the catch statement in trySomethingSafe: it’s meant to catch all types of exceptions by specifying the top parent Exception type, but this is actually not it. See, that code is inside namespace Foo, and I didn’t specify either a use Exception at the top of the file, nor did I use Exception’s full name, Exception. Yes, that leading backslash is really super important in this case, because it makes all the difference between what you meant (the standard Exception type) and what PHP understands (a completely imaginary FooException type).

To fix the problem, replace the catch clause in trySomethingSafe with this:

catch (Exception $e)

You will then get the expected result:

Caught exception: Catch this!

The tricky thing here is that PHP doesn’t seem to care that FooException doesn’t exist. It happily runs the script, gets the exception, which is of type FooBarException, figures out that the class name does not equal to FooException, and bubbles the exception up the call stack. It doesn’t stop to check that the exception type we want to catch actually exists.

So, yeah. You need to be careful with PHP namespaces, especially when you add them to a previously un-namespaced project.