Monthly Archive for October, 2005

s/major label/internet/g

I fantasize that, once upon a time, publishers helped to find talented musicians, distribute their art, and get them paid. These days, they manufacture marketable acts, engage in rampant payola to get air play, and then screw the artists out of every penny.

Now they’re installing viruses on your computer and calling it DRM.

I guess this is what happens when the Internet obsoletes you.

Debian: Purging an Already-Removed Package

Debian’s excellent package manager, apt, can remove a package two different ways. It can merely delete the binaries, leaving behind config files, or it can purge the package, removing all traces of it. Sensibly, the former is the default.

Every once in a while, you’ll accidentally invoke "apt-get remove foo" instead of "apt-get remove --purge foo". One way to fix this is to reinstall the package, and then re-remove it with the purge option. There is, however, a better way. To purge an already-removed package, do:


     dpkg --purge foo

Good Ideas

Seems like every time I have a good idea, I can go Google up someone who’s already had it.

On the one hand, it sucks to not be original. On the other hand, I probably wouldn’t trust my idea unless someone else had it — so the act of discovering prior-art actually legitimizes my idea.

It would be nice to invent something, but it’s also nice to know that I’m not, actually, crazy.

Const Constructors

If you’re a regular reader — and I’m pretty sure you’re not — you may have seen my infamous “craptimizing” articles: one and two. Read them if you like, but the short story is that I thought I had discovered a neat way to optimize using const member functions. Of course, there was a problem.

My approach is still flawed, but tonight I had an “ah-ha” moment. Suddenly, I knew what was missing — what had put the “crap” in “craptimizing”. What I really needed was a const constructor.

In today’s C++, during construction, we have no way of knowing if we are creating a regular ‘ole Foo, or a const Foo. But with a const constructor, I could differentiate:


#include <iostream>
#include <stdexcept>

using namespace std;

template < class T >
class Foo {
    private:
        bool initialized_;
        T data_;
    public:
        Foo() :
            initialized_( false )
        {}

        Foo( T data ) const :
            initialized_( true ),
            data_( data )
        {}

        void set( int data )
        {
            data_ = data;
            initialized_ = true;
        }

        void fubarize()
        {
            if( !initialized_ )
                throw invalid_argument( “Uninitialized Foo” );

            cout << "Called slow fubarize()" << endl;
        }

        void fubarize() const
        {
            // No initialized_ check required.
            // It's important to fubarize quickly.
            cout << "Called fast fubarize()" << endl;
        }
};

int main()
{
    Foo f;

    try
    {
        f.fubarize();   // Will throw invalid_argument
    }
    catch( invalid_argument &e )
    {
        cout << e.what() << endl;
    }

    f.set( 42 );
    f.fubarize();   // OK, calls slow fubarize()

    const Foo cf1( 42 );
    cf.fubarize();  // OK, calls fast fubarize()

    const Foo cf2;  // Error! (This is good)
}

Note that even if we exclusively used const Foos in our program, the compiler could not perform this optimization (omitting the initialized check) without our help. In short, this is because there are precious few circumstances under which the compiler can actually trust the const qualifier. If you want more details, you got ‘em.

Alas, I don’t think there is any reasonable way to get this behavior with standard C++. (To me, separate “Foo” and “ConstFoo” classes is unreasonable.) And, to make matters worse, adding this feature would break lots of existing code, because the status quo is:


const Foo cf;  // Calls Foo::Foo()

This obviously works fine: how else would we create a const Foo?

PS:
Google finds tons of references to “const constructor”. One very interesting document was this ISO/IEC Discussion Draft by Kevlin Henny. His proposal is notable in that it manages not to break backwards compatibility.

Adaptec’s RAID BIOS Sucks

I’ve been building my systems with RAID mirrors for the past few years. It costs only slightly more, and gives me a nice feeling of security. RAID mirroring nicely counteracts the nagging sense of doubt caused by my hard drive’s pathetic one-year warranty, and the meer existance of it’s MTBF.

The last system I built included the Adaptec 2410SA SATA RAID card. When I created the array, I was given two options: “Quick Init”, or “Build/Verify”. I chose “Quick Init” for the following reasons:

  1. I’m not a patient person.
  2. This choice was reminiscent of the Windows NTFS format process, which can include a nearly-pointless bad-block test at great expense.
  3. The interface gave me no other information on which to base my decision

Luckily, everything went fine. I installed the OS, all kinds of software, copied my data over, etc. It seemed like I had made the right choice. That was, well, until I rebooted and noticed that the RAID BIOS kept identifying my array’s status as “Quick Init”.

I know from experience that an array’s status can be “Optimal”. Why was my array not “Optimal”? Why are you telling me, on every reboot, some random information about how I created my array 10 years ago?

Suddenly, I am feeling less secure about my data. Is it really being mirrored on both drives? Maybe “Quick Init” is some kind of code for “just put the data on one drive for now, and I’ll do “Build/Verify” later?”

This was unsettling. I entered the RAID BIOS setup and decided to see what options I had. I was presented with four choices:

  • Manage Arrays
  • Create Array
  • Initialize Drives
  • Rescan Drives

OK I’m using my first lifeline: the 50/50. Computer, please take away two wrong answers. Well I’ve already created my array, so that isn’t right. Also, rescanning the drives apparently just looks for new drives that somehow weren’t detected a second ago, so that’s not useful either. I’m left with “Manage” or “Initialize”.

Oddly enough, the “Manage” option doesn’t actually provide me with the opportunity to actually change much. It displays a whole bunch of information (helpfully reasserting my array’s status as “Quick Init”) but it offers no way to change any of it. I can press CTRL-R to restore an array, but this pops up a giant warning message that scares me away.

Next, I try “Initialize Drives”. I’m already nervous, because at least in my brain, the word “initialize” has this connotation of writing-zeros across my whole disk or something. It gets worse, because I’m presented with a list that contains each drive — not each array — but each drive individually. I don’t think the operation I want to perform should happen to a drive, it should happen to an array of them. Ugh. If I press ahead, selecting both drives from my array, I’m presented with yet another giant red warning message that scares me away.

So that’s where I am, right now, today. I bought some Adaptec hardware to give myself confidence that I would not lose my data. I did it to feel secure. Except, I don’t feel secure. I am worried that my RAID mirror isn’t actually mirroring anything. All of the options that the RAID BIOS presents to me are guarded by giant red warning messages that scare me.

It’s like a game of Russian roulette where you pull the trigger, and you don’t find out if you’ve blown your head off for a year or two. All I can do is wait for the day when a drive fails, and hope that I’ve actually been mirroring all along.

Adaptec, what the hell have you done to me? RAID is not new. It’s literally as old as I am. You’ve had nearly 28 years to sort this out. Why does your RAID BIOS suck so badly? Why does it use meaningless words like “manage” and “initialize”? Why can’t you just tell me what is going on in a way that I understand?

If quality is job #1 at Ford, security should be job #1 at Adaptec. You need to make me feel more secure about my data. Instead, you have done exactly the opposite.

#include “irony”

The other day, I had this great (read: stupid) idea: I wanted to write a Perl script to process a .c file, find all the #include directives, and replace them with the included file’s contents. I wanted to do this recursively, such that the resulting .i file would have zero #include lines.

Notice that this is not the same as just running the C preprocessor on the file. That would have processed lines like #ifdef _AMD64_ and resulted in a non-portable .i file. All I wanted to do, was to “flatten” a complicated program down to one (still-portable, possibly enormous) file.

Please take my word for the fact that I have a totally reasonable justification for wanting to do this. Honestly. I could convince you, but it would take another page of text.

I wrote the Perl program in about 20 minutes, and turned it loose on my .c file.

A few minutes and 26 megabytes of .i file later, I decided the program would never terminate. That’s about the time it hit me: include guards.

In CS-nerd speak, all the files in a C program form a directed graph where the edges represent inclusion. This graph contains cycles. That means that A.h can include B.h which can include A.h, and so forth, until your brain explodes. You typically fix this problem with so-called include guards:


#ifndef __FOO_H
#define __FOO_H
//... text of foo.h goes here ...
#end

Beginner C/C++ programmers often learn about include guards the hard way. For me, they are reflexive — which is why I totally forgot about them.

So here’s the irony: I want only to process #include directives, and not #define directives, but I can’t sucessfully do the former without doing the latter too.

Pop Count

Larry Osterman recently blogged about some various methods for computing the population count (or pop count) of a machine word. For the uninitiated, pop count is the canonical name for the function which counts the number of asserted bits in a binary number. Larry’s blog entry was excellent, as usual, but it was of the comments that blew me away. Jeu George added a link to his blog describing the MIT HAKMEM pop count. Here it is:


unsigned popCount( unsigned x )
{
   unsigned r = x - ((x >> 1) & 033333333333)
                  - ((x >> 2) & 011111111111);
   return ((r + (r >> 3)) & 030707070707) % 63;
}

I spent hours figuring out how it worked.

Continue reading ‘Pop Count’

2400 x 1600

At work I’ve got a pair of Samsung 21″ LCD panels. Since each display is 1600 x 1200 pixels, the traditional landscape orientation gives me a virtual 3200 x 1200 display.

This past Monday, I decided to try pivoting them. I’m surprised at how much better this is.

I no longer have to turn my head side-to-side to see the whole display. Also, the 33% taller display means I scroll less. I never really thought about it before, but vertical scroll bars are a lot more common than horizontal scroll bars. Most apps work better in portrait mode.

The only exception I can think of is DVD video.

HDCP Free

I bought an HDTV years ago, before DVI or HDMI were around, so I’ve got it hooked up thru some quality component interconnects. Recently my old Toshiba DVD player died, so I needed to find a replacement. I started poking around to see what, if anything, had happened to DVD player technology in the last 3 years. The short answer is: not much.

One minor improvement is that many DVD players can now upsample the DVD video to HD resolution (720p or 1080i). Just to be clear, a DVD only contains 480 lines of pixels, so this is interpolation. A decoder chip looks at neighboring source pixels and more-or-less guesses the additional pixels. You might ask why anyone would do this, and it would be a fair question. There are a handful of reasons, but lets just take it for granted that some people would prefer 480i upsampled to 1080i, over regular 480i.

Getting to the point, the DVD Forum decided that they needed to make some rules to protect their copywritten works. One rule they made was that any digital output at HD resolution should be encrypted with HDCP. Of course, their evil customers might just grab the analog signal, so they made another rule: analog outputs should be capped at 480 lines of resolution.

So lets recap:

  • My TV is an HDTV that supports 1080i.
  • My TV is 3 years old, and only has analog component inputs.
  • Modern DVD players still have component outputs.
  • Modern DVD players have built-in scalers that upsample to 1080i.

I want to upsample to 1080i, but…

  • …the DVD Forum thinks I’m probably a criminal, so…
  • …DVD players prevent high-def analog output, however…
  • …I’m not a thief, I just don’t feel like buying a new damn TV yet.

It’s worth repeating, here, that the original source resolution is 480i. No matter how you interpolate, a DVD is not an HD source. This detail was apparently lost on the DVD Forum who weighed the utility of my expensive TV against the cost of movie piracy, and — not surprisingly — decided my needs were less important then theirs.

There’s a punchline to this whole thing:
After about 20 minutes of Googling, I discovered that some Samsung DVD players have a (not-so-secret) secret code that both disables HDCP, and enables high resolution output over the analog outputs.

I bought one.

As I used to say back in my gaming days: owned.

Pause Your PC

Here’s a trick that might be news to some people. You know that “useless” pause key on your PC’s keyboard? Well, it’s not useless at all. If you hit this key during POST (power on self-test) literally every PC I have ever used will actually pause. You can press any other key to resume booting. If you spam pause and, say, the space bar over and over, you can sort of “single step” thru the BIOS boot process.

Very handy to catch initialization screens that zip by too fast for you to read them.




Creative Commons Attribution-NonCommercial 3.0 United States
Creative Commons Attribution-NonCommercial 3.0 United States