“The art of the connection is the end result of a nerd’s highly obsessive due diligence performed on anything that falls into the relevant bucket.”
“Quit iTunes 10, and enter defaults write com.apple.iTunes full-window -1 in a Terminal prompt. Relaunch iTunes and—voilà!—the standard window controls return.”
“[anthropologist Susan D. Blum] contends that undergraduates are less interested in cultivating a unique and authentic identity — as their 1960s counterparts were — than in trying on many different personas, which the Web enables with social networking.”

IE6 and CSS media types

When trying to reduce the number of HTTP requests on a web project I was working on, I tried to combine my screen and print stylesheets into a single file. Using the @media declaration, one should be able to specify media-specific styles. Other browsers were ok, but as usual IE6 was playing up. My @media print block was completely ignored.

The setup

First, I had only generic rules and a single print block, like so:

body { font-size: 12px }
@media print {
    body { font-size: 14pt }
}

Then, I included the stylesheet on my page with a media type:

<link rel="stylesheet" href="styles.css" media="screen, projection">

As I understood the specs all generic styles (outside the @media print block) should apply to the media specified in the link, while the print-specific styles should apply only to the print media type.

The solution

It seems the media type from the link overrides the @media print block in IE6, so removing that un-ignored those styles:

<link rel="stylesheet" href="styles.css">

Then, in order to keep my generic styles (which are actually screen-only styles) from influencing my print styles, I used another @media block:

@media screen {
    body { font-size: 12px }
}
@media print {
    body { font-size: 14pt }
}

All was well and both my screen and print styles were picked up nicely. Now I could use one single stylesheet and remove one additional HTTP request, speeding up the site loading time.

Modifying Subversion commit messages

Sometimes when I try to quickly repeat my last command in the terminal, I end up firing off a svn commit. Unlike with Git, you cannot modify commits in Subversion, but you can modify a revision’s properties — like the log message.

Here’s how:

svn propedit --revprop -r 1234 svn:log

This will open your $EDITOR and it lets you edit the log message for the specified commit (1234).

Note: in order to make this work, you repository needs to be configured correctly. This means you should rename /path/to/your/repo/hooks/pre-revprop-change.tmpl to /path/to/your/repo/hooks/pre-revprop-change and chmod +x it.

Using relatedTarget in event handlers

Here’s a nice trick for working with mouse events in a web page. Given a simple drop down menu, I used to use a timer to delay the closing of a submenu while the mouse travels from the menu title to the sub menu (where it nog longer hovers over the menu title, that had the original event handler). The timer going off would hide the submenu, unless the mouse entering the submenu fired a new event handler that would reset the timer.

So, yeah, that wasn’t ideal.

I learned the other day that, given adjacent element you can actually use event.relatedTarget to get to the element the mouse travels to when leaving the element that fired the mouseout event. Neat!

Now you can check for the target element and do all kinds of nifty stuff, and get rid of all timers. They sucked anyway.

Example jQuery code:

$('nav a').mouseout(function(e) {
    var submenu = $('.submenu', this.parentNode);
    if(e.relatedTarget != submenu) {
        submenu.slideUp();
    }
});

Quick text manipulation with Ruby

Here’s a nice trick I like to use to quickly transform some random piece of text using Ruby and Textmate:

string = DATA.read
# do stuff here...
__END__
Text to transform goes here

By using the __END__ line you tell Ruby to not executre all that follows, but capture it in an IO which you can read. You can then quickly whip up a script and have Textmate run it using ⌘R. The script’s output can then be copied and pasted.

I use this all the time to transform plain text into HTML, crunch some numbers or filter some text. Think of it as a ‘filter through command’ (⌥⌘R) on steroids.

Here’s a quick example to convert ugly plain-text fractions in an HTML page to pretty entities:

input = DATA.read
{ 
  '1/2' => '&frac12;',
  '1/4' => '&frac14;',
  '3/4' => '&frac34;'
}.each_pair do |plain_text, html_entity|
  input.gsub!(/\b#{plain_text}\b/, html_entity)
end
puts input
__END__
1/2 an egg and 1/4 pint of milk
Use Kaleidoscope to spot the differences in text and image files. I like it better than Changes.

Use Kaleidoscope to spot the differences in text and image files. I like it better than Changes.

Open Mail window

Here’s something that has annoyed me ever since I got a Mac: when switching applications using the keyboard (e.g. ⌥-Tab), choosing Mail would not actually open a window if there wasn’t one open already. It seemed this was only good for switching to windows, not applications.

Although this bugged me, I never got round to finding a solution, until now. It struck me that you can switch between mailboxes using ⌘ and a number key. So ⌘1 will actually open my Inbox nicely.