Please work through these in order, as the first is most important and not quite finishing the last shouldn’t be too much of a problem.
Read and understand everything written on this page. Do the activities listed in exercise boxes like this.
You should be able to
portal.cs.virginia.edu
via ssh
ssh
without the need to re-type your password each time, see our ssh help sheet.
as meaning the current directory
..
as meaning the directory containing the current directory
~
as meaning my home directory– i.e.,
/u/mst3k
If you are unsure of any part of this, please talk to a TA in lab. You take priority over people working on later parts of this lab.
git
introductionWe’ll use git in this class, and many other classes that follow. Git is a versatile tool that does many useful things; among them are
hooksto automatically run when things change
untrackedor
modified
untrackedfile has no copy in the git-managed space
modifiedfile has been changed from the last git-managed version
addinga file tells git to care about your changes to it
committinga file tells git top update the git-manages copy to match your version. You can only commit added files.
push, saying
remote computer, you should know about what I’ve done lately.
pull, saying
remote computer, what have you done lately?
user.name
and user.email
Git is designed for collaboration, so it does not allow anonymous contributions. Hence, you have to tell it a name and email, either once per project or once for all projects on your computer. This information is visible only to other people who have access to your git project.
While inside the git project directory created by git clone
, run the following commands, using your name and email ID instead of those in the example:
From anywhere, run the following commands, using your name and email ID instead of those in the example:
Git will complain if you try to git commit
without having done this.
You’ll only need to do this once in this course, so we’ll only give a little explanation.
Create the git-managed project on the server, portal.cs.virginia.edu
. Use your user name, not mst3k
, and any name you want (we assume cso1-code
but you can change that)
Create a working copy of that project on the server
Create your local working copy of that project
If you have not set up a global username and email, you should then set those for this project (see user.name
and user.email
)
We may have you use projects we’ve made for you later in the semester, which uses step 2 of the above.
As a summary, the steps listed above that you should actually do are
ssh
your-computing-id@portal.cs.virginia.edu
mkdir cso1-code.git
cd cso1-code.git
git init --bare
cd ~
git clone
your-computing-id@portal.cs.virginia.edu:cso1-code.git
exit
git clone
your-computing-id@portal.cs.virginia.edu:cso1-code.git
cd cso1-code
git config user.name "
Your Full Name"
git config user.email "
your-computing-id@virginia.edu"
We expect the most common case will be you’ve created or modified a file on your laptop and want to try running it on the server. Let’s go through this step by step, assuming you start in Terminal/PowerShell in the directory of your project on your laptop
git add file1 file2 ...
Tell git
which files you want to have sent. If you want everything in the current directory sent, you can use git add .
.
If you created no new files, you can skip this step as described below.
git commit -m "I changed a few files"
Tell git
to update it’s internal copy of the files you’ve added and label this change I changed a few files
. Using good descriptive labels becomes more important as project teams grow.
You can add and commit in one step if you have only modified (not added) files by using git commit -a -m "fixed typos"
git pull
git pull
before git push
.
git push
ssh mst3k@portal.cs.virginia.edu
cd cso1-code
git pull
Writing scripts
If you find yourself repeatedly running the same commands, you can save them in a file and run them in bulk. For example, you might write a file like
git commit -a -m 'auto-commit caused by serversync.sh'
git pull
git push
ssh mst3k@portal.cs.virginia.edu "cd cso1-code; git pull"
and save it on your laptop as serversync.sh
; then any time you want to sync your code to the server, simply run bash serversync.sh
Create a git project with a copy on your laptop and on the server, as described under Creating a project
above
On your laptop, in the directory of this new project, create a file named lab01
that contains
I wrote this on my laptop! Hooray!
Don’t know how to make a file? See Lab 00 CLI Editor
then use commands from Laptop → git → CS server
above to get it into git and onto the server’s version of the project. Then show the TAs you did so. One way to show this is to ssh
into the server, go to your project directory, and type the following
… then call over a TA to show them the results.
Since you already created a project in the last exercise,
cd
into your project directory
use an editor to make a file, as described in Lab 00.
use git to add
that file, commit
the addition, and push
it to the server
ssh
into the server
cd
into your project directory on the server
use git to pull
the changes you previously pushed
call over a TA to show you succeeded by showing them the output of
There are several tutorials you may find useful. Don’t feel that you have to do all of these (unless you want to and/or you need to still learn it), but doing at least one all the way through may help you feel more confident. You should probably do them on your own time, though, not during lab time.
Claude Shannon founded the field of information theory. A core fact in information theory is that there is a basic unit of information, called a bit1
or a bit of entropy.
Roughly speaking, a bit
is an amount of information that is about as surprising as the result of a single coin flip. In the sentence Hello, my name is Claude
the word is
has low entropy; most of the time someone says Hello, my name
the next word they say is is,
so adding that word provides very little more information. On the other hand, the word Claude
in thart same sentence has many bits of entropy; a huge number of words could reasonably follow Hello, my name is
and any given one we pick is quite surprising.
In computers, we rarely encode things anywhere near as efficiently as its bits of entropy suggest. For example, most common encodings of strings use 8 bits per character. In this lab, you’ll replicate an experiment Claude Shannon published in 19502 to see just how inefficient that encoding is.
First, you’ll write a program in either Python or Java. Then, you’ll use that program to perform an experiment and reflect on the results.
You may either work alone or with a buddy in this lab. Buddy programming is where two people work side-by-side, each creating similar programs while talking together to help one another out. In well-running buddy programming each buddy is speaking about equally, describing what they are writing next or how they are testing what they have written. Buddy programming usually results in similarly-designed but non-identical programs.
If you use a buddy, you should sit next to your buddy and use the same programming language they use.
Your program should do the following:
Read a text file into a string in memory. You should be able to specify different file names each time you run the program.
Repeatedly
After some fixed number of iterations (20 might make sense), display
You got 14 out of 20 guesses correct!
)Once your program seems to be working, try it on a few different texts. For example, you might try
Add a comment to the top of your code that includes at least the following:
Show a TA your working code. They may ask you some questions about how your code works and what you think of the results. For most students, this should happen in lab; if you have completed the lab exercise before lab occurs, you are welcome to do it in their office hours.