Friday, March 18, 2011

ScreenGrabber and Github

The screenshotting program that I've been working on for so long is finally nearing completion. I've updated it to include a lot of neat features, and I've gotten rid of the stupid way that I was capturing screen areas, replaced with being able to draw a box around what you want.

It's too big to just post the code here, and I really can't upload anything here anyway. So I'll use this to also mention that I have a Github account. My repos are here:

https://github.com/insertAlias

ScreenGrabber has my screen shot program.

Download it, build it, and break it for me so I can make it better!

Also, if anyone wants to make any better icons for me, I'd love them, since mine suck.

Thursday, March 10, 2011

New Extension Method for IList: SafeInsert

IList.Insert takes an index and a value, and attempts to insert that value at that index, pushing all following values out to the next index. Of course, that index must exist to do the insert.

I figured, why? If I want to move something to position 50, but there are only 5 values in the List, is it reasonable to assume that I want it to go to the last spot, since 50 isn't available? Maybe. Especially in the case where I'm presenting the user a grid, and allowing them to change a row's index manually. I'd rather not bother testing the number they enter, and just assume that if they put an index greater than exists that they want it to be inserted at the end.

This really isn't challenging code or anything, but it's useful, and the first time I thought of it, so I'll share:

public static void SafeInsert<t>(this IList<t> list, int index, T val){
    if (index < 0)
        list.Insert(0, val);
    else if (index > list.Count)
        list.Insert(list.Count, val);
    else
        list.Insert(index, val);
}