Sunday, December 18, 2011

Switched to google blogger

Finally I have shifted my blog from Wordpress to Google Blogger :)

The new blogger interface is very refreshing and also very user friendly.

Saturday, January 8, 2011

Removing time from an sql datetime value

The following trick can be used to remove (set it to zero) time from an sql datetime value.

SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)

Wednesday, October 27, 2010

Multiple Inheritance and Interfaces

When we say we inherit from a class, what is it that we actually inherit?

We inherit the state and behavior of the class. Properties and variables define the state of a class and methods define the behavior.

But when we talk about interfaces, do they have state and behavior?

They don't, as you can only define signatures in an interfaces. Any class implementing this interface must provide the behavior and can have dependent state.

It is very obvious that we implement an interface and not inherit from it.

Many modern languages have learned from the older languages and choose not to support multiple inheritance because of the problems that they have. C# for that instance does not provide multiple inheritance.

There is a misconception that interfaces can be used to implement multiple inheritance in C#. But this is not true, as they do not have anything (state or behavior) that can be inherited.

Saturday, September 4, 2010

Solid State Drives (SSD) Now Available in India

A couple of months back I was looking at upgrading my computer. Specifically I wanted to upgrade my disk space. While searching on the internet I stumbled upon a new technology (it is kinda old as we all use it currently) Solid State Drives. It is similar to the flash memory drives (pen drives) that we use, except that these are available in higher capacities (160GB, 190GB and so on). The advantage of this technology is

  • It has no moving parts, hence no wear and tear (long lasting)

  • Since it has no moving parts the seek time is almost zero. So the SDD will take very little time while saving and retrieving data (high performance).



The only disadvantage is that it is very expensive and is not available in very high capacities. On the brighter side, since it is already launched in India we can expect the prices to go down as the market for SSD opens up. Till that time I am planning to buy an internal 1TB SATA HDD ;).

Wednesday, August 25, 2010

UserControl as a DLL made easy

To create controls in asp.net there are two options available.
  • Custom Controls
  • User Controls
User controls cannot be compiled into a dll and redistributed while a custom control can be compiled into a dll. But a custom control does not have separate files to hold your markup and code which user controls have.

If I can have separate files for markup and code in custom controls, its the best option for creating redistributable custom controls. This will make my design clean as I will achieve a clear separation of concern between my presentation (markup) and behavior (code).

Currently this option is not available in asp.net but there is a nice article to achieve this. The code is also clean and does not pass as a hack but a proper way to create custom controls.

Wednesday, June 30, 2010

HTML Encode Text in JavaScript

There are many ways of HTML encoding text in JavaScript. You may use string replacement using RegEx or simply hardcode replacements. These approaches help solve the purpose but make the code bloated and difficult to maintain. There is one clean way of achieving this.


function HTMLEncode(value){
var div = document.createElement(“DIV”);
var textNode = document.createTextNode(value);
div.appendChild(textNode);
return div.innerHTML;
}


The above code will html encode your text in a cleaner and faster way

Wrap long lines using CSS and JavaScript

I had this annoying problem of long unwrap-able lines breaking my website layout. After experimenting many fixes I finally settled on the following fix.


<script type="text/javascript">
$(function(){
$(".wrap").each(function(){
$(this).html(
$(this)
.text()
.replace(/([^\s-]{5})/g, "$&&shy;")
);
});
});
</script>



The above code uses jQuery and Regular Expression to wrap text in tags which have the class "wrap" by adding &shy; after every 5 characters in a long word. For more information on &shy; refer the references section below.

References: