Friday, April 5, 2013

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>
  <%} %>
.

Wednesday, March 27, 2013

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:
http://www.examcollection.com/microsoft/Microsoft.BrainDump.70-480.v2013-02-04.by.HakimAli.70q.vce.file.html

Thursday, February 28, 2013

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
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	---------------------------------------------------------
	-- 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]
	
END

Thursday, January 24, 2013

putting images into one bigger file to improve newtork performance and thus page-load

Getting all icons in one file requires some handy works to layout the pictures in both css and html.
I recently put some sample buttons and logo using the one is implemented by YouTube and is available here.

Wednesday, February 15, 2012

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();
    v.Drive();
    // output : Vehicle is driving.

    Car c = new Car();
    c.Drive();
    // 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();
    x.Drive();
    // 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();
x.Drive();
y.Drive();
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.");
        }       
    }