Monday 7 October 2013

Method Dispatch in Ruby (include, extend, super and prepend)


Include 

Include  is for adding methods to an instance of a class

Extend

Extend is for adding class methods. (like self. )

module Foo
  def foo
    puts 'heyyyyoooo!'
  end
end

class Bar
  include Foo
end

Bar.new.foo # heyyyyoooo!
Bar.foo # NoMethodError: undefined method ‘foo’ for Bar:Class

class Baz
  extend Foo
end

Baz.foo # heyyyyoooo!
Baz.new.foo # NoMethodError: undefined method ‘foo’ for #<Baz:0x1e708>
As you can see, include makes the foo method available to an instance of a class and extend makes the foo method available to the class itself.


References :
http://blog.jcoglan.com/2013/05/08/how-ruby-method-dispatch-works/
http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/

Monday 2 September 2013

AJAX problem

http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx  

Just in case of page removal here is the page content 

Gotcha: Don't use <xhtmlConformance mode="Legacy"/> with ASP.NET AJAX

Recently I've helped a few developers who have been having some weird JavaScript issues (both when using ASP.NET AJAX and with some other custom JavaScript routines they were using).  The culprit was that they had automatically migrated a VS 2003 Web Project to VS 2005, and still had the <xhtmlConformance mode="Legacy"/> switch configured within their web.config file. 
If you are writing custom client-side JavaScript in your web application and/or are going to be using AJAX, please read-on to learn how to avoid a common gotcha (note: for a list of other tips, tricks, recipes and gotchas I've previously posted, please check out this page here).
Symptom:
You see strange behavior when adding new client-side JavaScript to a project that was previously upgraded (successfully) from VS 2003 to VS 2005.  When using ASP.NET AJAX UpdatePanel controls, this strange behavior can sometimes include cases where the page does a full-page postback instead of just incrementally updating pieces of a page. 
When you open up your web.config file, you also see a <xhtmlConformance/> element within it like so:
<configuration>

    
<system.web>
        
<xhtmlConformance mode="Legacy" />
    </
system.web>
</configuration>
Background:
ASP.NET 1.0 and 1.1 didn't emit XHTML compliant markup from many of its server controls.  ASP.NET 2.0 changed this and by default emits XHTML compliant markup from all controls (note: you can learn more about ASP.NET 2.0's standards compliance from this excellent MSDN article).
One of the things we noticed in the early ASP.NET 2.0 betas, though, was that when upgrading customer applications a lot of the applications had assumptions that the page output was not XHTML compliant.  By changing our default output of the server controls to be XHTML, it sometimes modified the visual rendering of a page.  For backwards compatibility purposes we added the <xhtmlConformance> switch above that allows developers to render controls in "Legacy" mode (non-XHTML markup the same as ASP.NET 1.1) as well as Transitional mode (XHTML Transitional) as well as Strict mode (XHTML Strict). 
By default when you use the VS 2003->VS 2005 Web Project Migration wizard (for both web sites and web application projects), your web.config file will have the legacy switch added.
Solution:
Unless you know of known issues that your site has when running in XHTML mode (and which you don't have time yet to fix), I'd always recommend removing the <xhtmlConformance> section from your web.config file (or you can explicitly set it to "Transitional" or "Strict"). 
This will make your HTML output standards compliant.  Among other things, this will cause the HTML from your server controls to be "well formed" - meaning open and close tag elements always match.  This is particularly important when you are using AJAX techniques to dynamically replace the contents of certain HTML elements on your page (otherwise the client-side JavaScript sometimes gets confused about container elements and can lead to errors).  It will also ensure that ASP.NET AJAX works fine with your site.
Hope this helps,
Scott

Friday 30 August 2013

Validation of viewstate MAC failed problem

in Web Config 
<machineKey decryptionKey="A4B12CCDD50E95F8GB9GFH6JKAT4Y0U0I2OF2DF2AAFE5AB46189C,IsolateApps" validation="AES" validationKey="480CDF2AS9S9AS5CFDGF0GHFH9JJH4KHKAKLJ2L9F3SAS82A6C16911A29EF48903783F94529C21570AACB72766FB38CD4CE7B85B0ACE3149DC5FC1CCF1AA1CECE3579659996593B06,IsolateApps"/>
Or in aspx page 
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Admin/Site1.Master"  EnableViewStateMac="false" CodeBehind="MenuStructure.aspx.vb" Inherits="LogicTextile.MenuStructure" %>

Wednesday 28 August 2013

Space between RadioButtonGroup in ASP.NET

in code behind :

            rbMode.Items(0).Attributes.CssStyle.Add("margin-right", "15px")
            rbMode.Items(1).Attributes.CssStyle.Add("margin-right", "15px")

Tuesday 6 August 2013

SQL SERVER – Query to Find ByteSize of All the Tables in Database

SELECT CASE WHEN (GROUPING(sob.name)=1THEN 'All_Tables'
   
ELSE ISNULL(sob.name'unknown'END AS Table_name,
   
SUM(sys.lengthAS Byte_LengthFROM sysobjects sobsyscolumns sysWHERE sob.xtype='u' AND sys.id=sob.idGROUP BY sob.nameWITH CUBE

Friday 2 August 2013

using radio in ASP.NET treeview instead of checkboxes

<script type="text/javascript">
    function MakeRadio() {
        var tv = document.getElementById("<%= TV.ClientID %>");
        var chkArray = tv.getElementsByTagName("input");

        for (i = 0; i <= chkArray.length - 1; i++) {
            if (chkArray[i].type == 'checkbox') {
                chkArray[i].type = 'radio';
            }
        }
    }

    window.onload = MakeRadio;

    function OnTreeClick(evt) {
        var src = window.event != window.undefined ? window.event.srcElement : evt.target;
        var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "radio");
        if (isChkBoxClick) {
            SelectOne(src.id);
        }
    }

    function SelectOne(objId) {
        var tv = document.getElementById("<%= TV.ClientID %>");
        var chkArray = tv.getElementsByTagName("input");

        for (i = 0; i <= chkArray.length - 1; i++) {
            if (chkArray[i].type == 'radio') {
                if (chkArray[i].id != objId) {
                    chkArray[i].checked = false;
                }
            }
        }
    }
</script>

<asp:TreeView ID="TV" runat="server"></asp:TreeView>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                TV.Attributes.Add("onclick", "OnTreeClick(event)")
End Sub


Tuesday 14 May 2013

Using Git Hub in Visual Studio

This subject is definetely pain in the ass.
The best documentation I found in the net is http://codeasp.net/blogs/vivek_iit/microsoft-net/1881/how-to-use-github-with-visual-studio

Following these steps can sort this problem out. I only stucked in step 10 and our sysadmin helped me in this step. (SSH key )


Tuesday 30 April 2013

OOP or OOPS

Hi everybody,

I'm dealing with some strange codes developed by some other developers nowadays. In first sight they seem like Object Oriented. Let's have a look.

Codes are in ASP.NET using VB. Developer wrote these codes like that.
There are aspx UI pages and separete code pages which they are as they should be.
and there are module pages for each pair.
but WHY ?

First reasonable explanation came to my mind was reusability. But no. 95% of these modules used only once.  So why should we travel from function to function for a simple data save ? Is that what he understands about OOP ?

Please guys, codes must be in balance. Balance of performance, readability, standards and reusability.
we don't develope anything for ourselves. Someday in some point some other developer will continue the job you left. Think about him and leave clean, wise, readable codes.