Software Development Meme

Posted on July 1st, 2008 in Uncategorized by Jon Kruger

The Todd tagged me so I guess that means I’m it.

How old were you when you started programming?
I don’t exactly remember, but I think I was around 9 or 10. We had an Apple IIe with a green screen monitor. I don’t remember how I discovered that you could write programs on it, but I did.

How did you get started in programming?
See above… that was when I was younger. Once I got out of grade school, I spent all my time playing sports or hanging out with friends so I didn’t spend that much time on the computer anymore. When I graduated high school, they told me I had to pick a major and computer science sounded better than anything else out there.

What was our first programming language?
BASIC! Lots of GOTO and GOSUB. Ick.

What was the first real program you wrote?
I had an internship in college and I worked for a small consulting firm. The main project was a commercial video editing program written in C++ called CineStream. It was pretty cool getting to work on software that actually sat on shelves, and $11 an hour is a lot when you’re a college student!

What languages have you used since you started programming?
BASIC, C++, Java, PHP, Perl, Javascript, C#

What was your first professional programming gig?
I worked for Thomson Tax and Accounting (back then it was called Creative Solutions), where we wrote tax and accounting software for accounting firms. I lived in the C++ world for a couple years and then got to make the jump to C#/.NET. It was a fun place to work… we had a basketball court in the parking lot, so we had leagues after work and played often during lunch. More workplaces need stuff like that.

If you knew then what you know now, would you have started programming?
Heck yeah! My one reservation about going into computer science in college is that I was afraid that I would end up in some cubicle for the rest of my life and not talk to anyone all day. Now I sit in a room with 12 other developers every day. Quite the opposite of what I was afraid of. Some people say that computer geeks are anti-social, awkward people. I guess it just depends on who you’re talking to, because the software developers I know are a pretty social bunch.

If there is one thing that you learned along the way that you would tell new developers, what would it be?
You can always learn something from anyone, so don’t put other people down or think you’re better than them because everyone can teach you something (sometimes, they’ll teach you what not to do!). Find other smart people and learn everything you can from them. Put others first before yourself. Don’t throw your people under the bus. A lot of this stuff really applies to life in general, not just life as a software developer.

What’s the most fun you’ve ever had programming?
My favorite feature I’ve ever had to work on was a custom report generator for a financial analysis application. Basically I had to write a custom spreadsheet control that could do Excel-style formulas and lots of custom financial analysis functions. It was quite a challenge. But I’d have to say right now I’m having as much fun as I ever have in my career because I sit in a room with 12 other developers who know what they’re doing and we have a lot of fun doing it (even if I don’t write much code anymore).

How to automatically back up your personal files

Posted on May 23rd, 2008 in Uncategorized by Jon Kruger

Most of us have lots of pictures, music, and other stuff on our home computers that we can’t afford to lose.

We’ve all heard many times that we need to back our stuff up, and other people have posted about this before. Unfortunately I ignored all the warnings and was met with a “disk read error” when I booted up my laptop last week. Crap.

Luckily I had been backing up a lot of stuff to CDs, but I had slacked off over the last year. Most of the pictures that I really wanted I could get back from other people, so I didn’t lose too much.

(Side note: seeing “disk read error” has an upside — the wife turns to me and says, “I think we need to buy a new computer.” The Wife Acceptance Factor will never get any higher than that.)

My Backup Strategy

I need something that is automated so that it doesn’t rely on me having to manually go and burn CDs, upload files, etc. because I will forget to do it. I need something that happens frequently because with a newborn in the house I will be taking lots of pictures, and I can’t afford to lose them. I didn’t want to back up to another computer in my house either (because I don’t want to maintain it, and to protect against some unlikely event like a house fire or someone breaking in and stealing everything). Here’s how it all works:

I downloaded and installed WinSCP, which is an FTP client that has a very powerful scripting language and has built-in functions to help you synchronize data. I downloaded the 4.1.3 beta because I needed some of the scripting capabilities that they added in the later releases.

Now that I have WinSCP installed, I had to write my script. Luckily the WinSCP scripting language has some pretty good documentation. I have two files, a batch file that I will run and a WinSCP script file that is called from the batch file. I am going to synchronize files from my machine to my web hosting provider (which I have to host my blog), which is running on Linux.

Here are the two files (I have them in my C:\autobackup directory):

winscp backup batch file.bat:

@echo off
:waitloop
echo Waiting for wireless.…
Ping jonkruger.com -n 2 |find /i "Request timed out" > nul
if %errorlevel% ==0 goto waitloop
:connected
 
rem Stall for time so that I'm sure that the wireless is connected
Ping 127.0.0.1 -n 20
 
@echo on
 
echo connected to wireless
"C:\program files\winscp\winscp.com" /console /script="c:\autobackup\winscp backup script.txt" /log="C:\autobackup\backup detailed log.txt" > "C:\autobackup\backup log.txt"
echo done

winscp backup script.txt:

# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
 
# Disable overwrite confirmations that conflict with the previous
option confirm off
 
# Exclude files that I don't care about
option exclude "*.db; *.ini; *.tmp;"
 
# Connect to the server (replace with your username, password, domain)
open username:password@mydomain.com
 
# Do the work
synchronize remote -delete -mirror "C:\Documents and Settings\all users\Documents\My Pictures" "/pictures-backup"
 
# Close and exit
close
exit

Note that in winscp backup batch file.bat, the stuff at the top of the file is checking to make sure that I’ve connected to my wireless network before I try and connect to the server.

You can read more about the options for the WinSCP “synchronize” script command here. Basically what I’m doing is synchronizing the remote FTP server to have the same files that I have on my local machine. I’m only doing the synchronization one way (meaning that changes on the remote FTP server will not be synched back to my local machine), but WinSCP will allow you do the two-way synchronization if you want to.

Now I set up a scheduled task in Windows to run my “winscp backup batch file.bat” file. I checked the box that says “Wake the computer to run this task”.

Just like that, all of my pictures are backed up every night to a remote server, without any interaction from me, and I can see the results in a log file. I can easily update my script file to back up other directories too.

There are probably lots of other backup solutions out there, including Mozy.com, which allows you to back up 2 GB worth of data for free, or unlimited data for $4.95 a month. Web sites like this are probably worth looking into… I created my own solution because I already had the web hosting space available and WinSCP made it pretty easy.

So now that I’ve done all the work for you, you have no excuse! Don’t wait to back up your stuff or you might end up with nothing left to back up!

Filtering Intellisense lists in the WF RuleSetDialog

Posted on February 3rd, 2008 in Uncategorized by Jon Kruger

Recently on our project we’ve been diving into Windows Workflow Foundation, particularly the rules engine. This process is relatively painless since Microsoft was kind enough to expose the RuleSetDialog class so that you can use the WF Rule Set editor in your application. This code is as easy as doing something like this:

// Create a RuleSet that works with Orders (just another .net Object)
RuleSetDialog ruleSetDialog = new RuleSetDialog(typeof(Order), null, null);
 
// Show the RuleSet Editor
ruleSetDialog.ShowDialog();
 
// Get the RuleSet after editing
RuleSet ruleSet = ruleSetDialog.RuleSet;

That’s how simple it is to include the RuleSetDialog in your application. The problem is that the Intellisense dropdowns in the RuleSetDialog expose private and protected members of your class, and Microsoft doesn’t give you any way to filter the Intellisense list. So you end up with stuff like this:

Intellisense with private and protected members

Microsoft is aware of this issue, and they haven’t said anything definite about doing anything about this problem.

When you’re writing a commercial application or something that non-developers are going to use, you don’t want this kind of cryptic stuff in the list. I don’t want to expose all of the private members of my classes to the user, just like how you don’t expose private members of a class in a public API.

One way to filter the list is to create an interface and pass the interface type in as the first parameter in the RuleSetDialog constructor. This way you won’t have all of the private and protected members of the class in the Intellisense because an interface only exposes public methods. So now you’re constructor looks like this:

// Create a RuleSet that works with Orders (just another .net Object)
RuleSetDialog ruleSetDialog = new RuleSetDialog(typeof(IOrder), null, null);

This is a decent solution, but it still has problems:

  • You have to create the interface.
  • System.Object members like Finalize(), GetHashCode(), and Equals() are still exposed.

Like I said before, in my commercial application, I don’t want users to have to see all of this extra stuff. I only want to show them the things that I want to show them.

Well, thanks to Reflector, I was able to come up with a way to let you filter the list. In my example, I can filter out all of the protected and private members, filter out static types, only display members decorated with an attribute, or completely override the list to only display strings that I’ve added. So now you can easily get something that looks more like this:

Filtered Intellisense

Much better!

Now I must warn you. This solution is making extensive use of reflection to get at private and internal methods and events that Microsoft didn’t feel like exposing to us. So I felt a little dirty while I was writing it, but it gets the job done!

Here is the code. Please leave a comment if you find anything wrong with it.

Here are some other good posts about the WF Rules Engine:

Execute Windows Workflow Rules without Workflow
Introduction to the Windows Workflow Foundation Rules Engine
External Ruleset Demo

Enjoy!

Why I should’ve gone to CodeMash last year

Posted on January 13th, 2008 in Uncategorized by Jon Kruger

I went to CodeMash this year. Last year I did not. Sure, I knew that there would be a lot of good talks, but can’t I earn the same information by reading books and blogs, listening to podcasts, etc.?

Now I see why I was wrong. People I work with talk about the value of being involved in the .NET community, and now I see why they are right.

Sure, the talks were great. But by far the best part is being able to sit down with people who know way more than me and ask them about problems that I’m having right now on my current project. That kind of free advice is invaluable.

In the technology world, there is always tons of new stuff out there, and there’s no way that I can keep up with it all (especially with a wife and a kid on the way). If I want to be someone who can make good architectural decisions, how can I do that without having knowledge of what’s out there? Since I can’t keep up with it all, I could use some other people that can help out.

So I plan on trying to be more involved in the local .NET community (user groups, blogging, etc.), and I’m really excited about it. Hopefully I can make some worthwhile contributions of my own while I’m at it.

Minor batch file tricks

Posted on January 7th, 2008 in Uncategorized by Jon Kruger

Just so I don’t forget how to do these things…

Remove quotes:
SET Line=”C:\Program Files\”
SET Line=%Line:”=%
echo %Line% — will output: C:\Program Files\

Remove a trailing backslash:
SET Line=C:\Windows\
IF “%Line:~-1%”==”\” SET Line=%Line:~0,-1%
echo %Line% — will output: C:\Windows

I’ve been published!

Posted on July 24th, 2007 in Uncategorized by Jon Kruger

Winamp’s equalizer no longer works on DRM music files

Posted on June 29th, 2007 in Uncategorized by Jon Kruger

Winamp has been my media player of choice for years, and for two very simple reasons — global hotkeys that allow me to change what’s playing without opening up the app, and the Classic Skin which is really really small so that it doesn’t take up lots space on my desktop with some gaudy looking interface. No other media player has these things (even though someone could probably code something like this in a day or two).

I installed Winamp the other day (I had just been listening to music on my mp3 player for awhile) and I discovered that the equalizer no longer works on DRM tracks! I thought, there has to be some mistake. Without the equalizer your music doesn’t sound right at all.

Apparently there is no mistake. It sounds like AOL (which now owns Winamp) was in danger because it was fairly easy to create Winamp plugins that would allow you to strip DRM out of your music files. Because of this, AOL was getting pressure, so they first completely took away the ability to play WMA files in Winamp and eventually fixed so that you could play WMA again — but now the equalizer doesn’t work.

So now because Winamp was a little too user-friendly, Microsoft and the music industry are playing hardball and are forcing us to use their inferior media players. I never really minded DRM because DRM helped bring about iTunes and other online music stores without the mass piracy of the last 90’s, but when something like this happens, it’s really frustrating.

World travel, according to Google

Posted on April 11th, 2007 in Uncategorized by Jon Kruger

Apparently Google employees have their own preferred ways of getting across the pond (read the directions carefully!).