Wednesday, February 3, 2016

Introduction to Python - Course Overview

Webucator.com

In this Python training course, students learn to program in Python. The course is aimed at students new to the language who may or may not have experience with other programming languages.
This Python course is taught using Python 3; however, differences between Python 2 and Python 3 are noted. For private Python classes, our instructor can focus specifically on Python 2 if desired.




Class Goals

  • Learn how Python works and what it's good for.
  • Understand Python's place in the world of programming languages.
  • Learn to work with and manipulate strings in Python.
  • Learn to perform math operations with Python.
  • Learn to work with Python sequences: lists, arrays, dictionaries, and sets.
  • Learn to collect user input and output results.
  • Learn flow control processing in Python.
  • Learn to write to and read from files using Python.
  • Learn to write functions in Python.
  • Learn to handle exceptions in Python.
  • Learn to work with dates and times in Python.

Friday, February 27, 2015

Python: Copy Folder or Files using password (sudo)

Following code can be used to copy Folder or Files using sudo with password.

   def copyFolderOrFile(self, sourcePath, destinationPath):  
     if(os.path.isdir(sourcePath)==True):  
       os.chdir("/some_root_location/")  
       sudoPassword = 'password_of_user_having_sudo_rights'  
       try:  
         command="cp -R "+sourcePath+" "+destinationPath  
         os.system('echo %s|sudo -S %s' % (sudoPassword, command))  
         print "Directory Copied Sucessfully"  
       except OSError as exc:  
         if exc.errno == errno.ENOTDIR:  
           command="cp "+sourcePath+" "+destinationPath  
           os.system('echo %s|sudo -S %s' % (sudoPassword, command))  
           print "File Copied Sucessfully"  
         else:  
           print('Directory/File not copied. Error: %s' % exc)  

More suggestion are always welcome. In case if you wish me to write about any specific scenario, please feel free to write to me or else you can Comment below.

Monday, January 5, 2015

Java: Example of Wait Method in Java

Following is an example to implement Wait Method for predefined seconds in Java. Useful in Selenium, when you don't have control to wait for some element to load in Rich-faces, etc.

 package selenium;  
 import java.util.concurrent.TimeUnit;  
 import org.apache.log4j.Logger;  
 public class WaitMethod  
 {  
   protected void waitForAFewSecond(int timeS)  
   {  
     try  
     {  
       long timeInMS, timeInSec, timeOutMS, timeOutSec;  
       timeInMS = System.currentTimeMillis();  
       timeInSec = TimeUnit.MILLISECONDS.toSeconds(timeInMS);  
       do  
       {  
         timeOutMS = System.currentTimeMillis();  
         timeOutSec = TimeUnit.MILLISECONDS.toSeconds(timeOutMS);  
       }  
       while (timeOutSec - timeInSec < timeS);  
     }  
     catch (Exception e)  
     {  
       System.out.println(e.getMessage());  
     }  
   }  
 }  

Wednesday, November 19, 2014

Python: Find out dates from Last Week.

Following code can be used to findout the Dates of Last week starting from monday
 import time  
 from datetime import date, timedelta  
 def foo(year, week):  
   d = date(year,1,1)  
   d = d - timedelta(d.weekday())  
   dlt = timedelta(days = (week)*7)  
   return d + dlt, d + dlt + timedelta(days=6)  
 todaysDate=time.localtime()  
 weekNumber=time.strftime("%W",todaysDate)  
 yearInTest=time.strftime("%Y",todaysDate)  
 print "Current Week Number is :::" + weekNumber  
 print "Current Year is :::" + yearInTest  
 lastWeeknumber=int(weekNumber)-1  
 print "Last Week Number is :::" + str(lastWeeknumber)  
 yearInTest=int(yearInTest)  
 dateInTest=foo(yearInTest,lastWeeknumber)  
 print str(dateInTest)  

More suggestion are always welcome. In case if you wish me to write about any specific scenario, please feel free to write to me or else you can Comment below.

Wednesday, November 5, 2014

Python: Python Challenge - Level 1 : Proposed Solution

Second problem on "pythonchallenge.com" is an image which displays the offset of alphabets we should apply in the given string below the image. To solve this, I tried the following Solution:

 uRLStringConstant = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."  
 listSet=[]  
 for i in uRLStringConstant:  
      convertedValue = ord(i) +2  
      if convertedValue > 122:  
           convertedValue = 97  
      if convertedValue == 34:  
           convertedValue = 32  
      if convertedValue == 48:  
           convertedValue = 46  
      convertedCharater = chr(convertedValue)  
      listSet.append(convertedCharater)  
 print '[%s]' % ''.join(map(str, listSet))  

Output was:
 :::::OUTPUT::::::  
 Using 'map', we convert it to 'ocr'  
 Hence the URL is http://www.pythonchallenge.com/pc/def/ocr.html  

More suggestion are always welcome. In case if you wish me to write about any specific scenario, please feel free to write to me or else you can Comment below.

Tuesday, November 4, 2014

Python: Python Challenge - Level 0 : Proposed Solution

First problem on "pythonchallenge.com" is an image which displays the number 2^38. To solve this, I tried the following Solution:

 uRLStringConstant = "http://www.pythonchallenge.com/pc/def/"  
 variableComponent = 2**38  
 print '{}{}.html'.format(uRLStringConstant,variableComponent)  

Output was:
 :::::OUTPUT::::::  
 http://www.pythonchallenge.com/pc/def/274877906944.html  
 Redirected To  
 http://www.pythonchallenge.com/pc/def/map.html  

More suggestion are always welcome. In case if you wish me to write about any specific scenario, please feel free to write to me or else you can Comment below.

Friday, October 31, 2014

Python: Check if the string is "Palindrome"

I am trying to demonstrate one or two methods (among many to achieve the stated problem).

First let us try to understand what is Palindrome:

A palindrome is a word, phrase, number, or other sequence of symbols or elements that reads the same forward or reversed, with general allowances for adjustments to punctuation and word dividers.

First Method:
 FirstString="ABCDEFFEDCBA"  
 Reversed=(FirstString [::-1])  
 if list(FirstString) == list(Reversed):  
   print("It is Palindrome")  
 else:  
   print("It is not Palindrome")  


Second Method:
 SecondString="1234ABCCBA4321"  
 def palindrome(num):  
   return num == num[::-1]  
 if palindrome(SecondString) == True:  
   print("It is palindrome")  
 else:  
   print("It is not palindrome")  

You can try to run this code on Codebunk. You can refer to my Codebunk. These are simple code which can be used in complex algorithm.

More suggestion are always welcome. In case if you wish me to write about any specific scenario, please feel free to write to me or else you can Comment below.

Python - Reverse the String

I am trying to demonstrate one or two methods (among many to achieve the stated problem).

First Method:
 FirstString="First String"  
 print (FirstString [::-1])  
Above example is extended slice syntax. It works by doing [begin:end:step] - by leaving begin and end off and specifying a step of -1, it reverses a string.

Second Method:
 SecondString="Second String"  
 def reverse(text):  
   if len(text) <= 1:  
     return text  
   return reverse(text[1:]) + text[0]  
 print(reverse(SecondString))  
You can try to run this code on Codebunk. You can refer to my Codebunk. These are simple code which can be used in complex algorithm.

I am glad to add below video in my blog created by Webucator. This video explains the performance of two methods demonstrated above.


For more details on python training visit, Webucator-Python

More suggestion are always welcome. In case if you wish me to write about any specific scenario, please feel free to write to me or else you can Comment below.

Monday, November 12, 2012

Network Types

A key of network security is "know thy system". You cannot secure something that you do not understand or know how it works. In order to be proficient in network security, you have to understand the different types of networks since each network type poses different challenges, issues and risks. There are many types of networks which are used worldwide these days, both in houses and commercially we will discuss only seven which are most popular. 

LAN - Local Area Networks LAN connects network devices over a relatively short distance i.e. small offices, home, internet cafes etc. LAN uses TCP/IP network protocol for communication between computers. LAN is often but not always implemented as a single IP subnet. Since LAN is operated in short area so It can be control and administrate by single person or organization. • In a "peer-to-peer" network, in which communication is carried out from one computer to another, without a central computer, and where each computer has the same role. • In a "client/server" environment, in which a central computer provides network services to users.

LAN Sample




WAN - Wide Area Networks
As word 'Wide' implies, WAN, wide area network cover large distance for communication between computers. WAN is distributed collection of geographically LANs. A network connecting device router connects LANs to WANs. WANs are an important piece of enterprise networks. WAN used network protocols like ATM, X.25, and Frame Relay for long distance connectivity.
• The most well-known WAN is the Internet.
WAN Sample
 

WLAN - Wireless Local Area Network 
A LAN based on WiFi wireless network technology  Unlike LAN, in WLAN no wires are used, but radio signals are the medium for communication. Wireless network cards are required to be installed in the systems for accessing any wireless network around. Mostly wireless cards connect to wireless routers for communication among computers or accessing WAN, internet.
WLAN Sample

MAN - Metropolitan Area Network
A network spanning a physical area larger than a LAN but smaller than a WAN, such as a city. This kind of network is not mostly used but it has its own importance for some government bodies and organizations on larger scale. MAN, metropolitan area network falls in middle of LAN and WAN, It covers large span of physical area than LAN but smaller than WAN, such as a city
• A MAN is made from switches or routers connected to one another with high-speed links (usually fibre optic cables).
 
MAN Sample

CAN - Campus Area Network
Networking spanning with multiple LANs but smaller than a Metropolitan area network, MAN. This kind of network mostly used in relatively large universities or local business offices and buildings.

CAN Sample
 

SAN - Storage Area Network
SAN technology is used for data storage and it has no use for most of the organization but data oriented organizations. Storage area network connects servers to data storage devices by using Fiber channel technology.  
.
SAN Sample