Saturday, December 1, 2012

Count duplicates in an array

function compressArray(original) {     	var compressed = [];  	// make a copy of the input array  	var copy = original.slice(0);     	// first loop goes over every element  	for (var i = 0; i < original.length; i++) {     		var myCount = 0;	  		// loop over every element in the copy and see if it's the same  		for (var w = 0; w < copy.length; w++) {  			if (original[i] == copy[w]) {  				// increase amount of times duplicate is found  				myCount++;  				// sets item to undefined  				delete copy[w];  			}  		}     		if (myCount > 0) {  			var a = new Object();  			a.value = original[i];  			a.count = myCount;  			compressed.push(a);  		}  	}     	return compressed;  };

It should go something like this:

var testArray = new Array("dog", "dog", "cat", "buffalo", "wolf", "cat", "tiger", "cat");  var newArray = compressArray(testArray);     /*  console: [  	Object { value="dog", count=2},   	Object { value="cat", count=3},   	Object { value="buffalo", count=1},   	Object { value="wolf", count=1},   	Object { value="tiger", count=1}  ]  */

Wednesday, September 19, 2012

Console.log for IE and Chrome


<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript">
  <!--
  var alertFallback = true;
  if (typeof console === "undefined" || typeof console.log === "undefined") {
     console = {};
     if (alertFallback) {
      console.log = function(msg) {
              alert(msg);
         };
     }
   }
 //-->
  </script>
 </head>

 <body onload="console.log('Error Message')";>
  
 </body>
</html>

Saturday, September 15, 2012

Google image pop up effects in javascript

//Google image pop up effects:
// imgOld is Old image element
// imgNew is New Image element which is going to be show as it is
// Following function return left and top position of pop up dialog div in which we have to bind New image element

function getDivPos(imgOld,imgNew)
{
    var offset= imgOld.getClientRects();
   
   
    var left=offset[0].left-(imgNew.width/2-imgOld.width/2);
    var top=offset[0].top-(imgNew.height/2-imgOld.height/2);
   
    if((top + imgNew.height) > document.documentElement.clientHeight)
    {
    top= top - (top + imgNew.height - document.documentElement.clientHeight);
    }
    if((left + imgNew.width) > document.documentElement.clientWidth)
    {
      left=left - (left + imgNew.width- document.documentElement.clientWidth);
    }
   
    if(0> left)
    {
       left=document.documentElement.scrollLeft;
    }
    else
    {
       left=left+document.documentElement.scrollLeft;
    }
    if(0>top)
    {
      top=document.documentElement.scrollTop;
    }
    else
    {
      top=top+document.documentElement.scrollTop;
    }
   
       
    left=Math.round(left);
    top=Math.round(top);
   
    return ({"left":left,"top":top});
}

Friday, September 14, 2012

Resize image Proportionally using javascipt

function reSizeImage (imgToResize,expWidth,expHeight) {

          
            var originalImg = new Image();
            originalImg = imgToResize;

            var originalWidth = originalImg.width;
            var originalHeight = originalImg.height;
           
            // Return image if fit with the existing div without resize       
            if (originalWidth <= expWidth && originalHeight <= expHeight)
            {
                return imgToResize;
            }
            // Resize image
            var newImgSize = setSizePresetImage(expWidth, expHeight, originalWidth, originalHeight);
           
            var newImg = new Image();
            newImg= originalImg;
            newImg.width=newImgSize.width;
            newImg.height=newImgSize.height;
            return newImg;
       
    };
    function setSizePresetImage (expW, expH, orgW, orgH) {
        //Get radio
        var ratio = orgH / orgW;

        if (orgW >= expW && ratio <= 1) {
            orgW = expW;
            orgH = orgW * ratio;
        }
        else if (orgH >= expH) {
            orgH = expH;
            orgW = orgH / ratio;
        }
        //return new width and height
        return ({"width":orgW, "height":orgH});
    }

Monday, July 23, 2012

Xwiki introduction

XWiki is a second generation wiki that provides all the basic content management and administration features of common wikis, but with much more. XWiki takes the wiki approach to a whole new level by providing enhanced features and capabilities. With XWiki, you can build simple applications, extend the platform with custom plugins, or even build complex Web applications.

Tuesday, May 15, 2012

Read IIS SessionTimeout of Virtual Directory

class Program
    {
        static void Main(string[] args)
        {
            string urlSuffix = "";

            while(true)
            {
                Console.WriteLine("Please enter domain foldername(iis)/exit:");
                urlSuffix = Console.ReadLine();
                if (urlSuffix == "")
                {
                    urlSuffix = "ussi";
                }

                if (urlSuffix == "exit" ||urlSuffix == "Exit")
                {
                    break;
                }
                // Locals
                int iRet = 20;
                DirectoryEntry deVirDir = null;
                string vdPath = null;
                IEnumerator childs = null;
                bool gotVD = false;
                bool found = false;

                try
                {
                    //vdPath = "IIS://localhost" + System.Web.Hosting.HostingEnvironment.ApplicationID.Remove(0, 3);// Remove "/LM"
                    vdPath = "IIS://localhost/w3svc/1/root/" + urlSuffix;
                    deVirDir = new DirectoryEntry(vdPath);

                    try
                    {
                        childs = deVirDir.Children.GetEnumerator();
                        gotVD = true;
                    }
                    catch
                    {
                        // if application details are not available, check out root details
                        deVirDir = new DirectoryEntry("IIS://localhost/W3SVC");
                        childs = deVirDir.Children.GetEnumerator();
                    }

                    while (childs.MoveNext() && !found)
                    {
                        DirectoryEntry deApp = (DirectoryEntry)childs.Current;

                        if (deApp.SchemaClassName == (gotVD ? "IIsWebDirectory" : "IIsWebServer"))
                        {
                            PropertyValueCollection pvcAspSTO = deApp.Properties["AspSessionTimeout"];
                            iRet = (int)pvcAspSTO[0];// only one value
                            found = true;
                        }
                    }
                }
                catch
                {
                    iRet = 20;
                }
                Console.Write("Timeout:" + iRet.ToString()+"\n");
            } 
        }
    }

Wednesday, January 4, 2012

VS2010 error: Unable to start debugging on the web server


I run the following command in run window for installing .net 4 framework.

Now its working fine...


C:\Windows\Microsoft.NET{FrameworkFolder}\v{FrameworkNumber}\aspnet_regiis -i