Apr 27, 2012

Unix Shell Skills for Scientists and CIT Students

The Unix Command Line Interface (a.k.a. Shell, or CLI) for Web Developers

  1. Your CIT GTF will be your Unix Drill Instructor (DI) and run you through basic training: Unix for Web Developers, which is a Reader's Guide to the University of Surrey's Unix for Beginners tutorial, parts 1, 2, and 5.

  2. For more practice:

    The Command Line Crash Course: Controlling Your Computer From The Terminal.

    This free online mini-book teaches you Unix or Windows command line skills, in a few hours to a few days. It has little explanation and focuses more on doing a small set of commands until you remember them.

    Software Carpentry Project's Video Lectures on the Unix Shell.

    The Software Carpentry project's mission is "to help scientists be more productive by teaching them basic computing skills", including the Unix shell. All of their content is available at the Software Carpentry website.


Jan 10, 2012

How do I get into the 111 lab I want if it is full?

PC Lab in Tuttleman- classroom set upImage by wsh1266 via Flickr

If you are unable to enroll in the course or any lab because the course is full, your only option is to wait until someone drops the course.

Since some students are "shopping for courses" during week 1, you should see spots start to open up at the end of the first week.


If you are already enrolled in the course and a lab, but would like to switch to a different lab that is already full, here's what to do:

Go to the lab you want and ask the GTF if there's room for you. If your GTF says Yes, make sure that s/he has your name removed from your original lab and added to the new one. If the GTF says No, you will have to attend a different lab.

For labs that are full, two names may be added beyond the max on the condition that the added students bring a notebook computer or watch over someone's shoulder on days when the lab is full.

Students actually registered for the lab are guaranteed a workstation if they need one.

Oct 8, 2011

The Tilde (~) in Unix and URLs

A tilde (Punctuation mark)
Image via Wikipedia
UNIX

In the Unix shell, the tilde (~) is an abbreviation for the path to your home directory. (It has other expansions but this the meaning when the tilde is used as a separate word.)

Tilde expansion is the process of converting the abbreviation to the path to the user's home directory.

Example (not using ~)

/home4/susanQ/public_html/111/ is the Unix path to Susan Queue's 111 folder on shell.uoregon.edu.

Example (using ~)

~/public_html/111/ is the Unix path to Suzie's folder on shell.uoregon.edu

Example

$ pwd
/tmp

$ cd ~

$ pwd
/home4/susanQ/

$ echo $HOME
/home4/susanQ/

(~ is a synonym for the value of the shell's HOME variable)

URLs

In a URL, the tilde (~) has a related but different meaning: it stands for the path to your public_html folder on the web server.

Example: 

URL:
http://uoregon.edu/~susanQ/

Corresponding Unix path on the server:
/home4/susanQ/public_html/

Example: 

URL:
http://uoregon.edu/~susanQ/111/
Corresponding Unix path on the server:
/home4/susanQ/public_html/111/

Enhanced by Zemanta

Sep 1, 2011

1-Armed Bandits && Demorgan's Law

When simulating the spin of a three-wheel slot machine, how do we detect three of a kind?





The following condition recognizes three of a kind:

var s1 = 'lemon', s2 = 'lemon', s3 = 'lemon';
console.log((s1 == s2) && (s1 == s3) && (s2 == s3));

We can modify it to control a loop that spins the wheels:

       s1 = RandomOneOf(['lemon', 'cherry', 'bar', 'donut']);
       s2 = RandomOneOf(['lemon', 'cherry', 'bar', 'donut']);
       s3 = RandomOneOf(['lemon', 'cherry', 'bar', 'donut']);

       while (!((s1 == s2) && (s1 == s3) && (s2 == s3))) {
           //spin again...
       }

Applying Demorgan's Law we get:

       while (!(s1 == s2) || !(s1 == s3) || !(s2 == s3)) {
           //spin again...
       }

Equivalently:

       while ((s1 != s2) || (s1 != s3) || (s2 != s3)) {
           //spin again...
       }

To hit the jackpot, we must spin the wheels at least once. This leads to a final, simpler version using a do-while:

do {
       s1 = RandomOneOf(['lemon', 'cherry', 'bar', 'donut']);
       s2 = RandomOneOf(['lemon', 'cherry', 'bar', 'donut']);
       s3 = RandomOneOf(['lemon', 'cherry', 'bar', 'donut']);
} while ((s1 != s2) || (s1 != s3) || (s2 != s3));

The do...while loop will always be executed at least once, even if the condition is false, because the statements are executed before the condition is tested.

It is a post-test loop; the while loop and the for loop are pre-test loops.

=> Use a do-while when an action must be performed at least once.


Jul 1, 2011

Web Apps w/o Programming: If this, then that (IFTTT)

IFImage by alex drennan via Flickr
IFTTT. Put the internet to work for you by creating tasks that fit this simple structure:
if this then that.

 A Web Tool That Lets You Automate the Internet. (NYT)

7 Ways to Automate Your Life With ifttt. (NYT)

Mar 1, 2011

SSH and the Unix Shell's Erase Key

Polished Turtle Shell
SSH sometime uses the Delete key to erase characters, but I prefer to use the Backspace key. How do I set it up?

You have several options, as follows:

  • Windows: Start SSH, select Edit > Settings > keyboard, then select Backspace sends Delete (or whichever key you want to use), then click OK.

  • OS X: Start Applications > Utilities > Terminal, the select Terminal > Window Settings..., then select Keyboardin the drop-down list, then check Delete key sends backspace.

  • Set your Unix shell's Erase key--

    Use Pico or Emacs to edit your login shell's startup file, .bash_profile:

    $ pico .bash_profile

    Add this line to the .bash_profile:

    stty erase '^h'

    save the file and exit pico.