Personal Source Control

Personal Source Control

Do you use source control on your personal stuff? I used to use cvs, then switched to subversion, and next was sourcegear vault.  Since rebuilding my dev machines back in feb I haven't been using source control on my personal projects and recently that has caused me some grief.  So installed sourcegear vault, personal single user license is free so there's no reason not to try it out if you value your own code.  This also comes in handy when I'm switching between my laptop and my desktop machines.  Just this morning I tried something out with some code for panteravb, didn't like it after a few revisions, so I rolled back to the one I liked, no sweat.

AS DAYLIGHT DIES

Oh ya, mark your calendars.  Killswitch Engage will be releasing their next album on Nov 21.  If you haven't heard of Killswitch Engage then either you live under a rock or I am a loser metal head...WAIT! don't answer that.(and judging from the page extension, they are fans of dot net...or...they have no idea what dot net is and they hired some cool developers who do)

Scope Creep...

Not your typical scope creep.  But something closer to my personal todo list.  I have sooo many things I want to do.  It's funny really. 

I bought Getting Things Done and the helper book, and never had enough time to finish them.  I have tons of code I need to post, tons of article ideas I need to get written up, a gazillion tools and utility ideas that need to be realized, and always I end up with not enough time on my hands.

In less than 4 weeks, kid # 2,  Emmitt will be coming into this world and then it's game over, no more sleep for daddy :( Currently, I get up by 4am every day.  I'm a type 1 diabetic and need to make sure I have enough fuel in my system for my workout, so I get up and eat, then run 5 to 7 miles and follow that up with weights.  I'm usually eating breakfast by 7am, and get to work between 7:30 and 8.  I usually make it until 4 or 5 in the afternoon at the day job then split for home.  Now it's time to play with my first kid, Riley.  She goes to bed by 7pm, so from 5ish to 7 it's dinner and play time.  Then we clean the house a little bit, and I can sit down to figure out what needs to get done.  I start with my blogs that I read, there's not that many but I can spend at least an hour reading through those.  Then I finally I settle down to some code.  That's usually where I get stuck.  I'm writing my own blog tool so I can try out some concepts, like build providers and castle project's active record.  I have a dedicated linux box running ubuntu that's sitting there waiting to be used and abused.I have books(both geek and non-geek) to read. Plenty of new .NET 2.0(and now 3.0, jeez) concepts to wade through. I usually get done muckin around with stuff between 10 and 12 and start the same thing over in the morning.

I guess this entry is not helping getting any more things done, but now I feel better.

Finally...

Ok, I've realized that I worry too much about the quality of my code. I wanted to post my demo for the ActiveRecordBuildProvider sooner than later and then realized a couple of things.  First of all it depended on the CodeSmith schemaexplorer assembly to aid in walking the database objects.  I couldn't post that since it's not open source.  So then I started rolling my own schemaexplorer and came up with some really lame solutions; plus, I really wasn't interested in writing my own schema explorer, there are smarter people than me writing better code that I'd rather buy.  That said I also did not want to publish code with a database dependency either.  I went back and forth on this one, until I decided that if you're already using castle project activerecord then you probably already have a database to connect to and the dependency would not be a problem.  I only realized this after running through some mockup DataTable examples that I did not like at all so I pulled those out.  The concept here is exactly the same as the SubSonic project(which is too cool for words, you just gotta try it).  The only difference is that I probably spent a lot less time on it(hence the lame quality of my code) and I use the castle project activerecord implementation.

Here is the zip that includes version 0.0.0.0001 of an idea I wanted to code up.  Since I am a big fan of eating my own dog food, this site uses the exact same code as presented in the download.

Woo Hoo! Got my first laptop!

I never thought I'd get a lappie but today I did.  Today, while walking through Sam's club, I saw it, a 17 inch wide screen that was calling my name.  My requirements were simple, 17 inch screen and at least 1 gig of ram, the one I got has 2 gigs of ram and an NVidia 7600 with 256 megs of memory.  2 100 gig hard drives and all of the devices I could imagine; many of which I don't even know what they're for since I'm a lappie Noob.  Media Center edition of Windows is actually pretty cool;  I have remotes and devices galore for this thing, the first order of business was to play my Killswitch Engage video, loud.  My kid started banging her head, it was good times.  Also just noticed that apparently I have developed the editor interface for a 21inch monitor running at a way higher resolution than this laptop has cuz I'm having to do a whole lot of scrolling which is very annoying.

BuildProviders Rock

BuildProviders are new in .NET 2.0, and are one of the coolest features in the framework.  I was first introduced to the concept when I was messing around with SubSonic(aka ActionPack).  If you have not played with SubSonic yet, it's over here and very well worth your time.  SubSonic leverages BuildProviders by using them to inspect a specified database schema and generates all of the compiled data layer code using the ActiveRecord pattern.  The most important and coolest thing about this, is that your data access code is live and any change to a database object is immediately recognized the next time you build a project.

I've been digging into the ActiveRecord implementation that the Castle Project has created and is built on top of NHibernate.  It's a great model to use for your data layer but you still have to code up your entities, albeit with very little code, but it's still a step I could do without.  Last night I built a very simple BuildProvider that generates those entities.  I used the SchemaExplorer assembly that ships with CodeSmith to inspect the database.  Spinning through each table that I need generated, I generate the entity classes using the CodeDom inside of my BuildProvider.  I generate partial classes so that I'm allowed to add custom functionality that does not get stepped on during every build.

Here's the schema to a table named customers:

Now assuming the BuildProvider is configured properly, all you need to do is compile your project and the following class will be generated, compiled, and available for your using pleasure:

//------------------------------------------------------------------------------
// 
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// 
//------------------------------------------------------------------------------

namespace ActiveRecordGenerator {
    using System;


    [ActiveRecord("customer")]
    public partial class Customer : Castle.ActiveRecord.ActiveRecordBase {

        private Int32 _id = 0;

        private String _firstname;

        private String _lastname;

        private String _phonenumber;

        private DateTime _createdate;

        public Customer() {
        }

        [PrimaryKey(PrimaryKeyType.Native, "customer_id")]
        public Int32 ID {
            get {
                return this._id;
            }
            set {
                this._id = value;
            }
        }

        [Property("first_name")]
        public String FirstName {
            get {
                return this._firstname;
            }
            set {
                this._firstname = value;
            }
        }

        [Property("last_name")]
        public String LastName {
            get {
                return this._lastname;
            }
            set {
                this._lastname = value;
            }
        }

        [Property("phone_number")]
        public String PhoneNumber {
            get {
                return this._phonenumber;
            }
            set {
                this._phonenumber = value;
            }
        }

        [Property("create_date")]
        public DateTime CreateDate {
            get {
                return this._createdate;
            }
            set {
                this._createdate = value;
            }
        }
    }
}

 

I grabbed that code from a testing harness, using the System.Web.Compilation.BuildProvider you won't actually see that code, it gets compiled.  All you get to do is use the code like this:

I still think it's funny, that the codegen sticks in the comment This code was generated by a tool.That gets me every time...I need to clean up the code a little more tonight but hopefully I'll have it posted.

JavaScript table sorting made easy

I'm a big fan of the concept of unobtrusive javascript.  That's why I use prototype and scriptaculous and event-selectors to name a few.  Yesterday I came across Unobtrusive Table Sort Script and this thing frickin rocks.  Reference the tablesort.js script, add any class="sortable" to any column header(must be a th tag) that is sortable and you're done.  Start sorting.  Here is an example of how to hook that up:


  
    
  
  
    
      
        MySortableColumn
      
      Some Data
      Some More Data
      Some Other Data
    
  

 

There are plenty more examples  here.  If you're looking for a simple solution that "just works", check out Unobtrusive Table Sort Script.

Good Ol' StringBuilder...

I had a need to write a bunch of html, a whole page actually, programmatically.  No user controls, just old school html.  What a pain in the ass.  I thought about the System.Web.UI.HtmlTextWriter, however that turned out to be a gynormous headache due to the amount of typing involved.  So then I thought I'd be the clever guy and use an System.Xml.XmlDocument.  That sucked too, for the same reasons.   What do I end up with? My good friend the System.Text.StringBuilder.  She may not know what html is, or xml or nodes or stylesheets or scripts, but she can whip up simple html easier than the rest.  I didn't go down the path of using xsl stylesheets and System.Xml.Xsl.XslTransform for .NET 1.1, or the new and improved System.Xml.Xsl.XslCompiledTransform for .NET 2.0, that seems like overkill and I also want to display formatted code which sometimes is a pain(escaping   and what have you).

I am still looking for a better solution, an easier one.  I am generating this html from an assembly and it's based on what's inside of the assembly, so simple is key.  I've had a need in the past to make ajax calls to .NET stuff on the backend but sometimes hooking it up was a little bumpy.  So I'm playing around with a new thing that initially designed to demonstrate how to easily integrate prototype and .net but now I'm expanding this to include some unit testing and documentation generated from the assembly at runtime.  Here is a demo.

Generic Pluck

Here's a generic version of a Pluck method:

public class PluckableList : List{
  public Array Pluck(string propertyName){
    Type type = typeof(T);
    PropertyInfo property = type.GetProperty(propertyName);
    Array result = Array.CreateInstance(property.PropertyType, this.Count);
    for(int i=0;i
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
public class FindNames : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        string fragment = context.Request.Form["frag"];
        context.Response.ContentType = "text/html";
        List names = 
        	new List(new string[] { "Chris", "Christian", 
        		"Christy", "Christina", "Christmas" });
        List matches = names.FindAll(delegate(string name)
        {
        	return name.StartsWith(fragment, StringComparison.OrdinalIgnoreCase);
        });
        context.Response.Write("
    "); foreach (string match in matches) { context.Response.Write(String.Format("
  • {0}
  • ", match)); } context.Response.Write(""); } public bool IsReusable { get { return false; } } }

     

    Hooligans

    I'm a big fan of small time films.  Tonight I watched Green Street Hooligans with Elijah Wood, it was great.  Two thumbs up from me.

    SquishyWare has been overtaken by Wilco Bauwer SyntaxHighlighter...

    I love squishyWARE's SyntaxHighlighter.  However, I do have needs to html-ify many other things that squishyWARE does not support.  Wilco Bauwer has a great tool for syntax highlighting that I like better, compare for yourself:
    squishyWARE:

    var Person = Class.create();
    Person.prototype = {
      initialize: function(name){
        this.name = name;
      }
    }

    Wilco's
    var Person = Class.create();
    Person.prototype = {
      initialize: function(name){
        this.name = name;
      }
    }

    Prototype JavaScript Framework

    The Prototype JavaScript library kicks ass.  Period.  It lacks documentation but there are many out there doing there best to help.  This site has rounded up a good collection of intros and reference material for the Prototype library.  It has become an automatic include in any pages requiring much client interaction.

    I've used WebHandlers to help with processing Ajax requests on the server side when using the Prototype framework.  Most of the time it involves just parsing the QueryString to determine what the request is and then passing it on to whatever needs to do the job.  The demo has some very basic code in it to show how easy it can be to implement Ajax functionality.  You can click on the demo link and view source to see the code for the html page.  The following is the code for the WebHandler:

    using System;
    using System.Threading;
    using System.Web;
    public class SimpleAjaxRequestHandler : IHttpHandler {    
        public void ProcessRequest (HttpContext context) {
            string op = context.Request.QueryString["op"] ?? "default";
            string result = "";
            switch (op.ToLower())
            {
            	case "sayhello":
            		Thread.Sleep(3000);
            		result = "The server says hi!";
            		break;
            	case "default":
            	default:
            		result = "This is some default response";
            		break;
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(result);
        } 
        public bool IsReusable {
            get {
                return false;
            }
        }
    }

     

     

    Fort Collins is awesome

    I love living in Fort Collins, CO.  Since today was a holiday, we needed something to do.  We ended up starting the day by working out.  Early in the mornings around here, there are many  hot air balloons taking off and it's pretty cool to watch, I'd love to take my kid up in one, she always freaks out(in a good way) over any kind of balloon.  At the City Park in downtown FC they have a mini train for little kids and their parents, so we took the little one on there and it was a hoot, we had to drag her away screaming(seriously, she was screaming). 

    Later in the day we were bored and needed somethin to do so we took a little 40 minute drive up to Poudre Canyon, and was able to walk along the river; that just seemed too cool, 40 minutes and voila, we're up in the mountains.

    Fort Collins also makes some great brews.  New Belgium Brewery is awesome, they make great beers and have an awesome tasting room.  Odell's is great too, my favorite is their Cutthroat Porter

    Del.icio.us api

    Very cool.  I added the 'my del.icio.us ajax' section to the left by adding a little bit of javascript and grabbing a JSON feed from del.icio.us.  They send back an object populated with all of the links, which you can request by tag.  I use this url for the datasource of the links, http://del.icio.us/feeds/json/chrcar01/ajax.  Nice and simple.

     
    Author: , 0000-00-00