Saturday 28 July 2018

Find Largest Element of an Array using Function in Python

# Find Largest Element of an Array using Function

# python function to find maximum
# in arr[] of size n
def largest(arr,n):

# Initialize maximum element
max = arr[0]

# Traverse array elements from second
# and compare every element with
# current max
for i in range(1, n):
if arr[i] > max:
max = arr[i]
return max
# Drive Code
arr =[i for i in  range(100)]
   
n = input(" Enter total number of elements(1 to 100):")
n=int(n);

for i in range(n):
    arr[i]=  input(" Enter Number for index {0} ".format(int(i)));


Ans = largest(arr,n)
print ("Largest in given array is",Ans)


   


Thursday 26 July 2018

Swap two variables without using third variable in Python

# Swap two variables without using third variable in Python

a = input(" Please Enter the First Number: ")
b = input(" Please Enter the second number: ")
 
print('First Number {0} Second Number {1} '.format(a, b))

a=float(b)+float(a);
b=float(a)-float(b);
a=float(a)-float(b);   


print('After Swap First Number {0} Second Number {1}'.format(a, b))



Wednesday 25 July 2018

Two Number Sum in Python

# Simple Python program to Add Two Numbers

number1 = input(" Please Enter the First Number: ")
number2 = input(" Please Enter the second number: ")

# Using arithmetic + Operator to add two numbers

sum = float(number1) + float(number2)
print('The sum of {0} and {1} is {2}'.format(number1, number2, sum))



Thursday 12 April 2018

Track your Facebook login attempt


Facebook provides a feature which allows you to see all active sessions from different devices and apps together with the date it was last accessed, from where and which device type. In most cases, that should be enough information to find any suspicious activity.

This also comes in handy if you logged in to your friend's computer or on some public laptop, but forgot to log out.

To know if someone is logged into your Facebook account without your permission:-

Go to your settings page
Under option Security and Login you'll see the link "Where You're Logged In."

You will find all your active Facebook logins from desktop or mobile. It will also provide data on the location, browser and device. If something seems fishy, you also have the ability to "end activity" from individual or all devices. This means that the particular device or app cannot access your account anymore without your password.

Also keep in mind that the logged in location shown in report will not be accurate as some times it will show the gateway location of your internet provider which may be some different location. You can just check the device information from which account is accessed to confirm either it was wrong attempt.

Wednesday 4 April 2018

Convert AM/PM time to 24 hours format C#

C# hh:mm tt (12 Hours to 24 Hours Format) convert


using System.Globalization;

var cultureSource = new CultureInfo("en-US", false);
var cultureDest = new CultureInfo("de-DE", false);
var source = "03:00 PM";

 var dt = DateTime.Parse(source, cultureSource);
  Response.Write(dt.ToString("t", cultureDest));

Thursday 15 March 2018

MVC asp.net Multi Level Menu Bind


Model:


public class M_MenuModel
    {
        #region Variable
        public Int32   MMID { get; set; }
        public string MM_Name { get; set; }
        public string MM_Url { get; set; }
        public Int32 MM_Parent { get; set; }     
        public string MM_Icon { get; set; }       
        #endregion
    }

Controller :

 public ActionResult UserMenuShow()
        {
            ViewBag.Menu = BuildMenu();
            return View();
        }


 private IList<M_MenuModel> BuildMenu()
        {
IList<M_MenuModel> mmList = new List<M_MenuModel>(){
             
                // Parent
                new M_MenuModel(){ MMID = 1, MM_Name = "Home", MM_Parent = 0, MM_Url = "1"} ,
                new M_MenuModel(){ MMID = 2, MM_Name = "Admin", MM_Parent = 0, MM_Url = "1"} ,
                new M_MenuModel(){ MMID = 3, MM_Name = "Accounting", MM_Parent = 0, MM_Url = "1"} ,

                // Children

                new M_MenuModel() { MMID=21, MM_Name = "Create User", MM_Parent = 2, MM_Url="1", MM_Icon="" },
                new M_MenuModel() { MMID=22, MM_Name = "Create Group", MM_Parent = 2, MM_Url="2" },
                new M_MenuModel() { MMID=23, MM_Name = "Create Account", MM_Parent = 2, MM_Url="3"},

                new M_MenuModel() { MMID=31, MM_Name = "Manage Account", MM_Parent = 3, MM_Url="1" },
                new M_MenuModel() { MMID=32, MM_Name = "GL Accounts", MM_Parent = 3, MM_Url="2" },


                new M_MenuModel() { MMID=321, MM_Name = "Salary Accounts", MM_Parent = 32, MM_Url="1" },
                new M_MenuModel() { MMID=322,MM_Name = "Savings Accounts", MM_Parent = 32, MM_Url="2" },

            };

            return mmList;
}


View:



@{
    List<ProjectName.Areas.Admin.Models.M_MenuModel> menuList = ViewBag.Menu;
}


@foreach (var mp in menuList.Where(p => p.MM_Parent == 0))
                {

                    <li>

                        @if (menuList.Count(p => p.MM_Parent == mp.MMID) > 0)
                        {
                            <a href="#@mp.MM_Name" data-toggle="collapse" class="collapsed">@mp.MM_Name <i class="icon-submenu lnr lnr-chevron-left"></i></a>
                            @:<div ID="@mp.MM_Name" class="collapse">
                                @:<ul class="nav">
        }
                        @if (menuList.Count(p => p.MM_Parent == mp.MMID) == 0)
                        {
                            
                            @:<a href="@mp.MM_Url"> @Html.Raw(@mp.MM_Icon) @mp.MM_Name </a>
                        }

                            @RenderMenuItem(menuList, mp)

                        @if(menuList.Count(p => p.MM_Parent == mp.MMID) > 0)
                        {



                    @:</ul>
                        
                    @:</div>
                                            }

                    </li>
                }

@helper RenderMenuItem(List<Manav_Ashraya_V1.Areas.Admin.Models.M_MenuModel> menuList, Manav_Ashraya_V1.Areas.Admin.Models.M_MenuModel mi)
{
foreach (var cp in menuList.Where(p => p.MM_Parent == mi.MMID))
{


        @:<li>








    if (menuList.Count(p => p.MM_Parent == cp.MMID) > 0)
    {

            <a href="#@cp.MM_Name.Replace(' ','_')" data-toggle="collapse" class="collapsed">@cp.MM_Name <i class="icon-submenu lnr lnr-chevron-left"></i></a>

            @:<div ID="@cp.MM_Name.Replace(' ','_')" class="collapse">
                @:<ul class="nav">
        }
        if (menuList.Count(p => p.MM_Parent == cp.MMID) == 0)
        {
            @:<a href="@cp.MM_Url">@cp.MM_Name</a>


        }

        @RenderMenuItem(menuList, cp)
    if (menuList.Count(p => p.MM_Parent == cp.MMID) > 0)
    {
     @:   </ul>

    @:</div>
    }
    else
    {


         
        @:</li>
    }
}
}

Friday 9 March 2018

Update a table using JOIN in SQL Server

  1. UPDATE t1  
  2. SET t1.TID = t2.DOID  
  3. FROM dbo.Table1 AS t1  
  4. INNER JOIN dbo.Table2 AS t2  
  5. ON t1.CommonField = t2.[Common Field] 

Upload valid file in C#

    protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile)     {         try         {             Dictionary<string, byte[]>...