Thursday, 31 May 2012

How to gain detailed system information about your Windows 7 PC

 

1. Open the Performance Information and Tools option from control panel (or just hit [Windows Key] + [Break] together).

2. Click on the View and print detailed performance and system information link

image

3. Now you will see the following information, that you can event print out easily. This is how I found the model number for my laptop anyway...

image

4. For even more detailed information just run C:\Windows\System32\msinfo32.exe - or launch it from the msconfig.exe, Tools tab

image

Tuesday, 29 May 2012

JQuery event debugging

http://james.padolsey.com/javascript/debug-jquery-events-with-listhandlers/

CODE

Here’s a useful debugging plugin for jQuery. It will list the handler/’s of any event bound to any element:

/ UPDATED -> NOW WORKS WITH jQuery 1.3.1
$.fn.listHandlers = function(events, outputFunction) {
return this.each(function(i){
var elem = this,
dEvents = $(this).data('events');
if (!dEvents) {return;}
$.each(dEvents, function(name, handler){
if((new RegExp('^(' + (events === '*' ? '.+' : events.replace(',','|').replace(/^on/i,'')) + ')$' ,'i')).test(name)) {
$.each(handler, function(i,handler){
outputFunction(elem, '\n' + i + ': [' + name + '] : ' + handler );
});
}
});
});
};

USAGE


It’s pretty simple to use, you can specify the elements (as you usually would, via a selector), the events to be listed and the output function to which the plugin will feed the data.

If you’re using firebug then it’s best to use either the console.log function or console.info.

// List all onclick handlers of all anchor elements:
$('a').listHandlers('onclick', console.info);   // List all handlers for all events of all elements:
$('*').listHandlers('*', console.info);   // Write a custom output function:
$('#whatever').listHandlers('click',function(element,data){
$('body').prepend('<br />' + element.nodeName + ': <br /><pre>' + data + '<\/pre>');
});

Note, this will only work if you’ve used jQuery’s native event registration methods, e.g.$(elem).click() / $(elem).bind('click').

image

Thursday, 24 May 2012

How to change the default collation of SQL 2008 R2 database

I've managed to change mine with this following statement. It only took about 4 mins to fix, once I'd got the right installer files mounted on my V drive, and shut down my virus scanner.

Ran this from a VS 2008 .NET command prompt, after shutting down all my sql server services too…

V:\>setup /Q /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SAPWD=NotTellingYou! /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /SqlCollation=Latin1_General_CI_AI

Tuesday, 22 May 2012

How to query the TFS 2010 Source control database (TFSWarehouse) using TSQL

Found this blog useful today, when a colleague of mine asked how he can produce a report of all the changes from members of his team on their database scripts in TFS source control...

http://stackoverflow.com/questions/834107/tfs-query-in-visual-studio-to-get-all-check-ins

Something like this example was what we ended up using ...

USE [Tfs_DefaultCollection]  

SELECT distinct cs.CreationDate, cs.[ChangeSetId], c.DisplayPart, cs.[Comment] , v.[FullPath]
from [tbl_ChangeSet] AS cs
left outer JOIN [tbl_Identity] AS i ON cs.[OwnerId] = i.[IdentityId]
left outer JOIN [Constants] AS c ON i.[TeamFoundationId] = c.[TeamFoundationId]
left outer join dbo.tbl_Version as v on v.Versionfrom = cs.ChangeSetId
WHERE creationdate > '04/12/2012'
and (v.FullPath like '%\Database%')
ORDER BY cs.[CreationDate] desc

Friday, 18 May 2012

Microsoft MVC Best Practices

http://wiki.asp.net/page.aspx/1014/aspnet-mvc-best-practices

The ASP.NET MVC is becoming more and more popular each day.  As the application grows in size so does the maintenance nightmare.  Following are some of the better practices, that if followed, may help maintain our application and also provides a means of scalability as the demand increases.  Feel free to add/update practices/tips as required.

Do note that this checklist are just for quick reference and are not detailed materials and can be used as a quick reference.  

  1. Isolate Controllers
    Isolate the controllers from dependencies on HttpContext, data access classes, configuration, logging etc.  Isolation could be achieved by creating wrapper classes and using an IOC container for passing in these dependencies
  2. IoC Container
    Use an IoC container to manage all external dependencies  The following are some of the well known containers/framework.
    1. Ninject
    2. Autofac
    3. StructureMap
    4. Unity Block
    5. Castle Windsor

  3. No "magic strings"
    Never use magic string in your code.   More to come on this.
  4. Create a ViewModel for each view
    Create a specialized ViewModel for each view.  The role of ViewModel should only be databinding.  It should not contain any presentation logic.
  5. HtmlHelper
    For generating view html use HtmlHelper.  If  the current HtmlHelper is not sufficient extend it using extension methods.  This will keep the design in check.
  6. Action Methods
    Decorate your action methods with appropriate verbs like Get or Post as applicable.
  7. Caching
    Decorate your most used action methods with OutputCache attribute.

  8. Controller and Domain logic
    Try to keep away domain logic from controller.  Controller should only be responsible for
    1. Input validation and sanitization.
    2. Get view related data from the model.
    3. Return the appropriate view or redirect to another appropriate action method.
  9. Use PRG pattern for data modification
    PRG stands for Post-Redirect-Get to avoid the classic browser warning when refreshing a page after post.  Whenever you make a POST request, once the request completes do a redirect so that a GET request is fired.  In this way when the user refresh the page, the last GET request will be executed rather than the POST thereby avoiding unnecessary usability issue. It can also prevent the initial request being executed twice, thus avoiding possible duplication issues.

  10. Routing
    Design your routes carefully.  The classic route debugger comes to rescue http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
  11. There should be no domain logic in the views. Views must be, only, responsible for showing the data.
  12. Views should not contain presentation logic
    Views should not contain any presentation logic.  For e.g. If a "Delete" button is to be displayed only for "Admin" role this should be abstracted away in an Html Helper.  This is just an example and there will be many scenarios which will require this abstraction for easy maintenance of views.

  13. Use POST for "Delete" links instead of GET
    Using Delete links (GET) is more vulnerable than using POST.  Here is a detailed post on this along with a couple of alternatives.
    http://stephenwalther.com/blog/archive/2009/01/21/asp.net-mvc-tip-46-ndash-donrsquot-use-delete-links-because.aspx

Thursday, 17 May 2012

Apple iPod Touch won't start apps or games

Recently my iPod started stopping playing games or allowing apps downloaded from the app store to work. On attempting to open an app or game, it would redirect you back to the home screen immediately.

Found the answer on the way to work today on the train, and thought I'd share it here, as I managed to fix it by tethering my iPod to my Android phone and connecting it to the internet via my portable Wifi hotspot created on my phone.

All you have to do is simply sign back into the app store. I did this via updating an existing app I had on the phone. Downloading a new app would have worked as well.

See here for more information...

http://answers.yahoo.com/question/index?qid=20081228053307AADf6S8

Monday, 14 May 2012

Virtualization in WPF with VirtualizingStackPanel

First blogged about this on my previous blog site here
 
However, having come across this again today on a project, I thought it was important enough to re-blog!
Finally managed to figure out how to get virtualization to actually behave itself in a listbox wpf control.
Turns out that in order for Virtualization to work, you need three things satisfied.

1) Use a control that supports virtualization (e.g. list box or list view). (see Controls That Implement Performance Features section at bottom of this page for more info http://msdn.microsoft.com/en-us/library/cc716879.aspx#Controls )

2) Ensure that the ScrollViewer.CanContentScroll attached property is set to True on the containing list box / list view control.

3) Ensure that either the list box has a height set, or that it is contained within a parent Grid row, where that row definition has a height set (Height="*" will do if you want it to occupy the Client window height). Note: Do not use height=”Auto” as this will not work, as this instructs WPF to simply size the row to the height needed to fit all the items of the list box in, hence you do not get the vertical scroll bar appearing.

4) Ensure that there is no wrapping ScrollViewer control around the list box, as this will prevent virtualization from occuring.
 
5) Ensure that you use a VirtualizingStackPanel in the ItemsPanelTemplate for the ListBox.ItemsPanel
 
 
Example

<Grid Name="listBoxesGrid"
      Grid.Row="2">
  <Grid.ColumnDefinitions>
    <ColumnDefinition/>
    <ColumnDefinition/>
    <ColumnDefinition/>
  </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

  <!-- Target Organizations listbox -->
  <ListBox Name="targetOrganizationsListBox"
           Grid.Column="0"
           HorizontalContentAlignment="Stretch"
           BorderThickness="0"
           Margin="5,10,15,2"
           ScrollViewer.HorizontalScrollBarVisibility="Disabled"
           ScrollViewer.CanContentScroll="True"
           VirtualizingStackPanel.IsVirtualizing="True"
           VirtualizingStackPanel.VirtualizationMode="Recycling"
           SelectionMode="Multiple"
           Width="Auto"
           Background="Transparent"
           ItemTemplate="{DynamicResource TargetOrgContactCard}"
           Height="Auto"
           Expander.MouseDoubleClick="targetOrganizationExpander_MouseDoubleClick"
                      Executed="OnAddToCallList" />
      <CommandBinding Command="local:SearchCoverageCommands.OpenCallDashboard"
                      Executed="OnOpenCallDashboard" />
      <CommandBinding Command="local:SearchCoverageCommands.AddComment"
                      Executed="OnAddComment" />
      <CommandBinding Command="local:SearchCoverageCommands.TargetCompanyChecked"
                      Executed="OnTargetCompanyChecked" />

    </ListBox.CommandBindings>
    <ListBox.ItemsPanel>
      <ItemsPanelTemplate>
          <VirtualizingStackPanel IsVirtualizing="True"
                                  VirtualizationMode="Recycling" />
      </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
  </ListBox>

</Grid>

Friday, 11 May 2012

Alternatives to .NET Reflector

ILSpy = http://wiki.sharpdevelop.net/ILSpy.ashx

Decompilation to C#

  • Supports lambdas and 'yield return'
  • Shows XML documentation

 

JetBrains dotPeek = http://www.jetbrains.com/decompiler/

Uses similar keyboard shortcuts to JetBrains Resharper.

HTML Agility pack

My mate Hendy just pointed out this lovely little agility pack for HTML parsing

http://htmlagilitypack.codeplex.com/

Friday, 4 May 2012

TestDriven.Net does not require [TestMethod]

Just found out something interesting about TestDriven.Net. It allows you to run code logic as a test, even when the [TestMethod] attribute is not on the method you're testing.

However don't try doing this with an client side integration test, as you'll just get an endpoint not set in code exception!

Thursday, 3 May 2012

Altering an indexed view drops the indexes

Whilst altering the an indexed view yesterday I noticed some quirky behaviour that I was not expecting until a colleague of mine kindly pointed it out to me.

If you alter an indexed view, then all the indexes for that view will be dropped too! (This is not pointed out to you in any of the feedback messaging that SQL server outputs either when altering the view).

So you'll have to put back the indexes, with the clustered index being created again first, before you can use the NOEXPAND hint in any dependant database object.