JQuery – Remove link from anchor tag inside td based on a value


We have following html table with anchor tags

<table>
	<tr>
		<td>
			<a href="abc">value1</a>
		</td>
		<td>
			<a href="xyz">na</a>
		</td>
	</tr>
	<tr>
		<td>
			<a href="def">na</a>
		</td>
		<td>
			<a href="ghi">value2</a>
		</td>
	</tr>
	<tr>
		<td>
			<a href="jkl">value3</a>
		</td>
		<td>
			<a href="wxy">na</a>
		</td>
	</tr>
</table>

Here, if we want to remove link from all the anchor tags whose value is na, we can use following JQuery.

        $(document).ready(function () {		
            $('td').find('a').filter(function () {
                return $(this).text() === "na";
            }).removeAttr("href")
        });

Complete HTML

<html>
<head>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function () {		
			$('td').find('a').filter(function () {
				return $(this).text() === "na";
			}).removeAttr("href")
		});
	</script>
</head>
<body>
	<table>
		<tr>
			<td>
				<a href="abc">value1</a>
			</td>
			<td>
				<a href="xyz">na</a>
			</td>
		</tr>
		<tr>
			<td>
				<a href="def">na</a>
			</td>
			<td>
				<a href="ghi">value2</a>
			</td>
		</tr>
		<tr>
			<td>
				<a href="jkl">value3</a>
			</td>
			<td>
				<a href="wxy">na</a>
			</td>
		</tr>
	</table>
</body>
</html>
Posted in JQuery | Tagged , , , , | 1 Comment

Fix Eclipse error “Project is missing required library android.jar”


Eclipse missing required library android.jar

I got this error when I moved a running Android project to another system.

Error says, Project ‘MyProject’ is missing required library: ‘E:\android\adt-bundle-windows-x86-20130729\adt-bundle-windows-x86-20130729\sdk\platforms\android-19\android.jar’. The project cannot be built until build path errors are resolved.

A red exclamation mark also appears on project icon.

Steps to fix this error

Select project ‘MyProject’ in the Package Explorer and press [Alt+Enter] to open Project Properties.

Click on Java Build Path in left pane and Libraries tab on the right pane. Select android.jar library with the error icon and click on Remove. Finally click on OK.

 

Eclipse Project Properties

This should fix this error.

 

Posted in Android | Tagged , , , , | 1 Comment

C# – How to implement two interfaces having same method names in a class


We have two interfaces IMan and IBirds. Both the interfaces defines a method named Eat with same name and signature. A class MyClass is inheriting both the interfaces. How can we implement method of both the interfaces in the derived class MyClass ?

Here is the code:

public interface IMan
{
    void Eat();
}

public interface IBirds
{
    void Eat();
}

public class MyClass : IMan, IBirds
{
    void IMan.Eat()
    {
        Console.WriteLine("Roti");
    }
    void IBirds.Eat()
    {
        Console.WriteLine("Earthworms");
    }
}

We use interface name to access its method to implement.

Similarly, we call a method by instantiating the desired interface and assigning object of the derived class to it.

IMan man = new MyClass();
man.Eat();
IBirds birds = new MyClass();
birds.Eat();

//OR
                        
((IMan)new MyClass()).Eat();
((IBirds)new MyClass()).Eat();
Posted in .Net, C# | Tagged , , , , , | Leave a comment

Android – Read text file from assets folder


We can use assets folder in Android to store files that we want to use in the application as it is. Files in the assets folder are deployed to the device with the same name. For example, assets folder can be used to store application database. Files in this folder can be accessed using AssetManager class.

To read text from a file in the Assets folder, first create a text file with some text in the assets folder or just copy past file into the assets folder.

Java -Asset   Write following code to read contents of a text file from the assets folder

	public void btnReadText_Click(View vw) {
		String fileContents = ReadFile("ReadMe.txt");
		Toast.makeText(getApplicationContext(), fileContents,
				Toast.LENGTH_SHORT).show();
	}

	public String ReadFile(String fileName) {
		BufferedReader br = null;
		String fileText = "";
		try {
			String str = "";
			StringBuffer buffer = new StringBuffer();
			AssetManager assetManager = getAssets();
			InputStream stream = assetManager.open(fileName);

			BufferedReader reader = new BufferedReader(new InputStreamReader(
					stream));
			if (stream != null) {
				while ((str = reader.readLine()) != null) {
					buffer.append(str);
				}
			}
			fileText = buffer.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		return fileText;
	}
Posted in Android | Tagged , | Leave a comment

2014 in review


The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 100,000 times in 2014. If it were an exhibit at the Louvre Museum, it would take about 4 days for that many people to see it.

Click here to see the complete report.

Posted in .Net | Leave a comment

SQL Server – Restore database from Command Prompt using sqlcmd command


Introduction

Here, I will explain how to restore an SQL Server database from Command Prompt using sqlcmd utility.  We will use RESTORE DATABASE command to restore the database from a backup (.bak) taken using BACKUP DATABASE command. Click here for Backup Database from Command Prompt.

Step 1: Open Command Prompt and type sqlcmd -S localhost\SQLServer2014 -U sa , then press enter. Here localhost\SQLServer2014 is server name\instance name and sa is the username.

sqlcmd command

Note : To restore database using Windows Authentication, type sqlcmd -S localhost\SQLServer2014 -E and press enter and skip the Step 2

Step 2: Type your password and press enter

SQLCMD Command

Step 3: Type RESTORE DATABASE Galaxy FROM DISK=’D:\Data\Galaxy.bak’ and press enter. Here we are restoring a full database from a backup.

SQLCMD

Step 4: Type GO and press enter

SQLCMD RESTORE DATABASEFor more information and examples about RESTORE DATABASE command please visit http://msdn.microsoft.com/en-us/library/ms186858.aspx

Posted in SQL | Tagged , , , | Leave a comment

SQL Server – Backup database from Command Prompt using sqlcmd command


Introduction

Here, I will explain how to backup an SQL Server database from Command Prompt using sqlcmd utility

Step 1: Open Command Prompt and type sqlcmd -S localhost\SQLServer2014 -U sa , then press enter. Here localhost\SQLServer2014 is server name and sa is username.

sqlcmd command

Note : To backup database using Windows Authentication, type sqlcmd -S localhost\SQLServer2014 -E and press enter and skip Step 2

Step 2: Type your password and press enter

SQLCMD Command

Step 3: Type BACKUP DATABASE Galaxy TO DISK=’D:\data\Galaxy.bak’ and press enter.

SQLCMD

Step 4: Type GO and press enter

SQLCMD

Some common parameters of sqlcmd

Command Description
-S Server name
-U User name
-P Password
-E Use trusted connection
-i Input file
-o Output file
-q Command line query
-Q Command line query and exit

For more information about sqlcmd command please visit http://msdn.microsoft.com/en-us/library/ms162773.aspx

Posted in SQL | Tagged , , , | 1 Comment

Create MarkerCluster in Google Maps | MarkerCluster example in Google Maps


Download Source Code

Introduction

Here, I will explain how to create MarkerCluster in Google Map to group a large number of markers.

MarkerCluster Example

Description

MarkerCluster is a client side library that groups a large number of markers on Google Map into clusters. MarkerCluster is a grid based clustering where map is divided into square grids and markers found in a grid are grouped into a cluster to create a single marker. A cluster indicate the number of markers inside it and expands on zooming-in or clicking on the map.

To create MarkerCluster, first we need to import  MarkerCluster library (markerclusterer.js). Then create an object of MarkerCluster object and pass google.maps.Map object and google.maps.Marker array object to its parameter

var markerCluster = new MarkerClusterer(myMap, markers);

MarkerCluster Example

<!DOCTYPE html>
<html>
<head runat="server">
	<title>Google Maps MarkerCluster</title>

        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
	<!--<script src="markerclusterer.js" type="text/javascript"></script>-->
	<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js"
		type="text/javascript"></script>
	<script type="text/javascript">
		function initialize() {
			var mapOptions = {
				center: new google.maps.LatLng(23.195307, 77.370873),
				zoom: 4,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};

			// Create map
			var myMap = new google.maps.Map(document.getElementById("mapArea"),
				mapOptions);

			var locations = [['28.630290', '77.195799'],
				['28.622455', '77.220174'],
				['28.619291', '77.214853'],
				['28.612736', '77.237341'],
				['28.613037', '77.199318'],
				['28.511456', '77.185713'],
				['28.512285', '77.190391'],
				['28.506968', '77.202493'],
				['28.511003', '77.204296'],
				['28.471965', '77.510497'],
				['28.469702', '77.531010'],
				['28.472569', '77.514016'],
				['28.473550', '77.529551'],
				['28.460572', '77.536589'],
				['28.464496', '77.530603'],
				['28.462383', '77.532963'],
				['28.455969', '77.533156'],
				['23.293099', '77.366753'],
				['23.286161', '77.377052'],
				['23.273546', '77.427864'],
				['23.223075', '77.407265'],
				['23.229385', '77.480049'],
				['23.195307', '77.370873'],
				['23.216764', '77.484856'],
				['23.216133', '77.376366'],
				['23.265661', '77.472196'],
				['23.234827', '77.436790'],
				['23.226269', '77.432456'],
				['23.227216', '77.437091'],
				['23.224692', '77.430739'],
				['23.230491', '77.433819'],
				['24.784597', '84.974914'],
				['24.797843', '84.983325'],
				['24.797376', '84.975429'],
				['24.786934', '84.967875'],
				['24.775557', '84.963412'],
				['24.748902', '84.941268'],
				['24.780545', '84.990363'],
				['24.792077', '85.007873'],
				['24.752020', '84.988990'],
				['24.804232', '85.004611'],
				['24.766829', '85.007873'],
				['24.770803', '84.960365'],
				['24.766227', '84.954821'],
				['24.766773', '84.954939'],
				['24.768010', '84.955658'],
				['24.768594', '84.955787'],
				['24.768711', '84.957257'],
				['24.769539', '84.955776'],
				['24.769461', '84.958405'],
				['28.580142', '77.237684'],
				['28.579200', '77.239229'],
				['28.579275', '77.246353'],
				['28.576977', '77.244636'],
				['28.576977', '77.244636'],
				['28.576750', '77.250430'],
				['28.564831', '77.245151'],
				['28.564040', '77.243778'],
				['28.563945', '77.242490'],
				['28.562909', '77.246567'],
				['28.559437', '77.238928'],
				['28.558164', '77.236439'],
				['28.559580', '77.238029'],
				['28.560285', '77.237694'],
				['28.558977', '77.238930'],
				['28.553303', '77.239295'],
				['28.558053', '77.245260'],
				['22.862979', '70.801176'],
				['22.711046', '71.636137'],
				['22.310151', '70.790190'],
				['21.989622', '70.762724'],
				['22.264406', '68.977446'],
				['21.525357', '70.460600'],
				['22.205932', '70.087065']];

			var markers = [];
			for (var i = 0; i < locations.length; i++) {
				var latLng = new google.maps.LatLng(locations[i][0], locations[i][1]);
				var marker = new google.maps.Marker({'position': latLng});
				markers.push(marker);
			}

			var markerCluster = new MarkerClusterer(myMap, markers);
		}
	</script>
</head>
<body onload="initialize()">
     <form id="form1" runat="server">
          <div id="mapArea" style="width: 600px; height: 700px;">
          </div>
     </form>
</body>
</html>

Here, to create MarkerCluster we have stored location data(latitude/longitude) in an array.  In the following example we are loading location data stored in a JSON file.

MarkerCluster Example using JSON data

<!DOCTYPE html>
<html>
<head runat="server">
	<title>Google Maps MarkerCluster using JSON</title>

	<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
	<!--<script src="markerclusterer.js" type="text/javascript"></script>-->
	<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js" 
		type="text/javascript"></script>
	<script type="text/javascript" src="location.json"></script>
	<script type="text/javascript">
		function initialize() {
			var mapOptions = {
				center: new google.maps.LatLng(23.195307, 77.370873),
				zoom: 4,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};

			// Create map
			var myMap = new google.maps.Map(document.getElementById("mapArea"),
				mapOptions);

			var locations = [];

			var markers = [];
			for (var i = 0; i < locationdata.locations.length; i++) {
				var location=locationdata.locations;			
				var latLng = new google.maps.LatLng(location[i].latitude, location[i].longitude);
				var marker = new google.maps.Marker({'position': latLng});
				markers.push(marker);
			}
	
			var markerCluster = new MarkerClusterer(myMap, markers);
		}
	</script>
</head>
<body onload="initialize()">
     <form id="form1" runat="server">
          <div id="mapArea" style="width: 600px; height: 700px;">
          </div>
     </form>
</body>
</html>

Here, we are retrieving location data from a JSON file location.json to built markers.

Posted in Google API, Google Maps API | Tagged , , , , , , | Leave a comment

Restore SQL Server database using Management Studio


Introduction

Here, I will explain how to restore an SQL Server database from a backup file (.bak) file using SQL Server Management Studio (SSMS)

Step 1: Open SQL Server Management Studio

 image001

Step 2: Login with your credentials

image002

Step 3: Right click on Databases node in the Object Explore and select Restore Database

Microsoft SQL Server Management Studio_2014-09-14_10-52-37

Step 4: Click on Device in the Source section and click on browse button (…) to select your backup file.

Restore Database - _2014-09-17_00-46-02

Step 5: Click on Add button to select the backup file(.bak) then click OK.

Select backup devices_2014-09-17_00-49-06

Default name of the destination database will be the same as in the backup file. You can change it in the Destination section.

Restore Database - Galaxy_2014-09-17_00-56-44

Step 6: Click on File tab, select Relocate all files to folder then select folder where you want to restore your database.

Restore Database - Galaxy_2014-09-17_19-57-10

Default location of the restored database is the data directory of the SQL Server. To change it you need to follow this step. Otherwise you can skip this step.

Step 7: Click on OK to complete restore.

Microsoft SQL Server Management Studio_2014-09-17_20-13-27

Posted in SQL | Tagged , , , , , | 2 Comments

Backup SQL Server database using Management Studio


Introduction

In this article I will explain how to backup an SQL Server database using SQL Server Management Studio (SSMS)

Step 1: Open SQL Server Management Studio image001

Step 2: Login with your credentials

image002

Step 3: Expand Databases node in the Object Explorer. And right click on the database you want to back up. Then select Tasks -> Back Up

image003

Step 4: Select backup type as Full and destination as Disk as we want to create a full backup and want to save it on the local disk. Then click on Add to add backup location.

image005

Backup type can be Full or Differential. Backup destination can be Disk or URL. URL destination is selected when you want to store backup on Windows Azure Blob storage.

Step 5: In the Select Backup Location dialog box, select backup location, enter file name as “AnyName.bak” and click OK thrice to complete the backup.

image008

Step 6: You can view the backup(.bak file) at the location specified

image010

Posted in SQL | Tagged , , , , | Leave a comment