Skip to main content

Posts

Showing posts from January, 2015

Masked input plugin angular.js adapter and JS comma operator

I was recently adapting jQuery masked input plugin (http://digitalbush.com/projects/masked-input-plugin) for angular.js. This is the adapter itself:

In order to produce the adapter, it was necessary to familiarize myself with source code of the original library. It was a very interesting task indeed!

While the library works very well, it's source code is ... a bit too smart. It's uncompressed version looked a bit like it was compressed. But what was really interesting about it was how JavaScript comma operator was a bit abused. This lead me to research the topic a bit and I've found an amazing write-up on the topic, which I really recommend to read: http://javascriptweblog.wordpress.com/2011/04/04/the-javascript-comma-operator/

UPDATE: I should have researched it better. The link at the project site really does point to some semi-minified source code. The source code at github (https://github.com/digitalBush/jquery.maskedinput) looks much more readable!

Missing rows after updating SQL Server index key column

I'm reading the amazing "T-SQL Quering book" (http://www.amazon.com/Inside-Microsoft-Querying-Developer-Reference/dp/0735626030). It has an interesting example, where reading all rows from a table, while updating clustered index key column value, one can miss a row or read a row twice. Updating entity key is not a good idea anyway, so this behavior seemed to be acceptable.

I've tried to update this example, so that the same happens with a non-clustered index. This seems not to be acceptable with non-clustered indexes, since keys of these indexes are not domain keys and related values may very well be changing.

In order to simulate such situation, we need to create a covering non-clustered index, which takes at least 2 pages. Then we need to update it's key column in such a way that first row (in index order) becomes last (jumps to second page in the index) and then - back again. While this jumping happens in the endless loop, we need to select all rows in the ta…