Posted on June 29, 2007
Here’s a cool little script my boss showed me. If you want to find a snippet of code in a stored procedure, but you can’t remember the stored procedures name, use this query:
select so.name as 'storProc'
from sysobjects so
join syscomments sc
on so.id=sc.id
where so.type='P'
and sc.[text] like '%BIT_YOU_WANT_TO_FIND%'
Change the BIT_YOU_WANT_TO_FIND to whatever you want to search for.
Works a treat!
Posted on June 28, 2007
I found this on a Microsoft Forum Posting – apparently the navigation bar was slowing things down a bit – and if you’re anything like me, you never use it anyway.
The navigation bar is this thing at the top:

Go to Tools > Options > Text Editor > C# and click the Navigation Bar check box.
You should notice a speed boost when you type code or use intellisense!
(Be sure to turn it off for HTML if you use Asp.net as well. Tools > Options > Text Editor > HTML)
(I haven’t proved scientifically that this speeds things up yet…)
Filed under: Asp.net |
Posted on June 27, 2007
After using Textmate for a couple of weeks I’ve come to realise how incredibly powerful and beautiful it is! Creating text snippets is a breeze – and improves productivity no end!
To achieve the same affect in Visual Studio though is a right pain in the butt-ocks. All I wanted to do was create a very basic snippet to define a static method (because I was creating a bunch of them all at the same time) and had to get down and dirty with some XML.
Anyhoo – here’s my result:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Public Static Method Declaration</Title>
<Shortcut>pubs</Shortcut>
<Description>Code snippet for creating a static method</Description>
<Author>Chris O'Sullivan</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>return_type</ID>
<ToolTip>Return Type</ToolTip>
<Default>void</Default>
</Literal>
<Literal>
<ID>method_name</ID>
<ToolTip>Method Name</ToolTip>
<Default>method</Default>
</Literal>
<Literal>
<ID>param_type</ID>
<ToolTip>Param Type</ToolTip>
<Default>param_type</Default>
</Literal>
<Literal>
<ID>param</ID>
<ToolTip>Name of Param</ToolTip>
<Default>param</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[public static $return_type$ $method_name$($param_type$ $param$)
{
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Then you just type pubs[tab] and it will create a declation like this:
public static void method(param_type param)
{
}
With the ability to tab between the different fields.
But oh man what a pain that was to do! (I love you textmate – xx)
Filed under: Asp.net |
Posted on June 24, 2007
I’ve just been learning how incredibly powerful Test First Development is in Rails – being able to test for elements on the dom using assert_select is fantastico!
However I note that there’s no opposite – a deny_select if you will. Something that will test to see if a given element does NOT exist.
Here’s one I cooked up earlier:
def deny_select(element, message)
assert_select element, false, message
end
Use it by passing in the css element id and the message if the assertion fails like this:
deny_select 'table.calendar', "Calendar should not be on page"
Filed under: Ruby on Rails |
Tagged with: testing |
Posted on June 20, 2007
Something you can’t seem to do in RJS is to do conditional checking with the client side DOM.
For example, I want to be able to investigate an element to see if it has the CSS display tag set to none. The solution is to blend javascript and RJS together.
To do this you append the javascript as a string to the page object like this:
# Javascript check to see if the element is visible
page << "if ($('div_element').style.display == 'none') {"
# Wow - this is like being in a PROPER if statement!
# RJS stuff to make the element visible
page.replace_html 'div_element', :partial => 'some_partial'
page['div_element'].visual_effect :blind_down
# back to javascript
page << '}'
Thanks to Rails Casts for that particular little tidbit!
Filed under: Ruby on Rails |
Posted on June 18, 2007
So, I was working on something that required a loop through enumerated types (in this case, go through the different repayment methods of a mortgage calculator)
public enum RepaymentMethod
{
RepaymentOnly ,
InterestOnly,
MixOfBoth,
}
To loop through this, use Enum.GetValues() to grab an array of the enumerations, and walk through it like this:
Array repaymentMethods = Enum.GetValues(typeof(RepaymentMethod));
foreach (RepaymentMethod method in repaymentMethods)
{
calculator.RepaymentMethod = method;
calculator.doStuff();
Assert.AreEqual(0, calculator.MonthlyPayments);
}
Filed under: Asp.net |
Posted on June 15, 2007
So yesterday I was working on an application that was going ridiculously slow and I couldn’t figure out why.
That’s when I used the open source program nprof to profile my application to see where the bottlenecks are!
(Download it here )
According to the documentation, this can also be used to profile web apps too!
It’s really easy to use. Open nprof exe

Input your executable path into the Application textbox (and any command line args in the Arguments textbox) and then hit F5.
This will spawn a copy of your app that you can use normally. After the application successfully closes then you get a list of what methods were called during the running of the app and what percent of application time was spent in that application
e.g:

Also on the left hand side in the Runs list you can see previous times you’ve run the program in the profiler – allowing you to make comparisons to see what methods are currently slowing you down.
Pretty cool!
Filed under: Asp.net |
Posted on June 13, 2007
The Elements of Style is a fantastic little book detailing best practices for writing.
It's written as a series of rules about the best way of writing clear, concise elegant writing.
Subsequently, there's a series of programming language books that do a similar thing. One on my bookshelf is Baldwin, Gray and Misfeldts
The Elements of C# Style that provides style guidelines for C#.
For example:
Element 73: Choose Simplicity over Elegance
...there is nothing particularly elegant about a 50 line sequence of if-else statements, but if it's the simplest most straightforward approach to the problem, there is no reason to turn it into something it does not need to be.
And other tasty tid-bits.
If there's ever a language that's just CRYING out for a definitive style guide, it's Ruby. Rubyists are such purists about style, simplicity, DRY etc - but there doesn't seem to be (at least not to my eye) a list from on high as to best practices for style issues.
That was until I found Ian Macdonalds
Unoffical Ruby Usage Guide that seems to be a pretty exhaustive study into Ruby best practices.
For example:
We recommend two blank lines between each class and module definition, and a single blank line between each method definition
Hooray!
oo - I also see Jeremy McAnally has created a project to do just this. Find it at:
Elements of Ruby Style
Filed under: Ruby on Rails |
Posted on June 02, 2007
Ok, so you're creating a beautiful .aspx page - and then you flip to design mode to use an auto tag or something. You flip back to the source and WHAMMO your beautiful layout has been messed up by the stinking asp.net design mode!
So, you spend the next 5 minutes wasting your life by ensuring all the div tags etc line up...
OR
You hit Ctrl K then Ctrl D and in seconds your code is wonderfully, beautifully, elegantly laid out!
Fantastic!
This works on code-behind files as well
Filed under: Asp.net |