Author Archives: bill

Google Page Speed Plugin vs. Page Speed Online

Today, I took a look at Google Labs’ Page Speed Online app to check the score of one of my sites. I was shocked to find out it was scoring really low at 59/100. Pathetic in my opinion since I consider site speed a huge priority (and so does Google in fact). I had just done a site update earlier in the week, so I was thinking that I had broken something. I checked the Page Speed Plugin for Firefox (part of Firebug), and just like I remembered, we were scoring really high at 94/100. I decided to take a look at the Page Speed for Chrome to see where that plugin would score us. It wasn’t as high as Firefox, but not nearly as low as the Online version; scoring at 81/100.

So my question to Google is this: Why the difference? Aren’t they running the same rules? Which score means more to Google? Between the browsers I would assume the rules being run in Firebug instead of straight through Chrome could cause a slight difference. Also perhaps the rendering engines for the browsers could account for some difference too. If anyone knows the answer for sure and which score I should really believe, I’d love to know!

Close jQuery ColorBox on an Action

jQuery is awesome. If you use Javascript on your website, you should use jQuery. If you don’t, you don’t know what you’re missing.

Recently, on a new site I’m about to launch, I was looking for some better ways to use jQuery and ColorBox when estimating shipping charges for customers. Previously, I called out to an internal web service to do some calculations and then do a redirect with the values to display to the user. I was thinking, meh, a redirect? You really need to do that?

So I ripped it all out and started over. I basically decided I could use jQuery and element IDs to do the same thing. Hide some controls, set the html or text values of others where I wanted calculated values to show up. But the kicker was, I could easily do that from my ColorBox modal window, but I wanted it to close after hitting the submit button. Turns out this is stupid simple. From the ColorBox documentation, you can manually close the ColorBox window:


The key to making it work is to find the element that actually opened the ColorBox window. I managed to only get this to work by finding the form that owned the element that opened the window first, then get the element in question, i.e.

var myForm = $("#myForm ");
var myElement= shoppingCartForm.find('#myElement');
if (myElement!= null) {

For some reason, just doing this didn’t work:


That would have been simpler, but I got it to work and that’s all that I really cared about. Anyway, hopefully this will be useful to someone else!

Update: So it turns out, that I could simply do this too on a button:

$('#lnkButton').click(function () {

Simple and clean! Love it!

Website Speed & Performance Tuning with GTmetrix

I stumbled upon a little gem today while searching for a few more techniques to improve the performance of my ASP.NET web applications. I use YSlow and Google Page Speed almost daily, and it was great to find this website that combines the both of them called GTmetrix. GTmetrix combines both Google Page Speed and YSlow into an easy to read, tabbed, table of recommendations. Each recommendation, once expanded, offers you a list of tasks that you can complete to improve the performance of your test. What’s more, is it ranks the grouping of recommendations from Low to High so that you know what to get after first. If you’re serious about your web site’s performance, definitely check this one out!

Apple Macbook Pro Swollen Battery Problem

I get a lot of questions regarding issues I have had in the past regarding my Macbook Pro and the infamous swollen Macbook Pro battery issue. Apple won’t always warranty your battery for you, especially if your Macbook is out of warranty or older than a year. The issue is that batteries aren’t meant to last forever and depending on the battery usage and how well the battery is taken care of, they won’t replace it. There are some tricks you can use to keep your battery performance at a high level. In a nutshell, you want to charge the battery to 100%, then unplug your Macbook and let the battery run to 0% without having the Macbook plugged in. Then let it charge while in sleep mode until it is fully charged. Its pretty important to not use your Macbook Pro while its charging during this procedure.

If you are experiencing issues with your Macbook Pro battery though, I suggest you take your laptop and the battery in to your local Apple Store. Don’t bother calling Apple Support, they’ll most likely blow you off. You just want to make your Genius Bar appointment and plead your case. In my experience, I talked to the head Genius at my local Apple Store (in Natick, MA) and he took care of me. He also gave me a receipt because my new battery was under warranty for a year.

In the case that Apple won’t replace your battery, I suggest you take a look at these NewerTech NuPower batteries available at Other World Computing. They generally offer better performance and a longer life expectancy. Hope that helps!

Uploading Content to Amazon S3 with CloudBerry Labs’ S3 Explorer

I recently made the move to Amazon S3 and CloudFront to store and server static content, in particular images, for some of my e-commerce web sites. We have thousands of images to serve to our visitors, in all different sizes. To get started, I went to Google to do some searching for some quality tools. I stumbled upon CloudBerry Labs‘ application S3 Explorer and downloaded it to give it a try. Installation was a snap and fairly quickly, I was configuring my Amazon S3 account in S3 Explorer. What’s very cool about this is that you can store as many S3 accounts that you might have, storing them for use later on. To configure an S3 connection, you will need your Amazon Access Key and your Amazon Secret Key. Now it was time to upload!

Like I mentioned earlier, we have thousands of images. In fact, we have over 27,000 images. And that’s just in one image dimension size! We have 6 sizes, so that’s well over 160,000 images. That would be a bear to do through Amazon’s S3 web interface. Especially if I needed to set headers and permissions. CloudBerry S3 Explorer came in handy for this. I selected one set of images and before I started the upload, it allowed me to set any HTTP Headers I needed on my images. After that, up they went. I’d say with my connection, it took an hour or so to get all of them up to S3, depending on the file sizes. After uploading, I needed to set permissions, which I was able to do by just selecting all of the S3 objects and setting the proper permissions. This was kind of slow because CloudBerry S3 Explorer needed to get information on all of the objects I had selected, which was over 27,000.

All in all, I think it took me a couple of days to sporadically upload and set up all of our images. The beauty is now we’re serving them from CloudFront, which makes our sites quite a bit faster. A total win win for us.

A few notes about this wonderful application:

  • It’s incredible easy to set permissions on objects. They have a check box if you want to open the objects up for the world to download, which was nice for us. It would have been nice to be able to do this before upload like HTTP Headers, but I didn’t see how.
  • Very easy to set HTTP Headers and any meta data you need on your objects. And you can do it before the upload starts!

  • One thing that confused me a little was on Windows 7, when I minimized S3 Explorer, it went into my task bar and not with other minimized applications. It took me a little while to figure out where it was hiding. At first I just thought the application had crashed on me.
  • Overwriting object preserved HTTP Headers and permissions, something I was a little concerned about.
  • Moving data between S3 folders and buckets was really easy. Again, preserves HTTP Headers and permissions.

So, all in all, my impressions of this application are really good, and I was only using the Freeware version. The pro version, for only $39.99, offers the unlimited S3 accounts and multi-threading which speeds up your uploads. Other features available in the Pro version are:

  • Compression
  • Encryption
  • Search
  • Chunking
  • FTP Support
  • Sync

For more information on CloudBerry Labs’ S3 Explorer, check out their product page for S3 Explorer. Hopefully you’ll find this nifty little application as useful as I did!

Determine if Amazon S3 Object Exists with ASP.NET SDK

After my earlier posts on invalidating Amazon CloudFront objects, I thought it would be important to see if an Amazon S3 object existed before trying to invalidate it. With the 1,000 request limit on invalidation requests before Amazon charges you for them, this seemed to be a prudent thing to do. So, I turned to the Amazon Web Services ASP.NET SDK to help me out with it. This is what I came up with:

public bool S3ObjectExists(string bucket, string key)
    using (AmazonS3Client client = new AmazonS3Client(this._awsAccessKey, this._awsSecretKey))
        GetObjectRequest request = new GetObjectRequest();
	request.BucketName = bucket;
	request.Key = key;

		S3Response response = client.GetObject(request);
		if (response.ResponseStream != null)
			return true;
	catch (AmazonS3Exception)
		return false;
	catch (WebException)
		return false;
	catch (Exception)
		return false;
    return false;

I decided that if I found a valid ResponseStream on the S3Response, then I had a valid object. All I’m checking on is the object key itself, i.e. an image path in S3. Another note here is I’m checking for three different exceptions but returning false for all 3. The reason I have this coded this way for now is I wanted to see what different exceptions GetObject might throw depending on what was wrong with the request. This was done purely for testing purposes and will probably be changed in the future. For instance, I discovered that AmazonS3Exception is thrown when the object isn’t there. WebException is thrown when the object is there, but the request cannot be completed. I’m still in the testing phase with this, but I hope this helps some other Amazon Web Service developers out there.

Yahoo Shutting Down

Per this link that I read via digg, it appears so. I’ve used for years ever since Kyle turned me on to it. I don’t bookmark as many sites or pages as I should, but its always nice to know that something I’ve looked up in the past might be saved off on my account for retrieval. For instance, that’s my go to place to find a page I book marked to remind me how to backup/restore MySQL databases. Its not a thing I do every day or even every few months. Maybe once a year.

There are some alternatives out there like:

For a complete list of alternatives, you can check out this site. Some are better than others. Some are paid solutions, some are not. I will miss though. Sorry to see it go.

Finding Duplicate Row Values with SQL

Every once in a while I have the need to find duplicate row values in a SQL table. I seem to forget how to do it each time since its not something I have a use for every day, so I thought I’d record it here and share. The solution I found was here:

Basically, the SQL code is as follows:

SELECT ColumnName, COUNT(ColumnName) AS ColumnNameCount
	FROM MyTable
GROUP BY ColumnName
HAVING (COUNT(ColumnName) > 1)

That’s it, enjoy!

MacBook Pro 17″ Quick Blinking Status Light

I had quite the freak out moment this morning regarding my 17″ MacBook Pro (Duo 2.16GHz model). During the course of the morning I had to reboot the darn thing, but after the restart, it never came back up. Just a black screen. Then I noticed that the white status light on the lid clasp was blinking rather quickly. I’ve never seen that before so I started to panic. Especially when I couldn’t get it to boot even when plugged into the charger.

A quick search of Google made me really freak out. Most people seem to suggest that the quick blinking light means that the logic board (motherboard for those PC users out there) has an issue. Ugh, not the logic board. That’s an expensive repair typically and sometimes just worth it to buy a new system. So, I made sure the laptop was unplugged and dropped the battery out of the MacBook and let it sit a couple minutes. Then I put the battery back in and plugged it in and it turned back on. Phew. Good news is I just did a reinstall recently and had backed up ALL of my data. Bad news is that my MacBook is probably on its last legs. Hopefully it lasts through 2011 as I haven’t planned on purchasing a new one.

Adding an Image to a PDF Document Using C# and PdfSharp

A while back I wrote about generating PDF documents using PdfSharp. It worked really well for us to generate invoices and purchase orders on the fly to ship orders and receive product. One must on our invoices was showing our corporate logo on our invoices that went out to our customers. We also wanted to do the same on the documents we generated for our purchase orders so that our vendors could easily identify our company when processing the order. This turned out to be a snap using PdfSharp.

void AddLogo(XGraphics gfx, PdfPage page, string imagePath, int xPosition, int yPosition)
    if (!File.Exists(imagePath))
	throw new FileNotFoundException(String.Format("Could not find image {0}.", imagePath));

    XImage xImage = XImage.FromFile(imagePath);
    gfx.DrawImage(xImage, xPosition, yPosition, xImage.PixelWidth, xImage.PixelWidth);

    PdfDocument doc = new PdfDocument();
    PdfPage page = doc.AddPage();
    XGraphics gfx = XGraphics.FromPdfPage(page);
    AddLogo(gfx, invoice, "pathtoimage", 0, 0);
catch (Exception)
    // Handle exception

The arguments to DrawImage on the XGraphics object specify an XImage object, the starting position of the image (0, 0 in this case), and the dimensions of the image. You can get the dimensions easily from the PixelWidth and PixelHeight properties (the Width and Height properties can be used, but are deprecated) of the XImage object.

Then call the AddLogo() method above to draw your image in the document. Positioning and image dimensions are important to get correct otherwise the image won’t draw properly in your document. Keep track of where you place your logo when drawing text or additional images on your document as well. If you don’t keep track of positioning from element to element, you’ll actually draw over previous elements.