How to vertically align an image within a div. Again.

Posted by Maciej Kołodziej Fri, 25 Jan 2008 11:44:00 GMT

Yeah, so the topic is old, all right. One can find hundreds of articles on the web. Nevertheless, I spent a few hours yesterday looking for an elegant and simple solution to this problem.

I wanted to:

  • center an image of an unknown size (but of known maximum size) within a div element
  • simple implementation in pure CSS, no tables
  • cross-browser compatibility on all major browsers

I found one solution on Webmaster World forum. It worked on IE, but not in Firefox. After some more research I added a hack proposed by Nicholas Gagne and now it seems to work on both browsers:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style type="text/css">
    div {line-height:150px; text-align: center; width: 150px; 
         font-size: 150px;}
    img {vertical-align:middle;}
    *>div{font-size:12px;}
    </style>
  </head>
  <body>
    <div style="border:1px solid gray;">
      <img src="/images/examples/test.jpg">
    </div>
  </body>
</html>

Pay attention to the DOCTYPE declaration: it has to be strict XHTML. It doesn’t work with transitional in Firefox. You can replace the line-height, width and font-size of course, just keep the “vertical” pixel sizes the same - width can be different.

I tested it in IE6 and Firefox 2.0.0.11

Using IMAP to migrate email messages to GMail

Posted by Maciej Kołodziej Mon, 21 Jan 2008 14:51:00 GMT

Many people on internet forums are asking how to migrate their mailboxes from desktop email clients to GMail. I tried to do it myself today and it seems that the easiest solution is very hard to find on the web.

It appears that with the current GMail version supporting IMAP, you no longer need external tools like gExodus or Google GMail Loader. All you need is your desktop email client supporting IMAP. Thunderbird for example does support it, so to migrate all your messages you need to:

  1. Enable IMAP in your GMail settings
  2. [optional] Create label(s) in GMail for your imported messages
  3. Configure Thunderbird to access GMail account using IMAP - any of previously created labels will appear as folders in Thunderbird
  4. Move or copy your messages to All Mail folder or any of the label folders

That’s it! All the information in your messages will be preserved (including dates) and if you copy/move them to the labeled folders they’ll be automatically labeled in GMail.

Useful URLs for RoR 2.0

Posted by Maciej Kołodziej Tue, 18 Dec 2007 11:17:00 GMT

I spent last evening coding a new web app in RoR 2.0 till 2 a.m. This is fantastic how smooth and enjoyable the experience is. Although I had previously coded a few other apps in RoR and I loved it too, this time it was even better.

I feel it’s mainly because I found a ton of great tutorials and documentation I didn’t have previously. And although I own the 2nd edition of the Rails book it doesn’t cover the RESTful features deeply enough and this is the killer feature in 2.0.

Here’re some URLs that I think are worth sharing:

Hope it’s useful!

Eric Sink on Eclipse

Posted by Maciej Kołodziej Wed, 28 Nov 2007 16:50:00 GMT

Eric Sink, a die hard “Microsoftie”, is writing a series of articles on his experiences with Eclipse. Boy, it feels like a teacher prising my kid :). I didn’t think I’m one of those who feel so attached to their tools of choice :)

Tungsten T3 and Motorola V3

Posted by Maciej Kołodziej Thu, 23 Aug 2007 07:22:00 GMT

My collection of gadgets isn’t as impressive as Scott Hanselman’s is, but I’m constantly working on it, so last week I bought a Palm Tungsten T3. Yes, I know it’s not the latest and greatest, but it’s perfectly fine for me. It has a good calendar obviously, but also Bluetooth on board, which means email and web browsing work seamlessly (well, almost). It also has a 400 MHz CPU so it can play good quality MP4 videos on its wide screen. And I bought it for around $180 with a complete set of accessories that come in the original box.

I wrote “almost” about the connectivity part though, because of one little hiccup, which you probably won’t notice, unless you own a Motorola V3 (RAZR). Configuring a GPRS Internet connection over Bluetooth with this phone was a nightmare. Even though I had the latest drivers from Palm. They worked fine for the SMS/dialer part, but not for the GPRS modem part.

After two days of searching the Internet (I did the mistake of looking for a general solution, not the V3 specific one) it finally works, thanks to a post on Palm forum.

So, in short, here’s what you need to do. The settings I used are for polish provider Era GSM, so where I typed erainternet, you should put something specific to your provider; same for the DNS.

  1. Create a new connection on the Palm: go to Prefs -> Connection -> New and configure as follows:

    Name: LAN V3 (or whatever)
    Connect to: Local Network
    Via: Bluetooth 
    Device: (tap to find, select your phone, follow the guidelines)
    
  2. Go to Prefs -> Network -> New and type

    Service: Dialup Connection (or whatever) 
    User name: erainternet 
    Password: erainternet 
    Connection: LAN V3 (the one you created above)
    

    Select “Details” and and set it to:

    Connection type: PPP 
    Idle timeout: Never 
    Query DNS: (unchecked and put 213.158.194.1) 
    IP Address: (checked) Automatic
    

    Select “Script” and enter the following:

    Send: at+cgdcont=1,"IP","erainternet" 
    Send CR: 
    Send: ATD*99# 
    Send CR: 
    End:
    

You’re done.

If you want to use your Palm to send SMSs or use Dialer, add another connection, this time configuring it as Phone and using Universal Phone Driver.

Rails: Two Models in One Form

Posted by Maciej Kołodziej Tue, 24 Apr 2007 07:31:00 GMT

Note to self: On Rails Forum RyanB gives a good example on how to handle two models in one form when creating or editing.

Book recommendations

Posted by Maciej Kołodziej Tue, 31 Oct 2006 15:02:00 GMT

I plan to add a separate page with book recommendations but for now I’ve created the sidebar with titles I’m currently reading.

Just added Practical Common Lisp (I came back to this book after a short brake - you can use Lisp in a Box with it) and Concrete Mathematics. The latter is part of my quest to refresh my math knowlege - I’ll be writing more about that soon.

Dynamic Drive CSS Layouts

Posted by Maciej Kołodziej Tue, 31 Oct 2006 10:30:00 GMT

Check out those pure CSS page templates from Dynamic Drive.

Pick your fixed/fluid version and column layout and download!

CSS page templates