August 2010
3 posts
5 tags
Parse JSON Date into a javascript Date object
I’m recording this here so I don’t ever have to look for this solution again. It works perfectly with .net date json serialization and +400 timezones as well!
var date = new Date(parseInt(jsonDate.substr(6)));
The substr strips out the leading “Date” meta text.
2 tags
Linq : Converting a List to a List
Just like when I was learning regular expression, I find that I’m using Linq to do more and more with my data objects the more I use it.
Also with regular expression I’m wary of using it because it’s still not in the “everyday developer’s” skill set and if said developer ever has to debug my work, they might find it a steep learning curve.
This example...
4 tags
Detecting nested exceptions (because of CSLA)
CSLA is a pretty good middle-tier framework (though not without it’s complexity or problems). A colleague and I were discussing that for small organisations, it’s just not worth implementing it if you’re not going to be running the factory methods on one server and the executions method on another server…. but that is not what I’m here to talk about!
So my problem...
July 2010
3 posts
3 tags
Lightweight javascript graphics using SVN Vectors
Over at my favourite design website, they are discussing how to make a table of data gracefully upgrade itself from a table to a graph.. but to still be available as a table to non-supported browsers and spider-bots.
http://www.alistapart.com/articles/svg-with-a-little-help-from-raphael/
NOTE: Be aware, that at the time of writing, there is a bug that orders pie chart items by the highest to...
4 tags
Getting Started with NHibernate
A 6+ part series of “How-To’s” on getting started and mastering NHibernate.
Link to Article 1
4 tags
Versioning CSS and Javascript Files
I was reading a hints article regarding MVC and I came across a novel way of ensuring that you never have to ask a client to “Try clearing your cache”.
All you have to do is:
Implement auto version numbering on your application
Append the version number to the url for the .css or .js resource
So your resources will be cached until your version rebuilds, when the resource url will...
October 2009
2 posts
1 tag
Using jQuery with Greasemonkey (and including...
Since my recent, torrid love affair with all things jQuery, I decided to go back to Greasemonkey and see if I could integrate it with jQuery to make selection and manipulation jsut THAT much easier.. and guess what? …it is!
If you use the following script.. jQuery will be registered from Google’s CDN and then the code will loop until the script is included in the DOM and then execute...
2 tags
Online Unix Banner Generator
Sometimes you really want something to stand out. Unix banners are a great universal way of marking up text with an important message, but not having access to a Unix system, I couldn’t generate one!
Fortunately, this site has come up with the goods and will let you generate banners in a myriad of “fonts”. The example below was generated in “Letters” font.
OOOOO ...
September 2009
2 posts
4 tags
Handling multiple submit buttons in MVC v1
A lot of forms have input fields with multiple action buttons that act on that data. MVC doesn’t immediately offer an ability to detect which submit button was clicked.
One solution is to use different forms that are tagged with action labels that will invoke a method in a controller. The following works:
<% using (Html.BeginForm("Action1", "ControllerName")) { %> <%=...
2 tags
Thoughts on Oracle (FAIL)
So we’re starting new development on a web project. We’re also using Oracle with packages.
Oracle only supports object names of up to 30 characters. FAIL.
Oracle’s If..Else statement uses ELSIF. What? You didn’t want to waste space on an E? You can’t overload the loop to make it correct for future version? FAIL.
Want to quickly debug a stored procedure in TOAD?...
June 2009
3 posts
6 tags
How to Clone a DBParameter in .Net
DBParameter doesn’t support ICloneable. I wanted to clone my DBParameter collection because when I cached them, and then tried to reuse them, i was re-using a reference to the parameter which was already used in a different command object. This would throw a runtime error of “The OracleParameter is already contained by another OracleParameterCollection.”
The trick to getting...
4 tags
A list of free Windows utilities that do exactly...
There are a lot of dodgy freeware products out there. These do exactly what the name says:
AusLogics Disk Defrag - Fast, Efficient Defragger
Mouse Imp - Scroll vertically and horizontally by holding down your right-mouse button
TrueCrypt - The big daddy in reliable open-source encryption
Secure Delete OnClick - Removes any file without a trace.
Process Explorer - This is a task manager...
3 tags
Essential (and not so essential) Firefox plug-ins
Firebug - Amazing javascript/css/html debug tool
Download Statusbar - For the best downloading experience
Adblock Plus - No more annoying flash ads that yell out. Until the ads play nicely, I’m blocking them!
Tab Mix Plus - Lets you Control + Tab in last opened order
SearchPreview - Adds a preview thumbnail in standard Google searches.
Web Developer - The big daddy of...
May 2009
4 posts
4 tags
Oracle: Date manipulation
I’m just listing this because I ALWAYS forget the syntax for this small stuff.
Converting Varchar2 to Date:
SELECT to_date('01-JUL-2009','dd-mon-yyyy') FROM Dual;
Using todays date to build a relative date:
SELECT trunc(sysdate + 36) FROM Dual;
5 tags
Oracle: Searching for a keyword in the database...
It can be vitally important to know if an object is being referenced in a stored procedure or function, and although TOAD very helpfully will tell you all dependencies of an object, it is possible (if you are working on a horrible legacy project like me), to have SQL created on the fly and executed as a string. Yech!
SQL for searching your oracle procedures and functions:
SELECT * FROM...
3 tags
Oracle: Ampersands (&) in text/strings being...
While trying to specify a url with an ampersand inside a stored procedure I found TOAD (my favourite Oracle editor) asking me to specify a parameter. By default, Oracle will parse any string containing an & as a dynamic parameter within the text.
For example, a string of: ‘http://www.ibm.com/?fake=url&value=1’ will prompt you to specify parameter :VALUE
To change this...
3 tags
Oracle: Handling exceptions from child stored...
In some existing oracke procedure code I’m maintaining, I needed to handle and report on the exceptions thrown by a child stored procedure inside a parent stored procedure.
The child could throw expected custom exceptions using “”, but could also throw unexpected system exceptions. I wanted to be able to report on them all. This snippet of code below solved all my issues:
--...
April 2009
2 posts
5 tags
Oracle: CSV To String Array Function
So I was having difficulty passing an array of id’s as a parameter from java to an Oracle stored procedure. I didn’t seem to have many problems doing this in .Net, but java was a right headache for passing this as it was expecting a CERTAIN array type and a CERTAIN DB connection type.
For right or for wrong, I decided to pass the data through as a CSV string instead and have the...
4 tags
Firebug in browsers other than Firefox!
I love developing web apps in Firefox because of the Developers Tool bar and Firebug add-ins. Unfortunately my current web development target is IE 6 (curse you client!), so I’ve been toiling in the underground sugar-mines with IE Developer Toolbar, which just isn’t as fun.
Firebug have released a “Firebug Lite”, a javascript library (which i’m testing and updating...
January 2009
1 post
7 tags
Returning a result set from Oracle to .Net
Firstly, let me say how alien and difficult it is to change from SQL Server to Oracle. Secondly, if you are going to use Oracle, I definately recommend using it only in Toad for Oracle. It has built-in version control and intellisense.
Now to the issue at hand: Making an oracle stored procedure return a result set, and in my case, not just one result set, but multiple result sets. Unlike SQL...
October 2008
1 post
3 tags
Xpath Web Resources
Here are a list of Xpath resources that I’ve found useful:
Yahoo List of Processing XML with C#
MS XPathNavigator.Select examples
September 2008
2 posts
3 tags
Programming books online : Google Book Search
Google! Bless their little cotton socks! They are nice people (except any policy they have regarding China).
UPDATE: Go google! Way to stick to your guns (finally!)
They have a searchable collection of full and partial books online, which is great when you are trying to find book references on a specific code section.
Here is an example search for C# books that are partially and fully...
5 tags
WCF and Enums : The underlying connection was...
Problem:
I was getting the error “The underlying connection was closed: The connection was closed unexpectedly” when retrieving an array of a complex class.
Diagnosis:
It turns out that one of the enums in the class was not declared properly and this was causing this ambiguous error.
Solution:
Thanks to Merrick Chaffer for his article that told me what my I was missing.
The...
August 2008
6 posts
3 tags
SQL Server Database Locking (including Linq To...
Many thanks goes to Jeff Atwood for writing this concise article about MS SQL Server database locking problems and solutions, including a solution for locking hints for Linq to SQL.
Link to “Deadlocked!”
5 tags
Utilities I always install in Windows
DUPE! I’ve joined all my favourite installs at
A list of free Windows utilities that do exactly what they promise
3 tags
Setting Default Button when Hitting in a Text Box
The Problem:
You’re in a text box, and when you hit the <Enter> key, some random button is clicked instead of the button just below your set of text boxes.
The Fix:
Surround your text boxes and button with an <asp:panel> and set the panel property DefaultButton to the ID of the button you want to be clicked when the user hits <Enter>. You can set this property in either...
4 tags
Finding all references to an object in SQL Server
The problem: You want to change a parameter in a stored procedure or function, but you don’t know what other database methods are referencing it.
This SQL statement will show you all references, so you can be confident you’ve changed all references:
SELECT object_name(id), *
FROM syscomments
WHERE text LIKE '%SearchPhrase%'
3 tags
Performance: Method Calls vs. Extension Method...
I love the concept of extension methods. Code is neater, shorter, obvious to understand, more adaptable, a little more covoluted to find in code, but a great way to encourage a team to all use the same methods.
My one reserve I had about using them was their performance? Was there a noticable difference? It was time to test using my code from this post.
Ticks per 1,000,000 invokes
Method...
7 tags
Find Deeply Nested Child Objects in any Container...
We’ve all hit the problem of trying to find a deeply nested control and you loathe to say MyControl1.Controls[2].Controls[4].Controls[0] as it’s going to break at the first html change.
This function loops through an object and all nested objects until it finds the name you are after and breaks out.
This is also an extension method, so it can be called as a native method of any...
July 2008
8 posts
6 tags
Change Membership Password with Custom Password...
If you find that the Membership.ResetPassword() function generates too crazy a password, or you just want complete control over password generation, you may find it difficult to change the password.
The issue is that you need the OLD password to change to the NEW password. If you are storing your passwords in hashed format, you will never be able to retrieve the old password. This slightly...
6 tags
"Error Rendering Control" with a Custom Control in...
On the project I’m contracting on, there are some Custom Controls that override the Render method. These controls unfortunately were working perfectly at run-time in the browser, but in the WYSIWYG html designer in Visual Studio, the controls would render just as a grey box with the text
“Error Rendering Control - <control name> An unhandled exception has occurred. Object...
8 tags
Visual Studio Designer File Out Of Sync / Not...
I thought this was a rare occurance, but for whatever the reason, two people I know experienced an out of synchronisation aspx.designer.cs file in two days.
Firstly, make sure you’re not just being stupid :) Check that your .aspx page directive has a correct Codebehind property. Check the namespace AND the code file class name. Copy and paste them together to see if it looks the same.
...
3 tags
Moving the ViewState Hidden Input Control
A page with a heavy ViewState takes longer to load. A user with a slow conenction (dial-up or GPRS) will be waiting longer for the page to be served.
Additionally, many search engines have a page cut-off length. I believe Google pretty much stops indexing a page after 100k. Not that you should have a page that large, but if you have a large page and a large viewstate, google may well be...
4 tags
Matching html tags with Regular Expression / Regex
I <3 regular expression. To me it is pure programming joy. Creating an equation to find matches within highly varying strings.
I USED to know how to do this, but I had to look it up again, which is why it’s here.
I needed to parse some html comments out of code, but because Regular Expression is greedy by default if you have 2 html comments in code, a normal expression will start at...
4 tags
ASP.Net RadioButton control is teh sux0r
RadioButtonList controls are great as long as you don’t want any custom formatting or additional controls in your list. I like to avoid using the native HtmlControls controls (like HtmlInputRadioButton) as I feel if you’re going to use an Html control, you might as well use the “bells and whistles version” (unless the WebControl control isn’t accessiblility...
6 tags
Fix for bug Q316495 / 316495 : Radio Buttons Are...
Update: This “fix” unfortunately breaks postback logic. No matter what I seem to do, the radio buttons are unchecked on a postback. It must be a mismatch with the viewstate and what is in the Html. Any suggestions?
I thought I was going mad, but the ASP.Net RadioButton control completely ignores whatever you put in the property GroupName. Instead the INamingContainer control makes...
5 tags
Randomising an array, anti-sorting algorithms and... →
What I love about this article is how the obvious un-sorting method is plainly wrong and how a “thinking outside the box” method of using a guid to sort is a pretty even way to randomise a small array.
June 2008
3 posts
5 tags
Populate a ListControl with an Enum in C#
With the advent of ORM, a database can be used for just storing data. Data logic has moved back into the realm of the code application layers. This is great stuff.
Status types can be kept in enumerators and not duplicated in tables in databases. It however means that populating a DropDownList can be tricky as you can no longer populate them from datareaders.
Enum
public enum StatusType
{
...
3 tags
4 Guys From Rolla - Examining ASP.NET 2.0's... →
The first part of a very good and descriptive list of articles about asp.net membership.
3 tags
NHibernate, the original and better than LINQ to...
My first pure LINQ to SQL (L2S) greenfields project proved to be quite the headache (reasons for my headache)! I’ve decided for my next personal project to use NHibernate instead.
The reason I found L2S so attractive was that the designer did all the heavy lifting for me and generated all the code. I realise now that L2S is just Microsoft’s version of NHibernate, and that most of the...
May 2008
19 posts
4 tags
Things that are wrong with LINQ (VS2008 .Net 3.5)
A quick list of things that I think are wrong with this first interation of LINQ. Don’t misunderstand me, I am using it right now and it’s working well for me and I’ve not written a single stored procedure. Hooray! I am compiling this in the hope that the LINQ team (Scott Gu?) might find it and do something about it in the next version (or even the next service patch?)
In...
2 tags
Javascript Enumerators
Set up an enum In javascript,
var Enumerator = function(){}
Enumerator.DataType = {
COUNTRY : 1,
STATE : 2,
CITY : 3
}
To use, in javascript,
switch(dataType)
{
case Enumerator.DataType.COUNTRY:
itemContainer = $get('SelectedCountryContainer');
break;
case Enumerator.DataType.STATE:
itemContainer = $get('SelectedStateContainer');
break;
case Enumerator.DataType.CITY:
itemContainer...
3 tags
Ajax Control Toolkit UpdatePanel postbacks from...
In javascript,
__doPostBack('UpdatePanel1', '');
Note: __ is two(2) underscores
Web 2.0 Style Waiting Animated Gif generator... →
Generates different styles of waiting or processing animated gifs in any colour you choose. Recommended!
6 tags
Using javascript to set InnerText in Firefox and...
Internet Explorer has a nice property .innerText which sets non-HTML contents inside an HTML container. Firefox does not have this function. I found a solution that looks like this:
function UpdatePreview(sourceControl, destinationContainer)
{
if (destinationContainer.firstChild)
{
// if we have a child item, overwrite it
destinationContainer.firstChild.nodeValue = ...
4 tags
Using Page Methods with Ajax in ASP.Net 3.5
In your codebehind, make sure you include these two references:
using System.Web.Script.Services;
using System.Web.Services;
Then make sure the method you wish to connect with from javascript matches the following pattern. The method must have both attributes, be public and be static.
[WebMethod]
[ScriptMethod]
public static Object SaveData(Object data)
{
In your .aspx file (or master page) you...
3 tags
The LINQ .First() command throws an error if no...
I incorrectly assumed that this would return null or an empty record if no data was found, but instead it throws an exception!
Instead I should have used .FirstOrDefault() which returns a null value if no record was found.
tblKeyword keywordRow =
ageRanges.FirstOrDefault(a => a.Keyword == setWord)
as tblKeyword;
Which returns either a tblKeyword item or null.
Perl is the worst language I’ve ever had to work with.
– Me
3 tags
Using Ajax AutoCompleteExtender with Name and...
With release 4941 of the Ajax Control Toolkit, you can use name/value lists with Ajax AutoCompleteExtender! Huzzah!
1) In HTML, Declare an autocomplete extender with the OnClientItemSelected client event.
<cc1:AutoCompleteExtender
ID="KeyWordExtender"
runat="server"
TargetControlID="Keywords"
ServiceMethod="GetKeywordList"
ServicePath="~/Service/ServiceProxy.asmx"...
VS 2008 Web Development Hot-Fix Roll-Up Available... →
…until VS2008 SP1 comes out of beta.
Update: VS2008 SP1 came out!