Mainfram Reality


Archive for July, 2006

T-SQL statistical formulas (Correlation, Slope and Intercept)

I’ve found these on the web, T-SQL formulas for calculating the Correlation, Slope and Intercept. A colleague was looking for these for some statistical analysis software he is writing. I thought these formulas look complicated enough to warrant a post on the blog. You never know when I might need one of these.

– Create a test tableCREATE TABLE [TESTSTATS]( intKey INT, x FLOAT, y FLOAT)– Populate the test table with random dataDECLARE @intCount INTSET @intCount = 1WHILE @intCount < 100 BEGIN INSERT INTO [TESTSTATS] SELECT @intCount, @intCount, 5.12 * @intCount + 7 * rand() SET @intCount = @intCount + 1END– Ge the Correlation, Slope and InterceptSELECT sqrt(square(avg(x*y) – avg(x)*avg(y))/((avg(x*x) – square(avg(x)))*(avg(y*y) – square(avg(y))))) AS Correlation, (count(x)*sum(x*y)-sum(x)*sum(y))/(count(x)*sum(x*x) – sum(x)*sum(x)) AS Slope, (sum(y)*sum(x*x) – sum(x)*sum(x*y))/(count(x)*sum(x*x) – sum(x)*sum(x)) AS InterceptFROM [TESTSTATS]GO– Remove the test tableDROP TABLE [TESTSTATS]

No comments

Prototypify – Implementing prototype feature control

Prototype JavaScript framework adds many useful functions to several built in JavaScript classes. This can sometimes create problems if the Prototype framework is implemented along side legacy code, or badly written code.Alex Cruikshank of CNet has created a great library that turns some Prototype framework featues off and allows for those features to be turned on when needed within specific contexts within the application.Prototypify Homepage

No comments

Useful .NET Code

Daniel Olson has created a great collection of .NET Code. This is a collection of useful functions a programmer needs often, functions that are re-written again and again.Included functions:

ArraysGetMissingItemsRemoveDupsStringArrayToStringColorColorToHtmlGetColorTableGetRandomColorCollectionCollectionToHtmlTableDataSetsArrayToDataTableDataTable2ExcelStringDataTableToArrayDataTableToStringFilterSortDataDateTimeCountWeekdaysCountWeekendsIsDateIsWeekDayIsWeekEndTimeBreakdownFilesArrayToFileFileToArrayGetDirectoryFileInfoGetDirectoryInfoGetFileInfoReadFromFileWriteToFileFormsSetCheckboxesSelectSetComboSelectedIndexMathTriangulateUnTriangulateNetworkDNSLookupGetHttpHeadersGetImagesGetLinksGetServerVariablesReadWebPageSendMailSendNetSendNumbersGetDoublesGetIntsGetRandomNumberIsNumericStatsGetAvgGetCorrelationGetStandardDeviationStringsCountStringsGetASCIIProperCaseRemoveWhiteSpace

No comments

42 Recent AJAX Tutorials by Max Kiesler

Max Kiesler has written a great blog entry titled 42 Recent AJAX Tutorials. This is a great resource for learning about JavaScript wikipedia and AJAX wikipedia.

No comments

JavaScript string trim functions,

I just thought I post this. I constantly use these JavaScript wikipedia string trim functions.

// trim the string String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g, “”);}// trim the start of the stringString.prototype.trimStart = function() { return this.replace(/^\s*/g, “”); }// trim the end of the stringString.prototype.trimEnd = function() { return this.replace(/\s*$/g, “”);}// normalize spacesString.prototype.normalizeSpaces = function() { return this.replace(/^\s*|\s(?=\s)|\s*$/g, “”);}

Example:var strExample = "   This is an   example.  ";strExample.trim();               => "This is an   example."strExample.trimStart ();         => "This is an   example.  ";strExample.trimEnd ();           => "   This is an   example."strExample.normalizeSpaces ();   => "This is an example."
No comments

Next Page »