Thursday, February 9, 2012

Auto generated Numbers in SQL Query

Auto generated Numbers in SQL Query

create table CountryMaster
(
id int identity(1,1),
cityname varchar(50),
countryname varchar(50)
)

select * from CountryMaster

insert into CountryMaster values('New Delhi','India')
insert into CountryMaster values('Mumbai','India')
insert into CountryMaster values('Kolkata','India')
insert into CountryMaster values('Chennai','India')

insert into CountryMaster values('London','UK')
insert into CountryMaster values('Amsterdam','UK')
insert into CountryMaster values('Southampton','UK')

insert into CountryMaster values('Washington','US')
insert into CountryMaster values('New York','US')
insert into CountryMaster values('Chicago','US')

insert into CountryMaster values('Canberra','Australia')
insert into CountryMaster values('NSW','Australia')
insert into CountryMaster values('Melbourn','Australia')

insert into CountryMaster values('Islamabad','Pakistan')
insert into CountryMaster values('Karachi','Pakistan')
insert into CountryMaster values('Hyderabad','Pakistan')

select id, cityname, countryname,
ROW_NUMBER() OVER (PARTITION BY [countryName] ORDER BY id) AS Seq
from CountryMaster


Result
-------
.............................................
id cityname countryname Seq
.............................................
27 Canberra Australia 1
28 NSW Australia 2
29 Melbourn Australia 3

17 New Delhi India 1
18 Mumbai India 2
19 Kolkata India 3
20 Chennai India 4

30 Islamabad Pakistan 1
31 Karachi Pakistan 2
32 Hyderabad Pakistan 3

21 London UK 1
22 Amsterdam UK 2
23 Southampton UK 3

24 Washington US 1
25 New York US 2
26 Chicago US 3
.............................................

select id, cityname, countryname,
ROW_NUMBER() OVER (ORDER BY id) AS Seq
from CountryMaster

Result
-------
.............................................
id cityname countryname Seq
.............................................
17 New Delhi India 1
18 Mumbai India 2
19 Kolkata India 3
20 Chennai India 4
21 London UK 5
22 Amsterdam UK 6
23 Southampton UK 7
24 Washington US 8
25 New York US 9
26 Chicago US 10
27 Canberra Australia 11
28 NSW Australia 12
29 Melbourn Australia 13
30 Islamabad Pakistan 14
31 Karachi Pakistan 15
32 Hyderabad Pakistan 16
.............................................


select id, cityname, countryname,
ROW_NUMBER() OVER(order by id) AS Seq
from CountryMaster order by cityname

List of few CMMi level 5 companies in HYD, BLR, Pune

---
HYD
---
TCS
WIPRO
MAHINDRA SATYAM
INFOSYS
HCL
COGNIZANT
UHG
WELLSFARGO FINANCE COMPANY
SIERRA ATLANTIC
INTELLIGROUP
SEMANTICSPACE
IGATE
KEANE
INFOTECH

DELL
ORACLE
ADP
CGI
DELOITTE
VIRTUSA
CSC
CONVERGYS
ACCENTURE
CAPGEMNI
POLARIS
SONATA
JDA
NCR
KENEXA

----
BLR
----
ITC INFOTECH
TESCO
HP
MPHASIS
L & T INFOTECH
COVANSYS
INTEL
ABB
MCAFEE
FIC
SASKEN
LOGICA
SAPIENT
THOMSON REUTERS
PHILIPS

IBM
HONEYWELL
PEROT SYSTEMS
MINDTREE
JP MORGAN

-----
PUNE
-----
TECH MAHINDRA
SYNTEL
BLUE STAR INFOTECH
MASTEK
HEXAWARE
3I INFOTECH (ICICI)

Google maps - code to display image from URL

protected void Page_Load(object sender, EventArgs e)

{

if (!(Page.IsPostBack))

{

// to get the image stream

//http://www.greywyvern.com/code/php/binary2base64

// google maps image

// http://code.google.com/apis/maps/documentation/staticmaps/

//// working url

////string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=0&size=320x169&maptype=roadmap";

///////// ++++++++++++++++++++++++++++++++++++++

// working

//string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=12&size=480x313&maptype=roadmap¢er=52.4871716,1.7153936&markers=52.4871716,1.7153936";

// not working

//string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=12&size=480x313&maptype=roadmap¢er=51.5017821,-0.1154330&markers=51.5017821,-0.1154330";

// old

//string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=0&size=320x169&maptype=roadmap";

string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=12&size=480x313&maptype=roadmap¢er=-33.8389280,151.2085890&markers=-33.8389280,151.2085890&format=jpg";


/////////////////////////////////////string GoogleURL1 = HttpUtility.UrlDecode("http%3a%2f%2fmaps.google.com%2fmaps%2fapi%2fstaticmap%3fsensor%3dfalse%26zoom%3d0%26size%3d320x169%26maptype%3droadmap");

string strResponse = string.Empty;


WebRequest objWebRequest;

objWebRequest = WebRequest.Create(GoogleURL);

WebProxy proxy = new WebProxy();

objWebRequest.Proxy = proxy;

objWebRequest.UseDefaultCredentials = true;

objWebRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;

objWebRequest.ContentType = "Content-Type: image/png";

StreamReader loResponseStream = new StreamReader(objWebRequest.GetResponse().GetResponseStream(), Encoding.UTF8);

var bytes = default(byte[]);

using (var memstream = new MemoryStream())

{

var buffer = new byte[512];

var bytesRead = default(int);

while ((bytesRead = loResponseStream.BaseStream.Read(buffer, 0, buffer.Length)) > 0)

{

memstream.Write(buffer, 0, bytesRead);

}

bytes = memstream.ToArray();

}

image1.Attributes["src"] = "data:image/png;base64," + Convert.ToBase64String(bytes);

//Response.Clear();

//Response.ContentType = "Image/png";

//Response.BinaryWrite(bytes);

}

}

LINQ SQL Injection

http://msdn.microsoft.com/en-us/library/bb399403.aspx

http://csharp-codesamples.com/2009/05/preventing-sql-injection-using-linq/

reading data through Excel

private DataTable ReadExcelData(string strFilePath, string strFileType)

{

DataTable dt = new DataTable();

try

{

if (strFileType.ToLower().Contains("xls") || strFileType.ToLower().Contains("xlsx"))

{

OleDbCommand excelCommand = new OleDbCommand();

OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();

// for office 2003 and prior versions

//////////string excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + strFilePath + "; Extended Properties =Excel 8.0;";

/////// for office 2007 onwards and prior versions

string excelConnStr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + strFilePath + "; Extended Properties =Excel 12.0;";

// Microsoft.Jet.OLEDB.4.0 driver is only for uploading Microsoft-Excel 2003 and earlier versions.

OleDbConnection excelConn = new OleDbConnection(excelConnStr);

excelConn.Open();

DataTable dtSheetName = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

if (dtSheetName != null && dtSheetName.Rows.Count > 0)

{

string strSheetName = dtSheetName.Rows[0]["TABLE_NAME"].ToString();//gives first sheetname in the excel

excelCommand = new OleDbCommand("SELECT * FROM [" + strSheetName + "]", excelConn);//excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);

excelDataAdapter.SelectCommand = excelCommand;

excelDataAdapter.Fill(dt);

}

excelConn.Close();

}

}

catch (Exception objEx)

{

throw objEx;

}

finally

{

//Delete the saved file from server path after reading the data from the path.Because it is uploaded from client machine to database.We are saving to server to avoid errors.After process we are deleting here.

if (File.Exists(strFilePath))

File.Delete(strFilePath);

}

return dt;

}

shivprasad koirala URLS on WCF

http://www.codeproject.com/KB/WCF/WCFTransactions.aspx

http://www.codeproject.com/KB/WCF/WCFFAQPart5.aspx

http://www.codeproject.com/KB/aspnet/WCF.aspx

http://www.codeproject.com/KB/aspnet/WCFPart2.aspx

http://www.codeproject.com/KB/WCF/WCFFAQPart3.aspx

http://www.codeproject.com/KB/WCF/WCFTracingFAQ.aspx

sending emails through c# asp.net

web.config entry

<system.net>
<mailSettings>
<smtp from="yoursenderemail@corporate.com">
<network host="hostname" port="25" password="Password"
userName="PASSPORT2" defaultCredentials="false" /> </smtp>
</mailSettings>
</system.net>

Note: 1) Make sure from address domain name
2) IP address, port number should be valid

c# code

SmtpSection mailSettings = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
MailMessage MyMessage = new MailMessage();

string sendTo = this.txtEmailHard.Text;
string sendFrom = mailSettings.From;
string sendMessage = "hello now the time is : " + DateTime.Now.ToLongDateString();
MyMessage.To.Add(sendTo);
MyMessage.From = new MailAddress(sendFrom);
MyMessage.Subject = "Hi Welcome to eProfile";
MyMessage.Body = sendMessage;
MyMessage.IsBodyHtml = true;

this.lblComment.Text = mailSettings.Network.Host + " " + mailSettings.Network.Port;

SmtpClient emailClient = new SmtpClient(mailSettings.Network.Host, mailSettings.Network.Port);
if (mailSettings.Network.DefaultCredentials)
{
emailClient.UseDefaultCredentials = true;
}
else
{
emailClient.Credentials = new System.Net.NetworkCredential(mailSettings.Network.UserName, mailSettings.Network.Password);
}

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
emailClient.Send(MyMessage);
return;
}
catch (SmtpException smtpx)
{
throw smtpx;
}
catch (Exception ex)
{
throw ex;
}

sending emails through c# asp.net code

web.config entry




userName="PASSPORT2" defaultCredentials="false" />




Note: 1) Make sure from address domain name
2) IP address, port number should be valid

c# code

SmtpSection mailSettings = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
MailMessage MyMessage = new MailMessage();

string sendTo = this.txtEmailHard.Text;
string sendFrom = mailSettings.From;
string sendMessage = "hello now the time is : " + DateTime.Now.ToLongDateString();
MyMessage.To.Add(sendTo);
MyMessage.From = new MailAddress(sendFrom);
MyMessage.Subject = "Hi Welcome to eProfile";
MyMessage.Body = sendMessage;
MyMessage.IsBodyHtml = true;

this.lblComment.Text = mailSettings.Network.Host + " " + mailSettings.Network.Port;

SmtpClient emailClient = new SmtpClient(mailSettings.Network.Host, mailSettings.Network.Port);
if (mailSettings.Network.DefaultCredentials)
{
emailClient.UseDefaultCredentials = true;
}
else
{
emailClient.Credentials = new System.Net.NetworkCredential(mailSettings.Network.UserName, mailSettings.Network.Password);
}

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
emailClient.Send(MyMessage);
return;
}
catch (SmtpException smtpx)
{
throw smtpx;
}
catch (Exception ex)
{
throw ex;
}

Thursday, February 2, 2012

multiple end points scenario

---------------
Project Manager
---------------
Method 1
Method 2
Method 3
Method 4

---------------
Project Leader
---------------
Method 5
Method 6
Method 7

---------
Developer
---------
Method 8
Method 9
Method 10


End points - PMEndPoint - A B C
End points - PLEndPoint
End points - DevEndPoint

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IPMService

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IPLService

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IDevService

public interface IPMService
{

Method 1
Method 2
Method 3
Method 4

}

public interface IPLService
{

Method 5
Method 6
Method 7

}

public interface IDevService
{

Method 8
Method 9
Method 10

}

what is data center

A data center is a facility used to house computer systems and associated components, such as telecommunications and storage systems. It generally includes redundant or backup power supplies, redundant data communications connections, environmental controls (e.g., air conditioning, fire suppression) and security devices.

Tier Level 1 - 99.671% availability
Tier Level 2 - 99.741% availability
Tier Level 3 - 99.982% availability
Tier Level 4 - 99.995% availability

IT operations are a crucial aspect of most organizational operations. One of the main concerns is business continuity; companies rely on their information systems to run their operations.

The boom of data centers came during the dot-com bubble. Companies needed fast Internet connectivity and nonstop operation to deploy systems and establish a presence on the Internet.

Installing such equipment was not viable for many smaller companies. Many companies started building very large facilities, called Internet data centers (IDCs), which provide businesses with a range of solutions for systems deployment and operation.

New technologies and practices were designed to handle the scale and the operational requirements of such large-scale operations. These practices eventually migrated toward the private data centers, and were adopted largely because of their practical results.

WCF Instance

WCF instance dictates how the objects are created while WCF concurrency dictates how many requests can be handled by the WCF objects.


WCF instancing - per call, per session and single
WCF concurrency - single , multiple, reentrant


Single: -
==============
1) A single request has access to the WCF service object at a given moment of time.
2) So only one request will be processed at any given moment of time. The other requests have to wait until the request processed by the WCF service is not completed.

Multiple: -
==============
1) In this scenario multiple requests can be handled by the WCF service object at any given moment of time.
2) In other words request are processed at the same time by spawning multiple threads on the WCF server object. So you have great a throughput here but you need to ensure concurrency issues related to WCF server objects.

Reentrant: -
==============
1) A single request thread has access to the WCF service object,
2) but the thread can exit the WCF service to call another WCF service or can also call WCF client through callback and reenter without deadlock.

Note: By default WCF services are 'Single' concurrency and instancing mode ‘per call’.



Per call
==============

• You want a stateless services
• Your service hold intensive resources like connection object and huge memory objects.
• Scalability is a prime requirement. You would like to have scale out architecture.
• Your WCF functions are called in a single threaded model.

Per session
==============

• You want to maintain states between WCF calls.
• You want ok with a Scale up architecture.
• Light resource references

Single
==============

• You want share global data through your WCF service.
• Scalability is not a concern.

Tuesday, January 10, 2012

site to encode xml, html code

http://centricle.com/tools/html-entities/

JQuery Notes 12Jan12

------------------
Point 1
------------------
<script>
//hide all divs on the page
jQuery('div').hide();
//update the text contained inside of all divs
jQuery('div').text('new content added here');
//add css stylesheet to all div tags
jQuery('div').addClass("updatedContent");
//show all divs on the page
jQuery('div').show();
//add css stylesheet to all input tags
jQuery('input').addClass("updatedContent");
//hide all input tags on the page
jQuery('input').hide();

// all inputs with css1 stylesheets
jQuery('input.css1').hide();

</script>

------------------
Point 2
------------------

jQuery methods - hide(), text(), addClass(), show()

------------------
Point 3
------------------

alert('Page contains ' + jQuery('a').length + ' <a> elements!');
jQuery('a').attr("href", "http://www.google.co.in");
$('a').attr("href", "http://www.google.com");

------------------
Point 4
------------------

<form>
<div>murali</div>
</form>

<form>
<div>murali 100</div>
</form>

<div>murali 200</div>

<script>
jQuery('div').text('new content added here - with out form tag');
jQuery('div',$('form')).text('new content added here - with form tag');
</script>


------------------
Point 5
------------------
<style type="text/css">
.external
{
}
</style>

<div class='external'>1000</div>
<div class='external'>1001</div>
<div>1002</div>
<div>1003</div>
<div class='external'>1004</div>

jQuery('div').filter(".external").text("Hello Maccha");

------------------
Point 6
------------------
$('div').css('font-size','24px');
$('div').css('color','Black');
$('div').css('font-family','Roman');

------------------
Point 7
------------------
<ul>
<li><a href="#">Google</a></li>
<li><a href="#">Yahoo</a></li>
<li><a href="#">Gmail</a></li>
<li><a href="#">Telugu People</a></li>
<li><a href="#">Andhra Vilas</a></li>
<li><a href="#">Great Andhra</a></li>
</ul>


$('li:eq(0)').find('a').attr("href", "http://www.google.co.in");
$('li:eq(0)').next().find('a').attr("href", "http://www.yahoomail.com");
$('li:eq(1)').next().text("sajfklasdj fklsjd fklsjd fklsdj jkl");

$('li:eq(2)').nextAll().find('a').attr("href", "http://www.telugu.greatandhra.com");
$('li:eq(2)').nextAll().find('a').text("Great Andhra");



------------------
Point 8
------------------
<div id="first">This is the first statement.</div>
<div id="second">This is the second statement.</div>
<div id="third">This is the third statement.</div>

<ul id="empno">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>

$('a').filter('.css').remove();
$('a').remove('.css100');

$('#first').replaceWith('<p><b>Murali</b></p>');

$('ul#empno li').text('Employee Number : 1');

// adding multiple attributes
$('#company').attr({'class':'murali','title':'company information'}).text('Value Labs, Hyderabad');

// adding html text
$('#comp').html('<strong>Hello World</strong>');

------------------
Point 9
------------------
<a href="/category">Category</a>
<ul id="nav">
<li><a href="#anchor1">Anchor 1</a></li>
<li><a href="#anchor2">Anchor 2</a></li>
<li><span><a href="#anchor3">Anchor 3</a></span></li>
</ul>

$('#nav li').find('a').attr("href","http://www.google.com"); all a
$('#nav li a').attr("href","http://www.google.com"); all a
$('#nav li > a').attr("href","http://www.google.com"); only immediate a

------------------
Point 10
------------------
//$('h1 + h2').text('Murali'); // h2 follows h1. h2 is updated
//$('h2 + h1').text('Murali'); // h1 follows h2. h1 is updated
//$('h1').siblings('h2,h3,p').text('Murali');

$('li.selected').nextAll('li').css('background-color','red');
$('li.selected').prevAll('li').css('background-color','green');
$('li.selected').next('li').css('background-color','red');
$('li.selected').next().css('background-color','red');

------------------
Point 11
------------------

<table id="tblEmpDetails">
<thead><td>Emp Number</td><td>Name</td></thead>
<tr><td>Employee Number : 0</td><td>even - Murali Krishna V</td></tr>
<tr><td>Employee Number : 1</td><td>odd - Dasari Subrahmanyam</td></tr>
<tr><td>Employee Number : 2</td><td>even - Rakesh Mupparam</td></tr>
<tr><td>Employee Number : 3</td><td>odd - Suresh M</td></tr>
<tr><td>Employee Number : 4</td><td>even - Lakshman A</td></tr>
</table>


$('#tblEmpDetails tr:even').css('background-color','red');
$('#tblEmpDetails tr:odd').css('background-color','green');

<table id="Table1">
<thead><td>Emp Number</td><td>Name</td></thead>
<tr><td>Employee Number : 0</td><td>even - Murali Krishna V</td></tr>
</table>


$('tr:even').css('background-color','yellow');
$('tr:odd').css('background-color','cyan');

------------------
Point 12
------------------
<span>Hello Bob!</span>
// Select all SPANs with 'Bob' in:
jQuery('span:contains("Bob")');

jQuery('div:has(p a)');

------------------
Point 13
------------------
<div id="Menu">
<a href="#">Destinations</a><br />
<a href="#">Risk Assessments</a><br />
<a href="#">About Us</a><br />
<a href="#">Contact Us</a><br />
</div>

<script type="text/javascript">
$(function ()
{
$("div#Menu a").mouseover(function () { $(this).addClass("highlightRow"); })
.mouseout(function () { $(this).removeClass("highlightRow"); }
);
})

$("div#Menu a").click(function ()
{
alert( $(this).text() );
});

</script>

------------------
Point 14 - Chapter 3
------------------
Looping Concepts


<div id="Menu">
<a href="www.google.co.in">Destinations</a><br />
<a href="www.google.com">Risk Assessments</a><br />
<a href="www.yahoomail.com">About Us</a><br />
<a href="www.facebook.com">Contact Us</a><br />
</div>


var urls = [];
$("div#Menu a[href]").each(function(i) {
urls[i] = $(this).attr('href');
$(this).attr("href","http://www.murali.com").text("www.murali.com");
});

alert( urls.join(","));

WRONG CODE
--------------
$("div#Menu a[href]")(function()
{
$(this).attr("href","http://www.murali.com").text("www.murali.com");
});


------------------
Point 15
------------------
<ul id="names">
<li>Ralph</li>
<li>Hope</li>
<li>Brandon</li>
<li>Jordan</li>
<li>Ralphie</li>
</ul>

$("ul > li").eq(7).css("border-bottom", "1px solid #000000");
$("ul > li").css("border-bottom", "1px solid red").eq(7).css("border-bottom", "1px solid #000000");
$("ul > li:first").css("border-top", "5px solid green");
$("ul > li:last").css("border-top", "5px solid green");
$("ul > li:eq(5)").css("border-top", "5px solid green");

(function($){
$(document).ready(function() {
$("ul > li").each(function(i) {
if (i % 2 == 1)
{
$(this).css("border", "2px solid red")
}
else
{
$(this).css("border", "3px solid green")
}
});
});
})(jQuery);


------------------
Point 16
------------------
<h2>Value Labs - Employees</h2>
<div>
<ul id="names">
<li>Murali</li>
<li>Krishna</li>
<li>Rakesh</li>
<li>Subbu</li>
<li>Lakshman</li>
<li>Vara</li>
<li>Shiva</li>
<li>Suresh</li>
<li>Mitesh</li>
<li>Vishnu</li>
</ul>
</div>


(function($)
{
$(document).ready(function()
{
var lis = $("ul li").get().reverse();
//$("ul").empty();

$.each(lis, function(i)
{
$(this).css("color", "white");
});

$("ul").append("<li>+++++++++++++++++++++++++</li>");

$.each(lis, function(i)
{
$("ul").append("<li class='reverseCss'>" + lis[i].innerHTML + "</li>");
});

$("li").filter(".reverseCss").css("color", "gold");
});
})(jQuery);

$("h2").addClass("Emp");
$("div").addClass("divEmp");

------------------
Point 17
------------------
(function($)
{
$(document).ready(function()
{
$("div").click(function()
{
alert("You clicked on div with an index of " + $("div").index(this) );
alert("You clicked on div with an index of " + $(this).text() );
});
});
})(jQuery);

------------------
Point 18
------------------
<div>
<br />
<p>Murali Krishna - p element</p> <br />
<p>Murali - p element</p> <br />
<p>Krishna - p element</p> <br />
<input type="text" id="txt1" /> <br />
<a href="#">Google 1</a><br />
<a href="#">Google 2</a><br />
<a href="#">Google 3</a><br />
<b>India</b><br />
<strong>India</strong><br />
<br />
</div>

<div>
<p>Raju</p>
</div>

<div>
<p>Rakesh + Raju</p>
</div>


$("div").each(function(i)
{
if ($('div').index(this) % 2 == 0)
{
$(this).text('I am ' + $(this).text() );
}
else
{
$(this).text('You Are : ' + $(this).text() );
}
});

------------------
Point 19
------------------
<h1>jQuery Cookbook Authors</h1>
<ol>
<li>John Resig</li>
<li>Cody Lindley</li>
<li>James Padolsey</li>
<li>Ralph Whitbeck</li>
</ol>

(function($)
{
$(document).ready(function()
{
$.each( $("li") , function(i)
{
alert( $(this).text() );
});
});
})(jQuery);


------------------
Point 20
------------------
Note:- jQuery utility method $.map(), which will transform an existing array into another array of items.

(function($)
{
$(document).ready(function()
{
var arr = $.map([100,200,300], function(item, index)
{
alert( item + 1 );
});
});
})(jQuery);

------------------
Point 21
------------------

(function($)
{
$(document).ready(function()
{
var arr = $.map($("li"), function(item, index)
{
while (index < 3)
{
return $(item).html();
}
return null;
});

$(document.body).append("<span>The first three authors are: " + arr.join(", ") + "</span>");
});
})(jQuery);


------------------
Point 22
------------------

<ul>
<li>fskdjf</li>
<li>fskdjf</li>
<li>fskdjf</li>
<li>fskdjf</li>
<li>fskdjf</li>
<li>fskdjf</li>
</ul>

$("li").slice(1,2).wrap("<b><i></i></b>").css('color','red').css('background-color','gold').css('width','200px');

------------------
Point 23 - Chapter 4
------------------
<a href="#">Broken Links</a><br />
<a href="http://www.google.co.in">www.google.co.in</a><br />
<a href="http://abc.com">abc</a><br />
<a href="#">Broken Links</a><br />
<a href="http://xyz.com">xyz</a><br />
<a href="#">Broken Links</a><br />


(function($)
{
$(document).ready(function()
{
$('a').filter(function()
{
if ( $(this).attr('href') == "#" )
{
$(this).attr('href',"http://telugu.greatandhra.com");
$(this).text('Great Andhra');
}
}).click(function() {
});
});
})(jQuery);


------------------
Point 24
------------------
<a href="#">Broken Links</a><br />
<a href="h:/www.google.co.in">www.google.co.in</a><br />
<a href="http://abc.com">abc</a><br />
<a href="#">Broken Links</a><br />
<a href="hp://xyz.com">xyz</a><br />
<a href="#">Broken Links</a><br />


(function($)
{
$(document).ready(function()
{
$('a').filter(function()
{
if ( $(this).attr('href') == "#" )
{
$(this).attr('href',"http://telugu.greatandhra.com");
$(this).text('Great Andhra');
}
else
{
var myVariable = $(this).attr('href');
if(myVariable == 'http://abc.com')
{

}
else
{
$(this).attr('href',"http://andhravilas.com");
$(this).text('Andhra Vilas');
}
}
}).click(function() {
});
});
})(jQuery);

------------------
Point 25
------------------
<h1>Months</h1>
<ol id="months"></ol>

<br />

<h1>Weekdays</h1>
<ol id="weekday"></ol>


(function($)
{
$(document).ready(function()
{
var months = [ 'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October',
'November', 'December'];

$.each(months, function(index, value)
{
$('#months').append('<li>' + value + '</li>');
});

var days = { Sunday: 0, Monday: 1, Tuesday: 2, Wednesday: 3,
Thursday: 4, Friday: 5, Saturday: 6 };

$.each(days, function(key, value)
{
$('#weekday').append("<li>" + key + ' (' + value + ')</li>');
});
});
})(jQuery);
------------------
Point 26
------------------
(function($)
{
$(document).ready(function()
{
var months = [ 'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October',
'November', 'December'];

var months = $.grep(months, function(value, i)
{
return ( value.indexOf('A') == 0 );
});
$('#months').html( '<li>' + months.join('</li><li>') + '</li>' );
});
})(jQuery);

it can be written as below as well using map utility

var monthsNew = $.map(months, function(value, i)
{
return ( value.indexOf('J') == 0 ? value : null );
});
$('#months').html( '<li>' + monthsNew.join('</li><li>') + '</li>' );
------------------
Point 27
------------------
(function($)
{
$(document).ready(function()
{
var months = [ 'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October',
'November', 'December'];

months = $.map(months, function(value, i)
{
var monthname = value.substr(0,3);
switch(monthname)
{
case "Jan" :
case "Mar" :
case "May" :
case "Jul" :
case "Aug" :
case "Oct" :
case "Dec" :
return value + " - 31";
break;
case "Feb" :
return value + " - 28";
break;
case "Apr" :
case "Jun" :
case "Sep" :
case "Nov" :
return value + " - 30";
break;
default: return "";
}

});
$('#months').html( '<li>' + months.join('</li><li>') + '</li>' );
});
})(jQuery);

------------------
Point 28
------------------
Merging two arrays sets

$('#months').html( '<li>' + $.merge(months,monthsNew).join('</li><li>') + '</li>' );


------------------
Point 29
------------------



------------------
Point 30
------------------


------------------
Point 31
------------------



------------------
Point 32
------------------

JQuery Notes 10Jan2012

------------------
Point 1
------------------


------------------
Point 2
------------------

jQuery methods - hide(), text(), addClass(), show()

------------------
Point 3
------------------

alert('Page contains ' + jQuery('a').length + ' elements!');
jQuery('a').attr("href", "http://www.google.co.in");
$('a').attr("href", "http://www.google.com");

------------------
Point 4
------------------


murali




murali 100



murali 200





------------------
Point 5
------------------


1000

1001

1002

1003

1004


jQuery('div').filter(".external").text("Hello Maccha");

------------------
Point 6
------------------
$('div').css('font-size','24px');
$('div').css('color','Black');
$('div').css('font-family','Roman');

------------------
Point 7
------------------



$('li:eq(0)').find('a').attr("href", "http://www.google.co.in");
$('li:eq(0)').next().find('a').attr("href", "http://www.yahoomail.com");
$('li:eq(1)').next().text("sajfklasdj fklsjd fklsjd fklsdj jkl");

$('li:eq(2)').nextAll().find('a').attr("href", "http://www.telugu.greatandhra.com");
$('li:eq(2)').nextAll().find('a').text("Great Andhra");



------------------
Point 8
------------------
This is the first statement.

This is the second statement.

This is the third statement.



  • 1

  • 2

  • 3



$('a').filter('.css').remove();
$('a').remove('.css100');

$('#first').replaceWith('

Murali

');

$('ul#empno li').text('Employee Number : 1');

// adding multiple attributes
$('#company').attr({'class':'murali','title':'company information'}).text('Value Labs, Hyderabad');

// adding html text
$('#comp').html('Hello World');

------------------
Point 9
------------------
Category


$('#nav li').find('a').attr("href","http://www.google.com"); all a
$('#nav li a').attr("href","http://www.google.com"); all a
$('#nav li > a').attr("href","http://www.google.com"); only immediate a

------------------
Point 10
------------------
//$('h1 + h2').text('Murali'); // h2 follows h1. h2 is updated
//$('h2 + h1').text('Murali'); // h1 follows h2. h1 is updated
//$('h1').siblings('h2,h3,p').text('Murali');

$('li.selected').nextAll('li').css('background-color','red');
$('li.selected').prevAll('li').css('background-color','green');
$('li.selected').next('li').css('background-color','red');
$('li.selected').next().css('background-color','red');

------------------
Point 11
------------------








Emp NumberName
Employee Number : 0even - Murali Krishna V
Employee Number : 1odd - Dasari Subrahmanyam
Employee Number : 2even - Rakesh Mupparam
Employee Number : 3odd - Suresh M
Employee Number : 4even - Lakshman A



$('#tblEmpDetails tr:even').css('background-color','red');
$('#tblEmpDetails tr:odd').css('background-color','green');




Emp NumberName
Employee Number : 0even - Murali Krishna V



$('tr:even').css('background-color','yellow');
$('tr:odd').css('background-color','cyan');

------------------
Point 12
------------------
Hello Bob!
// Select all SPANs with 'Bob' in:
jQuery('span:contains("Bob")');

jQuery('div:has(p a)');

------------------
Point 13
------------------




------------------
Point 14 - Chapter 3
------------------
Looping Concepts





var urls = [];
$("div#Menu a[href]").each(function(i) {
urls[i] = $(this).attr('href');
$(this).attr("href","http://www.murali.com").text("www.murali.com");
});

alert( urls.join(","));

WRONG CODE
--------------
$("div#Menu a[href]")(function()
{
$(this).attr("href","http://www.murali.com").text("www.murali.com");
});


------------------
Point 15
------------------

  • Ralph

  • Hope

  • Brandon

  • Jordan

  • Ralphie



$("ul > li").eq(7).css("border-bottom", "1px solid #000000");
$("ul > li").css("border-bottom", "1px solid red").eq(7).css("border-bottom", "1px solid #000000");
$("ul > li:first").css("border-top", "5px solid green");
$("ul > li:last").css("border-top", "5px solid green");
$("ul > li:eq(5)").css("border-top", "5px solid green");

(function($){
$(document).ready(function() {
$("ul > li").each(function(i) {
if (i % 2 == 1)
{
$(this).css("border", "2px solid red")
}
else
{
$(this).css("border", "3px solid green")
}
});
});
})(jQuery);


------------------
Point 16
------------------

Value Labs - Employees




  • Murali

  • Krishna

  • Rakesh

  • Subbu

  • Lakshman

  • Vara

  • Shiva

  • Suresh

  • Mitesh

  • Vishnu





(function($)
{
$(document).ready(function()
{
var lis = $("ul li").get().reverse();
//$("ul").empty();

$.each(lis, function(i)
{
$(this).css("color", "white");
});

$("ul").append("
  • +++++++++++++++++++++++++
  • ");

    $.each(lis, function(i)
    {
    $("ul").append("
  • " + lis[i].innerHTML + "
  • ");
    });

    $("li").filter(".reverseCss").css("color", "gold");
    });
    })(jQuery);

    $("h2").addClass("Emp");
    $("div").addClass("divEmp");

    ------------------
    Point 17
    ------------------
    (function($)
    {
    $(document).ready(function()
    {
    $("div").click(function()
    {
    alert("You clicked on div with an index of " + $("div").index(this) );
    alert("You clicked on div with an index of " + $(this).text() );
    });
    });
    })(jQuery);

    ------------------
    Point 18
    ------------------



    Murali Krishna - p element



    Murali - p element



    Krishna - p element





    Google 1

    Google 2

    Google 3

    India

    India






    Raju





    Rakesh + Raju





    $("div").each(function(i)
    {
    if ($('div').index(this) % 2 == 0)
    {
    $(this).text('I am ' + $(this).text() );
    }
    else
    {
    $(this).text('You Are : ' + $(this).text() );
    }
    });

    ------------------
    Point 19
    ------------------

    jQuery Cookbook Authors



    1. John Resig

    2. Cody Lindley

    3. James Padolsey

    4. Ralph Whitbeck



    (function($)
    {
    $(document).ready(function()
    {
    $.each( $("li") , function(i)
    {
    alert( $(this).text() );
    });
    });
    })(jQuery);


    ------------------
    Point 20
    ------------------
    Note:- jQuery utility method $.map(), which will transform an existing array into another array of items.

    (function($)
    {
    $(document).ready(function()
    {
    var arr = $.map([100,200,300], function(item, index)
    {
    alert( item + 1 );
    });
    });
    })(jQuery);

    ------------------
    Point 21
    ------------------

    (function($)
    {
    $(document).ready(function()
    {
    var arr = $.map($("li"), function(item, index)
    {
    while (index < 3)
    {
    return $(item).html();
    }
    return null;
    });

    $(document.body).append("The first three authors are: " + arr.join(", ") + "");
    });
    })(jQuery);


    ------------------
    Point 22
    ------------------


    • fskdjf

    • fskdjf

    • fskdjf

    • fskdjf

    • fskdjf

    • fskdjf



    $("li").slice(1,2).wrap("").css('color','red').css('background-color','gold').css('width','200px');

    ------------------
    Point 23 - Chapter 4
    ------------------
    Broken Links

    www.google.co.in

    abc

    Broken Links

    xyz

    Broken Links



    (function($)
    {
    $(document).ready(function()
    {
    $('a').filter(function()
    {
    if ( $(this).attr('href') == "#" )
    {
    $(this).attr('href',"http://telugu.greatandhra.com");
    $(this).text('Great Andhra');
    }
    }).click(function() {
    });
    });
    })(jQuery);


    ------------------
    Point 24
    ------------------
    Broken Links

    www.google.co.in

    abc

    Broken Links

    xyz

    Broken Links



    (function($)
    {
    $(document).ready(function()
    {
    $('a').filter(function()
    {
    if ( $(this).attr('href') == "#" )
    {
    $(this).attr('href',"http://telugu.greatandhra.com");
    $(this).text('Great Andhra');
    }
    else
    {
    var myVariable = $(this).attr('href');
    if(myVariable == 'http://abc.com')
    {

    }
    else
    {
    $(this).attr('href',"http://andhravilas.com");
    $(this).text('Andhra Vilas');
    }
    }
    }).click(function() {
    });
    });
    })(jQuery);

    ------------------
    Point 25
    ------------------

    Months







      Weekdays





        (function($)
        {
        $(document).ready(function()
        {
        var months = [ 'January', 'February', 'March', 'April', 'May',
        'June', 'July', 'August', 'September', 'October',
        'November', 'December'];

        $.each(months, function(index, value)
        {
        $('#months').append('
      1. ' + value + '
      2. ');
        });

        var days = { Sunday: 0, Monday: 1, Tuesday: 2, Wednesday: 3,
        Thursday: 4, Friday: 5, Saturday: 6 };

        $.each(days, function(key, value)
        {
        $('#weekday').append("
      3. " + key + ' (' + value + ')
      4. ');
        });
        });
        })(jQuery);
        ------------------
        Point 26
        ------------------
        (function($)
        {
        $(document).ready(function()
        {
        var months = [ 'January', 'February', 'March', 'April', 'May',
        'June', 'July', 'August', 'September', 'October',
        'November', 'December'];

        var months = $.grep(months, function(value, i)
        {
        return ( value.indexOf('A') == 0 );
        });
        $('#months').html( '
      5. ' + months.join('
      6. ') + '
      7. ' );
        });
        })(jQuery);

        it can be written as below as well using map utility

        var monthsNew = $.map(months, function(value, i)
        {
        return ( value.indexOf('J') == 0 ? value : null );
        });
        $('#months').html( '
      8. ' + monthsNew.join('
      9. ') + '
      10. ' );
        ------------------
        Point 27
        ------------------
        (function($)
        {
        $(document).ready(function()
        {
        var months = [ 'January', 'February', 'March', 'April', 'May',
        'June', 'July', 'August', 'September', 'October',
        'November', 'December'];

        months = $.map(months, function(value, i)
        {
        var monthname = value.substr(0,3);
        switch(monthname)
        {
        case "Jan" :
        case "Mar" :
        case "May" :
        case "Jul" :
        case "Aug" :
        case "Oct" :
        case "Dec" :
        return value + " - 31";
        break;
        case "Feb" :
        return value + " - 28";
        break;
        case "Apr" :
        case "Jun" :
        case "Sep" :
        case "Nov" :
        return value + " - 30";
        break;
        default: return "";
        }

        });
        $('#months').html( '
      11. ' + months.join('
      12. ') + '
      13. ' );
        });
        })(jQuery);

        ------------------
        Point 28
        ------------------
        Merging two arrays sets

        $('#months').html( '
      14. ' + $.merge(months,monthsNew).join('
      15. ') + '
      16. ' );


        ------------------
        Point 29
        ------------------



        ------------------
        Point 30
        ------------------


        ------------------
        Point 31
        ------------------



        ------------------
        Point 32
        ------------------