Monday, September 26, 2011

Slick Javascript Trim

I found a great Trim function for Javascript that I wanted to share. Got it from http://developer.loftdigital.com/blog/trim-a-string-in-javascript 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

MVC?

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 vb.net. But MVC is such a different framework I'm not looking forward to the change.

Monday, May 10, 2010

Making Scrum Fail

http://glenndejaeger.wordpress.com/2010/05/06/how-to-make-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.

Sunday, October 18, 2009

LINQ Rocks

I'm becoming a convert. The new job is awesome, I'm loving Raleigh. But this new gig has me focusing on a subset of VB.Net (ADO.Net) that I've never had to dive into before. and it rocks.

LINQ to Entities is a small but durable subset of ado.net introduced in framework 3.5. It gives you separated OOP layers to run between a DB (or multiple db's) and the rest of your framework. You can define an EDMX file to obfuscate your data, and it will generate the XML to connect your business layer to. These become your objects (entities) for the entity framework.

I've always been inherently opposed to OOP layers, they just add complexity when it isn't really needed. You end up creating spaghetti code with LINQ to Entity, but it's not as bad as it could be. and once it's built, it's built. I'm becoming a convert.

Once your data layer is built it's done. This makes the front end extraction considerably easier. You write linq queries instead of T-SQL queries, which are a completely different syntax.

The ease of front end development and flexibility of the LINQ syntax are what's really making me turn over the leaf. In T-sql, I'm hooked on aggregates. I can do anything in t-sql, been writing it for years. I'm still at the bottom of the learning curve from the LINQ syntax. But using .Include's to create joins has me intrigued. I'm actually looking forward to learning more. which hasn't happened in a long time with vb.net.

Friday, October 2, 2009

Last day on the job

Well, it's good to be changing jobs. Today is my last day on this work from home job, and next wednesday I start the new gig with a software company in Raleigh, NC. The new job is all VB.Net web sites over SQL Server databases, hosted in the same environment. It's going to be nice to have something stable that isn't a pressure cooker environment where anything can be thrown at me.

Here's to new beginnings!

Wednesday, September 23, 2009

New Digs

Well, it happened. I accepted a new job offered to me yesterday. Looks like all that whining about switching to C# was unfounded. The new digs are strictly VB.Net over SQL Server. Now I have to get a car, sell the house, work my way out of this job, buy a house.... geez. let the whining begin.