Linksys WPC54G ver. 1.2 with WPA on Hardy

I’m pleased to say that my old trusty Linksys WPC54G ver 1.2 works without ndiswrapper Hardy Heron. I have been using this card since Hoary, but never “natively”. My last attempt at installing it was under Feisty and I failed. Whether it was me or Feisty being… Well, feisty and uncooperative remains to be determined. You were supposed to do something like this:

sudo aptitude install bcm43xx-fwcutter
sudo bcm43xx-fwcutter -w /lib/firmware/ ~/bcmwl5.sys

Where bcmwl5.sys was the original Windows driver you could obtain from the linksys ftp site. It did not work for me, and I ended up falling back on ndiswrapper like usual which always worked, but was always flaky.

I figured I might as well try the bcm43xx trick under Hardy. Things generally improve over time, and old bugs and quirky behaviors go away – it’s not like Debian where you get a stable release once in a century. Unfortunately, it once again failed miserably. Or rather I failed. Or perhaps, should I say we had a miscommunication. I asked Hardy to use the bcm43xx module and he did exactly that – despite the fact it was the wrong thing to use.

What I didn’t notice was that some sort of a switcharoo took place, and this time around the errors spewed forth by the card were something among the lines of: b43/ucode5.fw” not found. As you can probably see, they did not mention bcm43xx anywhere, but I assume that b43 == bcm43xx. I assumed wrong. They are two different modules. So how do you make the card work under Hardy? Like this:

sudo aptitude install b43-fwcutter

Yep, that’s it.It automatically pull down the relevant firmware, cut it and throw the relevant .fw files into /lib/firmware automagically. It’s that easy. This is what happens when you assume the “well, this worked last time so I’m just gonna keep trying and ignore this very helpful error message right here cause I know better” stance.

My next task was of course to configure the system to use WPA. Ubuntu is nice enough to support it out of the box via the wpa_supplican package – not all distros do though. Etch ships without it, and it took me a while before I figured out why I couldn’t connect. My Gutsy laptop had no issues picking up the Wifi in my house. All I had to do was to pick the network from a list using knetworkmanager, type in my passphrase and I was ready to go. It would be a bit more difficult with this system, because I was building it bare bones, without any window manager.

How do you set up WPA without the GUI? There is a really nice writeup in Ubuntu forums that shows you what you need to do. Let me summarize it here, for future reference.

First you need to convert your pass phrase to an actual hex key. You do this by running the following command:

wpa_passphrase my_ssid "my long passphrase"

If your passphrase is an actual phrase (ie. it contains spaces as it should) you will need to put it in quotation marks. The output will look something like this:

network={
    ssid="my_ssid"
    #psk="12345678"
    psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab1 5bbc6c52e7522f709a
}

You are interested in the last line – the psk value. Copy it, save it or hold on to it in some way. Next open up your /etc/network/interfaces and add the following lines to the bottom:

auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-ssid 
wpa-ap-scan 1
wpa-proto WPA
wpa-pairwise TKIP
wpa-group TKIP
wpa-key-mgmt WPA-PSK
wpa-psk 

The last line is where you paste in that long hex key we calculated in the previous step. Now running:

sudo ifup wlan0

should bring your wireless up, authenticate and negotiate an IP from the DHCP. The first line, will automate this process so that every time you boot, or insert your card into the machine, it will try to authenticate and connect.

There is one small issue with this setup that I noticed. The LED’s on my card no longer work, but that might be unrelated to this setup. They worked when I was using it under Feisty with ndiswrapper, and it did lit up when I briefly experimented with Debian Etch on this system. But they never switched on under Hardy for some reason. Then again, maybe the card just had it – I’ve been using it for few years now, and it is a little bit “bent” from that one time, I forgot to take it out before putting the laptop in my bag. so perhaps the LED’s just died a natural death. The card still works though.

[tags]linux, hardy, ubuntu, hardy heron, linksys, wpc54g ver 1.2, wpa, tkip[/tags]

4 Comments

Memento

On Monday I wrote about the horrible, brain damaging experience that was the new Indiana Jones movie. In the comments section Teague asked me what was the last good movie that I saw. Well, I decided that I will write about that movie today.

After watching Indy battle Roswell aliens on Saturday, I sort of needed to do something to counteract this experience. Sort of like rinsing my brain from the dreadful mental muck spewed by all recent George Lucas productions. I picked Memento because I had never heard a bad thing about this movie. Everyone kept talking about it in superlatives. When I took Psychology back as an undergrad my professor just couldn’t shut up about it during the lectures on memory and amnesia. Ever since then this movie was on my “to watch” lists.

Memento

This Sunday I really needed to watch something intelligent, and intriguing – anything to stop the recurring fantasy of me punching George Lucas in the face for making me waste $10 bucks on one of the worst movies of this year. It worked, Memento did not disappoint me and it was a hell of a ride.

The film is unique in almost every aspect – starting from the idea (a man anterograde amnesia hunts the killer of his wife seeking revenge), to the composition and story telling methods. We experience the movie very similar to the way Leonard (out protagonist) lives his life: few minutes at a time. Due to his condition, he cannot form new memories. He promptly forgets everything he sees and hears after it leaves his short term memory which usually only takes few minutes. We experience the movie in the same way. Each scene starts when Leonard just forgot what was going on, and ends at the point where he is about to forget everything again. Here is a twist though – we watch the events unfold in reverse chronological order and running in two parallel timeliness which merge at some point in the movie.

vlcsnap-10938236-custom.png

This may sound confusing, and initially it is. Things happen to our hero, and we don’t know why (and neither does he) but with each scene we get more information. And since most of us can form long term memories, we can always stay one step ahead of Leonard and put together all the pieces of the puzzle until we have a clear picture of what has transpired.

Since Leonard can’t do that, he has developed a system of notes, and reminders for himself. His method is so simple it is almost brilliant. He always caries a small Polaroid camera with him and snaps pictures of things he wants to “remember”. For example, how his new car looks, the motel where he is staying, the people he met recently. On the little white strips he writes relevant info – like “my car”, “my motel” or given person’s name and phone number. On the back he scribbles notes: like “don’t trust this person” or “this person will help you” and etc. Very ingenious.

vlcsnap-10942862-custom.png

Some facts are too important to trust to pictures. He tattoos them directly onto his body – some in reversed letters so that he can read them in the mirror. These facts include the fateful line “John G. Raped and Murdered my Wife”.

vlcsnap-10939243-custom.png

What initially bothered me was the fact that while Leonard would forget recent events so easily, but he had this intricate system in place. How did he remember to take notes – or how to take them? I did some research in this direction and apparently there are two types of memories we form – episodic and semantic. Episodic memories are snapshots of events, while semantic memories are more procedural and instinctive (like riding a bike for example) or factual (water is wet, sun is bright, etc…). The theory is that most episodic memories get translated to semantic memories over time – so you actually forget the exact details of the event, but you remember the “story” the way you tell it to people as sort of a monologue. But they also develop via repetition and training. People with anterograde amnesia seem to have more problems with forming episodic memories rather than semantic ones. Leonard mentioned at several points in the movie that he is able to learn by repetition and routine – so it is possible that his notes system, and the instincts he used to cope with his condition developed over time.

His amnesia is tragic, but also strangely liberating. Leonard never gets embarrassed, has no regrets and no remorse. He doesn’t have to live with his choices – only with their potential consequences. And he has a very strong drive – his quest for revenge, is what keeps him going, and keeps him motivated. All of these factors make him a very intense and memorable character, and Guy Pierce does an incredible job portraying him on the screen.

vlcsnap-10940776-custom.png

Memento raises interesting questions about the very nature of memory. At some point someone questions Leonard’s ability to collect and process facts for his investigation based on his condition:

Memory can change the shape of a room; it can change the color of a car. And memories can be distorted. They’re just an interpretation, they’re not a record, and they’re irrelevant if you have the facts.

Are Leonard last memories real? Does his story actually check out, or has he successfully deceived himself and conveniently forgot important details of his life? The ending, or rather the beginning of the story is rather ambiguous and puts a big question mark above Leonard’s whole quest. All the facts about Leonard’s we took for granted throughout the movie are questioned.

vlcsnap-10949610-custom.png

What would you do if you were Leonard in these last scenes of the movie? Would you make the same choice he did? And what do you think of Gamme’s version of the story? Do you think what he said about Leonard’s wife it was true?

If you haven’t watched it yet, I highly recommend it. It is highly entertaining, suspenseful and masterfully written, acted out and produced. And it only shows that what we talked about in The Kingdom of the Crystal Skull thread is true: good stories do not need any special effects or big budgets. These things are really just cosmetic stuff. But if you make them the focus of your project, you usually lose sight of what is the most important: the story and the characters.

[tags]memento, movies, review[/tags]

4 Comments

Design by Contract in PHP with Assertions

Recently I wrote about meta programming in php because my recent project involves quite a bit of it. I will probably write about it at some other point but it’s still in sort of early development stage. However while these techniques produce very compact and flexible code, they can also be hard to debug. Since code gets modified at runtime you can often run into situations where something gets passed to the wrong method and you don’t really know why and where. Each time I called some method, I was making certain assumptions as to the state of the program. For example, whether or not I am accessing the right type of class, or whether or not the method is called properly and etc. Here is a sample comment block from a function I wrote recently:

/**
 *  Returns an array built by querying another table. The name of the table is based on the
 *  foreign key passed in as an argument(param $name) which is expected to be in the form
 *  tablename_id. The method will import tablenameModel and tablenameView  classes, initializes
 *  them and run listRecords() method on the tableModel instance.
 *
 *  Note that tablenameModel and tablenameView classes must exist and be defined in files
 *  models/tablenameModel.php and views/tablenameView.php. The classes should be derived
 *  from DefaultModel and DefaultView respectively.
 *
 * @param string $name The name of the foreign key form tablename_id
 * @return array
 */

I’m assuming tons of things here. I’m expecting classes to be defined in certain files, I expecting them to be descendants of certain other classes, and I need the argument to be passed to me in a specific format. During normal execution all of these conditions should be met automatically. The correct files should be in the right place, because of the way the whole system is set up. The classes in question should extend the correct parents because that is the convention I’m using. Similarly, I’m also enforcing a convention that all foreign keys are ought to be named in the form tablename_id. So if someone passes me a parameter that is in the wrong form, or that does not have correctly defined Model and View classes associated with it, this is a big issue. This should never, ever happen at runtime.

How do I enforce these things though? I opted to take my comments and turn them into assertion statements. At some point this almost turned into sort of a Design by Contract methodology. Ensure preconditions, guarantee postconditions and etc.. Here is the method body itself:

function getComboBoxArrayFromOtherTable($name)
{
   assert('is_string($name)');
   assert('Util::EndsWith($name, \'_id\');');
            
   $tablename = substr($name, 0, strrpos($name, '_'));
   $modelname = $tablename."Model";
   $viewname = $tablename."View";
            
   assert('file_exists(\'models/\'.$modelname.\'.php\')');
   assert('file_exists(\'views/\'.$viewname.\'.php\')');
            
   include "models/$modelname.php";    
   $othermodel = new $modelname();

   include "views/$viewname.php";      
   $otherview = new $viewname();
            
   assert('is_a($othermodel, \'DefaultModel\');');
   assert('is_a($otherview, \'DefaultView\');');
                    
   $othermodel->listRecords();
   return $othermodel->getComboArray();
}

I could of course throw exceptions, or make my script die() if these conditions were not meant. But as I said before, failure to meet the asserted conditions were was not really something that could be introduced by a user stumbling to a wrong URL or entering malformed data at runtime. Failing these assertions would be primarily caused by someone calling my methods improperly, or passing wrong arguments. In other words – programmer errors. And so, we spank the programmer rather than the user by using assertions which can be disabled in production code.

They are sort of sanity checks that make sure I’m using my own methods the way I originally intended them, and that I’m not really building system around some curious side effect happening deep inside my code that I never really intended for, but over a period of time grown to really on. Not to mention that they really help you write a self documenting code.

I often forget to spell out all my assumptions like in my code block above. This one is a nicely fleshed out because but not all of my comment blocks are this informative. In fact when I’m in a hurry I will sometimes write a single sentence or two just to have something show up in the doc file. Assertions however must be explicit, and really flesh out my pre-conditions and post conditions. So even if I didn’t write any documentation for a given method, someone could pick it up and work out at least partial (bare bones) documentation just by looking at some of these statements.

I haven’t really used assertions that much in my PHP code before. But with this project I’m totally sold on them.

[tags]php, assertions, design by contract, meta programming[/tags]

9 Comments