Thursday, November 17, 2011

Interesting point about JavaScript array sorting

Hi All,
Would like to share one point on java script
array sorting, recently one of my team members had one issue during this we realized this one. So it made me to pen this article.

Sorting arrays in JavaScript is done via the method array.sort(). While calling sort() by itself simply sorts the array in alphabetical order.

For example :

//Sort alphabetically and ascending:
var myarray=["CC", "BB", "AA"]
myarray.sort() //Array now becomes ["AA", "BB", "CC"]

Notice that the order is ascending. To make it descending instead, the simplest way is to enlist the help of another Array method in combination, array.reverse():

//Sort alphabetically and descending:
var myarray=["CC", "AA", "BB"]
myarray.sort()
myarray.reverse() //Array now becomes ["CC", "BB", "AA"]

Now, before you start feeling comfortable, consider what happens if we call array.sort() on an array consisting of numbers: ????


var myarray=[7, 40, 300]
myarray.sort() //Array now becomes [300,40,7]

Although 7 is numerically smaller than 40 or 300, lexicographically, it is larger, so 7 appears at the very right of the sorted array. Remember, by default array.sort() sorts its elements in lexicographical order.

And there you have it with array.sort() in terms of its basic usage. But there's a lot more to this method than meets the eye. Array.sort() accepts an optional parameter in the form of a function reference that pretty much lets you sort an array based on any custom criteria, such as sort an array numerically or shuffle it (randomize the order of its elements).
Passing in a function reference into array.sort()
As touched on already, array.sort() accepts an optional parameter in the form of a function reference (lets call it sortfunction). The format of this function looks like this:

array.sort(sortfunction)

function sortfunction(a, b){
//Compare "a" and "b" in some fashion, and return -1, 0, or 1
}

When such a function is passed into array.sort(), the array elements are sorted based on the relationship between each pair of elements "a" and "b" and the function's return value. The three possible return numbers are: <0 (less than 0), 0, or >0 (greater than 0):

    Less than 0: Sort "a" to be a lower index than "b"
     Zero: "a" and "b" should be considered equal, and no sorting performed.
     Greater than 0: Sort "b" to be a lower index than "a".

To sort an array numerically and ascending for example, the body of your function would look like this:

function sortfunction(a, b){
return (a - b) //causes an array to be sorted numerically and ascending
}

More on this below.
Sorting an array in numerical order

To sort an array in numerical order, simply pass a custom sortfunction into array.sort() that returns the difference between "a" and "b", the two parameters indirectly/ automatically fed into the function:

//Sort numerically and ascending:
var myarray=[25, 8, 7, 41]
myarray.sort(function(a,b){return a - b}) //Array now becomes [7, 8, 25, 41]

This works the way it does because whenever "a" is less than "b", a negative value is returned, which results in the smaller elements always appearing to the left of the larger ones, in other words, ascending.

Sort an array numerically but descending isn't much different, and just requires reversing the two operands "a" and "b":

//Sort numerically and descending:
var myarray=[25, 8, 7, 41]
myarray.sort(function(a,b){return b - a}) //Array now becomes [41, 25, 8, 71]

Thats it.

Hope it will useful to many.

Note: Content is refereed from javascriptkit site.

 

Thanks,
Ravi




How to make default page for a site in IIS 7.0

Hi All
Though it seems simple, just wanted to share how to make a default page for IIS 7.0
Generally many applications may display login page as default, in some cases some other pages. So let see how can we do this in IIS 7.0

1) Run -> inetmgr  (It opens IIS settings)
2) Go to your site (application which is hosted / application / folder) on selection of your site,
    you can see options to view the settings at bottom side with 'Features View' and  'Content View'  select the 
    'Features View', here we go, under IIS section we have an option of  'Default Document' , it will allow us to 
     add us the page name which you want to display. And also it allows us to add many pages also and lists all pages which are added. So top one page is the default page which will display when you access the site.
And also it provides couple of actions to move up and down the already added default pages based on our requirement.  Just select the page you can see the 'Actions' window which has the options will allow us to do.


Thanks,
Ravi

Wednesday, October 26, 2011

Looking to add Free Analog Web Clock to web sites

Looking to add free clocks to web sites ??
Here you go, 
This is for your quick reference , It seems to be a good link where you can get the several types
of clocks with JS code available. All you need to do is select the region , model , if any customization needed, select it generate the javascript code and use this code in your html pages if at all you are looking to display clocks..
Have a glance this link..




Thanks,
Ravi



Monday, October 24, 2011

404.2 The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server

All,
Recently we faced one error (404.2 The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server) while accessing an application on 2008 R server (IIS 7.0). Our application is in .net framework 4.0. 
When I had seen about this error initially what ISAPI and CGI, i could not recall immediately. 
So just to give brief on this,
ISAPI : Internet Server Application Programming Interface.           
CGI    : Common Gateway Interface.

To avoid this problem, below steps were taken place. Let see it may helpful for you.
a) Go to inetmgr, (IIS)
b) Clicked on the server.
c) Double click “ISAPI and CGI Restrictions”
e) Right click of ASP.NET v4.0 (which is available from framework64 bit) -> and made it allowed.  
 f) iisreset (run  -> iisreset  )

After performing above steps, I could able to access my application with out issues.
Hope it may helpful .



Thanks,
Ravi

BadImageFormatException in 64 bit windows

All, 
Recently we were trying to move some of our dot net applications from one production server which is in 2003 R2 platform with 32 bit system to 2008 R2 platform with 64 bit system.

We just moved the application .net components / binaries to new server (which is nothing but 2008 R2 + 64 bit system) and as this application's back end is Oracle data base . We installed the Oracle 11g client (64 bit) and created the application pool and necessary virtual directory and pointed to application at IIS level. When we ran the application we are getting errors as 'BadImageFormatException ..etc' related. After couple of hours of analysis and google search, we realized it could be because of bit versions conflicts, as application binaries in 32 bit format, application containing oracle client dll of 32 bit and target system is 64 bit and newly installed oracle client is 64 bit.  

And we wanted to have total application in 64 bit format only, so below steps we have performed and able to load the application successfully.

a) Open the application , deleted the reference to existed oracle client dll.
b)  Refereed to newly installed oracle client dll which is of 64 bit version (this dll can be get it from GAC).
c) Now we have built the application in 64 bit mode. (This setting can be seen from visual studio, right click of project -> Project Properites -> Build Tab -> General Section -> here you go, option to choose the plat form, Platfrom target: selected to x64)
d) And after building the application, we published the project. It has given us fresh binaries of 64 bit compatible.

So we moved this binaries to new test server : Here we did as
(system is 2008 R2, 64 bit, IIS 7.0)
a) created application pool, selected associated framework with classic mode.
b) Created virtual directory, pointed to application pool which is created in above step.
c) mapped the application binaries which newly created.
d) did the iisreset (run -> cmd -> iisreset )

Thats it, We access the application with out issues.  Hope it may works for you ...


Thanks,
Ravi
'Whether article is small or big, nothing wrong in sharing, definitely every post may helpful to some one some where.....'



Unable to view the PDF files through web browser

Hi All,
I came across this problem where when we tried to open Pdf files via some links, which do open the Pdf files through browsers. We kept receiving 'The Adobe Acrobat/Reader that is running cannot be used to view Pdf files in a web browser. Please exit Adobe Acrobat/Reader and try again' . Finally we got some solution which worked for us, So I would like to share the same which may helpful to some one who needs this.


Solution is :
a) Please open the Adobe Reader.
b) Click on Edit on the toolbar.
c) Select Internet in the list of features on the left-side of the Preferences window.
d) Uncheck Display PDF in browser. 
e) Close the adobe reader. 


And now try to access the Pdf file again . Hope it will work.




Thanks,
Ravi

Tuesday, June 7, 2011

Install IIS on windows 7

All,
Let see how to configure IIS on windows 7. Its simple and straight away. In windows7 by default it does not come with IIS. And more over like windows XP, OS CD is not required to instal the same.
How ?
Go to Control Panel -> Programs -> Programs and Features -> Click 'Turn Windows features on or off'
It displays all features in this navigate to 'Internet Information Services' and select it  and click Ok. Wait for some time as shown in the dialog box on screen. That's it. You are done. Go to run prompt and type 'inetmgr' and one can verify the IIS settings.

Same can be done for Windows 7 Professional / Enterprise /Ultimate.



Thanks,
Ravikiran



Friday, May 13, 2011

About Devenv /ResetSkipPkgs cmd

Well, After couple of days, back with one small information (but for me it's big matter), 
Coming to the topic..
I am working on one application which is in VS2008 and FW 3.5, all of sudden my laptop got many conflicts and could not able to open VS2005 TFS and 2008 application, while opening the 2008 application it's showing ' can't open the .csproj file...etc like that' and showing some error messages like 'package loading is failed..' like that which seems irrelevant to me , as i had worked before on 2008 application with the same system. Could not get the exact reason, uninstalled the framework 3.5 and VS 2008 and installed again. But no luck. Irritated, after couple of hours google help i got one command to execute at run prompt 'Devenv /ResetSkipPkgs' , surprisingly it works for me. After executing this command i could able to open my VS 2008 solution. Immediately i am putting information here hoping that will helpful to some one. (Just thinking  if there is no google how would be our situation ???)

Then started searching about this command Devenv /ResetSkipPkgs,

whats exactly its doing ?  It clears all SkipLoading tags added to VS Packages by users wishing to avoid loading problem VSPackages. Because of any improper installations or if any internal visual studio packages are got conflicted it failed to load the packages. And it could be cause for improper projects loading during open. In order to avoid this kind of problems. It just needs to re-enable package loading. So this command will re-enable every disabled/problem package.

See you with another information.


Thanks and Regards,
Ravikiran


Wednesday, May 4, 2011

LINQ Introduction Tutorial URL Sharing.

Learning LINQ, just watched one video for basics, its good. Thought of sharing. 
Though all can get from google, just it could be a quick reference for who are searching.
http://www.asp.net/linq/videos/how-do-i-get-started-with-linq




Ravikiran

Tuesday, May 3, 2011

About MySql Connector/NET

Well, I recently came across about 'MySQL Connector', thought to share this one also as my second technical blog. Basically i am in .Net technology now, probably many of my articles will be related to this only.

Let come to our today topic :
Generally the connector enables us to easily communicate between front end languages and back end data bases. For .net technologies we know it has Microsoft's own  connector procedures ADO.Net which can be act as a interface between .net (C#,VB.Net...etc) and its own data base SQL server. Here we don't bother about any additional drivers installation. Most common all .net projects are having SQL Server as data base. Not all, some .Net applications are communicating to
Oracle and MySQL also. In this kind of heterogeneous communication it needs an interface/driver to communicate front end languages to back end data base.  Assuming MySQL has a back end, it needs driver/connector called MySQL Connector to communicate. As MySQL connector here talking as a interface to .Net framework it used to call MySQL Connector/Net. And this connector/NET is fully managed ADO.Net driver which was written in C# only.
 
Recently i was working one application where front end is C#.Net and back end is MySQL.
When i was debugging the application i was getting errors as its unable to retrieve some data from data base , Infact there was no communication to data base. As i am a typical .net guy with traditional ADO.Net and SQL Server programmer, did not think about any drivers or interface. 
After couple of hours research finally came to know MySQL Connector has to be installed.

And versions information and all other relative information can be found at
http://dev.mysql.com/doc/refman/5.0/en/connector-net.html

Have fun.

Thanks,
Ravikiran








Monday, May 2, 2011

Finding the machine/system name with IP address

Welcome back, 
The information which i am updating at this moment, what i am learning in my day to day tasks.
Some of the things seem to be basics and known to all, but rewinding basics is not a bad thought, Is isn't?That's Good. 

Before going to my actual content for the day, thought to tell some thing. Some times motivation can come from surroundings, people, movies, videos...etc. But my actual inspiration to start my blog came from two sources one is   'abhijit jana'  , a .net specialist and the author of his own life and owner of great .net technical blog http://abhijitjana.net/ .  When ever i do browsing definitely i open this blog. The way he explains and works at article narration simply awesome. Luckily i met him when i was working in Noida he was my fellow team member for another project.  Now i suppose he is with Microsoft.

Second person is my technical manager who is  'thirst for knowledge', in this position and time also  i was wondering about him and the dedication he is having.  He knows in and out of all. By seeing all these kind of people i really wanted to do improve my self (Hope, some body may write my name in their articles as i am their inspiration,  Just kidding).

Let come to today's information, I would like to share one general DOS command to know the machine/system name with IP address.

Command :   
 nbtstat -a <IP Address>

Eg:    nbtstat -a 1.2.3.4
Sample out will be as follows,

VMware Network Adapter VMnet8:
Node IpAddress: [1.2.3.4] Scope Id:
VMware Network Adapter VMnet1:
Node IpAddress: [1.2.3.4] Scope Id: 

    NetBIOS Remote Machine Name Tabl

       Name               Type         Stat
    ---------------------------------------
    RAVI-PC        <20>  UNIQUE      Regist
    RAVI-PC        <00>  UNIQUE      Regist
    WORKGROUP      <00>  GROUP       Regist
    WORKGROUP      <1E>  GROUP       Regist

    MAC Address = < >

Wireless Network Connection:
Node Ip Address: [ ] Scope Id: []
Actually in one of my application which i am working wanted to know the machine name with the help of IP address for some particular configuration setting. It helped me to find out.  Hope it may helpful to some one.

Have  fun..

Thanks & Regards,
Ravikiran

Sunday, May 1, 2011

My First Blog

Feel happy to start my first blog . I wish could continue my blog to explore new-things and as well to share. 
I thought to share what i am learning in all aspects in my day to day life.....
All,  wish me good luck to my new way towards beautiful life.

Thanks,
Ravikiran