Monday, March 21, 2016

Leaning Topics

Newtonsoft.Json 
Bigazi Modeller
Tiny MCE Editor
Less CSS
Kendo UI
MVC
Entity Framwork
DataAnnotations 
 Supergoo ABCpdf converter
Hammer.js 
Typemock
 

Thursday, March 17, 2016

Javascript Date format gotchas

I was debugging some date time format issue in chrome when I found out that in console

new Date('2016-04-16T15:15:00') returns Sat Apr 16 2016 16:15:00 GMT+0100 (GMT Daylight Time)

while

new Date('2016-04-16 15:15:00') returns Sat Apr 16 2016 15:15:00 GMT+0100 (GMT Daylight Time)


This is because JavaScript dates are parsed in the local time of the browser, unless you use the ISO date format "2015-03-22", which will be parsed as UTC.

Also, moment.js is probably the easiest and cleanest solution for all such issues.

More Info here: http://stackoverflow.com/questions/28989484/eliminating-javascript-daylight-saving-time-gap-a-cross-browser-solution

Thursday, March 10, 2016

Resolve relative path in MVC

To resolve a realtive path in MVC use HostingEnvironment.MapPath method


More Info: http://stackoverflow.com/questions/12239006/how-do-i-resolve-a-path-relative-to-an-asp-net-mvc-4-application-root

Reading CSV file

Reading a CSV file is not very difficult but why reinvent the wheel? The easiest way to parse CSV file in dot net is use VB class named Microsoft.VisualBasic.FileIO.TextFieldParser



Detailed Info: http://stackoverflow.com/questions/3507498/reading-csv-file

Wednesday, March 9, 2016

Forcing Internet Explorer 9 to use standards document mode

In IE 9 some scripts and styles dont work correctly if standards mode is not enforced, though this browser now does not have a significant market share, it is still important for some sites to be compatible with IE 9. The stackoverflow post below explains how to enforce standards mode in IE 9.

http://stackoverflow.com/questions/10975107/forcing-internet-explorer-9-to-use-standards-document-mode

Also, one more related issue is of console.log satement, this statement throws error in IE 9 if dev tools are not open, this is because IE 9 does not automatically initialize the console object till dev tools have been opened atleast once. To fix this just add some dummy console object and log method to it. Be aware that if instead of log any other method is being used on the console class then that should also be included.




<script type="text/javascript">if (!window.console) { window.console = {}; window.console.log = function () { }; }</script>


More Info: http://stackoverflow.com/questions/7742781/why-javascript-only-works-after-opening-developer-tools-in-ie-once

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

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...