March 21st, 2007

Gmail snippets include ALT text for images in HTML emails

While checking my email this morning, I noticed something interesting about gmail’s “show snippets” feature. It wasn’t something that jumped out at me or anything. In fact, it didn’t really register in my mind until after I’d already clicked to view the message. The words “Bank of America Customer using a laptop” seemed a little strange. So, I went back and looked at my Inbox again, and saw this snippet:
gmail snippet: Bank of America Customer using a laptop for  Online Banking

This seemed like an odd bit of text for an email notifying me that a direct deposit just posted to my account. Sure, I am a Bank of America customer, who usually uses a laptop to access Online Banking. But they shouldn’t know that, so I clicked on the message again to see what they had to say about using laptops.

Well, the message, itself, showed no signs of the word “laptop”, but the large header image in this HTML email had a picture of a laptop in it. That’s when I realized that gmail was probably showing the ALT text for the header image! To verify this, I used gmail’s “show original” option, to view the full message source. Sure enough, the header was made up of several images, each of which had ALT attributes, and the header images appeared before any of the actual message content. The ALT text for the laptop image was, as expected, “Customer using a laptop for Online Banking”.

Apparently, to generate message snippets, gmail strips the HTML out of the message, leaving behind the ALT text from any IMG tags that appear in that code.

That makes some sense, since the ALT attribute provides a textual representation of the image content, for accessibility purposes. However, I’d bet that most of the time, images in HTML emails are not meant to be part of the content… Most of the time, they’re probably things like company logos, navigation bars (linking to different parts of a company’s website), list bullet icons, pictures of your [family member/friend]’s children, etc.

Don’t get me wrong. I’m not complaining about Bank of America’s email header, or gmail’s snippet generation method. I just thought this was interesting behavior. I have a few ideas for who might benefit from this information, and how they might use it, but I’ll have to save that for another post, tomorrow.

August 7th, 2006

A Handy CSS Debugging Snippet

From A Handy CSS Debugging Snippet:

* { outline: 2px dotted red }
* * { outline: 2px dotted green }
* * * { outline: 2px dotted orange }
* * * * { outline: 2px dotted blue }
* * * * * { outline: 1px solid red }
* * * * * * { outline: 1px solid green }
* * * * * * * { outline: 1px solid orange }
* * * * * * * * { outline: 1px solid blue }

This code, if placed in your stylesheet, outlines every element on the page with colored boxes. I like this because it’s simple, and I learned something from it. I had no idea that you could use an asterisk for a css selector. Then, the idea of stringing them together to represent the elements that are most deeply nested with different colored outlines. Pretty slick!

I will probably still use the many functions in the Outline menu of the Web Developer Extension for Firefox, and the Internet Explorer Developer Toolbar, for most of my everyday outlining-for-debugging needs. There are also bookmarklets out there to do this type of thing. But, this snippet deserves a spot in my toolbox, because it seems like it could could come in handy someday.

July 15th, 2006

perl urlencode without libs

$url = “Foo bar com.dx?q=23″;
$url =~ s/([^\w\-\.\@])/$1 eq ” “?”+”:
sprintf(”%%%2.2x”,ord($1))/eg;

print $url;

I don’t remember where I got this, but it must have come in handy for me at some point. Never hurts to have this kind of stuff laying around, just in case.

June 28th, 2006

Making System.out.println() return a String

At some point, recently, I needed to do both of these things in one little Java expression:
- output a String to stdout
- return the same String

System.out.println() returns ‘void’, and you can’t cast void to String, so I struggled with this for a little while. Here’s what I came up with (download here if it looks ugly in the blog):

public class VoidToString
{
public static void main(String[] args)
{
System.out.println(”returned value: [” +
new Object()
{
public String q(String p)
{
System.out.println(”stdout: [” + p + “]”);
return p;
}
}.q(”blah”) + “]”);
}
}


It ended up not working in the context I was trying to use it in, because the 3rd-party API I was using did not appreciate the inner class, but I still thought it was a neat little trick.

May 4th, 2006

How to list duplicate lines in a text file, with counts next to each unique line

At some point, last year (it’s been in my ‘toblog’ file all this time), I needed to analyze the lines in a text file, removing duplicate lines, while counting how many times each duplicated line occurred within the file, and sorting from most common to least common.

For example, using a text file called ‘dupetest.txt’, containing:

foo bar baz
foo qux corge
spugbrap likes bacon
foo qux corge
spugbrap likes bacon
foo bar baz
oatmeal cookies are good
oatmeal cookies are good
foo bar baz
foo qux corge
foo bar baz

The output I want is:

4 foo bar baz
3 foo qux corge
2 spugbrap likes bacon
2 oatmeal cookies are good

I knew there had to be a simple way of doing this by just stringing together a few unix commands (in cygwin), but finding the right combination of commands took me some effort. Here’s what I came up with:

sort dupetest.txt | uniq -c -d | sort -n -r