Tuesday, 26 December 2017

How to swap div(or any jquery selector) element using jquery ID selector


$(function() {

  //var getCountryPath = window.location.host.split(".")[0];
  var getCountryPath="qa"
  console.log(getCountryPath);
  console.log("mahesh");
  console.log("path is ",getCountryPath);

  //qtr  oman  uae   india
  if(getCountryPath == "qa")
  {
// if your fist div is qa then no need to swap it by default come first , please change the code according to your requirement. 
  }

  if(getCountryPath == "in")
  {
    var india = $("#india").html();
    var qtr = $("#qtr").html();
    $("#qtr").html(india);
    $("#india").html(qtr);
  }

  if(getCountryPath == "om")
  {
    var oman = $("#oman").html();
        var qtr = $("#qtr").html();
    $("#qtr").html(oman);
        $("#oman").html(qtr);
  }

  if(getCountryPath == "uae")
  {
    var uae = $("#uae").html();
        var qtr = $("#qtr").html();
    $("#qtr").html(uae);
        $("#uae").html(qtr);
  }
});

How to change menu or tabs dynamic bases on URL

$(document).ready(function(){
  console.log("test1")
// following commented line take running url or (active)site name but i set  hard coded   for demo
  //var getCountryPath = window.location.host.split(".")[0];
  var getCountryPath="om";
  if(getCountryPath == "in"){
   
      $("li").removeClass("active");
      $("li > a[href='#india']").parent().addClass("active");
      $("#india").addClass("active");
    }
    if(getCountryPath == "qa"){
      $("li").removeClass("active");
      $("li > a[href='#qatar']").parent().addClass("active");
      $("#qatar").addClass("active");
    }
    if(getCountryPath == "om"){
      $("li").removeClass("active");
      $("li > a[href='#oman']").parent().addClass("active");
      $("#oman").addClass("active");
    }
    if(getCountryPath == "uae"){
      $("li").removeClass("active");
      $("li > a[href='#uae']").parent().addClass("active");
      $("#uae").addClass("active");
    }
    var hide = function (elem) {
    elem.classList.remove('is-visible');
};
});

Sunday, 24 December 2017

Diffrance bitween == to and === in javascript

Example :

            var a= 99; // variable a assigned the integer value .
            var b="99"; // variable b assigned the string value .
            if(a==b)

                {
                console.log(" using == to : True");
                }
            else

                {
                console.log(" using == to : False");
                }
            if(a===b)
            {
                console.log(" using === to : True")
            }
            else

             {
                console.log(" using === to : False");
            }

    // == is just check value 
    // === is check value and its data type
   
 o/p : 
using == to : True
using === to : False


Friday, 22 December 2017

Zen of Python (Every developer should be know this)

just write

import this
o/p (it is nothing but Principles Software developer)

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one—and preferably only one—obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.[5]
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea—let's do more of those!

Thursday, 21 December 2017

MariaDb connectivity using python

For create table through python program

#!/usr/bin/python
import MySQLdb
db=MySQLdb.Connect("localhost","root","root","Education")
cursor=db.cursor()
sql="CREATE TABLE Student(First_Name varchar(30),Last_Name varchar(30),Age int(20),Gender varchar(30),Email varchar(50),Languages Varchar(100),Contact_Number int(20),Department varchar(30),Year varchar(20))"
cursor.execute(sql)
db.close()

For Insert data into table though python 

#!/usr/bin/python
import MySQLdb
db=MySQLdb.Connect("localhost","root","root","Education")
cursor=db.cursor()
sql="""INSERT INTO Student(First_Name,Last_Name,Age,Gender,Email,Languages,Contact_Number,Department,Year) VALUES("Mohan","patil",28,"Male","mohan@gmail.com","Hindi",7875,"Mech","2nd");"""
try:
cursor.execute(sql)
db.commit()
except :
db.rollback()
db.close()


For Show  database 

#!/usr/bin/python
import MySQLdb
db=MySQLdb.Connect("localhost","root","root","Education")
cursor=db.cursor()
cursor.execute("SHOW TABLES")
data=cursor.fetchall()
for row in data:
dbname = row[0]
print "db name is =%s"%dbname
db.close()

For retrieve data from Mysql or maraidb

#!/usr/bin/python

import MySQLdb

db = MySQLdb.connect("localhost","root","root","Education" )
print "db connect success"
cursor = db.cursor()
print "cursor success"

sql = "SELECT * FROM Address"
print "sql success"
try:
   cursor.execute(sql)
   # Fetch all the rows in a list of lists.
   results = cursor.fetchall()
   for row in results:
      fname = row[0]
      lname = row[1]
      email = row[2]
      mobileno = row[3]
      uname = row[4]
      password = row[5]
      # Now print fetched result
      print "fname=%s,lname=%s,email=%s,mobileno=%s,uname=%s,password=%s" % \
             (fname, lname, email, mobileno, uname,password )
except:
   print "Error: unable to fecth data"

# disconnect from server
db.close() 

Tuesday, 19 December 2017

Mariadb connectivity using java i.e. jdbc

package com;

import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DbConnection {
public static Connection conn = null;

public static Connection getConnection() throws ClassNotFoundException, SQLException {
try{
Class.forName("org.mariadb.jdbc.Driver");
         System.out.println("Connecting to a selected database...");
         conn  = DriverManager.getConnection("jdbc:mariadb://localhost:3306/Eduction","root","root");
         System.out.println("Connected database successfully...");
         System.out.println(conn);
}catch(Exception e){
System.out.print(e);
}
return conn;

}

}

Saturday, 16 December 2017

Find n'th highast salary in mysql

select salary from employee ORDER BY salary DESC limit 1,1; or
select salary from employee ORDER BY salary DESC limit 1,n'th;

fist 1 is skip row and second 1 is how many result you want, if you want top 5 then just use 0,5.

Django rest api - filter

views.py from django_filters.rest_framework import DjangoFilterBackend class PollList(viewsets.ModelViewSet):     queryset = X.objects...