Difference between revisions of "CSC212 Lab 1 2014"
(→Part 2: Secure Shell, Login in to Beowulf2) |
(→Using a Shell/Terminal) |
||
Line 147: | Line 147: | ||
</tanbox> | </tanbox> | ||
<br /> | <br /> | ||
− | ==Using a Shell | + | ==Using a Shell or Terminal== |
<br /> | <br /> | ||
There are 3 different ways for you to connect to our server: | There are 3 different ways for you to connect to our server: | ||
Line 154: | Line 154: | ||
* From a Windows laptop. | * From a Windows laptop. | ||
<br /> | <br /> | ||
− | + | Whatever computer you have, it is good for a computer science to be familiar with more than one way to connect to remote computers. Try to use different methods during the semester. | |
<br /> | <br /> | ||
===Windows PC needs additional software=== | ===Windows PC needs additional software=== |
Revision as of 13:47, 3 September 2014
--D. Thiebaut (talk) 09:37, 3 September 2014 (EDT)
Contents
This is the first Lab for CSC212, and there are many different little details that you need to get familiar with. In this lab you will
- review some Python (just to make sure you remember the logic of programming)
- learn how to connect to your class account on beowulf2
- learn how to use the emacs editor
- create simple Java programs.
Part 1: Python Review
The problem below is taken from CSC111, Homework 10 given Spring 2014. Work out a solution in pair or individually. There is nothing to submit for this part.
Lost Cat
(image from nicepixy.net)
The program below is missing its class! And it is also missing its documentation! It used to contain a class defined, with methods and member variables, and a fully developed documentation, but unfortunately all of them got erased.
We do have the output of a run of the program, though, when it still had its class definition. Both the incomplete code and the output are shown below.
#
# missing class goes here...
#
def getNewCat():
print( "\nPlease enter the information for the new cat:")
name = input( "Cat name? " )
age = int( input( "Age, in years? " ) )
vac = input( "Vaccinated (Y/N)? " ).strip().lower()
vac = vac in ['y', 'yes']
neut = input( "Neutered (Y/N)? " ).strip().lower()
neut = neut in ['y', 'yes' ]
breed= input( "Breed? " ).strip()
return Cat( name, age, vac, neut, breed )
def display( L, caption ):
print( "\n\n"+caption )
print( "=" * len( caption ) )
for cat in L:
print( cat )
def main():
text="""Minou, 3, Yes, Yes, stray
Max, 1, Yes, No, Burmese
Gizmo, 2, No, No, Bengal
Garfield, 4, Yes, Yes, Orange Tabby"""
for line in text.split( "\n" ):
words = line.strip().split( "," )
if len( words ) != 5:
continue
name, age, vaccinated, neutered, breed = words
age = int( age.strip() )
if vaccinated.strip().lower() == "yes":
vaccinated = True
else:
vaccinated = False
neutered = neutered.strip().lower() == "yes"
cat = Cat( name.strip(), age, vaccinated, neutered, breed.strip() )
try:
cats.append( cat )
except NameError:
cats = []
cats.append( cat )
display( cats, "List of cats:" )
cats.append( getNewCat() )
display( cats, "List of cats with new addition:" )
vaccinatedNeuteredCats = []
for cat in cats:
if cat.isVaccinated() and cat.isNeutered():
vaccinatedNeuteredCats.append( cat )
display( vaccinatedNeuteredCats, "Vaccinated and neutered cats:" )
main()
Output
List of cats:
=============
Cat: Minou, age: 3, vaccinated, neutered (stray)
Cat: Max, age: 1, vaccinated, not neutered (Burmese)
Cat: Gizmo, age: 2, not vaccinated, not neutered (Bengal)
Cat: Garfield, age: 4, vaccinated, neutered (Orange Tabby)
Please enter the information for the new cat:
Cat name? Ralph
Age, in years? 4
Vaccinated (Y/N)? y
Neutered (Y/N)? y
Breed? Angora
List of cats with new addition:
===============================
Cat: Minou, age: 3, vaccinated, neutered (stray)
Cat: Max, age: 1, vaccinated, not neutered (Burmese)
Cat: Gizmo, age: 2, not vaccinated, not neutered (Bengal)
Cat: Garfield, age: 4, vaccinated, neutered (Orange Tabby)
Cat: Ralph, age: 4, vaccinated, neutered (Angora)
Vaccinated and neutered cats:
=============================
Cat: Minou, age: 3, vaccinated, neutered (stray)
Cat: Garfield, age: 4, vaccinated, neutered (Orange Tabby)
Cat: Ralph, age: 4, vaccinated, neutered (Angora)
- Question
Recreate the original Python program with its Cat class. Make sure that it will generate the same output shown above if fed the same cat information.
Solution
- Solution (will be released later)
Part 2: Connection to a Remote Computer Server: Beowulf2
In this section you will learn how to connect to a remote computer and work on it using the shell, or Terminal. The server for the CS department is called beowulf2. Its address is beowulf2.csc.smith.edu.
Using a Shell or Terminal
There are 3 different ways for you to connect to our server:
- From a Linux computer in FH342
- From a Mac laptop
- From a Windows laptop.
Whatever computer you have, it is good for a computer science to be familiar with more than one way to connect to remote computers. Try to use different methods during the semester.
Windows PC needs additional software
If you're using a Windows PC, go to https://www.smith.edu/smithsoftware/index.html and download the SSH package after having read the installation instructions.
Connection From a Linux Computer
To login refers to the action of connecting to the computer as a user. To connect to Beowulf2, the computer used for Computer Science classes, one must have an account and a password. Logout is the term used when you are finished with the computer and want to terminate your session.
You should have a Unix account form at this point, and have found on it
- your account name (of the form 212a-xx, where xx are two letters, different for everybody),
- and your password.
If the Quick Connect window is not greeting you, click on the Quick Connect icon to get it:
Enter beowulf.csc as the host name, 212a-xx as your user name (change the xx to reflect your 2-letter Id) Click on the Connect button Enter your password. and click "Connect".
If everything went well, you should see this:
SSH Secure Shell 3.1.0 (Build 235) Copyright (c) 2000-2001 SSH Communications Security Corp - http://www.ssh.com/ This copy of SSH Secure Shell is a non-commercial version. This version does not include PKI and PKCS #11 functionality. [212a-xx@beowulf ~]$
Keep your account and password information in a safe place, or learn both by heart! You will need them every time you need to use your account and work on your homework assignment or lab.
You may want to log out now, to practice this login procedure a couple times. If you are working with a lab partner, it is a good time to log out and let her/him try the procedure.
To logout of the session with beowulf, simply type exit at the Linux prompt:
[212a-xx@beowulf ~]$ exit
Don't hesitate to call on the TA or your instructor if you need help.
Part 3: Playing with emacs
In order for you not to suffer from a misbehaving backspace/delete key as happened in class yesterday, you should execute the following command (your input is in bold face)
[111c-xx@beowulf ~]$ getcopy .emacs cp: overwrite `./.emacs'? y
(That is "getcopy" space period "emacs") It's a configuration file that will allow emacs to understand the backspace key correctly. You only need to do this once and you will be set for the semester.
You will now get a copy of a file from your instructor's account, and edit it. The file is called Fulghum and is a short story from Robert Fulghum's book All I really need to know I learned in Kindergarten.
To get a copy of this file, type
[111c-xx@beowulf ~]$ getcopy fulghum
followed by the return key. Then edit the file with the command
[111c-xx@beowulf ~]$ emacs fulghum
Simply work on the first paragraph of the file, and try to straighten it up. I have indicated below, on the right-hand side, which emacs commands you can use to fix the text on your screen.
When you are done with the modification, or if you want to stop for right now and save your modifications, type C-x C-c, and press y when emacs asks if you want to save the file. Below is a summary of some useful emacs commands.
You should find some time this week to go to a lab and read the Emacs at Smith handout while in front of the terminal, on your own. This is the best way to test and learn the different features of the editor!
DEL/Shift Backspace | Delete previous character |
c-d | Delete character at cursor |
Esc-d | Delete word |
c-k | Kill line |
c-a | Go to beginning of line |
c-e | Go to end of line |
c-f | Move cursor 1 character forward |
c-b | Move cursor 1 character backward |
c-p | Move to previous line |
c-n | Move to next line |
c-x c-c | quit emacs and save file |
c-x c-s | save file but remain in emacs |
c-g | GE OUT OF TROUBLE! |
Part I of the homework assignment for this week is to edit the complete story about Larry Walters and his flight over Los Angeles.