About Me

My photo
Northglenn, Colorado, United States
I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).

Tuesday, October 30, 2007

Parallel Processor Programming

A good article in programming for parallel processors for .Net.

I really like this concept because it is easier to understand, implement and faster performance compared to threading.

http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx

Beware of AJAX update panel

A, "why I didn't see that before?", popped into my head thanks to:

http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/

He discusses the concept of the Update Panel. When you are doing a simple update inside the panel, you have to remember that it acts like a refresh but only returning the necessary data to that panel. This is obviously a huge load on the server.

Instead try using the web service method with the AJAX library to get a cleaner result.

I'm more of the old school ASP.Net 2.0 where I'm use to the asynccallback method. In thinking that the update panel was a simpler, quicker solution was nice though, but this just makes more sense.

String Sort vs. Word Sort in .Net

An interesting set of articles that Michael Kaplan has been discussing on why it might seem that there is a bug in the compare functions of a string.

In the two sorting styles these would be equal:
String Sort: 'co-op' vs. 'co_op'
Word Sort: 'co-op' vs. 'coop'

In the string sort the minus and underscore are treated as symbols which are given the same "weight".

In the word sort the minus and underscore are treated as "special" symbols with differ weights.



//
// Sorting Flags.
//
// WORD Sort: culturally correct sort
// hyphen and apostrophe are special cased
// example: "coop" and "co-op" will sort together in a list
//
// co_op <------- underscore (symbol)
// coat
// comb
// coop
// co-op <------- hyphen (punctuation)
// cork
// went
// were
// we're <------- apostrophe (punctuation)
//
//
// STRING Sort: hyphen and apostrophe will sort with all other symbols
//
// co-op <------- hyphen (punctuation)
// co_op <------- underscore (symbol)
// coat
// comb
// coop
// cork
// we're <------- apostrophe (punctuation)
// went
// were
//



Now there is a problem that occurs when using a hypen (‐) U+2010 vs. hypen-minus U+002d (-) in string comparisons. The hypen-minus is treated as a minus, which could cause confusion.

So be careful when using the String.Compare function.
Interesting Note: StringCompare is used in SQL-Server for sort keys.



Source: http://blogs.msdn.com/michkap/archive/2007/09/20/5008305.aspx

So basically use the default for a lingusitc sort, but use CompareOptions to do a ordinal sort.

Source: http://msdn2.microsoft.com/en-us/library/system.globalization.compareoptions.aspx

Monday, October 29, 2007

3 common ASP.Net AJAX mistakes

Source: http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/

In summary:

  • Page_Load executes during every partial postback, same as regular postbacks.
  • Use IsPostBack and IsInAsyncPostBack to avoid accidental execution of Page_Load code during partial postbacks.
  • In conjunction with __doPostBack, __EVENTTARGET may be used to limit UpdatePanel life cycle event execution to only the targeted panel.
  • Control events, such as Click and SelectedIndexChanged, fire after Load events.
    By using PreRender instead of Load, you can allow control events to be handled before your code executes.

Friday, October 26, 2007

Ramp Up

So, if you're an Aspiring Developer, Java Developer, VB 6.0 Developer or a developer with Visual Studio 2002/2003 then you have a good chance to ramp up to Visual Studio 2005. MSDN Ramp Up is a set of lessons for those who want to quickly learn and develop in VS 2005. http://msdn2.microsoft.com/en-us/rampup/default.aspx

I just hope they will have one for VS 2005 to VS 2008 soon.

Thursday, October 25, 2007

Optimize your regular expressions

An interesting article by Tess: http://blogs.msdn.com/tess/archive/2007/10/25/net-hang-case-study-high-cpu-because-of-poorly-formatted-regular-expressions-identifying-tight-loops.aspx

She went into the issue that if you don't optimize your regular expressions, the run time can be increase exponentially as the size of the string increases.

The reason for this, is because the regular expression is a NFA (Non-Deterministic Finite Automata)

Her example:
given the string: helloworldhelloworld
using regex: ([a-z]+)*= versus [a-z]*

given the string: abcde
Regexp: (abe|abc)(dg|dc|de) versus ab(e|c)d(g|c|e)

The long version

The order of execution here will be something like

a matches a in abe
b matches b in abe
c doesn't match e in abe, backtrack to try with the next expression
c matches c in abc - done with first part
d matches d in dg
e doesn't match g in dg, backtrack to try with the next expression
e doesn't match c in dc, backtrack to try with the next expression
e matches e in de - done with the regular expression


She recommends to avoid/decrease


  • nested quantifiers (*, +, {m,n})

  • backtracks

  • ambiguous matches (i.e. in this case the number of combinations that cause a positive match for part of the string)

Friday, October 19, 2007

Wednesday, October 17, 2007

Funny, but true: Tester's Translation Table

"It seems to me that lots of people are experiencing lots of confusion regarding what lots of the testing terms we throw around signify. In an effort to remedy this circumstance I have applied my investigatory powers to observe what people really mean when they say these words. Forthwith, the answers which I have compiled:"

http://blogs.msdn.com/micahel/archive/2007/10/17/ATestersTranslationTable.aspx

Concat strings in Javascript performance.

An interesting post to read: http://blogs.msdn.com/jscript/archive/2007/10/17/performance-issues-with-string-concatenation-in-jscript.aspx

So basically they are fixing the performance speed it takes to concat strings in javascript for the next release of IE. The improvement is very significant.

Monday, October 15, 2007

Command Line short-cut variables

%windir% = value from GetWindowsDirectoryW
%systemroot% = value from GetWindowsDirectoryW
%systemdrive% = first two characters from GetWindowsDirectoryW
%systemdir% = value from GetSystemDirectoryW
%username% = value from GetUserNameW
%programfiles% = value from ShGetFolderPathW(..., CSIDL_PROGRAM_FILES, ...)
%userstartmenu% = value from ShGetFolderPathW(..., CSIDL_STARTMENU, ...)
%allstartmenu% = value from ShGetFolderPathW(..., CSIDL_COMMON_STARTMENU, ...)
%userdesktop% = value from ShGetFolderPathW(..., CSIDL_DESKTOPDIRECTORY, ...)
%alldesktop% = value from ShGetFolderPathW(..., CSIDL_COMMON_DESKTOPDIRECTORY, ...)
%userfavorites% = value from ShGetFolderPathW(..., CSIDL_FAVORITES, ...)
%allfavorites% = value from ShGetFolderPathW(..., CSIDL_COMMON_FAVORITES, ...)
%userappdata% = value from ShGetFolderPathW(..., CSIDL_APPDATA, ...)
%allappdata% = value from ShGetFolderPathW(..., CSIDL_COMMON_APPDATA, ...)
%allusersprofile% = value from GetAllUsersProfileDirectoryW
%userprofile% = value from GetUserProfileDirectoryW
%appexedir% = value from GetModuleFileNameW

Optimizing SQL Server CPU Performance

http://www.microsoft.com/technet/technetmag/issues/2007/10/SQLCPU/default.aspx

Some interesting FYI facts from the article:

  • In performance value: high-end dual-core processor > RAM > fibre optics > disk drive
  • A data page in SQL Server is 8KB.
  • An extent in SQL Server is made up of eight 8KB pages, making it equivalent to 64KB.
  • Pulling a data page that is already cached from the buffer pool, at peak performance, should take under half a millisecond; retrieving a single extent from disk should take between 2 and 4 milliseconds in an optimal environment.

Check CPU utilization with PerfMon by monitoring: % Processor Time (<80%),>

Some optimizations are:
Query plan reuse
Reducing compiles and recompiles
Sort operations
Improper joins
Missing indexes
Table/index scans
Function usage in SELECT and WHERE clauses
Multithreaded operation

Resources for information on query plan reuse:
Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005 (microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx)
Optimizing SQL Server Stored Procedures to Avoid Recompiles (sql-server-performance.com/rd_optimizing_sp_recompiles.asp)
Query Recompilation in SQL Server 2000 (msdn2.microsoft.com/aa902682.aspx)

HL7 Schema Generation Tool

"Enables customizing schemas that ship with Microsoft BizTalk Accelerator for HL7"

http://www.microsoft.com/downloads/details.aspx?FamilyID=94877261-1f04-40b7-8c6d-cf92f38d09a3&DisplayLang=en

The tool they use to make HL7(v2.0) into XML.

Pre-req: BizTalk Server 2006 R2 or BizTalk Server 2006

Tuesday, October 09, 2007

Developing Tools to use with VS

Helpful developing tools:

Process Monitor -
"shows real-time file system, Registry and process/thread activity. It combines the features of two legacy Sysinternals utilities, Filemon and Regmon, and adds an extensive list of enhancements including rich and non-destructive filtering, comprehensive event properties such session IDs and user names, reliable process information, full thread stacks with integrated symbol support for each operation, simultaneous logging to a file, and much more."

http://www.microsoft.com/technet/sysinternals/FileAndDisk/processmonitor.mspx

Process Explorer -
"shows you information about which handles and DLLs processes have opened or loaded."

http://www.microsoft.com/technet/sysinternals/utilities/processexplorer.mspx

Auto Runs -
"has the most comprehensive knowledge of auto-starting locations of any startup monitor, shows you what programs are configured to run during system bootup or login, and shows you the entries in the order Windows processes them. These programs include ones in your startup folder, Run, RunOnce, and other Registry keys."

http://www.microsoft.com/technet/sysinternals/utilities/autoruns.mspx


Sources:
http://www.microsoft.com/technet/sysinternals/default.mspx
http://blogs.msdn.com/progressive_development/archive/2007/10/09/motley-says-the-only-tool-i-need-is-the-debugger-part-1.aspx

WaterMark It

So, I developed another personal window application. This app, WaterMark It, allows the user to take an image (hopefully that they own) and place a watermark on it. The program allows the user to make the watermark text/image with some opacity. The user can, print, save/save as, view thumbnail, etc....

I have also included in installation the source files, just incase you want to make fun of my horrible programming. <^_^>

The source file will be placed in (by default): C:\Program Files\Andrus Development\WaterMarkSetup\Source

http://williamandrus.tripod.com/WaterMarkIt.html

Tuesday, October 02, 2007

Implementing Custom ToolTip in C#

I needed to change the default font family, of the tool-tip, to a Unicode version; since it doesn't accept Japanese characters.

Here is my tool tip class, which inherent:

    1    class WaterMarkToolTip : ToolTip

    2     {

    3         public WaterMarkToolTip()

    4         {

    5             this.OwnerDraw = true;

    6             this.Draw += new DrawToolTipEventHandler(OnDraw);

    7 

    8         }

    9 

   10         public WaterMarkToolTip(System.ComponentModel.IContainer Cont)

   11         {

   12             this.OwnerDraw = true;

   13             this.Draw += new DrawToolTipEventHandler(OnDraw);

   14         }

   15 

   16         private void OnDraw(object sender, DrawToolTipEventArgs e)

   17         {

   18             DrawToolTipEventArgs newArgs = new DrawToolTipEventArgs(e.Graphics,

   19                 e.AssociatedWindow, e.AssociatedControl, e.Bounds, e.ToolTipText,

   20                 this.BackColor, this.ForeColor, new Font("Arial Unicode MS", 8.25f, FontStyle.Bold));

   21             newArgs.DrawBackground();

   22             newArgs.DrawBorder();

   23             newArgs.DrawText(TextFormatFlags.TextBoxControl);

   24         }

   25     }



Here is the implementation into the toolstripbutton:



    1     class WaterMarkToolStripButton : ToolStripButton

    2     {

    3         private WaterMarkToolTip toolTip;

    4         private string _toolTipText;

    5 

    6         public WaterMarkToolStripButton()

    7         {

    8             this.toolTip = new WaterMarkToolTip();

    9             this.toolTip.UseAnimation = true;

   10             this.toolTip.AutoPopDelay = 500;

   11             this.toolTip.AutomaticDelay = 500;

   12 

   13             this.MouseHover += new EventHandler(WaterMarkToolStrip_MouseHover);

   14 

   15         }

   16 

   17         void WaterMarkToolStrip_MouseHover(object sender, EventArgs e)

   18         {

   19             this.AutoToolTip = false;

   20 

   21             this.toolTip.Show(this._toolTipText, Owner, 1500 );

   22         }

   23 

   24         /// <summary>

   25         /// Get/Set ToolTipText for this control

   26         /// </summary>

   27         public new string WaterMarkToolTipText

   28         {

   29             get

   30             {

   31                 return this._toolTipText;

   32             }

   33             set

   34             {

   35                 this.toolTip.RemoveAll();

   36                 this._toolTipText = " " + value + " ";

   37             }

   38         }

   39 

   40     }

Visual Studio 2005 Add-In: Code to HTML

Ok, this is a very cool tool and time saving add-in for visual studio 2005. Just highlight the code you want to copy to html, right click > copy to html. It does the formatting, color scheme, etc..

http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/




1 class WaterMarkToolTip : ToolTip


2 {


3 public WaterMarkToolTip()


4 {


5 this.OwnerDraw = true;


6 this.Draw += new DrawToolTipEventHandler(OnDraw);


7


8 }


9


10 public WaterMarkToolTip(System.ComponentModel.IContainer Cont)


11 {


12 this.OwnerDraw = true;


13 this.Draw += new DrawToolTipEventHandler(OnDraw);


14 }


15


16 private void OnDraw(object sender, DrawToolTipEventArgs e)


17 {


18 DrawToolTipEventArgs newArgs = new DrawToolTipEventArgs(e.Graphics,


19 e.AssociatedWindow, e.AssociatedControl, e.Bounds, e.ToolTipText,


20 this.BackColor, this.ForeColor, new Font("Arial Unicode MS", 8.25f, FontStyle.Bold));


21 newArgs.DrawBackground();


22 newArgs.DrawBorder();


23 newArgs.DrawText(TextFormatFlags.TextBoxControl);


24 }


25


26


27 }


Monday, October 01, 2007

Reminder: TSQL date only

Get the date portion of datetime, correctly:

SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))


since,

CONVERT(VARCHAR(20),GETDATE(),112) returns the wrong date sometimes.

-----A cool and faster way:


DECLARE @datemask bigint
DECLARE @timemask bigint

SET @datemask = 0xffffffffff000000
SET @timemask = 0x0000000000ffffff

SELECT CAST(CAST((CAST(getdate() as binary) & @datemask) as binary(8)) as datetime)



//IF you need to grab a date and a time from two different locations in the database and combine them into one datetime (ex: shifts(time) and payperiod(date)):

SELECT CAST(CAST((CAST(getdate() as binary) & (@datemask | (CAST((CAST(getdate() as binary) & (@timemask) ) as binary(8)))) ) as binary(8)) as datetime)