Interesting programming ideas, solutions, and logic that I have used to solve problems or have come across throughout my career.
About Me
- William Andrus
- 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
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
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
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
I just hope they will have one for VS 2005 to VS 2008 soon.
Thursday, October 25, 2007
Optimize your regular expressions
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
Debugging Tools for Windows 32-bit version
http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx
Thursday, October 18, 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.
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
%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
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
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
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
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#
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
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
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)