Home ::  Admin

chris carter's web log

Save the cheerleader, save the world...

7:2 PM Monday Oct 30, 2006 Comments: 0

My favorite new TV show is Heroes(it's on right now). Great plot, probably guaranteed to not get past season 1, oh well.

curvy goodness

8:19 PM Friday Oct 27, 2006 Comments: 0

Today I found a a great JavaScript library that makes doing rounded corners a breeze.  curvyCorners is a free JavaScript library that helps people like myself who suck at graphics(that is, I couldn't make a simple rounded corner image if my life depended on it).  Here is all of the code needed to make simple rounded corners:

<html>
    <head>
        <script type="text/javascript" 
            src="scripts/rounded_corners.inc.js"></script>
        <style type="text/css">
        .roundedbox { 
            border: 3px solid silver; 
            width:200px;
            height:200px; 
        }
        </style>
        <script type="text/javascript">
        window.onload = function(){
            settings = {
                tl: { radius: 20 },
                tr: { radius: 20 },
                bl: { radius: 20 },
                br: { radius: 20 },
                antiAlias: true,
                autoPad: true,
                validTags: ["div"]
            }
            new curvyCorners(settings, 'roundedbox').applyCornersToAll();
        }
        </script>
    </head>
    <body>
        <h2>Rounded Corner Demo</h2>
        <div class='roundedbox'></div>
    </body>
</html>
 

View the live demo here

Check out the curvyCorners site for more details and examples and an example of the usage.

Pet Peeve: Not "using" IDisposable

9:51 PM Thursday Oct 26, 2006 Comments: 0

I am amazed that I see very little usage of the using statement in c# code.  This is a nobrainer for clean code, but continually I see people rolling their own try catch blocks around candidates for using statements.

    <p>Take the <b>System.Data.SqlConnection</b> for example.    I constantly see alot of the following style of coding:<pre><span style="color:#0000FF">string</span> connectionString = &quot;<span style="color:#8B0000">your connection string</span>&quot;;

SqlConnection cn = null; SqlDataAdapter da = null; DataTable dt = new DataTable();

try{ cn = new SqlConnection(connectionString); da = new SqlDataAdapter("select * from sometable", cn); da.Fill(dt); }finally{ if(cn != null){ cn.Close(); } } ...which is easily rewritten as the following:

string connectionString = "your connection string";
DataTable dt = new DataTable();
using (SqlConnection cn = new SqlConnection(connectionString))
using (SqlDataAdapter da = new SqlDataAdapter("select * from sometable", cn)){
  da.Fill(dt);
}
The IL that's generated from the using statements looks like this:
  .try
  {
    IL0014:  ldstr      "select * from sometable"
    IL0019:  ldloc.2
    IL001a:  newobj     instance void [System.Data]System.Data.SqlClient.SqlDataAdapter::.ctor(string,
                                                                                                class [System.Data]System.Data.SqlClient.SqlConnection)
    IL001f:  stloc.3
    .try
    {
      IL0020:  nop
      IL0021:  ldloc.3
      IL0022:  ldloc.1
      IL0023:  callvirt   instance int32 [System.Data]System.Data.Common.DbDataAdapter::Fill(class [System.Data]System.Data.DataTable)
      IL0028:  pop
      IL0029:  nop
      IL002a:  leave.s    IL003e
    }  // end .try
    finally
    {
      IL002c:  ldloc.3
      IL002d:  ldnull
      IL002e:  ceq
      IL0030:  stloc.s    CS$4$0000
      IL0032:  ldloc.s    CS$4$0000
      IL0034:  brtrue.s   IL003d
      IL0036:  ldloc.3
      IL0037:  callvirt   instance void [mscorlib]System.IDisposable::Dispose()
      IL003c:  nop
      IL003d:  endfinally
    }  // end handler
    IL003e:  nop
    IL003f:  leave.s    IL0053
  }  // end .try
  finally
  {
    IL0041:  ldloc.2
    IL0042:  ldnull
    IL0043:  ceq
    IL0045:  stloc.s    CS$4$0000
    IL0047:  ldloc.s    CS$4$0000
    IL0049:  brtrue.s   IL0052
    IL004b:  ldloc.2
    IL004c:  callvirt   instance void [mscorlib]System.IDisposable::Dispose()
    IL0051:  nop
    IL0052:  endfinally
  }  // end handler
What this means is that by incorporating the using statement in your code the compiler will generate the necessary try...catch blocks to make it work safely.

    <p>This is taken from the <a title="SqlConnection documentation" href="http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx">MS docs on SqlConnection</a>:<b>To ensure that connections are always closed, open the connection inside of a using block, as shown in the following code fragment. Doing so ensures that the connection is automatically closed when the code exits the block.</b></p>
    <p>
    		<b>
    				<br />
    		</b>
    </p></p>

Dirty Programmers

7:23 PM Wednesday Oct 25, 2006 Comments: 0

Funny post about a comparison of languages and number of F*cks per programming language and licenseGoogle Code Search is kinda cool, but I'm still a fan of koders and every so often codekeep comes in handy too.

Emmitt Stats

9:13 PM Monday Oct 16, 2006 Comments: 0

  • Born: 9:57 AM 10/14/2006
  • Total Labor Time: 8 minutes
  • Weight: 6 pounds 6 ounces
  • Length: 19.5 inches
  • 10 Toes
  • 10 Fingers
  • Good Lookin(like his daddy)

More Emmit Video

9:6 PM Monday Oct 16, 2006 Comments: 0

Digital Media Converter continues to amaze me(although I'm probably easily amazed at this point).  I have another video of the little Gladiator here, it was originally 23 megs and the Digital Media Converter brought it down to about 5.8 megs with "good enough" quality.  Very cool. 

Pics of the little Gladiator

7:20 PM Saturday Oct 14, 2006 Comments: 0
mommy and emmittmommy, daddy, and emmittdaddy holding emmitt

Emmitt Maximus Carter

10:14 AM Saturday Oct 14, 2006 Comments: 0

No Way

9:51 PM Friday Oct 13, 2006 Comments: 0

He was supposed to come tomorrow, but looks like my new baby wants out NOW! We're off to the hospital, wish us luck!!

ActiveRecord Noob

7:54 PM Friday Oct 13, 2006 Comments: 0

"Hi everyone. My name is Chris, and I'm an ActiveRecord noob."

I've been avoiding adding "tags" to my posts due to my perceived complexity of how to achieve this with  ActiveRecord.  Funnily enough, this was pathetically simple, so simple it made realize that I know very little about ActiveRecord.

Expressing, well actually using, a many to many relationship is intuitive. I have a Post class and I have a Tag class, each maps to a table with the same name.  They are associated to each other like this:

[ActiveRecord]
public class Tag : ActiveRecordBase {
    private IList _tags;
    [HasAndBelongsToMany(typeof(Tag), 
        Table = "post_tag", 
        ColumnRef = "tag_id", 
        ColumnKey = "post_id")]
    public IList Tags {
        get	{
        	return _tags;
        }
        set	{
        	_tags = value;
        }
    }
}

[ActiveRecord]
public class Post : ActiveRecordBase {
    private IList _posts;
    [HasAndBelongsToMany(typeof(Post), 
        Table = "post_tag", 
        ColumnRef = "post_id", 
        ColumnKey = "tag_id")]
    public IList Posts{
        get	{
        	return _posts;
        }
        set	{
        	_posts = value;
        }
    }
}

There is an association table named post_tag that just has the columns post_id and tag_id.  I never touch this, ActiveRecord and NHibernate take care of the details.  When I roll my own sql code, I usually end up deleting all associated tags with a post, and then adding back just the tags that are currently associated with the post.  ActiveRecord let's me do essentially the same thing but I just use the objects.  The following code does essentially the same thing:

post.Tags.Clear();
bool createIfNotFound = true;
post.Tags.Add(Tag.FindByName("JavaScript", createIfNotFound));
post.Save();

Slash does VW

9:11 PM Monday Oct 9, 2006 Comments: 0

This is awesome, just saw it tonight on the TV and of course was able to find it on YouTube, Slash, former guitarist for Guns, is promoting VW.  I was gonna post a link to Guns and Roses but the first couple I looked at only, had the new band(which does not include Slash) and therefore does not exist in my mind :)

FreeTextBox + Scriptaculous + Prototype Window Class = Goodness

8:38 PM Monday Oct 9, 2006 Comments: 0

Recently, I've needed to add some functionality that includes the FreeTextbox control and modal windows.  One of the things I've needed was to for this blog; I needed to be able to insert a reference to a code snippet easily.  While I'm typing, like now, I want to be able to click a simple button, pull up a window and search for a snippet by description.  This involves displaying a window modally, showing a textbox and using the autocompleter concept to search for snippets.  The example I'm posting here, which you can also test drive here, shows a simple custom button(the one that looks like this ) added to the FreeTextBox control, that displays a modal window and allows a user to search for something.  The example has "stupid" data, 10 items in the list that are always returned no matter what's typed in, but the possibilities could be anything(ie. a database query or a webservice query). 

Killswitch Engage - As Daylight Dies

5:16 PM Monday Oct 9, 2006 Comments: 0

New album is not out yet but they released the single with almost the same name as the album, you can listen to it here.  Hopefully I'll be able to make the show in Colorado Springs at The Black Sheep, Nov 17.

First Screencast Is Up!

7:10 PM Sunday Oct 8, 2006 Comments: 0

OK, figured out the avi compression a little better. Tried out a few apps that convert video formats and settled on Digital Media Converter.  One attempt compressed my 290 meg avi file down to about 6 megs, but the quality wasn't great, so I bumped it up a little bit, and settled on 22 megs.  I still have a lot to learn on video compression though, totally new concept for me.

Anyway, here is the build provider demo(remember, it's about 22 megs), again, it's just a proof of concept(so be gentle on the critique), but this site is using it so I know it(the concept anyway) has possibilities.  Here is an updated download of the code, it includes the source for the activerecord buildprovider and a sample website.

Grrrr...Screencast Bloat

1:57 PM Sunday Oct 8, 2006 Comments: 0

Apparently, there's more to screencasting than just pressing record. I have my first one ready to post. The problem is that it's just under 6 minutes long but the file size is around 290 megs! So, right now, some  avi to mpeg conversion software is crunching away on the video, hopefully this will bring the size to a more reasonable level.

I've also just realized that screencasts, presentations in general are a lot harder than I thought.  The whole practice of "winging it" sort of goes out the door, it takes too much time.  I've been working on this screencast since yesterday, and have rebuilt the demo code and re-recorded the presentation dozens of times.  I thought it would be cool to show all of the steps involved in not using the buildprovider code and then showing what it's like with the buildprovider, but I got bored watching myself type, so for the most part I've reduced the show and tell examples to some simple cut and pastes out of a cheat sheet I keep open in notepad++.

I'm new at the whole compression thing so I may have picked a lemon of a tool, it's been crunching for 33 minutes so far and is telling me that I have 46 minutes left, I'm gonna keep surfing for some other tools, that sure seems like a long time to convert a 5 minute AVI file to MPEG...

DNAP - Parameter Validation

9:56 PM Wednesday Oct 4, 2006 Comments: 0

I've been wanting to add some way of auto validating parameters passed to ajax methods.  Since we know the method parameters of the server method we're calling through ajax, we should be able to auto-magically determine the validation.  I've added an property to the GenericAjaxMethodAttribute where the auto validation of parameters can be toggled on and off.  The attribute looks like this now:

using System;
namespace DNAP
{
    public class GenericAjaxMethodAttribute : System.Attribute
    {
        private bool _validateParameters = false;
        public bool ValidateParameters
        {
        	get
        	{
        		return _validateParameters;
        	}
        }
        /// <summary>
        /// Initializes a new instance of the GenericAjaxMethodAttribute class.
        /// </summary>
        /// <param name="validateParameters"></param>
        public GenericAjaxMethodAttribute(bool validateParameters)
        {
        	_validateParameters = validateParameters;
        }
        /// <summary>
        /// Initializes a new instance of the GenericAjaxMethodAttribute class.
        /// </summary>
        public GenericAjaxMethodAttribute()
        {
        }
    }
}

The more I think about the more I need to re-work my examples. Here is the new demo.  It adds some basic validation to the parameters in the actual call.  I like that, it's simple, if you don't want it you don't get it(by default), and it should already be there to begin with.  I realize that we should already be doing input validation, but why not throw another layer of support into the mix.  If a dot net method accepts an int, you know it's gonna blow up if you send in something that's not an int from the client, so the ajax library should offer that simple validation without any hassle.  The example I've added is sooper lame, mostly just a proof of concept, and while posting I just noticed that I'm not able to round trip objects through the ajax proxy which is not cool, so I need to figure out where or why that doesn't work.  The zip file is updated with my latest code.

DNAP - Dot Net And Prototype

4:12 PM Sunday Oct 1, 2006 Comments: 0

I develop a lot of AJAX-y apps, mostly tools, at work.  Most of the time I need a very easy way of hooking up a server side call that returns html and/or an object model, hydrated with data.  I was using AjaxPro but since I also use the prototype javascript library, I've run into problems using both.  There are ways to make them play nice together but that requires config settings, and that's a little annoying to me.  Usually I end up skipping AjaxPro, and just using the built in Ajax.Request class in prototype.  That usually ends with me implementing a simple webhandler that just knows how to handle ajax requests.  The problem with this scenario is it takes time, time that i don't have.  What I need to do, is essentially reference an assembly, write a .NET method and call it from javascript client code, and nothing else.  I don't want to use webhandlers if I don't have to, and I don't want to set up any config settings, and I do not want to add code that registers a type that contains the ajax methods I want to call.  I want the application to do that for me, it needs to just work.

That's where DNAP(pronounced dee-nap) comes in.  It's the glue that connects .NET and client side javascript without completely changing server side code or client side code to enable this ability.  It uses prototype javascript for the ajax calls and Jayrock for JSON serialization of any return value from the server.  That's pretty much it.  You can get the code here.  It's a .NET 1.1 app, but there's nothing magical in there so it works in VS2005 as well.  There is a bare minimum example included and you can view the examples here