Skip to main content

Posts

Showing posts from 2013

Mobile journey options

In the last few years, we have seen rise in the use of mobile devices . As more and more users are using mobile devices , there is an increasing demand for businesses to have presence in the mobile world. Mobile devices have created tremendous business opportunities. The term mobile is not limited to mobile phones anymore, but it includes any device which can be used to access the information on the move. This includes tablets, hand held game consoles, media devices, watches etc. This list is increasing every day.  Options for mobile development There are number of options for developing apps with mobile presence, but we will explore the following 3 most commonly used solutions. Native apps: Native apps are downloaded and installed locally from platform specific marketplace. Cross platform apps: Using cross platform framework, you can develop native or hybrid apps. Hybrid apps are browser based apps but the user experience is same as a native app. Cross browser, mobile rea

Extending jQuery library

The beauty of jQuery is that is extensible. You can easily extend the jQuery function or its alias $. For e.g. $.fn.disable = function() {   return this.each(function() { if(typeof this.disabled != 'undefined') this.disabled = true; } ); } The above code creates a function which will disable the element and return the element collections so that you can cascade more jQuery funtions e.g $("input").disable(); The above code disables all input type elements.

window.onload vs jQuery doucment ready

Any script which manipulates DOM structure needs to wait till the document has loaded. The traditional way to do this was to use window.onload method e.g. window.onload = funcerion () { alert("document loaded"); } However the above method has drawbacks. It will wait till the entire document is loaded including images. Now if a web page is image heavy, the above alert won't be displayed until all the images have loaded. Ideally you want the function to execute once the DOM structure is ready. An alternative is jQuery document ready method e.g. $(document).ready(function() { alert("DOM loaded");}); The above function can also be written as $(function() { alert("DOM loaded"); }); The beauty of ready method is that you can have more than one for the same document and they all will execute in the order they are written. You can only have one window.onload method for one document.

LINQ Sort Operators - IEnumerable and IOrderedEnumerable

Consider following example var query = Process.GetProcessess(). .OrderBy(p => p.WorkingSet64) .ThenOrderBy(p => p.ThreadCount) In this case query is of type IOrderedEnumerable Hence you cannot user a Where Operation like this query = query.Where(p => p.ProcessName.Length < 10 You will get a compile error that you cannot IEnumerable to IOrderedEnumerable However if you add Where operator on first query, it will return IEnumaerable e.g var query = Process.GetProcessess(). .OrderBy(p => p.WorkingSet64) .ThenOrderBy(p => p.ThreadCount) .Where(p => p.ProcessName.Length < 10)

Document Object Model in IE vs Other browsers

It is intersting to see that document object model in IE considers all comments outside HTML tags as valid elements where as other browsers seems to be ignoring it Tryout  in a html document in IE with atleast one comment element outside html tag. IE reports one element more compared to other browsers. There is no such thing as Standard!!!!! Everyone is creating its own Standard

LINQ Filtering Operators

LINQ filtering operators are extension methods on IEnumerable and IQueryable . There are two types of filtering operators 1. OfType 2. Where OfType returns an filtered list of IEnumerable and works on IEnumerable also. E.g ArrayList myArray = new ArrayList { "one", 1, new object(), "two", 2 }; var stringOnly  = myArray.OfType ().Where(i => i.Length > 2); The above code filters only string types and returns as IEnumerable on which you can apply Where filter.

Implicit type in C#

C# 3.0 introduced implicit type declaration var. This is not same as var type in JavaScript which is a weak type. The variable is still strongly type however the type is inferred by the compiler based on the value. E.g. var s = "Joe"; will result in s a string type. Similarly var i = 10; will result i as int type. However there are certain restrictions on declaring var types 1. Implicit local variable must be initialized. e.g. var j; will result in error 2. Implicit typed local variable cannot  have multiple declarators e.g. var i, j=0; is not allowed 3. Cannot assign null to an implicit typed local variable e.g var i = null; is not allowed 4. Cannot impicitly convert string to int e.g. var i = "43"; int j = i+ 1; will result in error; You can use implicit type to create Anonymous types e.g var person = new {Name="Joe",Age=37}; Console.WriteLine("{0} : {1}",person.Name, person.Age); Compiler will create class with Read onl

How to detect HTML5 support for a browser?

HTML5 has introduced lots of new cool  tags . Not all the browsers support all tags and also the implementation of these tags may be different for each browser. HTML5 specification defines the functional aspects of these tags and not the implementation. Also the general concensus is that by 2022 all browsers will support all new features of HTML5. Of all the modern browsers, Chrome seems to have implemented most, if not all, featutes of HTML5. IE9 supports few. Firefox sits in between. So as a developer how do you make use of the cool HTML5 features without causing any compatibility issues with existing browsers? Traditionally developers have used User Agent to detect browser type and use the features accordingly. However these days, you can easily change a User Agent by using addons in your browser. So you need a more robust way to detect the features supported by the browser as the same engine of two different versions of a browser might support different features. To detect t

Jump start HTML5 with CSS and Javascript

Microsoft is giving away a free course (an accelerated one rather than full 5 day course) and a voucher to take exam 70-480 which prepares you for MCSD certification. You can find free voucher and course here http://www.microsoft.com/learning/en/us/html5-offer.aspx . I have started preparing for this exam. I will be using mostly online resources and will add posts here as I go along.

How to test Mobile Web Application locally

Recently I started building a mobile Web application. Now I wanted to test how it looks on a mobile device like an iPhone or Windows phone browser. One option was to use simulator or change user agents in browsers on PC. You can easily do this with Developers tools in Firefox. Another option is to setup you application as a website in local IIS. If you are running IIS on Windows 7, start IIS Manager and create a new site. Point this site to your local web application folder. Now add a binding to point local IP address of you machine (e.g. 192.168.1.1) to your web application. You can option local IP address by typing ipconfig on your command prompt. Now connect a mobile device to your local network over wifi. Try typing the local IP address of you machine in the browser. If you get message that page cannot be displayed, chances are that the firewall on your local machine is blocking incoming http request. To fix this, start Firewall on you machine and add a new incoming rule to

Free TFS service

Microsoft is giving free TFS service for upto 5 users. This is really useful if you are free lancer or like me have web development as a side hobby/business outside your main job. For more information, visit http://tfs.visualstudio.com/en-us/pricing/information/

Caching in Safari on IOS 6 for Ajax calls

When using caching for Ajax calls, the standard rule is to cache GET requests and not to cache POST requests. However Apple seems to have broken this rule in IOS 6 release. Safari seems to be aggresively caching in order to improve performance on iPad. We noted this problem when one of our applications started failing as it wasn't calling a webservice using Ajax. We couldn't replicate the problem on a PC. So after enabling logging for the webservice, we noticed that Safari wasn't calling the webservice after first call and caching the content. The logic Safari uses that if the parameters and the value of parameters is  same, then it will use cached reponse. We tried disabling the caching by setting response headers to prevent any form of caching. Safari ignores all caching headers (Thank you apple for deviating from standards...). The only workable solution is to set of the parameters which will have a different value for every request. We have used a timestamp. This f

Application Vs ApplicationInstance

Application refers to global application state in Classic ASP. Application is really a global dictionary object that was introduced in Classic ASP for lack of any global variables. ASP.Net uses ApplicationIntance property to refer to application instance that is processing current request. Application instances are thread safe hence it is not required to lock the non static members. ASP.Net has Application object purely for backword compatibility so that you can easily migrate a Classic ASP application to ASP.Net. It is recommended that you store data in static members of the application class instead of in the Application object. This increases performance because you can access a static variable faster than you can access an item in the Application dictionary. You can use following guidelines when accessing non static members in ASP.Net From the Global.asax, use the this or Me object. From a page, every page includes a strongly-typed ApplicationInstance prope