Tuesday, March 6, 2012

Definition of Done - 10 Commandments

At the development team level every team needs to have a definition of DONE which everyone needs to abide by. When someone says a task is "done" before checking in code the following points should be met for it to be really done:

10 Commandments of DONE:

1. Though shalt follow use cases, user stories or other requirement document
2. Though shalt use follow editorial document for any content ( content is the king)
3. Though shalt follow design
4. Though shalt comment your code
5. Though shalt follow naming conventions and coding guidelines
6. Though shalt unit test
7. Though shalt get your code reviewed
8. Though shalt properly test your code’s functionality. Though shalt really not wait for only QA’s to test for you
9. Though shalt consider performance and security while coding
10. Though shalt attach your code to proper work item and add comments while checking in

Detail:

1. The code is providing functionality as documented in requirement documents like use cases, change requests, user stories etc.
2. If there is any content/text to be displayed it need to be properly added especially if your site is multilingual make sure you add all resource keys.
3. The code is following the approved design for the module/project.
4. The code is properly commented if required. Some methods, classes are self-explanatory. Commenting just for the sake of it is not required.
5. The naming conventions and coding guidelines are followed.
6. A minimum accepted level of unit/integration testing is there.
7. Code is reviewed by another member in your team. This also lets people explore each other's code and can provide support if required (a member leaving the team, absence etc.) It’s also a great learning process.
8. Do at least some basic testing. It is not just QA's job to properly test functionality. Developers should test their code with all possible scenarios etc. before checking in. Also if the code touches or modifies existing functionality a minimum regression testing should be done. This would avoid lot of back and forth between development and QA team and save us lot of time.
9. Performance and security is not something to be pushed at the end and should be considered during development and code review.
10. While checking in attach it to the proper work item and add comments while checking in.

Disable copy paste in an input field

Needed to disable copy, paste in an input field and tried different javascript solutions. It worked on most of the browsers except some versions of IE. After spending sometime with custom java script I gave up and rather tried the following tags in markup which worked in all modern browsers:

<input id="myInput" onCopy="return false" onDrag="return false" onDrop="return false" onPaste="return false" autocomplete=off type="text"/>

More information on these events can be found http://developer.practicalecommerce.com/articles/1906-JavaScript-s-Copy-and-Paste-Events.

Disable div contents with javascript

It is a common requirement to disable ( not hide) div contents on client side depending on certain logic. For example if you have inputs like radio buttons in a div and you want to disable all of them within the given div, you can disable the div to disable selection of any element inside the div.

One way to achieve this via java script is to use the disable attribute.

$('div#myDiv').attr("disabled", 'disabled');

This works in all browsers except firefox. After trying different ways to do it I finally wrote a small script that iterates through your container element (div in this case) and disables them. This works in all browsers.

$('div#myDiv').children().each(function(i,element){

$(this).attr("disabled", 'disabled');
});

Tuesday, January 11, 2011

Enable-SPFeature command throwing exception

I wanted to enable a feature which required special admin rights through power-shell and kept on getting the following exception:

Enable-SPFeature : Failed to create receiver object from assembly "ASSEMBLYNAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=eaf1b7820cf1
fb30", class "CLASSNAME" for feature "FEATURENAME" (ID: 08284496-c68e-4f6c-befe-5777d14ad74b).
: System.ArgumentNullException: Value cannot be null.

Spent hours trying to find the reason. The class was there. I even gaced manually, tried everything. But later a colleague of mine helped me out with suggesting to open a new instance of power shell and try it again. And it worked perfectly. What a time waste.

Wednesday, June 3, 2009

Optional parameters in SQL server

There might be situations where you would like to pass optional parameters to a stored procedure. Instead of constructing dynamic queries or doing many if else there is a cleaner way to do it.

SELECT [ClubId]
FROM [Club] where
(@ClubId IS NULL OR ClubId = @ClubId)

The where clause checks each parameter to see if it is NULL and in case it is checks the fields value with that of the parameter.

Friday, May 29, 2009

Manipulating div display in javascript and c#

To hide or show a div using javascript:
myDiv.style.display = "none";
myDiv.style.display = "block";

in C#:
myDiv.Attributes["style"] = "display:none;";
myDiv.Attributes["style"] = "display:block;";

Tuesday, February 24, 2009

Scroll to top on partial postback

In one of a project that I worked on we had a datalist with paging(datapager). The datalist was in an update panel to give the ajax impact and to improve the performance. The issue was when you scroll down to the page and move to the next page the page doesnt scroll up after partial postback.

It can be done by adding the following code in code-behind file in page load for example.

if (System.Web.UI.ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(MyPage), "pagingAnchor", "window.location.href = '#';", true);

Where MyPage is the name of your page or control.

This javascript code needs to be added in the page to cancel the default scroll behavior.

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(beginRequest);
function beginRequest()
{
prm._scrollPosition = null;
}