Thursday, June 13, 2019

Sample program to create custom SVG Marker with Label for Google Map Api

Here is a sample program to create custom SVG Marker for Google Map Api. The marker will look like shown in the below image. You can change the color of the marker by passing the color as the parameter for the pinSymbol function.
HTML :
<div id="map_canvas" style="height: 400px; width: 100%;">
CSS :
html, body, #map_canvas {
    height: 500px;
    width: 500px;
    margin: 0px;
    padding: 0px
}
JAVASCRIPT :
function initializeMap() {
 var center = new google.maps.LatLng(30.5, -98.35);;
  var markerLatLng = new google.maps.LatLng(30.5, -98.35);

    var map = new google.maps.Map(document.getElementById('map_canvas'), {
        zoom: 12,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var marker = new google.maps.Marker({
        position: markerLatLng,
        map: map,
        draggable: true,
        raiseOnDrag: true,
        label: { text: 'WXYZ', color: '#fff', fontSize: '12px' },
        icon: pinSymbol('green')
    });
}

function pinSymbol(color) {
    return {
        path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z',
        fillColor: color,
        fillOpacity: 1,
        strokeColor: '#000',
        strokeWeight: 2,
        scale: 2,
        labelOrigin: new google.maps.Point(0, -30)
    };
}
OUTPUT IMAGE :

Sample C# program to find the Permutation of a given string

The below C# program is used to print all the possible way to arrange the characters in the given string. Also known as Permutation.

Program :
using System;
public class Permutation
{
    public void Permute(string inputString, int startIndex, int endIndex)
    {
        if (startIndex == endIndex)
            Console.WriteLine(inputString);
        else
        {
            for (int i = startIndex; i <= endIndex; i++)
            {
                inputString = Swap(inputString, startIndex, i);
                Permute(inputString, startIndex + 1, endIndex);
                inputString = Swap(inputString, startIndex, i);
            }
        }
    }

    private string Swap(string a, int i, int j)
    {
        char temp;
        char[] arr = a.ToCharArray();
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;

        return new string(arr);
    }
}

class Program
{
    static void Main(string[] args)
    {
        string inputString = "ABC";
        Permutation p = new Permutation();
        p.Permute(inputString, 0, inputString.Length - 1);

        Console.ReadLine();
    }
}


Output :

ABC
ACB
BAC
BCA
CBA
CAB

Wednesday, June 5, 2019

Add or ignore where conditions in SQL Server query based on a flag

Assume you want to select data from SQL Server based on a condition. But the condition should be considered only if another condition satisfies else it should return all data. How would you do that. Here is a sample program to achieve the solution.

declare @flagAll = 1;

Select *
from Students S
where @flagAll = 1
or S.Department = 'CSE'
In this example if the @flagAll is set to 1, then the first condition will be satisfied so the second condition will not be executed as it is OR condition, so all data will be returned. Else if @flagAll = 0 then the first condition will be failed, as it is OR condition the second condition S.Department = 'CSE' will be considered and all CSE department Student data will be returned.

If you have alternate solution, Kindly post as comment.