Friday, February 29, 2008

Help, my layout isn't centering!!1

It seems that this week, everyone and their dogs are asking me why their layouts aren't centering properly (when using the "margin:0 auto" css rule). Here's a quick list of reasons:

  • There's no doctype in the page. This causes IE to render in quirks mode. There are plenty of discussions on the web about why the quirks mode box model sucks, this is one of the reasons. Another variation of this is when there is an xml prolog on the page (the '<?xml version="1.0" ?>' stuff at the beginning of xml documents, which incidentally, also triggers quirks mode in IE. To fix it, add the doctype and remove the xml prolog.
  • There's no width on the div. The element taking the margin rule must have a quantifiable width (i.e. anything valid that is not "auto").
  • You have stray styles taking over. Open up the css inspector in Firebug and make sure that the div isn't floating (i.e. it must have no float rule, or have "float:none" applied to it) and that it's a block level element (i.e. it must have no display rule, or have "display:block" applied to it)
  • The parent element is too narrow. Make sure you don't set the width of the parent to something smaller than the div you're trying to center.

And no, "margin:auto auto" does not center stuff vertically.

More stupid security

View source on this page for a good laugh.

Thursday, February 28, 2008

Dee-dee-dee-dee

Is it my impression, or is D getting a fair amount of of attention lately?

Commenting tricks

Neat commenting trick, especially if you use a no-frills text editor, or can't be bothered learning the shortcuts for the dozens of editors you use.

I've actually used this myself for a long time. The only annoyance is that it doesn't work so well in CSS if you want to quickly comment out an entire stylesheet (or large portions of it) while debugging something.

Saturday, February 23, 2008

This is how NOT to do CAPTCHAs

Go here and try downloading a book. You'll get a CAPTCHA before the download. No biggie. Now try refreshing the page or download another book.

It's the same CAPTCHA! Talk about lame.

Hard drive encryption is broken

By cooling the DRAM, researchers can retain the logic state in the chip even without power.

It's becoming increasing difficult to protect data where untrusted parties have physical access to a machine.

Friday, February 22, 2008

Fun strip of the day

This is so cool.

IE8 User Agent String

Sites will break, people will complain. I think the IE team should put more thought into versioning in the javascript realm if they are really committed to "not breaking the web".

Thursday, February 21, 2008

More slickspeed results

Mootools added Dojo to their slickspeed benchmark page. DOMAssistant has its own benchmark page.

What's interesting to notice is that each library does well in Firefox, but not so much in IE6.

Wednesday, February 20, 2008

Mobile AJAX Performance

This is a very interesting research paper, about the perfomance and support of ajax libraris on new generation mobile devices.

Tuesday, February 19, 2008

Perls of Wisdom

You wouldn't believe how often I've seen this sort of stuff.

Microsoft giving away software

Microsoft is doing a massive software giveaway program, which is essentially the same thing hackers and pirates have been doing for ages.

Leaving the politics and business model discussions aside, this is definitely a good deal (even if you're a Microsoft hater).

Motorola acquires Soundbuzz

Motorola is up to something interesting here.

Versioning... again.

Jeffrey Zeldman and Jeremy Keith are at it again.

I'm not sure what's so bad about adding an extra meta tag to a document (other than bandwidth considerations), it's not like existing sites aren't full of extraneous IE-only code anyways.

Monday, February 11, 2008

XPath selectors pros and cons

John Resig wrote a nice piece on this latest trend in css selector libraries.

Friday, February 8, 2008

Thursday, February 7, 2008

Benchmarking noise

John Resig posted a neat article about the importance of eliminating the largest amount of variables possible from benchmarking tests, since things like hardware and poor data aggregation can skew results significantly.

Tuesday, February 5, 2008

silliest compiler in the world

Today, I wanted to try to write a compiler in D and this is what came out:

import std.stdio;

char[] filename = "test.com";
ubyte[] source;

void main()
{
 source ~= [0xB4, 0x02];//mov ah,02 ;set parameter stdout
 source ~= [0xB2, 0x61];//mov dl,'a';set parameter 'a'
 source ~= [0xCD, 0x21];//int 21    ;print 'a' to stdout
 source ~= [0xCD, 0x20];//int 20    ;exit program

 FILE* handle = fopen(cast(char*) filename, cast(char*) "wb");
 fwrite(cast(void*) source, ubyte.sizeof, source.length, handle);
 fclose(handle);
}

This program compile a puny 8 byte DOS executable that displays an "a" on the console screen. It's not very exciting and has no frontend, but for anyone interested in writing compilers, it's easy to see the next steps (namely writing a file reader and a parser to generate the source byte array from a more programmer-friendly asm source file).

More optimization goodness

The folks over at PBWiki ran a benchmark to test loading speeds for various libraries.

It's interesting to note that Dean Edwards' Packer doesn't necessarily make code load faster, since it incurs the eval overhead. As a matter of fact, the minified version (using Yahoo's minifier) runs faster.

Another thing that is worth mentioning is how much caching plays a role in speed optimization.

Monday, February 4, 2008

Javascript trim optimization

Simon Willison dug up this really neat article on trim and regex speed optimization.