teaching machines

CS 330 Lecture 3 – $h3||

Agenda

  • quarter sheets
  • tr
  • echoing a line (in Java)
  • system call (PHP and sed)
  • tcsh vs. bash vs. zsh vs. intellectual development
  • subshells in parentheses vs. curly braces
  • question
  • numbered parameters
  • environment variables
  • redirection and pipes
    • lineN with grep
    • new mail
    • spamming you all
    • what’s the frequency of kenneth?

TODO

Perry’s stages of intellectual development

  1. Dualism. The world is black and white. A is right, and B is wrong. iPhones are phat.
  2. Multiplicity. Rightness is just an opinion each person holds. Others feel differently. Phones are stupid.
  3. Relativism. What is right is often backed by reason, evidence, and personal experiences. My iPhone is more than cool; it’s a product of fine engineering and aesthetic sensitivity.
  4. Commitment. We form our identity using reason, evidence, and experience—tolerating others who have done the same. We recognize our fallibility and adjust when new information comes along. My iPhone is cool, but those Androids have some cool features too.

On shells

Question

What is better? Linear search or binary search?

Code

LineN.java

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class LineN {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new File(args[0]));
    int targetLine = Integer.parseInt(args[1]);

    int i = 0;
    while (in.hasNextLine()) {
      ++i;
      String line = in.nextLine();
      if (i == targetLine) {
        System.out.println(line);
      }
    }
  }
}

linen.php

#!/usr/bin/env php5
<?php
/* print_r($argv); */
$file = $argv[1];
$targetLine = $argv[2];
system("sed -n '$targetLine p' $file");
?>

fixext

#!/usr/bin/env zsh

ext=$1
shift

for file in $*; do
  mv $file ${file:r}.$ext
done

TLDL

  • Solving the same problem over and over leads to abstractions leads to a language’s strengths.
  • Huffman coding: find the frequently-occurring prefixes, swap them out for something shorter. “Economy of expression.”
  • Most languages are Turing complete, equally as powerful as one another.
  • Shell’s strong suit is in manipulating the file system and gluing programs together.

Haiku

I have a sickness
I’m real allergic to mice
And it’s terminal

Comments

  1. Di says:

    Hi Chris,

    I tried ssh laud@thing-0.cs.uwec.edu from my linux machine, I got “ssh: connect to host thing-0.cs.uwec.edu port 22: No route to host.

    Should I contact csadmin or did I do something wrong?

    Thank you!

    1. Chris Johnson says:

      You’ll need to create a VPN connection before logging in to the thingies: vpn.uwec.edu.

      1. Di says:

        Hi Chris,

        So after I download vpnsetup.sh, I opened the terminal and typed:

        chmod u+x vpnsetup.sh
        sudo ./vpnsetup.sh

        Then it said “done!” in my screen, so I tried to login to thing-0 with your instruction, but it still give me the same result: ssh: connect to host thing-0.cs.uwec.edu port 22: No route to host.

        What should I do?

        Thank you!

  2. Di says:

    Hey Chris,

    Sorry to bother you again, but when I typed
    /opt/cisco/anyconnect/bin/vpnui &

    a cisco window pops up and ask for “Connect to”. I tried “thing-0.cs.uwec.edu”, it will tell me “Could not connect to server. Please verify Internet connectivity and server address.”

    What should I type in to connect?

    Thank you again!

    1. Chris Johnson says:

      You’ll need to connect to vpn.uwec.edu through vpnui first. Then thing-[012].cs.uwec.edu through ssh.

  3. Di says:

    Never mind. I got that fixed. But when I typed
    “ssh laud@thing-0.cs.uwec.edu

    My machine complains

    “The authenticity of host ‘thing-0.cs.uwec.edu (137.28.8.166)’ can’t be established.
    RSA key fingerprint is 98:e1:ac:15:11:20:74:70:3c:c4:04:77:b9:6e:5e:57.
    Are you sure you want to continue connecting (yes/no)?”

    I typed “yes” . . .so

    “Warning: Permanently added ‘thing-0.cs.uwec.edu,137.28.8.166’ (RSA) to the list of known hosts.”

    Then I got stucked there forever and now. I tried

    “ssh laud@thing-0.cs.uwec.edu” again, but it will just stuck there, don’t know why.

    Any ideas?

    Thank you!

    1. Di says:

      It succeeded! Sorry to keep posting things on your blog. I guess I should be more patient for my machine :)

      Thank you! Again, sorry about these postings . . . ^_^

      Have a good night!

Leave a Reply

Your email address will not be published. Required fields are marked *