Experience: is what you get soon after you need it.

Experience: is what you get soon after you need it.



My Cloud Certifications:

Certified Kubernetes Administrator (CKA)

Cloud Certified Security Professional (ISC2)

CyberSecurity Certified Professional (ISC2)

AWS Certified Solutions Architect Associate

Azure Certified Architect Expert

Azure Certified Architect

Azure Certified Administrator

Oracle Cloud Infrastructure 2018 Certified Architect Associate.

Oracle Cloud Infrastructure Classic 2018 Certified Architect Associate.

Oracle Database Cloud Administrator Certified Professional.

Oracle Database Cloud Service Operations Certified Associate.

Search This Blog

Thursday, November 19, 2015

Reverse string,words and check for palindrome in Python



cat words.py
####START OF SCRIPT#########
words1 = "test"
ask = "test"

def splitinput():
        global ask
        ask = raw_input("\nEnter few words here:\t")
        global words1
        words1 = ask.split(' ')
        return words1
        return ask

def reverse():
        global words1
        global ask
        j = ''
        for i in range(len(ask)-1,-1,-1):
                j = j + ask[i]
        print "\nPrinting the Reversed string:\t",j

def same():
        global ask
        j = ''
        for i in range(len(ask)):
                j = j + ask[i]
        print "\nPrinting in the same order\t%s" % j

words2 = ''
def reverseword():
        global words1
        global words2
        for i in range(len(words1)-1,-1,-1):
            words2 = words2 + words1[i] + ' '
        print "\nPrinting in the reverse order\t%s" % words2
        return words2

def palindrome():
        global words1
        global words2
        global ask
        for i in range(len(words1)):
                j = words1[i]
                l = ''
                for k in range(len(j)-1,-1,-1):
                        l = l + j[k]
                #print "print j[k]\t%s" % l
                if j == l:
                        print "\nWord """"%s"""" is a palindrome" % l


while True:
        splitinput()
        same()
        reverseword()
        reverse()
        palindrome()
        ask1 = raw_input("\nDo you wanna play again? Type Y|y|YES|yes:\t")
        if ask1 in ['Y', 'y', 'yes', 'YES']:
                print "Okay..Let's do it again"
        else:
                print "\nThanks for playing....Exiting!\n"
                exit(0)
####END OF SCRIPT#########


Output:
=====

shaiks@MAC$py words.py

Enter few words here:    Sameer is good boy and GOOG

Printing in the same order    Sameer is good boy and GOOG

Printing in the reverse order    GOOG and boy good is Sameer

Printing the Reversed string:    GOOG dna yob doog si reemaS

Word GOOG is a palindrome

Do you wanna play again? Type Y|y|YES|yes:    n

Thanks for playing....Exiting!
 

Monday, October 26, 2015

Calculate age in Python


Calculate age:
Takes input a) Future Date(optional) b)Birth Date
Validates for leap year and some basic input validations

 vi age.py
#########START OF SCRIPT#########
from sys import argv
from datetime import datetime,timedelta

oddmonths = [ '01','05','07','08','10','12' ]

def getdata():
     global clockyear
     global clockmonth
     global clockday
     global iyear
     global imonth
     global iday
     global ageyear
     global agemonth
     global ageday
     ask = raw_input("\nDo you want to calc age at a certain date?...Press Y|y|yes:\t")
     if ask == "":
        print "Invalid Response...Exiting"
        exit(1)
     elif ask in ['Y', 'y', 'yes'] :
       get = raw_input("\nPlease enter the from date as yyyy/mm/dd:\t")
       if len(get)< 10:
         print "Invalid Date...Exiting"
       else:
         clock = get.split("/")
         clockyear = int(clock[0])
         clockmonth = int(clock[1])
         clockday = int(clock[2])
     else:
         clock = datetime.now()
         clockyear = clock.year
         clockmonth = clock.month
         clockday = clock.day
    #Assign input variables
     getdetail = raw_input("\nEnter you date of birth as yyyy/mm/dd:\t")
     input = getdetail.split("/")
     iyear = int(input[0])
     imonth = int(input[1])
     iday = int(input[2])
     if iyear > clockyear:
        print "\nCal year cannot be > the birth year..Please Enter valid year\n"
        exit(1)
     #Assign age variables
     ageyear = clockyear - iyear
     agemonth = clockmonth - imonth
     ageday = clockday - iday

getdata()


#Assign age variables
#ageyear = clockyear - iyear
#agemonth = clockmonth - imonth
#ageday = clockday - iday

#print "Your ageyear\t:",ageyear
#print "Your age month\t:",agemonth
#print "Your ageday\t:",ageday

##### Function checks for Leap Year
def leapyear(a):
    if a % 400 == 0:
        return True
    elif a % 100 == 0:
        return False
    elif a % 4 == 0:
        return True
    else:
        return False

#Calc month & year
def month(a,b):
  if imonth < 0 or imonth > 12:
     print "You Entered invalid month...Exiting."
     exit(1)
  elif a < imonth:
      return(12+(a-imonth),b-1)
  elif a > imonth:
        return((a-imonth),b)
  else:
        return(0,b)


def prints(ageyear,agemonth,ageday):
        print "\nYour age is:\t%s Years:\t%s Months:\t%s Days\n" % (ageyear,agemonth,ageday)

def age():
        global imonth
        global iyear
        global iday
        global ageyear
        global agemonth
        global ageday
        global clockmonth
        global clockday
        if iday < 0 or iday > 31:
           print "You Entered invalid day...Exiting."
           exit(1)
        elif clockmonth !=03 and ageday >= 0 and agemonth >  0:
             prints(ageyear,agemonth,ageday)
        elif clockmonth !=03 and ageday >= 0 and agemonth < 0:
             agemonth,ageyear = month(clockmonth,ageyear)
             prints(ageyear,agemonth,ageday)
        elif clockmonth !=03 and ageday < 0 and (clockmonth-1) in oddmonths:
             ageday = 31 + ageday
             agemonth,ageyear = month((clockmonth-1),ageyear)
             prints(ageyear,agemonth,ageday)
        elif clockmonth !=03 and ageday < 0 and (clockmonth-1) not in oddmonths:
             ageday = 30 + ageday
             agemonth,ageyear = month((clockmonth-1),ageyear)
             prints(ageyear,agemonth,ageday)
####Condition for Leap Year check
        elif clockmonth == 03 and leapyear(clockyear):
           if ageday >=0:
             agemonth,ageyear = month((clockmonth),ageyear)
             prints(ageyear,agemonth,ageday)
           elif ageday <0:
             ageday = 29 + ageday
             agemonth,ageyear = month((clockmonth-1),ageyear)
             prints(ageyear,agemonth,ageday)
        elif clockmonth == 03 and not leapyear(clockyear):
           print " I am in 03"
           if ageday >=0:
                    agemonth,ageyear = month((clockmonth),ageyear)
                    prints(ageyear,agemonth,ageday)
           elif ageday <0:
                     ageday = 28 + ageday
                     agemonth,ageyear = month((clockmonth-1),ageyear)
                     prints(ageyear,agemonth,ageday)


def main():
        global imonth
        global iyear
        global iday
        if imonth == 02 and leapyear(iyear) and iday >29:
                print "You cannot have >29 days in Feb of a leapyear:\n"
                print "Enter valid day:\n"
        elif imonth == 02 and not leapyear(iyear) and iday >28:
                print "You cannot have >28 days in Feb,if the year is not a leapyear:\n"
                print "Enter valid day:\n"
        else:
                age()

main()

#########END OF SCRIPT#########


Output-1:
############
shaiks@MAC$py age.py

Do you want to calc age at a certain date?...Press Y|y|yes:    y

Please enter the from date as yyyy/mm/dd:    2017/08/31

Enter you date of birth as yyyy/mm/dd:    2000/02/29

Your age is:    17 Years:    6 Months:    2 Days


Output-2:
############
shaiks@MAC$py age.py

Do you want to calc age at a certain date?...Press Y|y|yes:    n

Enter you date of birth as yyyy/mm/dd:    2000/02/29

Your age is:    15 Years:    7 Months:    27 Days


Error Handling:
###############
shaiks@MAC$py age.py


Do you want to calc age at a certain date?...Press Y|y|yes:    y

Please enter the from date as yyyy/mm/dd:    2017/08/31

Enter you date of birth as yyyy/mm/dd:    2000/02/31
You cannot have >29 days in Feb of a leapyear:

Enter valid day:

Friday, October 23, 2015

Python using functions & argv

Python using functions & argv
Below code takes filenames as input min 2 max -unlimited, verifies if the input files exists on the OS:$PWD or not if exists it will read the file and displays the contents if the file doesn't exists it just skips it.


shaiks@MAC$vi funcs.py
from sys import argv
from os.path import exists

#print argv
#print len(argv)
#print range(len(argv))

def check_input():
 if len(argv) < 2:
        print "Need two variables\t"
        exit(1)
 else:
#       print "Your first file is\t",argv[1]
        return(argv[1])

##Opens file and prints the contents
def files(a):
  if a == argv [0]:
        print "Not reading my own file"
  else:
        read = open(a,'r+')
        print "File contents of file:\t%s\tare%s\n" % (a,read.read())

def check_file():
        for i in range(len(argv)):
#         print "%s" % argv[i]
          if exists(argv[i]):
               print "Input file verified\t",argv[i]
               files(argv[i])
          else:
               print "Input file doesn't exists:\t",argv[i]
#              exit(1)


check_input()
check_file()


shaiks@MAC$ls -lrt *.out
-rw-r--r--  1 shaiksameer  5000  162 Oct 19 16:35 ps.out
-rw-r--r--  1 shaiksameer  5000  162 Oct 19 16:42 ls.out


shaiks@MAC$py funcs.py a.out ps.out ls.out
Input file verified    funcs.py
Not reading my own file
Input file doesn't exists:    a.out
Input file verified    ps.out
File contents of file:    ps.out    are
Write these new lines into the ls file

line3 left blank



Input file verified    ls.out
File contents of file:    ls.out    are
I am ls.out and I have only one line

Monday, October 19, 2015

Copying contents from one file into another using python:

Copying contents from one file into another using python:

shaiks@MAC$vi 8files.py

from sys import argv
from os.path import exists


script, old, new =argv

while True:
        if exists(new):
           print "file already exists\t",new
           if (raw_input("Continue with wipe out: y|n:\t")) == 'Y':
                new1=(new,'w')
                break
           else:
                print "You entered No.....appending data to the %s file\t" % new
                #exit(1)
                new1=open(new,'a')
           break
        else:
         print "Creating new file....%s\t:" % new
         new1=open(new,'w')
         break

old1 = open(old).read()
print "Old file contents are%s\n" % old1

#new1.close()
print "Appenind data to the file\t",new
new1 =  new.write(old1)

print "Closing files that were opened..."
#old.close()
#new.close()


#Contents of ps.out
shaiks@MAC$cat ps.out

Write these new lins into the ls file

line3 left blank
Write these new lins into the ls file
Write these new lins into the ls file
line below me left blank


#Contents of ls.out
shaiks@MAC$cat ls.out

I already have this line in this file

##Executing the  script

shaiks@MAC$python 8files.py ps.out ls.out
file already exists    ls.out
Continue with wipe out: y|n:    n
You entered No.....appending data to the ls.out file   
Old file contents are
Write these new lins into the ls file

line3 left blank
Write these new lins into the ls file
Write these new lins into the ls file
line below me left blank



Appending data to the file    ls.out
Closing files that were opened...

shaiks@MAC$cat ls.out

I already have this line in this file

Write these new lins into the ls file

line3 left blank
Write these new lins into the ls file
Write these new lins into the ls file
line below me left blank

 

Thursday, October 15, 2015

Use partitioned indexes



SHAIKDB>create table part1 (i int,j int ,k int,l number,
      constraint iunique unique(i),
      constraint junique unique(j))
     partition by range(i)
    ( partition p1 values less than (10),
    partition p2 values less than (100),
    partition p3 values less than (10000));  

Table created.


SHAIKDB>begin
 2  for i in 1..1000 loop
 3  insert into part1 values (i,i,1,0);
 4  commit;
 5  end loop;
 6  end;
 7  /

PL/SQL procedure successfully completed.


SHAIKDB>select count(*) from part1 partition (p1);

 COUNT(*)
----------
    9

SHAIKDB>select count(*) from part1 partition (p2);

 COUNT(*)
----------
   90

SHAIKDB>select count(*) from part1 partition (p3);

 COUNT(*)
----------
      901


create table part2 (a int not null,b int,c number, constraint afkey foreign key(a) references part1(i))
    partition by reference(afkey);

Table created.

create table part3 (x int,y number,z number not null,constraint zfkey foreign key(z) references part1(j))
       partition by reference (zfkey);

Table created
SHAIKDB>select table_name,partition_name,high_value from dba_tab_partitions where table_name like 'PART_';

TABLE_NAME PARTITION_NAME         HIGH_VALUE
---------- ------------------------------ ----------
PART1       P1                 10
PART1       P2                 100
PART1       P3                 10000
PART2       P1
PART2       P2
PART2       P3
PART3       P1
PART3       P2
PART3       P3


.SHAIKDB>begin
    for i in 1..1000 loop
    insert into part2 values(i,i,i);
    commit;
    end loop;
    end;
    /  2    3    4    5    6    7  

PL/SQL procedure successfully completed.

SHAIKDB>begin
    for i in 1..1000 loop
    insert into part3 values(i,i,i);
    commit;
    end loop;
    end;
    /  2    3    4    5    6    7  

PL/SQL procedure successfully completed.

select table_name,partition_name,high_value from dba_tab_partitions where table_name like 'PART_';

TABLE_NAME PARTITION_NAME         HIGH_VALUE
---------- ------------------------------ ----------
PART1       P1                 10
PART1       P2                 100
PART1       P3                 10000
PART2       P1
PART2       P2
PART2       P3
PART3       P1
PART3       P2
PART3       P3

9 rows selected



SHAIKDB>create index part1idx on part1(k);

Index created.


.