Html

position:relative

I started this morning learning something I should have known for ages. I have been coding HTML for well over a decade, and CSS for nearly a decade. I have even taught HTML and CSS both at the University of Bergen and for student groups at Bergen University College.

Of course, that’s no guarantee of how much I actually know about the subject, but I think I have a pretty good knowledge of HTML and CSS. Even then, how position:relative actually works has managed to slip completely under my radar. I find this rather embarrassing, but I write about it here, because if I haven’t managed to get this before now, there is probably several other webdevelopers that also don’t know this (I hope).

The functionality of position:relative is not complicated, it’s actually very simple, you just have to know this.

Merkelapper

De observante der ute (og som ikke bare leser bloggen min fra rss-leseren sin) kan ha oppdaget at merkelappene på bloggpostene har fått et nytt utseende. Det begynte egentlig med at jeg så på en post jeg hadde skrevet og tenkte “Hm, de taggene der ser ikke ut som om de egentlig hører hjemme der”. Videre tenkte jeg, hva skal jeg gjøre for å få dem mer inn i det visuelle uttrykket på bloggen.

CSS foredrag

Foilsett med notater til CSS-foredraget avholdt for Bergen Teknikersamfund 2. Februar 2009 er tilgjengelig her. Jeg glemte å nevne hvordan en faktisk kobler sammen stilarket og html-dokumentet. En kan enten putte stilarket i head-delen av HTML-dokumentet, inni en blokk. For eksempel: <style type=“text/css”> a { text-decoration:none; color:#FF0000; } </style> Eller, dere kan (helst) ha stilarket i en fil, da refererer dere til stilarket med en tag som denne: <link rel=”

HTML foredrag

the right tool for the job

So, you’re going to parse a webpage, to extract some information. For instance if you want to get the tracking information for your last online order, and you want to display the tracking information changes using growl, dbus notifications or xosd.

You know regular expressions, so you go to the job with your long range missiles ready. But wait a minute, you’ll probably solve the problem but is regular expressions really the right tool?

The pro for regular expressions is that you can use the same tool you always use for parsing jobs, but then again you doesn’t learn anything new out of this. You might fortify your position as regex wizard even more, but how about something completely different?

Now. Most webpages is written in HTML, and some even in XHTML, for HTML documents languages like Python has a built-in parser, after the model of the SAX-parser. (It’s probably the other way around, the SAX parser is built on the base of the HTML parser…) Most programming languages has good support for XML, so for XHTML documents, you can use the HTML-parser, a SAX-parser or even the XML-DOM parsers.

The benefit of doing it this way is that your parser will probably be more robust to minor changes in the webpage. You don’t reinvent the wheel (The best way I’ve found to parse HTML documents using regular expressions is to make a specialized SAX-like parser anyway). Your code will probably be readable in a year, and others might even be able to understand your code. And finally, you learn something new, which might give you a fresh view on a lot of problems.

Now back to the original issue, to make a parser for the parcel tracking of your postal service. Here’s an example parsing the shipment tracking page of posten, the norwegian postal service.

Upgrading WordPress to 2.5

My bookshelf

For nerdene blandt oss

Charset

Mange undervurderer viktigheten av charset taggen på nettsidene sine. (<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />) De klipper ut denne taggen fra en annen nettside, og limer den inn i sin, for at siden skal validere. Og, ja, den validerer, men feil tegnsett kan føre til at æ, ø og å (++) ikke vises korrekt i andre OS. Dersom en bruker windows kan det hende at iso-8859-1 kan føre til det samme problemet for brukere av andre OS.