Nov 02 2008

Links for the week

Tag: UncategorizedJeremiah Peschka @ 3:37 pm

Brent Ozar provided the inspiration for this blog post and the others that will follow. Essentially, the goal is to put together a list of the most interesting/entertaining links that I’ve found in the last week. If you’re easily offended by SQL Server, I suggest you turn away now.

5 Quick Tips for the Query Using the ‘Wrong’ Index - Quick tips from Jason Massie about making sure the ‘correct’ index is being used by the query engine.

What is a ‘good’ SQLServerPedia article? - Brent covers what makes for a good article on SQLServerPedia. Shockingly, this covers what makes for any good technical article.

Constraint Yourself! - Joe Celko put together a great introduction to the intricacies of using constraints not just for verifying data integrity but also to ensure that business rules are implemented in one place, in one way, and at one time.

7 Steps to Shameless (Successful) Self Promotion - Jeff Blankenburg covers the basics of promoting your personal brand. Not just from the standpoint of having a better blog, but how to cultivate your brand and brand recognition offline too.

Career Guidance: Become a More Successful IT Professional by Managing Your Own Personal Brand Within Your Organization - Brad M McGehee covers the same topic from the standpoint of building your brand within your organization. But the same rules apply whether you’re building your brand inside your company or throughout the community as a whole.

That’s it for this week.


Oct 11 2008

Custom Sorting ArrayLists

Tag: UncategorizedJeremiah Peschka @ 9:59 am

A co-worker approached me with the problem of sorting an ArrayList of ArrayLists. Normally you might handle this in a DataTable or entity collection in your particular ORM. In this case, this was the data structure that was available to sort:

[[sortorder][type][message]
 [sortorder][type][message]
 [sortorder][type][message]]

Knowing a little bit about how ORM tools work, I made the guess that they implement a custom comparer to perform this functionality, so I took a look at what it would take for this instance.

This turned out to be a lot easier than I thought, you need to create a class that implements IComparer and pass an instance of that class to the Sort method of the ArrayList.


public class CustomArrayListComparer : IComparer {
    int IComparer.Compare(object x, object y) {
        return ((int)((ArrayList)x)[0]).CompareTo((int)(ArrayList)y))[0]);
    }
}

// example:
myArrayList.Sort(new CustomArrayListComparer());

I know that the above code looks somewhat unreadable, but for the sake of the efficiency of the sort operation, all casting is done in place. It’s necessary to cast objects x and y to an ArrayList in order to access their collection of objects. Since we know that, in this case, the 0th item in the ArrayList is an int, that is cast to an int and the Int32.CompareTo() method is used.


Sep 12 2008

Navigating Code with VS2008

Tag: UncategorizedJeremiah Peschka @ 6:37 am

Here are a few keyboard shortcuts in Visual Studio 2008 that I’ve recently (re)discovered:

  • CTRL + - Move to the last position in code.
    This is very helpful if you’ve been jumping through a file while searching for a particular function, variable, whatever.
  • CTRL + SHIFT + - Just like the above, but in reverse.
    This moves forward through code, if any forward position is available. Otherwise you’ll just wonder why you’re pressing CTRL + SHIFT + - over and over.
  • CTRL + K, CTRL + K Add a new bookmark.
  • CTRL + K, CTRL + N Move to the next bookmark in the file.
  • CTRL + K, CTRL + P Move to the previous bookmark in the file.
  • CTRL + K, CTRL + L Clear bookmarks
  • CTRL + K, CTRL + C Comment line(s).
    Comment out the current line or selected lines. Take note, this will not put a comment at the beginning of empty lines, which drives me nuts.
  • CTRL + K, CTRL + U Uncomment line(s).

The bookmark functionality is great when you’re focusing on refactoring several common code blocks that have subtle differences and you want to make sure you account for all edge conditions when you’re combining them into a single method.


Sep 01 2008

Fast VPC boot times

Tag: UncategorizedJeremiah Peschka @ 10:23 am

Sick and tired of virtual machines booting slowly? Yeah, me too. I’m impatient.

Apparently Greg Low was even more annoyed at it than I am and wrote a post about Virtual PC performance using flash drives.

Essentially, use a sizable flash drive to make your Virtual PC boot twice as fast. 2x the fun! 2x the productivity! 2x the USB slots!


Jul 28 2008

Missing cookies in jQuery AJAX callbacks?

Tag: UncategorizedJeremiah Peschka @ 3:05 pm

For my current project, we’re making use of a large number of jQuery AJAX callbacks, as well as cookies, to deliver some rich functionality to the users of a web site. Unfortunately this created a little bit of an issue when trying get this to work in IE7.

Here’s what I originally attempted:


function do_something() {
  $.ajax({
    url: 'http://example.com/AjaxRocks',
    type: 'POST',
    dataype: 'json',
    success: success_response
  });
}
function success_response(json) {
  var cookie_data = load_data_from_cookie(); // the implementation of this is not important
  // unfortunately, cookie_data is null so this doesn't really give us the important cookie_data
}

For some reason, the full contents of document.cookie are not available from inside the success_response function call. The solution? Load the cookie’d data before making the AJAX call:


function do_something() {
  var cookie_data = load_data_from_cookie();
  $.ajax({
    url: 'http://example.com/AjaxRocks',
    type: 'POST',
    dataype: 'json',
    success: function(json) {
      success_response(json, cookie_data);
    }
  });
}
function success_response(json, cookie_data) {
  // do something successful
}


« Previous Page