May 29, 2017

How to split up the Terminal on MAC?

Here is a quick tip to split the Mac - terminal horizontally to facilitate the switch between edit and execution in no time.

GNU Screen (screen from terminal) lets you do that on Mac

• Launch Terminal
• Type screen from Terminal
• Split Screen Horizontally: Press ctrl+a then release everything then press shift+s splits the screen
• Switch to other split: ctrl+a then Tab switches to the other split
• Create bash prompt in new split: ctrl+a then c creates a bash prompt; type exit to come out of command prompt.
• Un-split: ctrl + a then d to un-split the terminal

Note:
  1. Unlike Linux, the GNU Screen on MAC, lets you split the terminal only horizontally but not vertically. The above steps have been verified in OS X version 10.11.6
  2. Caveat: ctrl + a does not take the cursor to the beginning of the bash prompt in split window, as it is expecting for next command (either Tab or c )

iTerm for macOSX
Alternatively you may also download iTerm for macOS from here, which helps to split both vertically and horizontally
Use cmd + d for vertical split and cmd + shift + d for horizontal split
To navigate between the vertical splits in left/right or up/down fashion use cmd + [ / cmd + ]
iTerm 2 because of these features.

April 19, 2017

Python script for file handling - Read & Write

# Basic File Handling in Python - Read & Write
# coding: utf-8 # for Non-ASCII character support

# Writing to a file
f = open("<file path>/file_read_write.txt", "w");
f.write("Name                    Age                  \n")
f.write("-----------------------------------------\n")

mystring = "%s                   (%d) \n" % ("Ram", 32)
f.write(mystring)

f.close() 

# Reading from a file
f = open("<file path>/file_read_write.txt", "r") 
print f.read() 

f.close()

Note:
you may also try the following commands for selective read(s)
    print f.read(4)
    print f.readline()
    print f.readline(3)

April 6, 2017

How to validate an email address using Python Script?

Code snippet to validate the email id taken as an input via command line

# Python script to validate input email address
# for system input
import sys
print(sys.argv)

# for regular expression
import re
print "\n" 

email_id = raw_input("Please enter your email id: ")
if re.match("[^@]+@[^@]+\.[^@]+", email_id):
print "Hurray! you have entered a valid email id: ", email_id
else:
print "Better luck next time with a valid email id"

March 15, 2017

How to upload files to S3 using Python Boto3?

The below script gives you a quick example of uploading a specific file to the S3 bucket, provided the IAM user calling the API has the s3:GetObject permissions on the S3 bucket.

# Boto3 script to upload a file to S3
import boto3
session = boto3.Session(profile_name='<profilename>') #ensure to use appropriate  profile
s3_client = session.client('s3')

print "Upload the your test file to S3"
s3_client.upload_file('<file path>/<file name with extension>', '<s3 bucket name>', '<prefixfolder/filename with extension>)

print "Success! Upload complete"
print "Getting list"
files=s3_client.list_objects(Bucket='<s3 bucket name>', Prefix='<prefixfolder/filename with extension>')['Contents']

for key in files:

   print key

December 27, 2016

Guest Lecture on `Industry Awareness` @ BIT Sathy

It is the time of the year again to visit my Alma Mater to address the highly energetic and enthusiastic final year Engineering students from Computer Science department upon the invite from our revered head of the department, Dr. Thangaraj.

The lecture was on Industry Awareness covering 3 major aspects to prepare the budding engineers for the onward journey when they set their foot loose from the compassionate college life to the competitive corporate world.

1. What does the Industry Expect from the emerging Engineers?
2. The other side of the coin for the Engineers. 
3. When do you quench your Entrepreneurial thirst? 

Followed by much involved students interaction and all is to inspire our juniors to dream more, to learn more and to do more in-turn to the society.


Guest Lecture @ BIT Sathy

Refer the link to certificate of appreciation  from the college for the Guest Lecture.