Category Archives: Bits

The Danger of Null Values

I made a goof ball mistake today.  I was using LINQ to query a List<> and return the ToString() of the result.  As usual I was using FirstOrDefault() and I simply added .ToString() to the end of it.

fieldValue = (from d in customFields where d.CustomFieldId == fieldId select d.data).FirstOrDefault().ToString();

Of course things worked swimmingly until the Default (null) was hit. At that point I got an Object not set to an instance error.  I had to laugh at myself.

var fieldData = (from d in customFields where d.CustomFieldId == fieldId select d.data).FirstOrDefault();
fieldValue = fieldData != null ? fieldData.ToString() : "";

Dragging Files To OneNote

I just learned something really cool about OneNote.  I was not sure how it would respond if I did a drag and drop of a PDF file to a OneNote page.  The result is impressive.  Well done OneNote team!

Insert Link, Insert a copy of the file onto the page, Insert the file as a printout so I can add notes to it

Drag and Drop Dialogue

Left or Right Curly Braces

Should you put your curly braces on the left or right?

function foo(){
    //My curly brace is on the right.
}

function bar()
{
    //My curly brace is on the left.
}

Read the rest of this entry

Some History Of I, J, And K

I learned a little bit of geek history today.  A lot of us have used the variable I (or i rather) in our loops, and sometimes for nested loops we would use j and then k.  Do you know where that started?

Apparently it started in FORTRAN.  The variables i, j, and k were to be only used for integer type variables.  I am sure there is more to it than that but a quick search gave two different sources that confirm it.

Wikipedia

StackOverflow

I know this is nothing ground breaking or anything, I just thought it was something neat.

Breaking Into Your Lambda

I just learned something new today at Microsoft Virtual Academy.  Heck I almost always learn something new or even things I forgot at Microsoft Virtual Academy.  In this case I thought it was pretty neat.  We all use break points throughout our code, most of the time I just break on a line.  I just learned how to break into a Lambda expression.

Basically you click inside your Lambda expression and then press F9.  To show this I will create a quick class called Stuff.

    public class Stuff
    {
        public string Name { get; set; }
        public int Quantity { get; set; }
    }

In another area I am going to use this class to create a List<Stuff> and then use a Lambda on that list.

            List someStuff = new List()
                            {
                                new Stuff{Name = "Dice", Quantity = 2}, 
                                new Stuff{Name="Cards", Quantity = 52}, 
                                new Stuff{Name = "Tokens", Quantity = 20}
                            };

            var result = someStuff.Where(s => s.Name.Length > 4);

Next I click in my Lambda and press F9, below is a screenshot of the break point inside my Lambda.

Breaking Into Lambda

How To Create A Console Application In Visual Studio Express 2012 For Web

If you use the Web Express version of Visual Studio 2012, you will notice one thing missing; creating a console application.  The solution is fairly simple.  I found a blog post at Possibly the most boring blog ever that explains it perfectly.  So instead of rehashing what has already been posted, I will let you use that link above.

In a nutshell though, you will create a new class library.  In its property page set its output type to Console Application.  Please see the original post for screen shots and more details.

How To Move An Off-Screen Window Into View

Isn’t it nice to have dual 21″ or larger wide-screen monitors in the office?  Don’t you wish you had them at home, especially when an application opens itself off-screen?

Well, this won’t magically give you your nice in office setup, but it will bring that pesky program into view.  There are two basic ways.

First is to alt tab to that program and right-click it in the task bar.  From this menu pick Move.  Use your arrow keys to slide it into view.  Then a simple left click of the mouse or hit your enter key and you’re done.

The second method can be used all of the time.  The reason for this one is because some programs do not offer that move option.  In this case, you still alt tab to the program.  Next you hit Alt + Space + M.  That puts it in move mode, so now you just use your arrow keys to move that window into view.  Finally, like in the first method, you can hit your enter key or do a left click of the mouse.

Mask a String Using Linq Aggregate Method

I had a need to mask a string from a database.  I knew there had to be a way to do this using LINQ, and of course I knew someone had to have already done it.

So not wanting to be one to re-invent the wheel I did some searching and found this great post by Shawn Sweeney.

Mask a String Using Linq Aggregate Method.

Content Delivery Networks (CDN) by Microsoft and Google

In case you are not wanting to host your own jQuery or other library references Google and Microsoft provide free hosting for the libraries. There are some differences so you should look at both of them. Please see the links below.

Microsoft Ajax Content Delivery Network

Google Libraries API – Developer’s Guide

A posting by Scott Guthrie that gives a bit more detail about Microsoft’s CDN.

Another interesting link, albeit dated is this one by Pingdom about CDN performance.

DropDown List Of States (USA)

I have to throw one of these together every now and then. I would prefer not to make something like this database driven to not waste the resources on a database call. So I am putting it in this post. It contains all 50 states plus DC.

Read the rest of this entry