« November 2008 | Main | January 2009 »

December 26, 2008

Using the Power of LINQ to Easily Manage Collections of Objects [Awesome] | Posted at 4:15 PM

I am currently working a WPF BlackJack implementation to further develop my object-oriented and .NET skills. I have a great book called VB 2008 Recipes. It’s all sorts of useful and I recently came across a super great way to manage my annoying collections of cards, players, etc. in the game.

Instead of implementing interfaces like IList or IEnumerator for, say, a Hand of cards, you can create a variable/property called Cards with a type List(Of Card). This creates a generic list of objects of type Card (your card class, or any other type of class you want a collection of).

Then, as in my case, you can perform some powerful functions that would otherwise take more lines of code to do. For example, in BlackJack an Ace can be valued as either 1 or 11, depending on whether or not it will make the Hand total over 21 (a bust).

The way I calculate the total value for a hand, I calculate the total of all non-ace cards and then calculate the total of the Aces based on that other total.

Here was the original code I used before implementing LINQ:

Dim Cards() As Card
Dim hasAces as Boolean = False
' Calculate total for non-Ace cards
For Each myCard As Card In Cards
    Select Case myCard.Rank
        Case Card.RankType.Ace
            ' Aces
            hasAces = True
        Case Else
            intTotal += myCard.Value
    End Select

If hasAces Then
    ' Do the same thing as above, only select case Ace
    ' and figure out the total
End If

That is a simplified version. Now, witness the power of LINQ combining that Select statement into a single line!

Imports System.LINQ.Enumerable


Dim Cards As List(Of Card)

' Calculate total for non-Ace cards
' PS. I <3 LINQ
intTotal = Cards.Where(Function(c) c.Rank <> Card.RankType.Ace).Sum(Function(c) c.Value)

' Any Aces?
If Cards.Any(Function(c) c.Rank = Card.RankType.Ace) Then

End If

As you can see, WAY more manageable! The reason LINQ can do this is because the System.Linq.Enumerable namespace has Extension methods like Sum, Where, Average, Max, Min, etc. that work with any kind of collection.

Previously, I was aware of LINQ to SQL and how great that was, but I didn't realize LINQ also worked with Objects (hence, LINQ to Objects).

Like I said earlier, instead of making my Hand class implement an IList, etc. I can just make Cards a property so that when I need to add a card, retrieve a card, etc from an external class, all I need to do is:

MyHand.Cards.Add(new Card)



If you want more information about LINQ to Objects, check it out on MSDN!

December 19, 2008

Oh My God, Browsing the World in 3D [Google Earth] | Posted at 12:05 PM

Minneapolis in Google Earth, 3D Buildings

(Not a photo. Click for larger. Source: Google Earth)

So I read a little post about the new Google Earth update and how NYC is in 3D.

I decided to download Earth and look at Minneapolis (see above). So. Awesome.

To enable 3D buildings, just check "3D Buildings" in the sidebar. Then hold down right-mouse button and zoom in. Once you're in far enough, the view still start to tilt and the buildings will take on depth.

It is SO COOL to just fly around the city, I was looking at the U of MN campus and I recognized all the buildings instantly. I was half expecting to see little people moving around. I think they should add that, just for fun!

Welcome to SimWorld.

December 16, 2008

Image Grid Creator [.NET] | Posted at 2:40 PM


Update (3/5/09): Added project to Intrepid Studios.

I told you I was going to create some software that would let you make album cover grids. And I did!


To download the software, head on over to the Image Grid Creator project homepage.

December 13, 2008

SurveyMonkey Broken in Firefox 3 on Windows XP | Posted at 1:13 PM

It seems as though SurveyMonkey is not working properly in Firefox 3 using Windows XP. I used it fine on OSX Firefox 3, but two machines using Windows XP are unable to use the site because it seems to be missing some .NET scripts that enable post backs. The JavaScript console asserts that __dopostback is undefined. Strangely, it works in Windows Vista.

Hopefully they'll get this sorted out, it's ironic that I can't contact them because I need those scripts in order to use their forms.

This is why I make sure to design in a way that does not require Javascript to use the site's major functions. Like logging in and reporting bugs.

In the meantime, IE and Opera work.

December 9, 2008

Review: Where Wizards Stay Up Late by Katie Hafner | Posted at 7:39 PM

Where Wizards Stay Up Late Ever wonder what that little "@" sign means in your email? What about why we put "www" before we visit a website? How about the origin of email itself? Look no further than Katie Hafner's Where Wizards Stay Up Late: The origins of the Internet. In it, Katie and co-author Mathew Lyon outline the origin of the Internet from concept to implementation, from the very first networked terminals in ARPA to the modern TCP/IP-driven Internet we know and [mostly] love.

This is not so much a book of the technical underpinnings of the Internet, though there is much of that, so much as it is about the people who did it all. Let it be known that I love technology, I live for it. What amazed me while reading this book was the people who were involved that no one except people knee-deep in computer science/networking talk about. Take J.C.R. Licklider, a prominent psychologist turned computer enthusiast. He was put in charge of ARPA (the Advanced Research Projects Agency department), a strange choice considering he was a behavioral psychologist. However, without him we may not have had the Internet as we see it now. The ARPANET was the predecessor to the Internet and without ARPA and Licklider's passion for keeping the department alive there would not have been an ARPANET. The book says it best:

"Lick's thoughts about the role computers could play in people's lives hit a crescendo in 1960 with the publication of his seminal paper "Man-Computer Symbiosis." […] In the moment Licklider published the paper, his reputation as a computer scientist was fixed forever. He shed the mantle of psychology and took on computing. There was no turning him back." (pp. 34-35)

To think a former psychologist would be the one are the forefront of computing, it was amazing even back then.

There were other fascinating facts that I had never read about before contained in the book. For example, people keep citing the development of ARPANET was a way to protect national security after a nuclear attack. In fact, my IT Infrastructure teacher cited this reason! I didn't know better until I read this book. Bob Taylor, one of the former heads of ARPA and the starter of ARPANET, has tried his best to distill this common myth, having known "the project embodied the most peaceful intentions—to link computers at scientific laboratories across the country so that researchers might share computer resources" (p. 10).

Later in ARPANET's life, there are still surprises to be had. Will Crowther, who I had never heard of, developed a game called Adventure for ARPANET. It was a cave exploring game, it even had graphics, and "was a simplified, computer version of Dungeons and Dragons" (p. 206). When Crowther, dispirited by a recent divorce, ceased development of the game and left it on a BBN computer, Don Woods, a graduate student at Stanford heard about the game and downloaded it from there. He got the source code from Crowther and fixed it up, adding new features and ridding it of bugs. He created a guest account for people to login to the Stanford computer to play it and it was a huge hit. Myself being a gamer, this little tidbit of fact was especially fun to read.

Reading Where Wizards Stay up Late is definitely not a chore. I definitely recommend picking this one up, you won't be disappointed. It's a joy to read, both for the interesting historical anecdotes along with the conversational and engaging storytelling nature of the narrative. It is definitely not a vanilla history book but rather is a deep and fascinating read about the lives of those who spent nights upon nights building us one of the most valuable tools in human history: the Internet.

Review: The Art of Deception by Kevin Mitnick | Posted at 6:39 PM

Art of Deception

When you think of a hacker, what comes to mind? A scruffy man sitting in his parent's basement, the constant whirring of servers and computers in the background, staring at all three of their computer monitors, Moutain Dew cans strewn about, typing away madly while streams of code scroll madly down one of the screens? At some level, that may hold true but in the case of social engineers, that is, the craft of conning persons into divulging sensitive or seemingly innocuous information, a different impression should be formed. By their very nature, social engineers are friendly, helpful, clean cut, and have a very good way of making you trust them. That's the other kind of hacker, the kind, it could be argued, that is more dangerous.

This is the mind of the person we are privileged to enter through Kevin D. Mitnick's recent book, The Art of Deception: Controlling the Human Element of Security. Mitnick, one of the more famous, or perhaps infamous, social engineers of our time shares his secrets about how the mind of a social engineer works and how they ply their trade.

Mitnick discusses two ways of formulating a social engineering attack: from the outside and from the inside. By that, he means that you can either use the telephone or actually entering the premises. He cites several techniques a social engineer uses to compromise a victim including directly asking the question, building trust, causing a problem then fixing it, reverse social engineering, email attachments/phishing scams, and a "reverse sting" or causing the victim to ask the attacker for help. A social engineer uses psychological methods to appeal to people's specific emotions like guilt, empathy, and trust.

What I most found interesting in this book was the way Mitnick explained the techniques and methods. Instead of outlining how to attack, he created fictional (but based on real attacks) stories that are from both the attacker's perspective and the victim's perspective. I found that these really helped me understand how social engineering worked, along with his definitions and "Mitnick Messages" peppered throughout. Sometimes, however, I felt that he used too many anecdotes when instead he could have explained more about the background of the attacks. There was minimal use of actual, non-fictional stories to illustrate his points which I think would have increased the impact of these stories. Despite these shortcomings, the stories are very illustrative and thought out, often raising your curiosity as to how these types of attacks can actually succeed. Indeed, there are many stories that will tickle your spine as you realize how vulnerable these large corporations really are.

Mitnick doesn't only provide all the different kinds of problems and attacks your company is susceptible to, he also outlines an entire policy to combat the weaknesses in your human element of security. However, no amount of security policy will ever protect you from all social engineering attacks, as Mitnick warns, "unless everyone in the enterprise understands that security is important and makes it his or her business to know and adhere to a company's security policies, social engineering attacks will always be a grave risk to the enterprise," (p. 259). Even so, there are important ways you can minimize risk from attacks. Some of these include:

  • Classifying your data effectively such as Confidential, Private, and Internal.
  • Extensive and detailed verification and authorization procedures
  • Management policies aimed at executives and management-level employees

There is an entire chapter dedicated to a large and extensive security policy.

While social engineering may not have been something you've heard of, after reading Mitnick's book it is apparent that this is a serious consideration in any organization's policy. Chances are you have been victim of a social engineering attack, I know I have. One time, a solicitor who came to our house was so friendly and convincing that I went out of my way to donate money to his cause in exchange for a magazine subscription. Needless to say, I never got one. If I had read The Art of Deception before that con-man had manipulated me, I might have been smart enough to catch his lie. Don't get caught like I did, do yourself a favor and buy this book, or you may end up losing far more than $20.

How To: Create a Grid of Album Covers [Zune] | Posted at 1:16 PM


If you are looking for a way to easily create a grid of your favorite album covers or artists, there is a decent implementation of the technique in the Zune Software. You don't need a Zune to use it.

All you do is let it scan in your library, then start playing a song. Click the bar graph in the bottom right corner to go into Now Playing view. You will see the program fill in your albums like it shows above.

You can take a screen shot and cut out whatever you want.

This gave me an idea, though. There's no easy way to customize how that grid looks because it constantly gets updated. So I was thinking of making some simple software that would do the same thing, only with better customization.

It'd be a fun project and someone would find it useful, I think. Winter break work!

December 6, 2008

Sample: Using A Strongly Typed Data Source in .NET [Exercise] | Posted at 1:40 PM

From my IDSC 3102: Intermediate Programming class, here is the second program we had to complete. It was a simple Database connection project, but I used and played with a strongly typed dataset.


What It Is

A grading program that allows you to input grades for a select number of students, save changes to the DB, and view a semester report. The report should show a list of students and their cumulative semester average calculated using a specific formula. It should also display a "printable list" for your students to view their grades, showing only the last 4 digits of their SSN.

What You Will Learn

  • How to set up and utilize a typed DataSource (DataSet.xsd)
  • Dynamically save any changes from a DataGridView to its underlying Datasource
  • Validate and prevent data entry errors
  • Set up a Mask (i.e. ***-**-1234 for a social security number) for a  column on a DataGridView control

Download Source

Download zip (165KB)