Monday, October 1, 2012

On to C# and MVC

I have finally gotten rid of the ghost that is VB.Net now.  Got a new job as a C# and MVC developer, and I love it!  The new gig is all working on internal apps for a very large company.  Actually some of the older apps (2003-ish) are still in, converted up to use VS 2010.  I can't wait to tear them apart.

Also I'm surprised at how much I'm enjoying living in C# land full time.  So far it is seriously cool.  No major translation problems or anything.  All good in the hood!

Friday, March 23, 2012

Don't call it a thread-off

I had to do something incredibly cool the other day so I thought I would share.

A web site I was building calls two WCF services per data request.  It's not my architecture.  But in this case, the data call was to take a text file and dump the contents into the SQL database.  Since those files can get longer than a typical HTTP request can stay alive, I started getting timeout errors while waiting for the WCF service to finish its processing.  My first thought was to make the processing asynchronous.

The fun thing about multithreading and asynchronous operations is that I was passing the file name and path to the saved text file into the WCF service.  I needed to spin off a new thread while passing in the parameter, which I didn't expect to be this easy.  Here's the code:

Public Function ImportThis (byval psFileName as string) as Boolean
     Dim MyAsync as New System.Threading.Thread(AddressOf AsyncImport)
     Return True
End Function

Private Sub AsyncImport(psFileName as String)
     'Put code to process text file here
End Sub

The end result is that my service returns true back to the calling page, but of course I wrapped it in a try/catch statement and had to do a couple of other things in there.  I watched the database just add records into the table, then clear them back out as the DB finished processing the import.  All while the web site thinks everything is ok.  Good practices also dictated that I put plenty of error trapping in the AsyncImport process, where it emails an administrator a list of bad records in the import, or anything else that goes wrong. 

Bottom line is that it was easy to spin off a new thread for some asynchronous processing, and pass a parameter value into the process.  Method #2 for doing the same thing is to create a private property for the service, set the property value in the public function, and call the property value from the async function.  But just passing the argument in is still the simpler approach.

Thursday, October 6, 2011

No More Steve

I started out as a PC user with DOS 2.16 or some really early version like that running on a 386 back in high school, and used the old 5.25" floppy disks for storage. As a sophomore in college my roommate had an Apple II that we used to write papers on. I used to take money (or beer) to type up papers for other students, because typing was the only thing I knew how to do on a computer, and that was before we had the internet publicly available. Senior year we finally started learning how to get online so I switched over to the PC. After college I went back to school to learn how to write code and fix pc's

That was the only time I ever used an Apple product. Still with Steve Job's passing away yesterday nobody can deny the influence he has given over technology as a whole. His vision will be missed by us all in the future.

Back in the mid-2000's when I had the business I did my fair share of Mac support and repair work, got to know the IOS pretty well. I could do all of your basic setup and admin work on mac's, getting them network connectivity. I remember when the first (maybe second) generation iMacs came out with intel processors and my business partner and I were some of the first people to roll out dual boot options with Windows 2000 and the Mac OS 9.

Now as developers we build web sites for use with mobile browsing, size and graphic constraints thanks to Steve Jobs influence. Designers alone are making everything with rounded corners now creating the same feel to products that Steve gave the Apple product lines.

I'm sure with a few more years we would have gotten more from him. He'll be greatly missed. But like I tell my kids today, you get what you get and you don't get upset. Thanks for everything Steve.

Monday, September 26, 2011

Slick Javascript Trim

I found a great Trim function for Javascript that I wanted to share. Got it from and it has the cleanest explanation of space removal I've seen in a while.

My task has some form validation for incomplete fields, and it was reported back to me that users were entering a space and it was passing the validation. Now this is also why you should use both server side and client side validation so that extra space crud doesn't go into your database. But that's another post.

My javascript (inherited - I found it but didn't write it) was doing a

if (document.formname.elementname.value == "") ....

so if you enter a space, that's not equal to empty string. Validation passed, right? That syntax alone is enough reason for me to switch to JQuery. But that's out of my control

Javascript by default will use regular expressions for string comparison. If we change the if statement to read:

if (document.formname.elementname.value.replace(/^\s+|\s+$/g, '') == "")

then it will remove all spaces in the form element text no matter what. The regular expression breaks down like this:

/ start the regex
^ from the beginning
\s look for spaces
+ not just as the first character
| or (really more like also)
\s+$ look for spaces until the end of the form text
/ end regex
g = make it global

And since this is in an IF statement, it's just going to check and see what happens if you strip out all of the spaces. If you type two words separated by a space it will still go into the database as two words. and the conditional statement will still return false.

This is the cleanest and "most right" trim statement I've seen yet. Very cool!

Tuesday, September 20, 2011

Binary Fun

Today's XKCD is worth a quick read. Too funny!

Sunday, May 1, 2011


Why is Microsoft pushing MVC so hard? All I hear about the new certification exams is that they are very heavy on MVC and JQuery. We've been using plenty of JQuery at work lately, I feel really comfortable in there.

But WHY all the MVC? I'm sure I can pick it up. But I'm going into it a bit begrudgingly. I know eventually I'm going to have to tell somebody who's currently in elementary school how "we used to do some really cool stuff in But MVC is such a different framework I'm not looking forward to the change.

Monday, May 10, 2010

Making Scrum Fail

I saw this article today about how to make scrum fail. We use Agile Scrum and I love it. others are not so enthusiastic. You do have to have the right people in the right roles.

I am posting a link to this because I think it's funny, not because I'm implying that we are falling victim to any of the conditions listed.