Apr 12

How to make your website Location-Aware



These days with web apps being run on tablets and smartphones, location-awareness is becoming of a preferable feature to have. Instead of an app asking the user to enter his location, the app finds it on its own.

The most reliable way of finding a user’s location in terms of latitude/longitude was using the Google Geolocation API, which was part of Google Gears. which unfortunately has been discontinued some months back.

However, geolocation still works if you are using Google Maps. And again it is NOT necessary to have to display a google map just because you want to do a geolocation call.

We are just using Google Maps to use its geolocation features.

The sample javascript is below:

<script src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
	function doLocation() {
   		 if (navigator.geolocation) {
		        navigator.geolocation.getCurrentPosition(function(position){
		        var latitude = position.coords.latitude;
		        var longitude = position.coords.longitude;
				var fld = document.getElementById("address");
				if (fld) {
					fld.value = "(" + latitude + "," + longitude + ")";
				}
		        var coords = new google.maps.LatLng(latitude, longitude);
		        var mapOptions = {
		            zoom: 15,
		            center: coords,
		            mapTypeControl: true,
        		    navigationControlOptions: {
		                style: google.maps.NavigationControlStyle.SMALL
		            },
		            mapTypeId: google.maps.MapTypeId.ROADMAP
		            };
		            map = new google.maps.Map(
		                document.getElementById("mp"), mapOptions
		                );
		            var marker = new google.maps.Marker({
        		            position: coords,
		                    map: map,
		                    title: "Your current location!"
	            });

    		   });
	    }else {
    	    alert("Geolocation API is not supported in your browser.");
	    }
	}
</script>

The front end script shown below:

<style type="text/css">
#mp {
    height: 0px;
    width: 0px;
}
</style>

<div id="mp"></div>
  • In the javascript function, it is assumed there is a textbox called ‘address’, which will be assigned the lat/long value obtained from the geolocation call. Once you have the coordinates, you can assign it to anything you want.
  • The div which will hold the google map has been given a width and height of zero, so it does not show. If you need a map then you can give it height and width and position.
  • The function doLocation can be called at page load or on some click event in the page.
Apr 06

Listing files by Update date in SVN and zipping them



How to get a list of all files changed from a specific date in the past. Secondly, how to zip them all up.

Step 1

svn diff http://subversion-url –summarize -r {2012-03-01}:{2012-03-31} > /var/log.txt

What this does is list the files with full path changed between Mar 1 to Mar 21 and append all the filepaths into a file called log.txt

Step 2

cat /var/log.txt | while read a; do zip changes.zip $a; done

Use piping to get each line from log.txt into variable a and pass the value of a into the zip command. Each filename from log.txt is added to the file changes.zip


Mar 07

Fixing nyroModal positioning in iOS devices



NyroModal is a JQuery component for showing fancy popups. It has a problem in centering the popup in iOS devices .

The specific problem being that if you have scrolled a few pages and then you click on something which calls a Nyromodal popup , you have to scroll back all the way to the top of the page to see the popup. As a result , either you will either see the top of the popup being cut off or not at all. See image below for an example:

The workaround for this is to call the endShowContent callback function and reposition the popup. The sample code for this is given below:

 $.nyroModalSettings({
              type: 'iframe',
              height: 250,
              width: 520,
              resizable: true,
              autoSizable: true,
              titleFromIframe: true,
              modal: false,
              // selIndicator: '#loading',
              contentLoading: "" // use our own,
			  	,cssOpt: {
					bg: {
						position: 'absolute',
						overflow: 'hidden',
						top: 0,
						left: 0,
						height: '100%',
						width: '100%'
					},
					wrapper: {
						position: 'relative',
						top: '50%',
						left: '50%'
				    },
					wrapper2: {
				  	},
				    content: {
		   		    },
				    loading: {
					  position: 'absolute',
					  top: '50%',
					  left: '50%',
					  marginTop: '-50px',
					  marginLeft: '-50px'
				    }
				},
				endShowContent: function(nm){
                    if( $("div.nyroModalBg").outerHeight() < $(window).outerHeight() ){
                        $("div.nyroModalBg").css("height", $(window).outerHeight());
                    }
                    if ( $("div.nyroModalBg").outerHeight() < $("body").outerHeight() ){
                        $("div.nyroModalBg").css("height", $("body").outerHeight());
                    }
                } // Will be called one the content is resized
Mar 03

Difference between an Emulator and a Simulator



Simply put, an emulator mimics the outward behaviour of a system and a Simulator actually models the internal behaviour of a system.

A Flight Simulator program actually models all the principles of aerodynamics and physics while flying a plane.

 

 

 

 

 

An iPad emulator looks like an IPad and interacts with the user like an IPad but it is not really an IPad behind the scenes.

Jan 20

Dynamic positioning of the jquery tooltip object



We are using dynamic plugin which repositions our tooltips so that it is always visible on the viewport.

If there is no room on the top edge then the tooltip is shown on the bottom edge. The same happens on every edge of the tooltip: top, bottom, left and right. When there is no room then the opposite edge is used. Note that this demo is only for vertical repositioning.

It is possible to change the style, effect and other configuration variables whenever the dynamic repositioning occurs.

We are using the offset option to position the tooltip a little higher by default. When using the dynamic effect this value is inverted. Higher means lower and further right means further left.

JavaScript coding

After initializing the tooltip we will chain our dynamic()plugin. We have used the bottom parameter to alter the tooltip configuration for the bottom edge. Every configuration option can be used to alter the tooltip’s behaviour.

<script type=”text/javascript”>

jQuery(function() {

$(“.tooltip_anchor”).tooltip ({

offset : [10,2],
effect : ‘slide’,
predelay: ’10′
// add dynamic plugin with optional configuration for bottom edge
}).dynamic({ bottom: { direction: ‘down’, bounce: true } });

});

</script>

Note : the dynamic plugin and the slide effect are not included in the standard jQuery Tools distribution. You must download a custom combination to include those effects.

Jan 04

Downgrading IIS from 64 bit to 32 bit after reinstalling ASP.NET 2.0



To enable 32 bit apps to run:

1.Go to command prompt and navigate to  %systemdrive%\Inetpub\AdminScripts

2.Run the command cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 “true”

 

 

Next to reinstall ASP.NET 2.0.x

1.Go to command prompt

2.Navigate to C:\%WINDIR%\Microsoft.NET\Framework\v1.1.4322 

3. Type aspnet_regiis /i

 

 

 

Jan 04

Install SQL Server 2008 Express



SQL 2008 Express is available free from Microsoft.

This article will take you through the process of how to install  and configure SQL Server 2008 Express.

Step 1 : Download SQL Server 2008 Express

First, you will need to download SQL Server 2008 Express.

You have two options to download.

OR

I recommend to install “SQL Server 2008 Express with Tools” because it is worth the extra 150 MB to be able to troubleshoot your SQL Server if anything ever goes wrong.

Step 2: Install SQL Server 2008 Express

SQL Server 2008 Express requires .NET Framework 3.5 SP1, if your server does not have .NET Framework 3.5 SP1 you will need to download .NET Framework 3.5 SP1 and install it on your server. You can download .NET Framework 3.5 SP1 from http://go.microsoft.com/fwlink/?LinkId=120550

SQL Server 2008 Express requires Windows Installer 4.5, if your server does not have Windows Installer 4.5 you will need to download Windows Installer 4.5 and install it on your server. You can download Windows Installer 4.5 from http://go.microsoft.com/fwlink/?LinkId=123422

SQL Server 2008 Express requires Windows PowerShell 1.0, if your server does not have Windows PowerShell 1.0 you will need to download Windows PowerShell 1.0 and install it on your server. You can download Windows PowerShell 1.0 from http://go.microsoft.com/fwlink/?LinkId=120552

When you are ready to install SQL 2008 Express, follow these steps

  1. Run your exe to install SQL 2008 Express.
  2. At the “SQL Server Installation Center”, choose “System Configuration Checker” to make sure you are ready to install SQL 2008 Express
  3. When the “System Configuration Checker” has validated that you are ready to install SQL 2008 Express, return to the “SQL Server Installation Center” and click on Installation.
  4. Select “New SQL Server stand-alone installation or add features to an existing installation”
  5. A setup support check will run. Make sure there are no errors or warnings, press OK.
  6. The “SQL Server 2008″ Setup will now appear, on the Product Key page, click Next.
  7. Check the box “I accept the license terms” and click Next.
  8. Click “Install” to install the Setup Support Files.
  9. When the Setup Support Files install is complete, click Next.
  10. You will now be in the “Feature Selection” page. Select “Database Engine Services” and “Management Tools – Basic” and then click Next.
  11. In the “Instance Configuration” page, specify MSSQLSERVER in both the “Named instance” and “Instance ID” fields, this will force SQL Server 2008 Express to install as the Default instance. If you want to install as a named instance, specify a name other than MSSQLSERVER.
  12. Click Next twice.
  13. You will now be in the “Server Configuration” page. Change the SQL Server Database Engine’s Account Name to “NT AUTHORITY\SYSTEM” and SQL Server Browser’s Startup Type to Automatic, then click Next.
  14. On the Database Engine Configuration page, you can either leave it configured to use Windows Authentication Mode only or Mixed Mode (SQL Server authentication and Windows authentication). I usually enable Mixed Mode so that if for some reason my security gets messed up I always have a backdoor account (the SA account). If you choose Mixed Mode, you will need to enter and confirm a password for the SA account.
  15. Before you can continue, you will need to specify the group(s) that you want to have unrestricted access to SQL Server. Click “Add…” and select the group(s). I recommend that you at least add Administrators and the “Current User” (Service Account). When you are done here, click Next three times, and then click Install.
  16. When the installer completes, click Next and then Close.

 Step 3 : Firewall Exceptions

If you have a software firewall installed on your server, you will need to add exceptions for the SQL Server and SQL Browser services. If you are using Windows Firewall, do the following:

  1. In your Control Panel, open the Windows Firewall applet.
  2. Go to the Exceptions tab.
  3. Click Add Program
  4. Browse to and select “C:\Program Files\Microsoft SQL Server\MSSQL.10\MSSQL\Binn\sqlservr.exe”
  5. Click OK.
  6. Click Add Program
  7. Browse to and select “C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe”
  8. Click OK and then click OK again.

If you are using a third-party software firewall, you will need to follow their instructions to add exceptions to sqlservr.exe and sqlbrowser.exe.

Now when you have completed all of these , restart your SQL Server to complete the process.