Showing posts from April, 2014

MSSQL Statistical Z-Score

Computing the z-score of individual values in SQL Server is not a built in function (although average and standard deviation are). The z-score tells us how far off from the average value the individual values are.
The following function computes the z-score: for a table named [data] having an [objectId] and [score] fields.

SELECT [D].[objectId], [D].[score], [E].[avg_score], [E].[stdev_score], ([D].[score] - [E].[avg_score]) / [E].[stdev_score] as zvalue FROM [data] D CROSS JOIN (SELECT Avg(CAST([score] as float)) as [avg_score], StDevP([score]) as [stdev_score] FROM [data] ) E ;

Bootstrap Menus and EmberJS

I love Bootstrap. Mostly because I'm not a very good graphic designer; but also because I'm lazy. I like the things it does for me that make my websites suck less. One of those things is the Bootstrap menu.
One of the nice features of the Bootstrap menu is that you get a gradient highlight when the menu has a "selected" css class applied to it.

I am looking at EmberJS. Ember has lots of nifty features as well. As a Single Page Application (SPA) framework, it likes to handle URL routing, and does something especially nifty with links that it manages: It applies a "selected" class to the current URL.

Did the stars just align? Is this too good to be true? "Um, yea. Why?"

Well, they almost align. It turns out that Bootstrap wants to have a "selected" css class applied to thelist item that contains the anchor tag for the menu item while Ember's linkTo helper applies it directly to the anchor tag. Ouch.

In other words, this ember code does…

Access web.config settings from your JavaScript

When you create a set of interconnected web applications, or a mobile application that accesses a web service back-end, you have different service addresses that need to make their way into your JavaScript. Visual studio has XML transformations that apply to the app.config or web.config files, depending upon your build configuration, but that doesn't do you a lot of good if your client-side JavaScript is looking for the appropriate settings.
You can isolate those settings in a single JavaScript file, but that file needs to change when you deploy to the web or the cloud.
Here is a simple solution:
Create an IHTTPHandler that reads all the application settings from your web.config file and transforms them into a constant object (named appSettings) containing all the application settings. Add the reference to this "dynamic" JavaScript in your master page template.
As a HTTP Handler, it is fast, and because IsReusable is set, it is cached too.
/// /// Summary descri…

KnockoutJS, WebAPI, and TypeScript

JavaScript is not Java As Brent so famously once said "JavaScript is not Java". My reply was "Dynamic, loosely typed, AND case sensitive...yea, that'll work". I tried to ignore JavaScript, hoping it would go away. jQuery helped a lot, but it still felt loose and dirty. Somebody out there heard my complaints. My biggest complaint with JavaScript has always been that it didn't have any concept of types, and you got very poor build-time support from development environments.
Enter TypeScript I believe that Anders Hejlsberg would have been one of the great contributors to software developers productivity just for TurboPascal, Delphi, or C#, or .NET, but his work to modernize without breaking JavaScript through TypeScript, I predict will be far more reaching than any of the others. Add to that the fact that Microsoft has made TypeScript open source, and that it has IDE support in Eclipse and Visual Studio (among others), and you have the makings of a perfect st…