Wednesday, March 2, 2016

Read collation information about a column in SQL Server


If collation of two columns is different then SQL server throws and exception when migrating data between the columns like so


Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation. 
 Thus we need to know about collation of the columns if we want to migrate information from one column to the other. I tried to open sys.sp_help stored procedure and figured out that its possible to read collation information of a column with following statements

declare @objid int
declare @sysobj_type char(2)
select @objid = object_id, @sysobj_type = type from sys.all_objects where object_id = object_id('<Table Name>')
select collation_name from sys.all_columns where object_id = @objid and name = '<Column Name>'



Tuesday, March 1, 2016

Set viewport settings correctly for all device types

Different devices like IPad, IPhone, Androind Mobiles and Laptops may automatically set viewport of a webpage to a custom setting, and though this helps to get a better user experience in most cases, sometimes it may not help our media queries and web page looks scattered.

The quick and 'least damaging' solution is to set viewport scale to 1.0 in viewport meta tag, but sometimes even that may not be enough, and we have to resort to using a custom script inside document head.

<!-- in head -->

    <meta name="viewport" id="viewport" />
    <script>
    (function (doc) {
        var viewport = document.getElementById('viewport');
        if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
            //viewport.setAttribute("content", "initial-scale=0.3");
        } else if (navigator.userAgent.match(/iPad/i)) {
            viewport.setAttribute("content", "initial-scale=1.0");
        }
    }(document));
    </script>



<!-- in head -->

Copied from http://stackoverflow.com/questions/4787304/how-to-set-viewport-only-for-iphone-or-ipad

Monday, January 18, 2016

Very useful utility functions in knockout

I found functions explained in following post are very useful for developing knockout applications, particularly array compare and flatten array.

http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html

Friday, January 8, 2016

Serialization in .Net

The OOB binaryserializer does not work in some cases for no apparant reason, while searching on net I came across this serializer library which could help solve many problems

https://github.com/mgravell/protobuf-net

Tuesday, January 5, 2016

List all constraints in database or table

The post below shows various methods to list all constrains in a SQL Server database or table, it is quite handy to know sysobjects table.

I normally use the query

SELECT OBJECT_NAME(object_id) AS ConstraintName,
SCHEMA_NAME(schema_id) AS SchemaName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc LIKE ‘%CONSTRAINT’ AND OBJECT_NAME(parent_object_id)=‘Employee’


https://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/

Tuesday, December 15, 2015

IE 9 Compatibility

While searching for ways to ensure IE 9 compatibility in HTML pages, some articles suggest that

Just having <!DOCTYPE html> at the very top of the page with nothing preceding it should be enough to make IE9 use standards mode.

While this is true, I found out that even after having the document type declared as above, few pages in my MVC application were not being rendered properly. While searching more I came across this post

http://stackoverflow.com/questions/27571231/x-ua-compatible-not-working-in-ie-9-for-intranet-sites

Which says that console.log puts IE in quirks mode inspite of doctype and meta tags referring to IE 9. And commenting out all console.log statements really has fixed this issue for me.


Thursday, December 10, 2015

Javascript multithreading

It is interesting to know that multithreading is supported in javascript, though it has to source a different file it is still a relief for very cpu intesive UI operations

This is a demo code for the webworker

<!DOCTYPE html>
<html>
<body>

<p>Count numbers: <output id="result"></output></p>
<button onclick="startWorker()">Start Worker</button>
<button onclick="stopWorker()">Stop Worker</button>
<br><br>

<script>
var w;

function startWorker() {
    if(typeof(Worker) !== "undefined") {
        if(typeof(w) == "undefined") {
            w = new Worker("demo_workers.js");
        }
        w.onmessage = function(event) {
            document.getElementById("result").innerHTML = event.data;
        };
    } else {
        document.getElementById("result").innerHTML = "Sorry! No Web Worker support.";
    }
}

function stopWorker() {
    w.terminate();
    w = undefined;
}
</script>

</body>
</html>
 
and the demo_worker.js contains
 
var i = 0;

function timedCount() {
    i = i + 1;
    postMessage(i);
    setTimeout("timedCount()",500);
}

timedCount();
 

Regex Email validation in c# dot net core

 Use this regex /^_?[a-zA-Z0-9]([a-zA-Z0-9]*[._+-])*[a-zA-Z0-9_]+@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.[A-...