2012 in review

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

600 people reached the top of Mt. Everest in 2012. This blog got about 3,500 views in 2012. If every person who reached the top of Mt. Everest viewed this blog, it would have taken 6 years to get that many views.

Click here to see the complete report.

Microsoft’s Free Certification Exam for “Programming in HTML5 with JavaScript and CSS3

Hello Friends,

HTML 5 is in buzz nowadays and to promote that buzz Microsoft has announced a certification exam for “Programming in HTML5 with JavaScript and CSS3” course. And that too at no cost (Yes it is Free…….).

They are also providing online materials for the same to help you clear the exam, the tutorials include topics such as HTML5, CSS3 and JavaScript.

Check out the following link for the same.

http://www.microsoft.com/learning/en/us/offers/html5.aspx

Thanks,
Jigar

P.S. Hurry the free vouchers are limited, so go grab it before they are out of stock!!!!!!!!!

Tips to improve website load time (Web Page Render Performance)

Hello All,
Yesterday I was checking few articles that describe some of the best practices that help in improving website performance.
I am mentioning below few of them; good thing is that they are not limited to any technology; so most of them can be applied in word press, jhoomla, magento, ror, and yes asp.net and MVC as well. They are more related to front end.
Remember even any website has fewer users (yet) but if it has slow rendering it annoy users and hardly attract new users; also Google’s ranking logic includes page loading performance so for SEO also the speed of the page is crucial.

1. First and the most common thing that almost all the developer do is to put the JavaScript on the top; within the head tag; The problem with this is that is when a scrip is downloading the browser stops parallel downloading and only when all the scripts downloaded it starts parallel downloading again.

This is because to perform any script related operation Browser uses “Script Engine” and wait for its “DONE” response before progressing again.

Solution: – Better approach is to put the script tags in bottom.

Possible Test: – To test this put the JavaScripts in bottom in your application that is under development and test the result with ySlow or Page Speed Monitor.

2. Avoid inline CSS and Inline JavaScript as much as possible; this is because let’s say there are three component of a page is developed by different developers and every component has inline css it takes additional effort by browser to identify them and render them; so better to have it common.

On top of that if you put you style classes and script tags in external files they will be cached by modern browsers upon first request to the page.

Solution: – Try to keep habit of having the styles in CSS file only and avoid duplicate css classes; even better let only one developer/ designer handle the CSS changes and review it periodically.

Possible Test: – Remove inline tag from your page and test the page again with speed test monitor tool.

3. Images are the most common part of the webpages; and that trend will never go or slow down.
Solutions: –
a. Use compressed images.
b. Use image sprite so that all the common images loads at once as soon as the first page gets loaded and used multiple time.
c. Sprite image also reduce no of HTTP requests so always use it when possiable.
d. Do not Resize image in HTML page because when you resize image to show smaller the browser has to load the full image and then present the reduce version on browser.
e. Use two types of images Full image and Thumbnail image when appropriate.
f. Always specify Height / Width attribute in HTML.
g. Good to have images bungle with div tag.

4. Large JavaScript files cause longer loading time.

Solution: – User JavaScript Compressing tools like JSMin and YUI Compressor. In case on not opting to tools you can at least remove unwanted white spaces and too large comment sections from your js files.

Also make sure that special functionality related JavaScript file can be included in that particular page rather having them in common php or .Master Page.

5. Have the device specific css for specific devices. This because when your mobile user hit your site he don’t want to pay for the additional desktop browser specific CSS which in normal case a bigger one. So have device specific CSS

6. User Use a Content Delivery Network (CDN) when possiable.

7. This is something we mostly do; include DOCTYPE in page. HTML that have DOCTYPE tends to render faster compare to those who don’t have them. But we hardly forget this.

8. Use DIV tag instead of TABLE tags, this makes Clean code + better SEO + speed up rendering.

9. User HTML5 and CSS3; It is true that not all but most browsers are supporting this especially if you are targeting mobile sites. And after all this mix is the FUTURE MIX.

10. Use less FLASH on home page and replace with HTML5 when possiable.

11. Use ajax and partial page; this may not speed up the page but can give relaxation to user.

12. Most important; always have the images, font and other things in place and so it don’t produce 404 error; because to produce this error browser spend very heavy time. E.g a missing font can cost you up to 3 second additional load time.

Tools you can keep looking at for page performance.
• Yahoo’s YSlow
• Google’s Page Speed
• AOL’s WebPageTest (Provide recording kind of visualization for your webpage)

I hope this helps. You can add your views and tips in this post.
Happy Coding,
Jigar (Love Stack Overflow)

how to serialize the object in .net

One need to serialize the data in case of passing data from/to webservice or making frequent operation on xml.

Here is the code to serialize the object

C#:
public static string GetSerializeData(object obj)
{
string output = String.Empty;
System.IO.StringWriter writer = new System.IO.StringWriter();
System.Xml.Serialization.XmlSerializer serializer = null;
serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
serializer.Serialize(writer, obj);
output = writer.ToString();
writer.Close();
return output;
}

VB:
Public Function ToXML(ByVal entity As Object) As String
Dim output As String = String.Empty
Dim writer As New StringWriter
Dim serializer As XmlSerializer = Nothing
serializer = New XmlSerializer(entity.GetType)
serializer.Serialize(writer, entity)
output = writer.ToString
writer.Close()
Return output
End Function

In both the above case, pass your class object which you want to serialize and you’re done.

Happy Programming 🙂

Use of Dynamic SqlQuery and its Optimization

Before writing this article I have many misconceptions for using the dynamic sql in sqlserver.
We are basically using the Execute statement for executing the dynamic query in sqlserver.
There are two options to execute the dynamic query
1) Execute @SqlQuery
2) Execute Sp_executesql @Sqlquery
In this article I will explore the Second option and how useful that option in Development.
Below is the example of Sp_executesql.

DECLARE @IntPatientID int;

DECLARE @SQLString nvarchar(500);

DECLARE @ParmDefinition nvarchar(500);

DECLARE @EncouterCount int;

SET @IntPatientID = 286;
SET @SQLString = N’Select @EncouterCnt=count(EncounterID) from Pat_Encounter where PatientID = @PatientID’;
SET @ParmDefinition = N’@PatientID int, @EncouterCnt int OUTPUT’;

EXECUTE sp_executesql @SQLString, @ParmDefinition, @PatientID = @IntPatientID, @EncouterCnt=@EncouterCount OUTPUT;

SELECT @EncouterCount;

In Execute option you will not get option of parameter you must define the variable in the dynamic sql to achieve the functionality.
In Sp_executesql you will get input and output parameter and that’s very useful in Development.
Another thing is Execute is not reuse Execution query plan else you are not define same value in condition of where.
Sp_executesql is reuse the Execution Plan and give fast output then Execute clause.
For the Optimization Sp_executesql is very handy in procedure.
You will get syntax from below link.
http://msdn.microsoft.com/en-us/library/ms188001(SQL.90).aspx

I hope this article is useful to you and enhance your knowledge of sqlserver.

Difference between object-oriented and procedural programming languages?

A major factor in the invention of Object-Oriented approach is to remove some of the flaws encountered with the procedural approach.

Object Orientation Languages (OOL) is concerned to develop an application based on real time while
Procedural Programing Languages (PPL) are more concerned with the processing of procedures and functions.

In OOL, more emphasis is given on data rather than procedures, while the programs are divided into Objects and the data is encapsulated (Hidden) from the external environment, providing more security to data which is not applicable or rather possible in PPL. In PPL, its possible to expose Data and/or variables to the external entities which is STRICTLY restricted IN OOL.

In OOL, the Objects communicate with each other via Functions while there is no communication in PPL rather its simply a passing values to the Arguments to the Functions and / or procedures.

OOL follows Bottom Up Approach of Program Execution while in PPL its Top Down approach.

OOL concepts includes Inheritance, Encapsulation and Data Abstraction, Late Binding, Polymorphism, Multithreading, and Message Passing while PPL is simply a programming in a traditional way of calling functions and returning values.

Here is the list of OOL languages :- JAVA, VB.NET, C#.NET

Here is the list of PPL languages :- C, VB, Perl, Basic, FORTRAN.

Shrink Log File (.LDF Files)

We all know the pain because of log files of sql databases. Uhh, it consumes so much of the space on hard disk;many time it grows like any thing.

Here is the one way to shrin Log file in sql 2005. You just need to chagne the database name with you database name (YOUR_DB_NAME with your DB in following script).

Hope this will help you to shrink your database without renaming the file and doing detach and all that.

(P.S This will shrink the ldf file upto 1 MB.. Sounds good na?)

================================
Print ‘Result before shrinking the log file’
=================

SELECT name AS ‘File Name’ , physical_name AS ‘Physical Name’, size/128 AS ‘Total Size in MB’,size/128.0 – CAST(FILEPROPERTY(name, ‘SpaceUsed’) AS int)/128.0 AS ‘Available Space In MB’–, * FROM sys.database_files;

USE YOUR_DB_NAME
GO
DBCC SHRINKFILE(‘YOUR_DB_NAME_log’, 1)
BACKUP LOG [YOUR_DB_NAME] WITH TRUNCATE_ONLY
DBCC SHRINKFILE(‘YOUR_DB_NAME_log’, 1)
GO

================================
Print ‘Result after shrinking the log file’
=================

SELECT name AS ‘File Name’ , physical_name AS ‘Physical Name’, size/128 AS ‘Total Size in MB’,size/128.0 – CAST(FILEPROPERTY(name, ‘SpaceUsed’) AS int)/128.0 AS ‘Available Space In MB’–, * FROM sys.database_files;

~ LUV Jigar Pandya ~~

USE of XML datatype, Read XML and Write XML in Sqlserver

ML data type is very useful in SQLserver 2005 and 2008.

Check the below script and learn how to use XML data type.

Create Table Patient(FirstName Varchar(20),LastName Varchar(20))
insert into Patient
values(‘Jack’,’Sparrow’)
insert into Patient
values(‘Peter’,’Parker’)
insert into Patient
values(‘John’,’Black’)

Below is the simple Feature of the XML.
You can set your table data in the XML type of variables
And read that.
Important feature is you can pass that XML type variables
To any procedure and you can read and process that data.
It’s like you pass table from one procedure to another procedure.

DECLARE @xmlDoc XML
SET @xmlDoc =
(
SELECT FirstName,LastName FROM Patient
FOR XML AUTO
)
SELECT @xmlDoc

Below code will fetch data from xml variable created above.

select
SelCat.CatDet.value(‘@FirstName’, ‘varchar(20)’) as FirstName,
SelCat.CatDet.value(‘@LastName ‘, ‘varchar(20)’) as LastName
from
@xmlDoc.nodes(‘Patient’) as SelCat(CatDet)

Below is the example of Write the rows to the XML TYPE
And you can read that as rows in any procedure.
This is useful when you have to pass block of rows
Without defining the table name.
Below is the example of that.

DECLARE @xmlDoc XML
SET @xmlDoc =
(
SELECT FirstName,LastName FROM Patient
FOR XML RAW
)

Below code will fetch data from xml variable created above.

SELECT
SelXML.xmlDetail.value(‘@FirstName’, ‘Varchar(20)’) AS FirstName,
SelXML.xmlDetail.value(‘@LastName’, ‘varchar(20)’) AS LastName
FROM
@xmlDoc.nodes(‘row’) AS SelXML(xmlDetail)
drop table Patient

I hope this post is useful for you and upgrade your knowledge.

Load/Unload css/JavaScript dynamically

In my project I need to load new css and unload existing css dynamically. So I have search on the net about it and I got one good link which solved my problem.

Add css dynamically

var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'FireFox.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);

Add JavaScript dynamically

var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://www.somedomain.com/somescript.js';
headID.appendChild(newScript);

Unload Js or Css file

function removefile(filename, filetype) {
var targetElement = "script"; // in case of css this will be "link"
var targetAttr = "src"; // in case of css this will be "href"

var allCtrl = document.getElementsByTagName(targetElement);
for (var i=allCtrl.length; i>=0; i--)  { //search backwards within nodelist for matching elements to remove
if (allCtrl[i] && allCtrl[i].getAttribute(targetAttr)!=null &&
allCtrl[i].getAttribute(targetAttr).indexOf(filename)!=-1);
allCtrl[i].parentNode.removeChild(allCtrl[i]);
}
}

Replacing JavaScript or CSS file dynamically

The same way you can also replace existing css with new css by creating object of old and new css using dynamic css creation and unload function I have shown above and use “replaceChild” function of parentNode property.

Document Source:  http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml

Happy Scripting

~ With Love – Pranav ~

Difference between Implicit and Explicit Interface

There are 4 basic difference between Implicit and Explicit interface. To understand all four of them see the below example first:

There is a class C1 which implements two interfaces I1 and I2. and Both the class have method with same name i.e. sum().

public class C1 : I1, I2
{
      //Explicit Implementation of interface
      void I2.sum()
      {
      }

      //Implicit Implementation of interface
      public void sum()
      {
      }
}

public interface I1
{
      void sum();
}
public interface I2
{
      void sum();
}

The Interface I1 is implemented implicitly and I2 is explicitly. Below are the difference based on above example.

1)  In Implicit implementation, no need to specify Interface name with its method.
e.g. public void sum() { }
Where as in Explicit implementation, you need to specify Interface name with its method
e.g. void I2.sum() { }

2) In implicit, access specifier is required with method name and it must be public, even protected will not work.
Where as in Explicit, no access specifier will be required.

3) You can not make virtual method in explicit implemention and same will work in implicit implemention.

4) You can not make abstract method in explicit implemention and same will work in implicit implemention.

Practical Example

Now you wonder, by considering above scenario, what is the use of these two implementation because only Implicit implementation will also work for all type of method then why these two has been introduced by Microsoft. or what should be the practical scenario where we need to use either Implicit or Explicit.

Suppose you need to implement 2 interface and both interface will have method with same name. At that time you can not create one method in your class for both interfaces, rather you must implement one interface Implicit and one Explicit (or both Explicit) for showing two different method in your class. (Check above example).

Hiding Interface Details:

If you implement interface explicitly then it will not show in class Intellisense list. So, if you want to hide your method name to display when creating object of class then you need to go for Explicit interface implementation and in this case you need to create object of your interface to know the method name.

E.g.: In our above example if I want to invoke method of I2 interface:
I2 obj = new C1();
obj.sum();

Hope this helps you 🙂