IIFE stands for: Immediately-Invoked Function Expression
It is a self-executing anonimous function like this:

    $.fn.myplugin = funnction(options) {
        var settings = {};
        $.extend(settings, this.myPlugin.defaults, options);
        return this;

    $.fn.myPlugin.defaults = {
        option1: 'option1',
        option2: 'option2',
        option3: 'option3'

Another good example

// Create an anonymous function expression that gets invoked immediately,
// and assign its *return value* to a variable. This approach "cuts out the
// middleman" of the named `makeWhatever` function reference.
// As explained in the above "important note," even though parens are not
// required around this function expression, they should still be used as a
// matter of convention to help clarify that the variable is being set to
// the function's *result* and not the function itself.

var counter = (function(){
  var i = 0;

  return {
    get: function(){
      return i;
    set: function( val ){
      i = val;
    increment: function() {
      return ++i;

// `counter` is an object with properties, which in this case happen to be
// methods.

counter.get(); // 0
counter.set( 3 );
counter.increment(); // 4
counter.increment(); // 5

counter.i; // undefined (`i` is not a property of the returned object)
i; // ReferenceError: i is not defined (it only exists inside the closure)

Source: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

Passing Date parametere from Javascript to WCF

Having a service method that accepts two parameters will look like this:

public class ServiceRequest
Nullable<DateTime> DateTimeFrom {
get; set; }
Nullable<DateTime> DateTimeTo {
get; set; }

public interface IService
[WebInvoke(UriTemplate =
"getServiceCall", Method = "POST")]
ServResponse GetBusinessObjects(ServiceRequest filter);

Now, To start calling this method we need to construct a Json data representing the parameters.

      var fromDate = new Date(2013, 06, 18);
var toDate = new Date();

var datavar = {
DateTimeFrom: fromDate.toMSJSON(),
DateTimeTo: toDate.toMSJSON()
var parameters = JSON.stringify(datavar);

But, before calling the toMSJSON on date object we need to define it as follows:

// Let Date type be compatible for Microsoft WCF
Date.prototype.toMSJSON = function () {
/// <summary>Let Date type be compatible for Microsoft WCF.

var date = ‘/Date(‘ + this.getTime()  + ‘-0000)/’;


Getting DateTime from WCF

// convert WCF date to Javascript
String.prototype.DateWCF = function () {
/// <summary>convert string into Date</summary>
var matches = this.match(//Date(([0-9]+)(?:.*))//);
if (matches)
return new Date(parseInt(matches[1]));

Notice that when you use a date in javascript it is representing your local date based on the settings on your systemn and browser. As a result you might pass different notation to WCF. For example, my broweser has an timezone offset of -120 minutes. So when I ask to convert 06/20/2013 02:10:04 I see 2013-06-20T00:10:04.000Z which is perfectly normal because that represents the same exact time as I meant on my browser. Thus WCF will get the correct date aswell.

Minify js and css files in Visual Studio 2012

Finally we got an integrated tool in VS2012 that does the jobin Solution Explorer:
Web Essentials
You can enable this tool using the Extensions And Updates from the TOOLS menu.

  1. First, right-click on the css file and from the Web Essentials context menu choose to Minify CSS Files. This will ensure that with every build it will generate the accompanying .min.css file too.
  2. Make sure you have the Web.Release.config beside your web.config
  3. In your .aspx or .master file put an if statement to figure out if this is running on your debug mode or release mode:
<% if (HttpContext.Current.IsDebuggingEnabled) { %>
<link href="/css/MyFile.css" rel="stylesheet" type="text/css"></link>
<%} else {%>
<link href="/css/MyFile.min.css" rel="stylesheet" type="text/css"></link>
<%} %>

Do more with less

You can do more with less by reducing your design to its essence, and solving for distractions,
not discoverability. Create a clean and purposeful experience by leaving only the most relevant
elements on screen so people can be immersed in the content.

  • Be great at something instead of mediocre at many things.
  • Put content before chrome.
  • Be visually focused and direct, letting people get immersed in what they love, and they will explore the rest.
  • Inspire confidence in users. 

Desktop browsers have quite a lot of chrome (menus, options, status bars, and so on) that is
only sometimes useful. Typically, however, users open a browser to see a webpage, not to
interact with the browser. Moving commands off the browser chrome and into the app bar or
into charms helps users focus on what they care about.

Copied from Windows 8 User Experience Guidelines

Passed 70-480 exam

Yesterday morning I passed the exam in very short time (about an hour).
Amazingly, most of the questions were very familiar and the hints people provided earlier has been very helpful.

  • http://moustafa-arafa.blogspot.nl/2012/12/study-material-for-programming-html5.html
  • http://geekswithblogs.net/WTFNext/archive/2012/10/08/exam-70-480-study-material-programming-in-html5-with-javascript-and.aspx
  • http://www.techexams.net/forums/microsoft-developers-certifications/79076-70-480-programming-html5-javascript-css3.html
And a magor help from ExamCollection:

Finds Close Points by Distance

In this example I am trying to find the distance between the locations in a table and a given point. When I found the distance I will return thee result filtered by a allegible distance.

-- =============================================
-- Author: Asghar Panahy
-- Create date: 28-Feb-2013
-- Description: Zoekt objecten binnen bereik van gegeven punt
-- =============================================
ALTER PROCEDURE [dbo].[BereikbareObjecten]
-- Add the parameters for the stored procedure here
@orig_lat REAL ,
@orig_lng REAL,
@binnenMeter integer
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.


-- Select your SRID wisely. Don't follow me.
-- select * from sys.spatial_reference_systems
-- where spatial_reference_id in (4937, 4258, 4326, 4269)
DECLARE @SRID as int = 4326;

DECLARE @orig geography;
SET @orig = geography::Point(@orig_lat, @orig_lng, @SRID);

SELECT *,CONVERT(INT, @orig.STDistance( geography::Point([object].[Latitude], [object].[Longitude], @SRID))) As [Distance]
INTO #MyTempTable
FROM [Object]

SELECT * FROM #MyTempTable
WHERE [Distance] <= @binnenMeter
ORDER BY [Distance]


Favor Composition over Inheritance

Even though you “could” solve a problem by inheriting, see if there’s another option that doesn’t require you to inherit and compose your object of other helper object instead.
The above statement sounded so sophisticated when I read it first, that I wanted to put it in my blog. Yet there is something deep in my heart that tells me: don’t through away your years of experience and achievements gained by reusing objects through inheritance.

Original Thought

When 2 classes, let’s say Car and Vehicle implemented as follows:
    public class Vehicle
        public void Drive()
            Debug.WriteLine(“Vehicle is driving.”);
    public class Car : Vehicle
        public void Drive()
            Debug.WriteLine(“Car is driving.”);
By default the new implemented Drive method in the Car class hides the implementation in vehicle for any reference of Car type. So the following instances are expected:
    Vehicle v = new Vehicle();
    // output : Vehicle is driving.
    Car c = new Car();
    // output : Car is driving.
But the next one might cause unexpected situations when the construction occurs in a method far from calling the drive method.
    Vehicle x = new Car();
    // output : Vehicle is driving.
The output for the last call (Vehicle x) changes to “Car is driving.” when the Drive method in Vehicle is defined as virtual and in the Car defined as override.
Looks like the problem is solved.
But sometime I have a factory class creating some instances for me and I simply declare my variables and request for an instance:
Vehicle x = Factory.GetBMW();
This means that the place I use the instance might have no knowledge of how the instance is created and might not even know how they are implementing the Drive method.
For me, the ideal situation might be when I have a reference to a class of type Vehicle, I like it to drive as Vehicle. And when I want to have a Car that drives as a Car, I will define my reference as a Car.
Vehicle x = Factory.GetBMW();
Car y = Factory.GetBMW();
I can see that my point might not be important for BMW factory and they would rather to create a Car that drives the same way, no matter who is driving it.

Suggested Solution

The Composition over inheritance suggests that Car and vehicle does not inherit from each other. To make sure that they both are sharing functionality, the BMW class needs to implement both interfaces.
Let’s say that the following code is where we like to achieve:
    x.Drive();                  // output : Simply driving.
    (x as ICar).Drive();        // output : Car driving.
    (x as IVehicle).Drive();    // output : Vehicle driving.
To get there I have introduced three interfaces as follows:
    public interface IDrivable
        void Drive();
    public interface IVehicle : IDrivable
        void Drive();
    public interface ICar : IDrivable
        void Drive();
The BMW needs to implement them as it suites. This implementation has nothing to do with the way they are overloaded.
public class BMW : IVehicle, ICar
        void IVehicle.Drive()
            Debug.WriteLine(“Vehicle is driving.”);
        void ICar.Drive()
            Debug.WriteLine(“Car is driving.”);
        void IDrivable.Drive()
            Debug.WriteLine(“Simply driving.”);

Convert XmlText to HtmlText

I have been using Xml streams for quite some time. When I use them in an ASP.Net page, using SOAP or Ajax calls, I sometimes want to see what I send and what I recieve from the server. Showing them on the page was always a bit of tweak. This ample code demonstrates a very simple tweek. It provides a label that can show the xml Text (as its content or Text property) on the page, by rendering the simpel characters.
When the control is compiled I can use it as one of the two ways:

<panahyAjax:XmlLabel runat=”server” ID=”xmlLabel”>
<is just=”one”>sample</is>


XmlLabel label = new XmlLabel();
var file = File.OpenText(“Sample.xml”);
label.Text = file.ReadToEnd();
And the code is as folllows:

public class XmlLabel : Label
 public static string ConvertXmlTextToHtmlText(string inputText)
  // Replace all start and end tags.
  string startPattern = @”<([^>]+)>”;
  var regEx = new Regex(startPattern);
  string outputText = regEx.Replace(inputText, “&lt;<b>$1&gt;</b>”);
  outputText = outputText.Replace(
” “, “&nbsp;”);
  outputText = outputText.Replace(
“rn”, “<br />”);
  return outputText;

 protected override void RenderContents(HtmlTextWriter output)
  string xmlText = XmlLabel.ConvertXmlTextToHtmlText(Text);