Anant Anand Gupta Let Me Make You Think Like Me

21Jun/111

jQuery Plugin Release – jQuery Spinner Control

I was from a long time searching for a best spinner control (spin button / stepper button) to be used in the web pages, but non of them available on the internet were able to satisfy my requirement in a very simple way. so I decided to create one by myself.

This control in its simplicity is very powerful and is capable of doing the things in a very easy way. I general use where you have a dropdown input available, you find a very less scope of this kind of control, but when you are thinking fancy and have a RIA application, where you want something sleek and compact, you probably start looking for a control something like this. writing more about this control (jQuery Plugin) and documenting again over here in this post seems to be just a waist of time, when a nice documentation with a few online samples are available on the plugin site.

you can download this plugin from the jQuery plugin site at the plugins page.

18Jun/103

Website Optimization: Try to Escape from 404 – Page Not Found

Article ID : Tip-003

Article Topic : Website Optimization

Article Title : Try to Escape from 404 - Page Not Found


Preface

Wen client always creates a request for the resources referenced in the page it is rendering and if server can’t find it sends 404 – Page Not Found.

Explanation

When we create a website with a number of webpages and embedded resources like images (in HTML and CSS), JavaScript Files or Cascading Style Sheets, it is well obvious that we may skip something to include or we have referenced which is not present in the application. If this missing is visible, it can be caught and taken care. But, what if it is not visible?

Let’s talk about the favicon.ico. Microsoft started the concept of the favorite’s icon with IE 4. Since then the trend is started ad is adopted by major browsers to fetch and display the favorite’s icon in the address bar o on the tabs icon (for the bowsers supporting tabs). Earlier the concept was to fetch this icon only when the page is added to the favorite’s menu. But today if the browser has no previous visit recorded for the site the page belongs to will create a domain/favicon.ico request. Once the data is fetched it will cached by the browsers. But if the server returns 404 Error it will try to get that every time the page is requested from the domain.

Most of the cases even after the deployment is over for the site we skip this small thing favicon.ico to be included in the application root and the server is bothered again and again by the requests to provide the information which actually it doesn’t have. Every time without getting frustrated it calmly says 404 – Page Not Found.

How to Resolve

You can avoid this very common situation specifically for the icon case by

  • Using a favicon.ico file in the root of the application.
  • Specifying the page icon in the header of the page.

There a number of tools available out there in the market (freeware or paid), which can help you find out the web requests and response for your browser. Using them you can identify what is requested and what you have received in response. Fiddler is a free tool used for the same purpose.

Conclusion

Any request which cannot be fulfilled by the server is a burden to the server and to the network and to the client who is making that request. We can actually avoid them by using little cautiousness.

Download Word Document

10May/103

Creating System StoredProcedures in SQL Server

What is System StoredProcedures

A system StoredProcedure is a general stored procedure which started with 'sp_'. System StoredProcedures are stored into the master database in SQL Server.

Requirement of System StoredProcedure

There are instances when you are required to perform some operations on the different databases, like finding the dependency of the table (sp_depends), you use the system StoredProcedure. There are many System StoredProcedure already provided by the SQL Server. some of the most commonly used are:

  • sp_who
  • sp_depends
  • sp_help
  • sp_helptext

Each of the above provide some pre-defined functionality, but there are chances where you want your own functionality. In that case you can create your own System StoredProcedures. Just create a StoredProcedure with prefix 'sp_' in the master database and you are ready to go. Here I am showing one I have created for my ease.

Example

-- ======================================
-- Author:      Anant Anand Gupta
-- Date:        2010-05-10
-- Description: Return the number of
--              records in the Table
-- ======================================</p>
<p>USE master
GO</p>
<p>IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetCount]') AND type IN (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_GetCount]
GO</p>
<p>CREATE PROCEDURE [dbo].[sp_GetCount] @TableName NVARCHAR(776)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @str NVARCHAR(1000)
    SET @str = 'Select Count(*) [Record Count] From ' + @TableName
    EXEC (@str)
END

Now you can execute the stored procedure in any database you want like this:

EXEC sp_GetCount '<TableName>'

Extras

You can also create a keyboard shortcut for the above StoredProcedure to use quickly in between your SQL Code to find out the number of records in the selected table. Go to Tools -> Options -> Keyboard in SQL Server Management Studio. Select the text box in front of the predefined shortcuts which are not used. Enter the name of your StoredProcedure in the TextBox.

Click OK.

Open New Query Window (modifications are not registered with the windows already opened) for the required database. Enter the desired TableName and select the text and press your shortcut (Ctrl + 5 in my case). Here is your result

Enjoy and be more productive at your workplace !!!

16Jan/102

Design Patterns

What is a Design Pattern?

If you are here reading this post you might be looking a knowledge on Design Patterns and the first question which comes on anyone's mind is "What is a Design Pattern?". Lets answer this question in your own way.

You are person who know the syntax of a programming language and you are able to successfully convert any requirement into the code. One fine morning you reach office and your senior tells you about a new project requirement. You understood the requirement and have decided whats need to be done and what are the object of classes required to achieve this. But internally, whole the time from beginning to the end of the development you always know that there can be a better way to achieve this, and of course you search for other solutions to. Whatever you decide to implement you will finish off the task, but was that the best solution for the requirement? When this question comes in to you mind, the answer can be only given in terms of Design Patterns.

A design Pattern is nothing but a conceptual way to represent a reusable solution for a typical problem.

Here is a list of all known Design Patterns:

  1. Strategy Design Pattern
  2. Decorator Design Pattern
  3. Factory Design Pattern
  4. Observer Design Pattern
  5. Chain of Responsibility Design Pattern
  6. Singleton Design Pattern
  7. Flyweight Design Pattern
  8. Adapter Design Pattern
  9. Facade Design Pattern
  10. Template Design Pattern
  11. Builder Design Pattern
  12. Iterator Design Pattern
  13. Composite Design Pattern
  14. State Design Pattern
  15. Proxy Design Pattern
  16. Command Design Pattern
  17. Mediator Design Pattern
  18. Abstract Factory Design Pattern
  19. Prototype Design Pattern
  20. Bridge Design Pattern
  21. Interpreter Design Pattern
  22. Memento Design Pattern
  23. Visitor Design Pattern
  24. Circular Design Pattern
  25. Double Buffer Design Pattern
  26. Recycle Bin Design Pattern
  27. Model-View-Controller Design Pattern
  28. Model-View-View-Model Design Pattern

I will updating the details of each kind of design patterns as soon as they are ready to be posted.

Filed under: Programming 2 Comments
28May/092

Server.MapPath

In general whenever we need to get physical location of the file in ASP.Net Application, we use Server.MapPath. This is the most commonly adopted method. If you want the file to be located with reference to the path of the current WebPage, then the implementation holds good, but, in case you have to always refer the file from the application root, this method gives you different results. Take the following scenario, where the application directory structure is as follows:

  • Root
    • Data
      • Data.XML
    • ClassA.cs (uses Server.MapPath("\Data\Data.XML"))
    • ClassB.cs (uses ClassA to get the XML file contents)
    • SubDir
      • ClassC.cs (uses ClassA to get the XML file contents)

In the above scenario the ClassC will fail to retrive the contents in case of the WebApplication is hosted in a virtual directory. The application will work fine if it is a website. So the implementation will not show any errors when we run the application from the Visual Studio. to make it more generic we can replace the Server.MapPath with

System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + @"Data\Data.XML".

Page 1 of 212