Wednesday, October 31, 2007

My First Mac OS 10.5 Review

So I've had leopard for about 24 hours now. The best things are: Finder, TimeMachine, and, uhh, Terminal. heh, I'm a nerd. Spaces is good too.

The UI: Mixed bag

Hmmm, well, it's a mixed bag. Lots of minor changes that are "fine," with others being good and bad

Good.

  • All windows now have the same theme. This is huge.
  • The annoying hidden right-side panels are gone

bad:

  • The dock has all sorts of annoying reflections
  • Doc and folder icons not nearly as clear as Tiger ones
  • Stacks is kinda silly. It only works in the doc and looks ugly.
  • Instead of button1, and button 2 (control-click), we now have click-and-hold (open stacks) and select-hit-spacebar (finder) modifications. Why two different invisible mechanisms? When can just agree that having two buttons is better. Oh well.

Finder: fast preview rules

Hey now, it's a lot better. Everything now has a real preview. Coverflow for folders is kinda cool. Hitting "space" on any item opens a fast preview. It's great for source files and pictures.

Time Machine: must have

Wow, this really works. You might want to buy a dedicated external hard drive for this. you plug it in, and it just works. Nothing to configure! Need to free up space? just go into hard drive and delete whatever backup you want. Multiple computers can use the same hard-drive (in fact, you might be able to do something tricky with firefire and have each computer backup each other.)

Spaces: good

Real virutal desktops! I have cheap machines that use main memory instead of dedicated graphics memory so I wondered how this work. I have to say switching between 1920x1280 virtual desktops is fast and painless. On my tiny 1024x768 laptop it is a godsend. The only down side is their is no small icon preview of the other desktop like you see in some other OS.

To turn it on, go into system preferences

Safari: much better

Safari V3 is a lot better. First I think/hoped they fixed a lot of annoying web-dev bugs. Lots of heavy ajax sites that didn't work or worked strangely in V2 now work. Also SVG is supported and easily 10x faster than firefox (more on this another time). I guess you can download V3 without leopard too.

AddressBook and Calendar and Mail: whatever

I don't use these much, but it's a bit odd how you can sync your address book with yahoo, and that yahoo doesn't have POP/IMAP for their email. Google has horrible contact management, but now has free IMAP/POP for email. Go figure.

iChat: tabs

You can have tabbed conversations, if you go into preferences. The "tabs" are really a sidebar. I don't use any of the fancy stuff so I can't comment.

UPDATE 01-Nov-2007: ichat let's you become "invisible" now. You can send and receive messages, but you don't show up as "online". excellent!

Terminal: tabs

Finally tabs. The font clarity and colors seems improved too.

Firewall: Off by Default

Leopard turns it off by default. Go into SystemPreferences:Security to turn it back on.

gcc: Still 4.0.1

It's still 4.0.1 but the build number is slightly different. boo. The reason is probably because Apple is working on a snazzy gcc replacement!

Scripting: All up to date!

Include are the latest versions of Python (2.5.1), Ruby (1.8.6), and PHP (5.2.4)!

Firefox: works, but...

It works, but only until I deleted my ~/Library/Application Support/Firefox directory. I must of had a bad plugin.


There you go. So far so good.

Wednesday, October 17, 2007

php string "startswith" let me count the ways

I bounce around between half a dozen different programming languages, so I forget all the little variations. Recently I needed to test in php if a string starts with another (a prefix). So I typed in php string startswith, expecting to get the php manual with some built-in function.

oh no. It's not built in, that's fine. It's the online advice that frightens me. In order from google:

Take 1: use strstr

if (strstr($source, $prefix) == $source)) {
    echo "'$source starts with '$prefix'\n";
} else {
    echo "'$source' does not start with '$prefix'\n";
}

Uhhh if the source does not contain the prefix, then the entire string is searched. Worse then you have to do a full string compare.

Take 2: use strpos

if (strpos($source, $prefix) === 0)) {
    echo "'$source starts with '$prefix'\n";
} else {
    echo "'$source' does not start with '$prefix'\n";
}

Marginally better. Very fast if the source does start with the prefix, very slow if it does not. Lots of confusion on how to test for false (!!!) online.

Take 4: Use substr

The first example I saw just had hardwired examples, but it was something like this:

if (substr($source, 0, strlen($prefix)) == $prefix)) {
    echo "'$source starts with '$prefix'\n";
} else {
    echo "'$source' does not start with '$prefix'\n";
}

Requires creating a new string and doing a full string comparison, however it does not scan the whole string.

Take 5: Use preg_match

good grief. My favorite was this "tip" to "check if a string starts with a specific character."

   if (preg_match('/^a/', $str)) {
                echo "String starts with an a";
   }

No comment on this one.

PLEASE READ

ok team, here it is.

function str_startswith($source, $prefix)
{
   return strncmp($source, $prefix, strlen($prefix)) == 0;
}

It fails fast, it doesn't create new strings that get thrown away, it works in all cases. Granted strncmp is a bit cryptic to people who have never used "C", but it's a of shocker that I didn't see this online.

Here's my "unit test" for it.

function mytest($source, $prefix) {
    if (str_startswith($source, $prefix)) {
       echo "'$source' starts with '$prefix'\n";
    } else {
       echo "'$source' does not start with '$prefix'\n";
    }
}

mytest("foobar", "foo");
mytest("foobar", "food");
mytest("foobar", "bar");
mytest("foobar", "FOO");
mytest("foobar", "foobar1");
mytest('', '');
mytest('', 'foo');
mytest('foobar', '');

It better output:

'foobar' starts with 'foo'
'foobar' does not start with 'food'
'foobar' does not start with 'bar'
'foobar' does not start with 'FOO'
'foobar' does not start with 'foobar1'
'' starts with ''
'' does not start with 'foo'
'foobar' starts with ''

Interview Question

Since it seems that people have trouble with this, it makes a great interview question.

Here's a list of the php string functions. Write down as many functions as you can that check to see if one string starts with another. What are the pros and cons for each method? What test cases do you need to check?

Saturday, October 13, 2007

yay, more rendering bugs in librsvg

The display: none CSS snippet does not work. The item gets rendered. Bug filed here

Tuesday, October 2, 2007

Path parsing bug in librsvg

When it rains it pours, and somehow I always get wet. Just after this bug in librsvg I find another.

From the SVG Spec, it says:

If a moveto is followed by multiple pairs of coordinates, the subsequent pairs are treated as implicit lineto commands.

So the following should be equivalent:

<path d="M0,0  1,1">
<path d="M0,0 L1,1">

In librsvg 2.18 the first version does nothing. In Firefox and Opera, both work. How can I be the first person to bump into this?

The excitement continues here.

Number parsing bug in librsvg

Why lord me

I seem to have an odd knack at finding really obscure bugs. Today's episode, librsvg which converts SVG files to PNG, appears to have number parsing bug. Good grief.

In particular, if stroke-width is between 0 and 1, and has a lot of digits, then the CSS is parsed differently than if it was defined inline with style.

<style>
.foo { stroke-width: 0.11111111111111111111 }
...
</style>
<rect clas="foo" ... >

will be parsed with a stroke of 0, i.e. invisible. While

<rect style="stroke-width: 0.11111111111111111111" ....>

is just fine. Firefox and Opera render both cases just fine.

Read all about it here.

UPDATE 02-Oct-2007: This probably a bug in libcroco which parses CSS2

UPDATE 19-Nov-2007: Yes libcroco. Read all about it here.