Unit Testing for Life

My grand C# project as of late has been a WPF Powerball simulator. I once hacked it up with WinForms and got everything to work by smearing public modifiers all over the place and ignoring good practice, but now that it really matters, I have taken the more professional approach.

At first, things were working great. The code behind was executing flawlessly, and the last thing to do was implement the payout logic. That’s when it occurred to me that my code behind was getting sloppy, and I wanted to pull out the logic into a separate class file. The moment I did, all functionality broke, as I no longer had access to the Window instance. Thus began a two day journey to learning bindings and MVVM, and I cannot honestly say there are any truly good tutorials out there on it.

Just a few minutes ago, I finally got the Powerball values to start populating. You see, I’ve learned so very much in the past two days, but what I learned actually had little to do with WPF. Sure, there has been a lot of confusion about the ICommand interface and how in the world to get events to work as bindings, but I learned that a { get; set; } declaration is required even on public properties when you want to access them from outside, that one should be really careful not to mistake an object for one of its properties, and that using constructors properly is very important for getting things to work they way you want. This is OOP in the trenches.

My greatest mistake has been trying to convert my application all at once. Without finding simple ways to understand bindings, I found myself flinging solutions at the whole thing, and it turns out what primarily kept my application from working was a mistaken understanding of how to pass values between the model and viewmodel. I suspect that one of the best ways to learn is to bite off one piece at a time, similar to unit testing. If you can get that basic piece to work, they you are far better equipped to to solve the next larger piece, and so on until you can isolate bugs to the newest features and their implications to other elements of the application. I’ve never thought about actually approaching learning from this perspective.

Next steps are to get those commands to work, but after a very long day, it’s time for a movie.

Capture the Flag

Yesterday I attended my second security Capture the Flag event and it was once again quite fun. The challenges had not changed, but I was able to get further into the Linux challenges and onto the second AppSec challenge, which features a rather grizzly C program in all of its archaic goodness.

I learned, with the help of my friend Mike, that…

  1. sudo can work at the group level, and apparently I don’t know how to set permissions for that
  2. less is a powerful program and you can perform operations on chunks of text or the entire text, such as a base64 decode on a cryptic file
  3. the password system that allows teams to increase their scores on the score board get sent in plaintext over the network.

Yeah, about that #3. I took a long Wireshark catpure which I will be using soon to extract all the passwords that people entered onto the scoreboard. No big deal. Granted, I will be revealing my strategy once it works, but once again I have encountered the conundrum of how to encrypt traffic over an intranet. Why work hard when you can work smart? That’s what hackers do. I do still plan to learn, of course, but my hope is to teach a lesson.

Visual Studio Woes


I put my old Powerball Simulator up on GitHub today, and started to continue working on the newer version that uses WPF. I decided to rename the namespace I was working in as I wanted to tame all of the elements in the solution, and came face-to-face with my greatest frustration with Visual Studio: the absolute ubiquity of configuration and code behind files, which nest and hide references everywhere.

See, I come from a Python background. As long as the program is in your path, all you have to do is insert an import statement to pull in other libraries, type your program, then you type “python yourfile.py” on the command line and BOOM, you have a working program. C#? You have debug directories, assembly directories (because apparently the system doesn’t know where to find System.Core etc.), and God forbid you write a simple program that doesn’t have a “code behind” to match every other file in your program. It took me a good half hour just to figure out what was causing my program to die because that old namespace was referenced in five places I never manually typed it out.

I do appreciate how much Visual Studio automates, especially with XAML presentations, but I wish I understood why all of the things in place are there. Long ago, I opted to learn ASP.NET by manually typing the aspx file and discovering what worked, what did not work, what was required in the declaration, and what I could safely exclude which VS  otherwise automatically supplies. That was great. It will take time and experience to really figure out whether I even need all of this messy configuration for other programs.

Rant over.

// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>

Falling Behind

I used to be a CSS master back in the CSS2 days. Granted, I was not a webdesign master by any means, I simply had a strong knack for whitespace, layout, and colors. As time has gone on, I have read about CSS3 and even realized that my understanding of the positioning system had been wrong (master status revoked!), but I keep forgetting new features and keep stumbled into new ones. Not going to lie, it really frustrates me. The downside to all this programming and markup is that you really never master anything. You can only strive to be highly proficient, and even then Google is your friend.

I have been beefing up my Bootstrap skills because I’ve done quite a bit of on-the-job work with Bootstrap, but I haven’t really built anything from the ground up. Going from the basic grid structure, I built out a few “row”s and needed to style everything starting with “col” so I wouldn’t need to type out every possibility (col-md-1, col-md-2, etc). I stumbled across a new CSS feature on Stack Overflow and was able to apply the following to get what I wanted:

div[class^=”col-“] {
border: 1px solid #000;

Since when did regular expressions get absorbed into CSS? And why that kind of syntax? Shouldn’t you just be matching an attribute value with an attribute itself, not the actual string that sets the value of the attribute?

Looks like I have a lot to learn, but at least I’m also learning how to override Bootstrap classes so I can avoid building a cookie-cutter website. Sure, that’s what my previous company did with a few different colors and our client loved it, but most of the time it shouts “lazy” from the rooftops. Lazy is good for a throw-away test, not a unique identity.