Meet our living room

March 13, 2010 at 1:41 pm (Personal)

Our living room is still not entirely complete but it is close to being there so I wanted you to see the progress. Click on the image below to view more photos:


I also wanted to thank all the friends that helped us move into our home. The money we saved from the move is the one we used to purchase the living room sofas. Thank you for the perfect house warming present! We hope to see you guys using them a ton =)

And this is for my friends and family in Guatemala that are not used to snow. It was snowing when I took the living room pics so I took a quick video:

And a picture:


Permalink Leave a Comment

C# ASP.NET: Generating Image Buttons with Dynamic text

March 11, 2010 at 2:34 pm (Computer Science)

After writing several websites with custom buttons. I’ve had it with having to create images for each button that has a different text!

If you feel the same way then you’ll love this solution. With the code below you’ll be able to create a button.aspx page that takes a “t” url query parameter where you can specify the text and it will return the desired image. Here are some usage examples:!” will give you:” will give you:” will give you:

Even though the links to the image are not your usual *.png or *.jpg, the button.aspx page returns an image (content type image/x-png or image/jpeg) so it is OK to do the following in your aspx code:

<asp:ImageButton runat="server" ID="btnFormBack" ImageUrl="button.aspx?t=Continue" />


<a href="targeturl.html"><img src="button.aspx?t=Continue" /></a>

Pretty cool ha!

Well, and now to the code. This is your button.aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="button.aspx.cs" Inherits="controls_button" %>
<%@ OutputCache VaryByParam="m;t" Duration="9123123" %>

And your button.aspx.cs file:

public partial class controls_button : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        var text = this.Request.QueryString["t"];
        if (string.IsNullOrEmpty(text))
            throw new ApplicationException("The text url parameter must be specified");

        var sMirror = this.Request.QueryString["m"];
        bool mirror = (!string.IsNullOrEmpty(sMirror) && sMirror == "t");

        var rightImageWidth = 10; // in pixels
        var imageHeight = 42;
        var topPadding = 11; // top and bottom padding in pixels
        var sidePadding = 10; // side padding in pixels
        var textBrush = new SolidBrush(Color.White);
        var font = new Font("Arial Black", 11);

        //-------- Calculate the text's width
        // this graphics and bitmap object is just temporary. I could not 
        // find a way to calculate the text' width witout having one.
        var bitmap = new Bitmap(300, 300);
        var graphics = Graphics.FromImage(bitmap);
        var textSize = graphics.MeasureString(text, font);

        //-------- Create the graphics object
        var bitmapWidth = sidePadding * 2 + (int)textSize.Width;
        bitmap = new Bitmap(bitmapWidth, imageHeight);
        //bitmap = new Bitmap(500, 40);
        graphics = Graphics.FromImage(bitmap);

        // Draw the background
        var leftImage = System.Drawing.Image.FromFile(this.Server.MapPath("~/resources/button-left.png"));
        var rightImage = System.Drawing.Image.FromFile(this.Server.MapPath("~/resources/button-right.png"));
        graphics.DrawImage(leftImage, 0, 0, bitmapWidth - rightImageWidth, imageHeight);
        graphics.DrawImage(rightImage, bitmapWidth - rightImageWidth, 0, rightImageWidth, imageHeight);
        // These disposes are necessary, otherwise the files get locked 

        if (mirror)

        // Draw the text
        graphics.DrawString(text, font, textBrush, sidePadding, topPadding);

        //-------- Serve the Image

        this.Response.ContentType = "image/x-png";
        // The line below breaks on the production and development servers
        // (it does not break on my computer). I was getting the following
        // vague exception "A generic error occurred in GDI+". I found this 
        // post that showed
        // me the work around . In short it says
        // that some image formats (like Png) require a seekable stream when 
        // saving. The Response.OutputStream is not seekable so we
        // have to use a MemoryStream as an intermediary.
        //bitmap.Save(this.Response.OutputStream, ImageFormat.Png);

        var memStream = new System.IO.MemoryStream();
        bitmap.Save(memStream, ImageFormat.Png);

        // Some cleanup, not sure if it is all needed

And you also need to have these images in the ~/resources folder of your website. If you want to have them in another folder, update the .cs code.

~/resources/button-left.png :

~/resources/button-right.png :


Permalink 1 Comment

Bike Season is around the corner!

March 3, 2010 at 9:15 am (Personal)

Last night I finished putting together my mountain bike and tuned my commuter bike.

My mt bike now has new Mavic Crossline rims and shimano XTR pedals. Hopefully i don’t get more broken spokes. And I got the pedals so that I could have my two bikes with spd pedals and could use the same shoes on both bikes. I moved the old pedals from my mt bike to my commuter bike.

We’ll see how long the commuter bike holds the training. I might end up getting a road bike. But at least I’ll start training with what I have.

We’re heading to St. George this weekend. The weather will be warmer for sure, but it might be rainy. Hopefully we can do some mountain biking on the red rock desert, some road biking with great scenery, and some trail running.

Permalink Leave a Comment


Get every new post delivered to your Inbox.