February 2012
1 post
Tonight's lesson
Sometimes the best way to express yourself is in code…. so here it goes.
Guys and girls are both people
public abstract class Person
{
...
}
public abstract class Male : Person, IMan
{
...
}
public abstract class Female : Person, IWoman
{
...
}
The longer one interacts with members of the opposite sex, the more you will realize that, the basic person method are all virtual. This...
January 2012
1 post
Strong Enough To Save - Tenth Avenue North
[Verse 1:]
You faught
but you were just too weak
so you lost
all the things you try to keep
now you’re on your knees, you’re on your knees
But wait,
everything can change,
in a moments time you don’t have to be afraid,
cause fear is just a lie
open up your eyes
[Chorus:]
And he’ll break
open the skies to save
those who cry out his name
the One the wind and...
November 2011
4 posts
6 tags
Dynamic View Model
When doing MVVM I find that much of the time putting together the view model is spent creating properties that look like the following:
private string _userName;
public string UserName
{
get { return _userName; }
set
{
if (_userName != value)
{
_userName = value;
RaisePropertyChanged("UserName");
}
}
}
Especially while just banging...
7 tags
Key Input Text Box
On a recent project I had the need to allow the user to input a key stroke. After a quick Google search, I decided to roll my own. The following is the result.
First the boring stuff. Three dependency properties to hold the values.
public class KeyInputTextBox : TextBox
{
public static readonly DependencyProperty KeyProperty =
DependencyProperty.Register("Key", typeof(Key),...
5 tags
RemoveWhere extension method
Often we need to iterate over a collection and remove items that meat a given criteria. Sure List<T> has RemoveAll, but what about the cases where you do not have a List<T>?
Typically this results in code like the following:
var collection = new ObservableCollection<int> { 7, 2, 3, 4, 6, 5 };
var toRemove = collection.Where(x => x % 2 == 0).ToList();
foreach (var item in...
7 tags
MVVM Popups
Recently I was faced with an interesting problem of how to properly display a popup and still follow the MVVM pattern. After a lot of thought, the following is the solution that I have finally landed on.
First of all the main window for the application:
<Window x:Class="MVVMPopup.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
...
October 2011
1 post
4 tags
C# Nullable gotcha
Recently I ran into a interesting gotcha will System.Nullable<T>.
Below is some code that was run through the immediate window.
new Nullable<bool>() is bool
false
new Nullable<bool>(false) is bool
true
new Nullable<bool>(false) is Nullable<bool>
true
new Nullable<bool>() is Nullable<bool>
false
September 2011
4 posts
5 tags
Hidable WPF Menu Part 2
« Part 1
After implementing my hidable WPF menu, I realized there was a bug when the menu items are bound.
Here is the change to the XAML.
<Window x:Class="AutoHideMenuBar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
...
6 tags
Hidable WPF Menu
** ATTENTION THERE IS A BUG IN THIS CODE SEE PART 2 FOR THE FIX **
Recently I needed to create a menu on a form that would remain hidden until the user pressed the Alt key. Similar behavior to the menu in Firefox 6.x.
To accomplish this I elected to make a custom control that extends System.Windows.Control.Menu. The code for it is pretty trivial.
using System.Windows.Controls;
using...
2 tags
Wedding vows of a WoW geek
I, <insert name>, take you, Paladin, to be my chosen class, my constant tank, my faithful protector and my guardian from this day forward. In the presence of GMs, our guildies and pugs, I offer you my solemn vow to be your faithful raid leader in poisons and through over-heals, in good times and in bad, and in boss kills as well as mob wipes. I promise to run back unconditionally, to give...
5 tags
Wedding vows of a programmer
For my wedding I plan on writing my wedding vows. I figured I should get in some practice, and here is what I came up with.
“I <insert your name> take you .Net 4.0 to be my prefered platform, to use and to code from this day forward, for implementation or for frustration, for performance, for crashes, through handled and un-handled exceptions, to debug and to execute; from this day...
August 2011
4 posts
8 tags
Shadow Box in WPF Part 2
First of all,. if you have not read part 1, please go back and do so. I am only going to cover the changes needed to the window in part 1 to make the shadow box re-sizable.
Since the shadow box is being displayed within a grid, the easiest way to add re-sizing to it, is by utilizing the GridSplitter class. First we need to add some rows and columns to the...
Job Satisfaction →
This article struck home as recently I have been viewing different job opportunities as more than just some other way to pay the bills. One should not hunt for a job that pays well, rather the focus should be to find a career that you enjoy. That just happens to pays enough to cover the bills.
3 tags
Coding erros
In testing some old ruby code a co-worker came accross a method similar to this:
def should_pass?( obj )
return true if self.pass_condition.nil?
return true
end
Looking at old code is usually good for a laugh.
jhuizingh asked: Your post "Shadow Box in WPF Part 1" was great! Just what I was looking for. Can I look forward to part 2 any time soon? Thanks!
July 2011
2 posts
11 tags
Shadow Box in WPF Part 1
On a recent project I ran into the need to show a modal dialog box to a user without displaying a second window. For web based applications there are many libraries that provide methods of doing this, jQuery, ASP.NET AJAX, or boxy to name a few. I am going to refer to these “dialogs” as shadow boxes. These shadow boxes are simply user controls that sit on top of the other...
3 tags
Displaying camel case
Sometimes it is convenient to convert a string that is in camel case (variable name, enum value, method name etc.) to a well formatted string that look nice to an average user.
The following Regex will find all capital letters that are surrounded by lower-case letters.
(?<=[a-z])(?<Letter>[A-Z])(?=[a-z])
Here is the complete program for testing.
class Program
{
static void...
June 2011
3 posts
10 tags
Simple home network setup that anyone can do
On several occasions I have been asked to help setup someone’s home network. I hope this guide helps those of you who have the confidence to do it but lack the know-how. Often home router will come with a disk that will assist you in setting up your router as part of a network. If you follow these directions you will not need that disk.
This guide will merely guide you in setting up a...
7 tags
LINQ OrderByDescending gotcha.
As I discovered today the LINQ OrderBy and OrderByDescending do not always return collections that are in inversely ordered.
Consider the following code:
var array = new[]
{
new {key = 3, value = "e"},
new {key = 1, value = "a"},
new {key = 2, value = "c"},
new {key = 2, value = "d"},
...
7 tags
String format constructors
Recently I noticed that I had a class with a constructor that had a single string parameter. For discussion lets assume that the class looked something like this.
public class SomeException : Exception
{
public SomeException(string message)
: base(message)
{ }
}
In my code I found several calls that looked something like:
throw new SomeException(string.Format("Could not find {0}...
May 2011
3 posts
Loving things like you has wrecked my life, made me cry
Loving things like you...
– http://www.sing365.com/music/lyric.nsf/Things-Like-You-lyrics-Sanctus-Real/877A5CFE0FEAB76548256EBF0015763B
3 tags
Hardening your computer's security →
These are great guides posted by the NSA for hardening the security on your computer.
5 tags
C# combination (subset) extension method
Recently I needed a way to get all of the subsets of a specified size within a given list. Lets start with a brief example. Given the array [1, 2, 3, 4], and a desired subset size of 2, I wanted a method that would output a collection containing:[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]. Or given a subset size of 3 the expected output should be [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4].
...
April 2011
1 post
10 tags
Retrieving information off of a hard drive for...
Being a geek, I typically get phone calls when people have computer problems. Almost all non-closet geeks know this. This has led to one of my favorite T-shirts.
I have been asked to fix a lot of, IMHO, simple problems. Usually people just do not know that a particular solution is available.
Recently I was asked to get information off of a computer that was not able to boot up. This is a...
March 2011
8 posts
If I could find yesterday
I would take You back to where I’m coming from...
– http://www.elyrics.net/read/l/letter-black-lyrics/best-of-me-lyrics.html
My past has followed me and
I just can’t get away
I’m not the same...
– http://www.elyrics.net/read/l/letter-black-lyrics/hanging-by-a-thread-lyrics.html
Just a face in the city
Just a tear on a crowded street
But you are one in a...
– http://www.sing365.com/music/lyric.nsf/More-lyrics-Matthew-West/81BB6099EA9C307548256F3200065E5C
If the whole wide world is on your back
If the strength you need is the...
– http://www.sing365.com/music/lyric.nsf/You-Know-Where-To-Find-Me-lyrics-Matthew-West/14CAAD9E5ED15E8548256F3200065EE2
Look me in the eye and tell me honestly
What ever lies behind your broken heart...
– http://www.lyricstime.com/brandon-heath-reaching-out-lyrics.html
3 tags
Visual Studio clipboard gotcha
I am a huge fan of ReSharper’s Multiple Entries Clipboard. However, recently I have been struggling with a weird issue where the clipboard always seemed to get entries that contained a bunch of empty lines. This issue was especially common when I was moving code around and would delete extra empty lines.
I favor keeping my fingers on the keyboard and will often highlight text with the...
I’ve noticed how you’ve been withdrawn
everybody’s asking...
– http://www.metrolyrics.com/let-it-go-lyrics-the-oc-supertones.html
Just read through James’ book
Start to pray and ask God for a wife...
– http://www.metrolyrics.com/so-great-a-salvation-lyrics-the-oc-supertones.html
Well I pretend
I just need me
I seem so strong
But it’s make believe
...
– http://www.metrolyrics.com/perfect-love-lyrics-the-oc-supertones.html
February 2011
10 posts
My insides all turned to ash, so slow
And blew away as I collapsed, so cold
A...
– http://www.azlyrics.com/lyrics/linkinpark/valentinesday.html
I wander through the world
No meaning in my life
My mind is driving me insane...
– http://www.azlyrics.com/lyrics/dht/depressed.html
Your best friends with the word regret
Your afraid that your life’s been...
– http://www.sweetslyrics.com/805093.Luminate%20-%20Come%20Home.html
Get so caught up everyday
Tryna keep it all together
While the time it slips...
– http://www.azlyrics.com/lyrics/aliciakeys/tellyousomethingnanasreprise.html
Illusion never changed
Into something real
I’m wide awake and I can see...
– http://www.lyrics007.com/Natalie%20Imbruglia%20Lyrics/Torn%20Lyrics.html
Sidewalk Prophets - The Words I Would Say →
3 tags
Visual Studio 2010 not compiling projects when...
This problem has caused me many hours of grief due to how long to just put up with it before looking for a solution. How the setting got changed is still a mystery to me.
The problem manifested itself when I set a breakpoint and proceeded to hit the Debug tool strip button in VS 2010. It is important to note that I had the setting “Require source files to exactly match the original...
4 tags
Computer Controlled Garage Door Opener
So tonight I had my first lesson in robotics.
My goal was to be able to open my garage door from my computer using a RS-232 (serial) relay board.
The Parts:
R220HPRS RS232 Relay National Control Devices also offers a similar single relay control board, but since this was my first one, I knew I would find a use for the other relay at some point.
Enercell™ Adaptaplug™ K and Enercell™...
January 2011
6 posts
What Love Really Means →
One of my new favorite songs.
Windows Visa/7 Repair disks →
Great article on creating repair disks for Windows Vista/7.
4 tags
Exploiting NUnit attributes (ValuesAttribute)
Similar to my last post about using NUnit’s ValueSourceAttribute, this post offers another example of how to extend an NUnit attribute to get better unit tests.
For this example NUnit version 2.5 or greater is required.
Consider the following enum and test object.
public enum AnimalEnum : byte
{
None,
Dog,
Cat
}
public class ObjectToTest
{
public object...
Exploiting NUnit attributes (ValueSourceAttribute)
Often times it become necessary to use reflection in a unit test to verify that all child classes pass a particular test.
There are three basic ways to handle this:
Don’t write the test, code with no tests is always bug-free right?
Create an array of all of the child types. This is easy to do but not very scalable if the object is likely to be extended many times.
Use reflection to find...
2 tags
Dynamic context menu not showing on first click
Today I was faced with a very interesting problem. Given a user control the context menu was not being shown the first time the user right clicked. There was nothing special about the user control nor the context menu except that the menu items were dynamically generated during the context menu’s opening event.
Consider the follow code snippet:
bool _showItem1;
bool _showItem2;
private...
3 tags
Toggle an enum
Recently I have run into the problem where I created an enum to keep track of two states within my object. Sure could have just used a boolean but the enum seemed to make the code easier to read.
private enum SomeEnum : byte
{
FirstValue = 0,
SecondValue = 1
}
private SomeEnum _value;
public void ToggleValue()
{
...
December 2010
5 posts
Through my temptation to walk away,
and through the endless troubled days,...
– http://www.sing365.com/music/lyric.nsf/Lift-It-lyrics-Thousand-Foot-Krutch/FA22076C4289340A48256C81002F7BAC