Archive for March, 2007

PHP References revisited

After writing this post a few weeks ago about PHP references, I realized I missed one great use for references. The example scenario is this, you have an array of array’s representing rows returned from a database. You want to convert these arrays to specialized objects quickly and easily.

1
2
3
4
5
$rows = $this->findRows();
 
foreach($rows as &$row){
    $row = new RowObject($row);
}

Basically, what is happening is we are referencing the $row reference in the foreach loop. The reason this must be done is because we want the actual $rows array to change, so we have to change all the references in it.

Using overflow:hidden in tables

Until today, I never used the CSS properties overflow: hidden and white-space: nowrap on table cells. I always thought it was useless, since it never seemed to work for me. As a disclaimer, I am not a CSS guru. In fact, CSS is probably where I am least knowledgable in web development.

Fortunately, I ran across the table-layout: fixed property on the W3 website. This changes the table algorithm to just take into account the table cell width. All that is required is the table have a width defined. As with most great web development breakthroughs, it isn’t fully supported in IE.

In order to get IE to work, there is one small trick that must be used. All data inside the table cells must have all spaces converted to  . This will prevent a nasty IE bug of wrapping even though the nowrap property was used.

Thanks to this article for helping me figure out how to put all the CSS together.

Boston

A while ago I said I would try to keep this blog fairly technical, but sometimes you have to let loose and relax. I just got back from a long weekend in Boston and figured I would write a little about it.

Boston seems like a great city to live and to visit. Surprisingly, it was very similar to what I thought it would be. It’s a city that has a very homey feel and because of all the colleges, a great crowd. While the public transportation system isn’t the greatest, it’s still very easy to get around and see the city. I was able to see Soutie, Thaniel Hall, and Brookeline, which all seemed to be great parts of the city.

Since I was there for St. Patrick’s Day, it was very crowded and expensive. Nevertheless, I was there with some great friends, and made some other ones while I was there. It was a crazy fun time, so much so that I slept through the parade on Sunday. I definitely want to go back on a normal weekend to see more of the city, and what the night life is really like.

Possibly the greatest thing about the trip was the break from work. Not to say I don’t enjoy my job, but after a very long 2 weeks preparing for Webmail’s 6.3 release, a break was needed. I was able to walk into work today and focus, even though I had very little sleep all weekend. So for all you workaholics, take a break, it definitely helped me to be a better worker.

Sound Juicer hassle

After a Googling for a few hours, I finally got Sound Juicer, an audio extraction application for linux, setup correctly. Although I am very happy with Ubuntu, problems like this are why I think the rest of the world still isn’t ready for linux. There are still just too many simple problems that require experts knowledge (I am not an expert, Google is my expert).

Problem #1: Lame

Ubuntu doesn’t include any Lame or MP3 plugins. This was a fairly easy fix that I found a few months ago here. All that needs to be done is install all the GStreamer plugins.

Problem #2: VBR

When I had Windows, I used Exact Audio Copy (EAC), to rip my CD’s. EAC provides variable bit rate encoding which helps increase quality without changing filesize. I really wanted this feature in Sound Juicer, but after a lot of wasted time, I found this bug report. To make a long story short, VBR in GStreamer 0.10 doesn’t work very well, so it was back to the drawing board.

Problem #3: Help Documents

Finally, I gave up trying to create the perfect audio files and settled with a constant bitrate of 192kbs. To get the correct GStreamer pipeline, I looked in the Sound Juicer help documents and found this:

audio/x-raw-int,rate=44100,channels=2 ! lame name=enc vbr=0 bitrate=196 ! id3v2mux

After changing my preferences, I tried to rip a CD and it froze. At first I didn’t realize the problem, but then it quickly dawned on me. 196 isn’t a valid mp3 bitrate, 192 is. Good job help docs.

Summary

Linux is awesome, if you have days to waste on configuration. And finally, the GStreamer plugins for mp3’s are awful.

Breaking instanceof in Javascript

That’s right, this afternoon I figured out how to break instanceof in Javascript. Since I don’t use it, I figured it worked just like it does in PHP. Basically it does, with one major caveat. Mozilla’s javascript reference gives this definition of the instanceof operator:

Use instanceof when you need to confirm the type of an object at runtime. For example, when catching exceptions, you can branch to different exception-handling code depending on the type of exception thrown.

Earlier today, I was trying to pass data from a child window to its parent window. From there, the parent window used JSON to encode the data ….. but it never got encoded. Upon further investigation, I saw that JSON used the instanceof operator to determine if an object was an Array. I created these test pages to confirm my results:

parent.html

1
2
3
4
5
function foobar(value){
  alert(value instanceof Array);
  alert(value instanceof child_window.Array);
}
var child_window = window.open('child.html');

child.html

1
window.opener.foobar(new Array(1,2,3));

The first alert is false, while the second one is true.

In Javascript, all objects are “owned” at the root level by the window. Since the window is different for child windows, it makes sense that instanceof would break.

For most small applications, this doesn’t matter. But for Webmail, it does. I have a couple ideas for a good workaround, but nothing set in stone yet.