Archive for the ‘Howtos’ Category.

Simulating Blackjack

The code we went over in class to simulate the game of Blackjack can be found at . Instead of removing the programming shortcuts (a.k.a. “syntactic sugar”) I use in the uploaded code, I’m attaching a small section of the code in this post with comments to help you understand and perhaps use them in your own programs:

Continue reading ‘Simulating Blackjack’ »

How to use the concept of String Building

A brief description: String Building involves the careful preparation of strings to be used elsewhere in the program. Typically this takes the form of manipulating a string to be used with a puts statement.

Say you have a puts statement. We all know that puts adds a hard return (new line) at the end, so two puts back to back will print on different lines. There are ways to stop puts from doing that, but it’s typically more clear to simply avoid the problem. Say also that the reason you want to use different lines is because you are printing something that takes a lot of space to calculate. It can also be used to build single lines of repeating patterns.

Continue reading ‘How to use the concept of String Building’ »

Ctrl-C, Ctrl-L, and the &

I’m getting some feedback from students regarding problems getting “stuck” on the command line, especially after entering commands that run programs (e.g., SciTE and ruby, as opposed to commands like ls and cd).

Here are a few potentially helpful hints:

  • When you find yourself stuck at the command line — i.e., it doesn’t respond to anything you enter — you can try holding down the ‘Ctrl’ key and hitting ‘C’. We refer to this ‘Ctrl-C’ (read: ‘Control C’) combination as a “software interrupt”. You can do it a few times in succession, and it’ll frequently interrupt whatever else the command line is trying to do, and get it to pay attention to you.
  • Sometimes it’s possible that you’re not stuck, and that you just can’t see what’s going on. ‘Ctrl-L’ is a combination you can use to redraw the screen.
  • Remember, too, that you can force the command line to run a command in the background by putting an ampersand character (&) after the command. So, for instance, you can use the command SciTE filename.rb & to start up the editor with the file “filename.rb” and at the same time continue using the command line.

Installing Lab Tools on Windows

In this series we’ll cover how to get the software packages used in lab on your own computer so that you can work on lab assignments at home or on a laptop. There’s not much to it, and the best news is that everything’s free!

Continue reading ‘Installing Lab Tools on Windows’ »

Using git with a flash drive, oh what fun!

Git does a lot of stuff. Fortunately, we don’t care about most of it. Here are some tips to make git work for you (and not the other way around).

If you have a flash drive, and would like to use it for the class, git can make that work for you!

Continue reading ‘Using git with a flash drive, oh what fun!’ »

Accessing lab resources and examples

We’ll soon be posting information on how to install the lab software on your computer, so that you can work on lab exercises at home or on a laptop. In addition to using git from the command line to download lab materials that accompany the writeup on the course blog, however, there are a few other options available to you.

You can browse examples and lab materials in your browser by visiting http://github.com/michaelee/cs105/. From here you can click on the “examples” or “labN” links to view examples or the materials for lab N. You can even download the entire directory of examples and lab materials (called a “tree”) as a zip file — look for the “download” link — so that you can work with them on your computer.

Pronouncing “puts”

A question came up after lecture as to why I pronounced puts the way I did; i.e., I say “put-ess“, instead of just “puts”.  Reason: puts really stands for “put string”, and so I say the ’s’ separately for emphasis.  

This might seem a little odd, though, as we can use both numerical and String arguments to the puts method.  Ignoring this odd fact for now (we’ll explain it away in the future), I hope this helps clear things up.