Regular Expressions are powerful things, but they are difficult to learn when your main objective is to produce business-critical information systems and you must also keep up to date with the latest .net features, the latest browers and quirks, the latest version of CSS, new Javascript libraries.....I think you get the picture. It's something else to learn. This is the reason we google our parsing requirements and re-use existing regular expressions, without actually understanding them.
I had a couple of requirements of my own and couldn't solve the more complex parsing with regular expressions. So, I've knocked up a light-weight string parser to satisfy my needs. I thought I'd share it with you. Here's the class in C#:
Here is one technique for creating a consistent/equal height column layout in CSS. This takes advantage of relative and absolute positioning.
Copy the HTML and CSS below and paste into a text file. Save the file as default.htm and double click. Add and remove lorem ipsum text to the content div and watch the right-hand columns grow and shrink consistently.
A common aspect of transactional and analytical programming in information systems is searching on a date range. When performing a search it's important that our SQL is accurate. Take a look at the following SQL that will exclude rows that should be included in the results.
This isn't difficult to fix, but it's something that is often overlooked, or missed.
What's wrong with this where clause?
Let's try a scenario:
We are working with Win Forms or Web Forms and we need some neat method of allowing a user to pick a date range so they can get results. We drop a couple of pickers on a form and code accordingly. The datetime values received from said controls will have their time portions set to 00:00:00 because these controls, by default, allow us to pick dates. Let's face it, users aren't really concerned with time when they're producing month end reports.
So, when a user picks 1st Nov 2009 to 30th Nov 2009 they want the search to be inclusive, meaning they want data from the 1st and from the 30th to appear in the report. Here's the problem: where SubmittedTime <= @DateTo is searching for all rows whose SubmittedTime is less than or equal to the 30th November 2009 at midnight. Will the data that John Smith entered on the 30th Nov 2009 at 10:05:12 be included in this report? No. Neither will any rows entered on the 30th.
Add One Day and Trunc
To fix this problem we need to add one day to the end date, remove(trunc) the time portion and then use the less than(<) comparison operator in the search. I'm truncating the time portions to be on the safe side.
A Re-useable Function
I'm human and I don't write SQL every day. If you're human and occasionally forget things then try this function for size.
Data stored in the cache is shared; it is not thread-safe. If you modify the data then the next request will see your changes. Sometimes developers are under the illusion that because they have assigned the data in the cache to a new object variable or performed a shallow copy of the cached data that they can make change without consequence. Not true. Here are a few classes to help protect you. However, you still need to ensure that your cacheable objects are deep copied (derive from my IDeepCopy and implement).
Combine this code for request-safe data caching.
The contents of CacheArgs.csThe contents of IDeepCopy.csThe contents of Cacher.cs
I've been doing some reading on Microsoft forums and I came across quite a lot of posts with questions about string manipulation using various Transact-Sql string manip. functions. It prompted me to write this little snippy-snappy-snoo
One of the questions was about extracting a portion of a string. Here's an example of how to extract a sub string from a string that has consistent seperation of parts. The following Sql will extract and print the third part (number 6717) from the string assigned to the @data variable.
How to Check the Latest Version of .Net Framework Installed
Type javascript:alert(navigator.userAgent) into your browser's address bar and you will receive an alert informing you of the versions of .Net installed on the local machine. Hats off to Walker News for this little jogger.
Here is a snippet of code you can use if you require some global, catch-all error logging. Create a Global.asax file in your web project and replace the generated Application_Error handler with the following code. Also, create a Logs directory in the root of your web app. This is where the log files are written.
There are better logging solutions out there but this is still a useful snippet if you need something snappy that doesn't require much of a learning curve.
Hello. I'm Mark Graham. In no particular order, I love creativity, fine-art/ graphics/ photography, innovativeness, my partner, my kids, guitar music, Joe Satriani(no, not in that way), .net, programming, the web, golf, coffee in, coffee out, my blog, my ambition
Code and Rock is a new methodology that I designed. You basically start up Visual Studio, then slap on a rocking track. Snare that spacebar! Try it with this one from Joe Satriani...