Grax
Geeks Researching And eXplaining

Grax Coding Blog

Advanced Coding Techniques Explained

Safely deal with the impossible
   I wanted to point out this little hidden coding gem from Ted Neward's column in the September 2014 issue of MSDN Magazine. if (locAmt == remAmt) { ... } else if (locAmt < remAmt) { ... } else if (locAmt > remAmt) { ... } else th ...More

Detecting infinite recursion
   TLDR: Use ThreadStatic static variables for a performant recursion test.As I was building fFastInjector, I found that it was fairly easy to create infinitely recursive configurations of the dependency injection. As fFastInjector examines a construct ...More

Windows Phone 8.1 Goodies
   Two of my favorite features in Windows Phone 8.1 are the hands-free texting and the Word Flow Keyboard.With hands-free texting, I can reply to an incoming text without touching or looking at my phone. I can send a new text by pressing two buttons an ...More

T-SQL ForEach style loop
   Here is a simple pattern that I came up with for executing a ForEach style loop in t-sql against a set of data in T-SQL.declare @Enumerator table (id int)insert into @Enumeratorselect UserIdfrom Userswhere IsActive = 1 -- your query to select a list ...More

CSS Gotchas - Part 2 - CSS Margin Height In Percent is Calculated Using the Width of the Parent Object
   TLDR: In CSS, when you specify margin height using a percentage, that height is calculated using that percentage against the width of the parent object. The only workaround that I have found, assuming you want the margin to be set to a percentage of ...More

CSS Gotchas - Part 1
   TLDR: 2 CSS Gotchas today. First, the default CSS box model will cause an overflow if a box contains 2 boxes that are each set to 50% of the outer box's height or width if either of the boxes contain a margin, border, or padding. Second, if you are ...More

Debugging Visual Studio 2013 Code Coverage with ILSpy in under 2 minutes
   So I am working on getting 100% code coverage for my tests on fFastMapper (My tool to do high-speed, precompiled mapping between 2 objects). The following method is a single line and was being called in my tests. However, Visual Studio 2013's code ...More

Notes on Time Zones
   TLDR Version (Too Long Didn't Read Version)In your persistence medium, database or otherwise, convert all times to UTC before storing them, store all times as UTC, and convert on-the-fly to the user's local time zone when displaying. In order to con ...More

Orlando's Giant Melrose Technology Center is a Maker's Paradise
   I just returned from my vacation to Orlando, Florida. This time we did things a little different and skipped the Disney and Universal parks. We visited some museums, Leu Gardens, Gatorland, the Merritt Island Manatee Overlook, and a couple of beach ...More

Get Rid of Bad Code once and for all with nDepend 5
   nDepend is a tool used for analyzing a .NET code base. It can find issues, track metrics, and create reports.nDepend version 5nDepend comes with a lot of rules for analyzing your code base. It comes with over 150 rules to check your code against in ...More

The Free Way Get Started In Programming
   At our recent Code Camp, our keynote speaker was Iris Classon. She told us the inspiring tale of her journey into software development. Several of her stories struck a chord with me and reminded me of some of my own experiences. One part that stoo ...More

Better Array Fill Function
   So last week, +Michael Hsu visited my blog and took my array fill function and made it better.First, he turned it into an extension method and changed the signature so that the overload isn't needed. public static class ArrayExtensions { ...More

Female Code Camp Speakers?
   Yesterday was the first day of 4th annual Nebraska Code Camp. It is an opportunity for developers of all types to meet, learn, and network with each other.Today is the free portion of Code Camp. It is a totally free event. All people are welcome, ...More

On Success
   "... the strikingly successful groups in America today share three traits that, together, propel success. The first is a superiority complex — a deep-seated belief in their exceptionality. The second appears to be the opposite — insecurity, a feeling ...More

SubtractJS: The Video
   SubtractJS: The Video SubtractJS: The Web Page ...More

SubtractJS Update
   Some of you already know how amazing SubtractJS 1.0 is, but now I have something else to add to it. With SubtractJS 1.0.1, you can add an additional class "sj-margin-box-model" to make it easy to set up percentage-based sections. For example, here ...More

Announcing SubtractJS
   Quick Summary:SubtractJS is a layout assistant for HTML that makes it easy to mix fixed-width or fixed-height elements on the page edges with a re-sizable body. It is great for managing headers, footers, menu bars, navigation elements, or advertisin ...More

Buying and Updating My New Surface RT Tablet
   This has been a great year for me for getting new or updated electronic devices. When I saw the Black Friday special for the $199 Surface RT 32GB, I decided it was time to buy.Black Friday Online MadnessI started trying to order at 11 PM my time, wh ...More

Testing Custom LINQ Filter Operators (and LINQ Where clauses in general)
   Quick SummaryIn my last post, I outlined how to build a Custom LINQ Filter Operator. In this post I will demonstrate how to write a unit test for that filter operator. The same basic methodology can be used for testing Where clauses in general.We a ...More

Custom LINQ Filter Operators
   Generics, expressions, and extension methods are amazing features that open the doors to incredible new features and abilities in C# (and .NET in general).Quick SummaryUsing C# extension methods, we will rewrite commonly used Linq "where" clauses int ...More

Response to fFastInjector concerns
   Below are some comments from Daniel de Palme's IOC Container performance benchmark and my responses.http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison Post #48Something to notice about fFastInjector is that it is st ...More

Why is fFastInjector so fast? Is it thread-safe and otherwise safe?
   fFastInjector gets its speed from creative use of static variables within a generic static class, optimizer friendly coding, coding to do activities not related to the resolution outside of the resolution piece.Generic static variablesGeneric static ...More

Fast array fill function (revisited)
   Update: A reader ( +Michael Hsu ) posted a faster improved version at https://github.com/mykohsu/Extensions/blob/master/ArrayExtensions.cs and I blogged about it at http://coding.grax.com/2014/04/better-array-fill-function.htmlLooking back at my fir ...More

Simple Strongly-Typed pattern for ViewData, Session, Request, etc
   Here is a simple pattern for setting up strongly-typed but flexible access to your ViewData, Session, and Request variables.If you have worked with jQuery much, you are familiar with the pattern of using "SomeMethod(value)" to set a value and "SomeMe ...More

How fast is fFastInjector?
   I downloaded Danial Palme's wonderful IoC Container Benchmark and added an adapter for my own fFastInjector. As you can see from the results, fFastInjector is clearly faster than all other IoC containers, even managing to beat Hiro, Munq, and Funq b ...More

fFastInjector - World's Fastest Dependency Injector
   (2013-6-16: See updated lifestyle section for details on singleton lifestyle)What is it?fFastInjector is the world's fastest .NET dependency injector/service locator. In order to prove that it is the fastest, I downloaded the code that accompanies th ...More

Linking db2 to MS Sql Server
   My current project has a need to read and update DB2 data in addition to MS Sql Server data. The primary server is Sql Server, DB2 is additional. Our selected way of doing this is by creating a linked server on Sql Server (2008 R2). As you will se ...More

A FakeDbSet that implements IDbSet and uses IList for data manipulation
   Author's note: At some point, I managed to destroy all of the formatting for this post. The formatting should all be back now but you may not see the inline code. Still working out the way that works and that I like for posting code on my blog. +Sc ...More

Fun with Generic's Source Code
   Last night I gave a presentation about C# generics to the Lincoln .NET user's group. If you were there and want to see the code or if you weren't there and just want to see some interesting generic code, check out this source code. You will want to ...More

Generic TryParse, convert string to any type
   I came up with this nifty little extension method today. This method works in a similar fashion to TryParse but you can pass in any type. You may want to throw an exception if converter == null, as that means there is no converter available for the ...More

Announcing fFastMapper release 0.5.2
   Announcing fFastMapper release 0.5.2. Get fFastMapper from nuGet.fFastMapper is a component (like AutoMapper) to automatically copy values between objects of different types. The default mapping is based on a match of property name and property typ ...More

Announcing fFastMapper release 0.5
   (Sorry for any confusion. The name HyperMapper is trademarked by another organization, so I had to change it).fFastMapper is ready and available via NuGet. Use "Install-Package fFastMapper"fFastMapper is a component to map property values between ob ...More

Fun with C# Generics in Visual Studio 2010
   For those of you that need a Visual Studio 2010 version of the generics sample code from my Nebraska Code Camp presentation, you can download it fromhttp://sdrv.ms/15hAXYZ ...More

Code Camp Code for Fun with C# Generics
   The source code from my Nebraska Code Camp presentation on Fun with C# Generics can be downloaded from http://sdrv.ms/119gDMP. This is a Visual Studio 2012 project.The example code is in the Unit Tests project. Feel free to ask questions of me here ...More

Kinect sample code from Code Camp
   I have posted my code from Nebraska Code Camp. The most significant change is that I am using shaders to merge the multiple layers I am creating.The original way to merge the layers was using C# code and reviewing each pixel to determine whether it ...More

Nebraska Code Camp
   Don't miss my Nebraska Code Camp session on Augmented Reality with Microsoft's Kinect for Windows. I will be talking about the commercial API for the Kinect. (The description was written before the commercial API was released)I will be presenting a ...More

Working Kinect sample code available
   When the commercial API came out, I found that they had made quite a few changes. I am sure they are mostly good changes but they broke my previous sample code. Here is the new WPF sample code, unfortunately minus the special effects such as 3D fre ...More

Kinect sample code available
   Here is the code the goes along with my January 25 presentation titled "Augmented Reality with the Kinect" at the Lincoln .NET Users Group.Remember to check the Kinect for Windows site to verify you have all of the system requirements.To get started ...More

Specifying and using a WebResource to access embedded resources
   Adam Miller had a great post on this blog about returning an embedded resource in an aspx page. Since I have some experience with embedded resources, I wanted to share instructions to access embedded resources using the WebResource attribute.If you ...More

Initialize an array to a value in C# very fast
   Update: I decided to revisit this with a new blog post.Updated Update: A reader ( +Michael Hsu ) posted a faster improved version at https://github.com/mykohsu/Extensions/blob/master/ArrayExtensions.cs and I blogged about it at http://coding.grax.com ...More