how to get Get current URL with JavaScript

In this tutorial I will show you that how can we get url of the server where website is hosted.

Example: http://shahvaibhav.com/tutorials/Index.html

Here:

So we can get full URL in Javascript as

If you want to break up the pathname e.g.http://shahvaibhav.com/tutorials/asp.net/mvc/webgrid/Index.html, you can split the string on “/” characters.

To put that pathname back together, you can stitch together the array and put the “/”‘s back in:

Get location (Latitude & Longitude) for given address in c# using google api

In my application I wanted to find Latitude & Longitude of address of a person.

To do this I have used google api.

Bellow is c# code:

Here What I did is just called google service & just extracted the latitude & longitude from the xml response which I got from service.

This free service has limitation of 2500 request per IP per day, so If your application is will request more than that then google api will block your IP temporarily & If you continue to do this then It may ban your IP also.

I your application will request more that 2500 request per day per IP then you may have to buy service from google.

Get distance between two points using cloudmade

In my application I wanted to find distance between several points (latitude & longitude) which I had plotted on my leaflet map.

After searching for some time I found that coludmade provides service for finding distance & time between points.

Lets See how can we do this:

Bellow is my javascript

In getDistanceTime() function I am creating url string for service & calling it using ajax.

On click of this button service will be called & in response we will get shortest distance between two points.

Demo : http://jsfiddle.net/FhfVW/15/

Here I have found shortest distance in kms traveling by “car”.We can also find traveling by “foot” or “bicycle” also.We can also find distance between two points via come mid points

Demo : http://jsfiddle.net/Am69G/

More Details of this service can be found on http://developers.cloudmade.com/projects/routing-http-api/examples

Solving Error ‘SET OPTION SQL_QUOTE_SHOW_CREATE=1′ in mysql while exporting data

While exporting my database from MySql Database using Workbench 5.2 I got error as bellow

Before that when I clicked then I got this warning
“mysqldump.exe is version 5.5.16, but the MySQL Server to be dumped has version 5.6.10.
Because the version of mysqldump is older than the server, some features may not be backed up properly.
It is recommended you upgrade your local MySQL client programs, including mysqldump to a version equal to or newer than that of the target server.
The path to the dump tool must then be set in Preferences -> Administrator -> Path to mysqldump Tool.”

After searching for solution for some time I got solution for it.
Just follow the steps
1. Go To Edit -> Preferences -> Administrator.

2. In ‘Path to mysqldump Tool’ we have to chose path for mysqldump.exe.
But there are two mysqldump.exe present
1) C:\Program Files\MySQL\MySQL Workbench CE 5.2.47\mysqldump.exe
2) C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe
If we see details of files then we will come to know that 1st file version is 5.5.16 & 2nd files version is 5.6 & By default Workbench considers 1st file

3. Select File which is at path ‘C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe’

Its done now try to export database, you will be able to export it without any errors.

create polylines with different colors in leaflet/ dynamically change color of polyline

Recently while working with leaflet polyline I had a situation where I wanted to add multiple polylines with different colors.
number of polylines were different all the time, so I was not able to give different color to each polyline as my javascript was generic for adding all polylines to map.
So I found way for creating dynamic color for each polyline.
Bellow is function which creates polyline for each set of points.

Here If we see instead of giving any color I am calling function get_my_color()
This function is shown bellow.

This will create color dynamically & send it to color property of polyline

How to draw polyline using leaflet

For creating polyline we need to have at least two points.

So we first create two points.

Polyline needs an array of points to be entered, so will create array for this points.

Now we will create between these two points.

We can add different properties like weight, colour, opacity, smoothFactor, etc. to polyline also.
See bellow example

Solving “The requested service, ‘http://MyService.svc’ could not be activated. See the server’s diagnostic trace logs for more information.” error

While working in WCF project I got this error while accessing wcf service.
“The requested service, ‘http://MyService.svc’ could not be activated. See the server’s diagnostic trace logs for more information.”

But when I was running service separately then It was running.

After searching for some time I got one solution which works for me.

Solution is as follows:

In of your web.config of your application just add

Understanding OOPS SOLID Principles

SOLID principles

Thanks to Al-Farooque Shubho’s article on codeproject

Single Responsibility Principle

“There should never be more than one reason for a class to change.”
Or, differently said: “A class should have one and only one responsibility”.

It says, “Just because you can implement all the features in a single device, you shouldn’t”. Why? Because it adds a lot of manageability problems for you in the long run.

If you have a class that has more than one reason to change (or has more than one overall responsibility), you need to split the class into multiple classes based upon their responsibility.

You surely can have multiple methods in a single class. The issue is they have to meet a single purpose. Now, why is splitting important?

It’s important because:
• Each responsibility is an axis of change.
• Code becomes coupled if classes have more than one responsibility.

We should break up the class based on its responsibilities.SRP seems to be an idea of breaking things into molecular parts so that it becomes reusable and can be managed centrally.

So, shouldn’t we apply SRP in the method level as well? I mean, we might have written methods that have many lines of code for doing multiple things. These methods might be violating SRP.

Yes, you should break down your methods so that each method does a particular work. That will allow you to re-use methods, and in case a change is required, you are able to do the change by modifying minimal amount of code.

E.g.:
Let’s say we have Rectangle class which implements two functionalities i.e. Calculate Area & Draw Rectangle.
So we should break this rectangle class
1. Rectangle: This class will only calculate area.
2. RectangleUI: This will inherit Rectangle class & will implement method which will draw rectangle.

Open-Closed Principle

“Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”

At the most basic level, that means, you should be able to extend a class’s behaviour without modifying it. It’s just like I should be able to put on a dress without doing any change to my body.

Liskov’s Substitution Principle

“Subtypes must be substitutable for their base types.”
Or, if said differently:
“Functions that use references to base classes must be able to use objects of derived classes without knowing it.”

E.g.:
Lets consider Class Bird which implements method Fly () & Kingfisher class which will extend Bird class.

Here, the Kingfisher class extends the Bird base class and hence inherits the Fly () method, which is pretty good.
Let’s create one more class Ostrich which also extends Bird class.

Now, can it fly? No! Here, the design violates the LSP.

So, even if in real world this seems natural, in the class design, Ostrich should not inherit the Bird class, and there should be a separate class for birds that can’t really fly and Ostrich should inherit that.

Interface Segregation Principle

“Clients should not be forced to depend upon interfaces that they do not use.”

Suppose you want to purchase a television and you have two to choose from. One has many switches and buttons, and most of those seem confusing and doesn’t seem necessary to you. Another has a few switches and buttons, which seems familiar and logical to you. Given that both televisions offer roughly the same functionality, which one would we choose?

Obviously the second one with the fewer switches and buttons.

Yes, but why?

Because we don’t need the switches and buttons that seem confusing and unnecessary to us.

Similarly, suppose we have some classes and we expose the functionality of the classes using interfaces so that the outside world can know the available functionality of the classes and the client code can be done against interfaces. Now, if the interfaces are too big and have too many exposed methods, it would seem confusing to the outside world. Also, interfaces with too many methods are less re-usable and such “fat interfaces” with additional useless methods lead to increased coupling between classes.

This also leads to another problem. If a class wants to implement the interface, it has to implement all of the methods, some of which may not be needed by that class at all. So, doing this also introduces unnecessary complexity, and reduces maintainability or robustness in the system.

The Interface Segregation principle ensures that Interfaces are developed so that each of them has their own responsibility and thus they are specific, easily understandable, and re-usable.

E.g.:
Consider IBird Interface which defines behavior like Fly (), Walk (), Chirp (), Eat ().
Note that the IBird interface has many bird behaviours defined along with the Fly () behaviour. Now, if a Bird class (say, Ostrich) implements this interface, it has to implement the Fly () behaviour unnecessarily (Ostrich doesn’t fly).

The “Fat Interface” should be broken down into two different interfaces, IBird and IFlyingBird, where the IFlyingBird inherits IBird.

If there is a bird that can’t fly (say, Ostrich), it would implement the IBird interface. And if there is a bird that can fly (say, KingFisher), it would implement the IFlyingBird interface.

Dependency Inversion Principle

“High level modules should not depend upon low level modules. Rather, both should depend upon abstractions.”

Let’s consider a real world example to understand it. Your car is composed of lots of objects like the engine, the wheels, the air conditioner, and other things.None of these things are rigidly built within a single unit; rather, each of these is “pluggable” so that when the engine or the wheel has problem, you can repair it (without repairing the other things) and you can even replace it.

While replacement, you just have to ensure that the engine/wheel conforms to the car’s design (say, the car would accept any 1500 CC engine and will run on any 18 inch wheel).Also, the car might allow you to put a 2000 CC engine in place of the 1500 CC, given the fact that the manufacturer (say, Toyota) is the same.

In real world, Car is the higher level module/entity, and it depends on the lower level modules/entities like the Engines or Wheels.

Rather than directly depending on the Engines or Wheels, the car depends on the abstraction of some specification of Engine or Wheels so that if any the Engine or Wheel conforms to the abstraction, these could be assembled with the car and the car would run.

Binding static dropdown list with model in mvc3/mvc4 razor

In this tutorial I will show you that how can you bind your static drop down list with you view model.

Above code is placed in view only.
First what I did is that I made list of listitems (Here I have used example of marital status)

After this I have just passed this list to @Html.Dropdownlistfor where model & list are bidden.

Like this you can bind your static list with model.
If model has any default value then it will be selected in drop down & also when we will select any value in drop down then we can get this value from model in controller.

Micromax a116 Canvas HD launched

Micromax has recently launched new mobile Micromax a116 Canvas HD with congiguration:

5-inch (1280 x 720 pixels) HD IPS 16.7 million color display
1.2 GHz quad-core MediaTek MT6589 processor
Android 4.1 (Jelly Bean)
8MP rear camera with LED Flash, VGA front-facing camera
3.5mm audio jack
1GB RAM, 4GB internal memory, 32GB expandable memory with MicroSD
3G, WiFi 802.11 b/g/n, Bluetooth, GPS/A-GPS
2100 mAh battery

You can watch hands on video by IGyaan bellow:

1 2 3 14  Scroll to top