Wednesday, 25 May 2016

Learn Python the easy way - 4. String Operators

Input function

  The input function is used to gather input from user. It's mainly useful in actual programming world. This input function prompts the user for input and returns what they entered.

>>>input("What is your favorite programming language:")
What is your favorite programming language: Python

'Python'

Concatenation

Concatenation is nothing but an addition of two or more strings. This can be done by adding mathematical operators in between the strings.

>>>"Hello"+"World"
'HelloWorld'

As you can see, it adds two strings. You can use single quotes or double quotes, both will works. 
In this concatenation, If your string contains numbers it takes as string and not as an integer.

For example,

>>>"43" + "4" + "1"
'4341'

You can also multiply strings by using integers.

>>>print("Hello" * 4)
HelloHelloHelloHello
   

Type Conversion

The problem is getting input from user is probably as in the form of strings. In order to make it as an integer, we use the concept of type conversion.
For an example, take the following code;

>>>int(input("Enter a number:")) * int(input("Enter another number:")) 
Enter a number: 3
Enter another number: 2
6

Tuesday, 17 May 2016

Fedora 24 Graphical Upgrade Test Day - Red Hat, Bangalore

I got my first exposure to the Fedora community and open source contribution. It was an exciting event held on the 16th of May 2016 at Red Hat, Bangalore. In total, there were four people attending the event in person. Many others attended the event through Hangout &IRC. Sumantro (QA Intern), Karthik (Storage Intern) , two new open source enthusiasts (Vipul Siddharth and Prakash Mishra) and I attended the event at the Red Hat office in Bangalore.

Vipul Siddharth and Prakash Mishra had come from Christ University, Bangalore. They have a keen interest in contributing to open source technologies. Sumantro deserves a special mention. He mentored the new comers and also took us through the entire Red Hat enterprise workflow operations.







The Fedora Graphical Upgrade procedure is here. We were able to make the Fedora Graphical Upgrade test day a success. One great news is that the new comers got a part-time internship opportunity at Red Hat. Congrats Vipul Siddharth and Prakash Mishra! :)

In this event, Each and every one exposure their workflow in Red Hat. I had an opportunity to know the operations of other teams like the storage team and the quality testing team. This event also helped us to group together quality assurance (Sumantro), storage (Karthik) and infrastructure (Me) :) and share our point of views with each other.



We published the result on the Fedora test results page. The link for Fedora test results page is here. In upcoming days, we plan to work on the Fedora release validation testing project. 

Finally I want to say thanks to Sudhir Dharanendraiah (QA Manager). He is organised the Fedora Graphical Upgrade Test Day very well and also helped us a lot.

Monday, 16 May 2016

Learn python the easy way - 3. Strings

String is nothing but an text. The plain text is called as string in programming. It can be done by adding two single or double quotation marks between the text.

>>>"Python is easy!"
'Python is easy'

In string, some characters are cannot be included directly. Because each character in Python has represent something. In order to print that characters as a string, we use escaping character (back slash) \.

for an example

>>>"Hello "How are you"?"
  File "<stdin>", line 1
    Hello "How are you"?"
                      ^
SyntaxError: invalid syntax

To avoid this, add back slash before the character

>>>"Hello, \"How are you\"?"
'Hello,  "How are you"?

New Lines

Add \n to get a new line.

>>>print("Hello \nPython!")
Hello
Python!


Learn Python the easy way - 2. Simple operations

We can use mathematical operations in Python. Enter a calculation directly into Python console, and it will display the answer.

>>>5 + 2
7

>>>6 * 4
24

>>>4 + 1 - 3
2

Note: There is a space should be there in between the operator. It should work with out operator, but it makes easy to read. (operator -> +, - , / and etc; operand -> values such as 3, 4, 7)

Floats

Floats are used in Python to represent numbers that are not integers. There is a dot would be there in float. Example 3.45, 45.4. When you divide something in Python it will give you an floating value.

>>>3 / 4
0.75

>>>8 / 2
4.0

Exponentiation

We can also manipulate exponentiation in Python. It is the raising of one number to the power of another number.

>>2 ** 3
8

These two asterisks equal to ^ (The power symbol).

Quotient and reminder

To determine the quotient

>>>50 // 3
16

To determine the remainder

>>>10 % 4
2

Example (try to solve your self)

>>>78 % (6 // 4)


Learn Python the easy way - 1. Introduction to Python

In this tutorial i will cover the Python language tutorials.

What is Python?

   Python is a high level programming language. which is used in numerous areas like web programming, automating tasks, scripting and artificial intelligence. It is very popular language. It is used in Google, NASA and many organizations.

   Python is processed by runtime by the interpreter. Interpreter is a program that runs scripts written in an interpreted language. There are 3 major versions are available in Python. That is 1.x, 2.x and 3.x. This tutorial i will cover latest version of Python 3.

Installing Python
   
     You can get the Python program from this link. Installation procedure is same as other programs installations.

The Python Console 

     Open your python program, to do this 
     In Linux -> Go terminal -> python3
     In Windows -> Simply get it from the start menu.

First Program

   >>>print('Hello Python!')
Hello Python!

We written our first program :). To exit the python console 
   >>>quit()


Thursday, 27 August 2015

Lock any application in Linux

Some times we need to lock some applications for security purposes. In this article we will learn how to lock any application in Linux (It is support for both Debian and Redhat based systems)

Our Objective

     We are using .desktop file to lock any application in Linux. All applications has it's own .desktop file. Commonly, .desktop file is used to define various performance of application, when it run in X based system (Commonly GUI). We can modify application's performance via it's .desktop file. .desktop file is also called as configuration file for an application.

Where .desktop file is located?

  All apllications .desktop file is located in /usr/share/applications directory.

 What we need?

  1. Terminal
  2. Any text editor

How to do?

  • Open your terminal window, then go to /usr/share/applications directory.
     cd /usr/share/applications  
    
  •   I have following applications .desktop files. You can view it by typing ls command

/usr/share/applications









  • For an example, i want to lock firefox applications. So that the application will can ask password (root passord), whenever it launced.
  •  Open firefox.desktop file via any text editor. Where now am using nano text editor
     sudo nano /usr/share/applicatios/firefox.desktop  
       Find Exec=firefox and change it in to Exec=gksudo -k -u root firefox %u. Now save and exit. 
      Now launch firefox, it will ask password to run the application. 

    Thursday, 6 August 2015

    Understanding man pages


    Man pages are stands for manual pages. In Linux, all types of tools have it's own manual page. Manual pages are commonly contains informations and instructions about a command. man pages are very useful for learning commands in Linux.
    Even if we forget the commands, that time also man pages are helpful to remember. To get detailed information about man pages in Linux, then type following commands

    To know respective commands with our needs, then type following command in terminal 
     man -k keyword  
    

    For an example  
     man -k time  
    

    where, -k stands for keyword. the above command lists many commands with numbers. This number is refer to section of man pages command. Each section of man describes different kind of commands. You can get an over view of man pages by typing following command
     man man-pages  
    

    It gives look like following result


    In section 1 commands are described for ordinary users.
    In section 5 documents are document configuration files.
    In section 8 describes management commands.
    When we are using man pages, grep is an very useful utility. grep is the most important command in Linux. It is a filtering utility whcih is allows to search resolves of a command in a specific time. You can also use to find a text in text files. Let we use grep in man pages 
     man -k time | grep 1  
    
     If a commands separates by pipe means the output of the first command is goes to the input of the second command.
    The above command is gives following result
     
    Now we can easily identify the command 'date' to know date of the system.
    So now let as see the man page of date command 
     man date  
    

    For this command we will get following result

     
    The synopsis is very clearly shows how to use the date command.

    Let we see some useful options
    Look at -s which is describes "set time described by STRING". So we need to set the time. Now our dought is what a STRING?
    To get the detail about STRING type /STRING in the same man page. Now you will get look like following information about the STRING 
     
    when we are typing date -s with time. We will get human readable format. Now we are learned how to find a command using man -k.
    There is another way to get information about an command  
     date --help  
    


    Hope you understand!