Skip to content

chence08/cs2030

Repository files navigation

Being an efficient coder

vim

How to do Lab 1 like a pro? (This is the way you're expected to work through your labs and eventually your practical exams.)

  1. We read through the entire problem statement and notice we need 2 java and 1 jsh file.

  2. We can quickly set up our tabbed vim environment.

    vim -p Point.java Circle.java maxDiscCoverage.jsh
  3. Use gt to move to the right tab, gT to move left.

  4. Saving files

    Action Keystroke
    Save current file :w
    Save current file and quit :wq OR :x OR ZZ
    Quit current file without saving :q!
    Save all files (that are opened in multiple tabs) :wa
    Save all files and quit :wqa
    Quit all files without saving any :qa!

    *Note: If a new file is empty, it will not be created the first time you try to save it. For that you will need

    touch emptyfile
  5. I want to create another file, how to do it without leaving vim?

    :tabnew AnotherClass.java
    
  6. I want to open all my existing java files into tabs immediately!

    vim -p *.java

testing with jshell

jshell> /open Point.java 

jshell> /open Circle.java 

jshell> /open maxDiscCoverage.jsh 

jshell> List<Point> points = List.of(new Point(0, 0), new Point(1, 0))
points ==> [point (0.000, 0.000), point (1.000, 0.000)]

jshell> findMaxDiscCoverage(points)
$.. ==> 2

jshell> points = List.of(new Point(0, -1), new Point(1, 0), new Point(0, 1), new Point(-1, 0))
points ==> [point (0.000, -1.000), point (1.000, 0.000), poi ... 0), point (-1.000, 0.000)]

jshell> findMaxDiscCoverage(points)
$.. ==> 4

jshell> /exit

You probably saw this in the Level 5 jshell testcase which was not readily provided to you as a jsh file. You can make your own level5.jsh by removing all the jshell> in vim. Then, you can automate testing using:

jshell < level5.jsh

Notice the tests always begin with the /open command, if you don't load your classes in order (superclass before subclass), things may go wrong that was not a result of an error in your code but rather JShell misunderstanding your input.

You can do testing without the hassle of typing out any jshell commands like this:

Your level5.jsh will now look like this without the extra commands:

List<Point> points = List.of(new Point(0, 0), new Point(1, 0))
findMaxDiscCoverage(points)
points = List.of(new Point(0, -1), new Point(1, 0), new Point(0, 1), new Point(-1, 0))
findMaxDiscCoverage(points)
jshell *.java maxDiscCoverage.jsh < level5.jsh

  • Link to the official course repository, where you earn participation through contributions to Issues and Wiki, the instructions are pretty comprehensive on how to setup your local environment!

  • Always take note of LumiNUS Announcements for updates!


Setting up Java locally

Useful resources

Only use IDE for Projects, you need ample practice on vim for PAs.

Shortcut for easy ssh and scp*

Prerequisite: expect (this should be preinstalled in most linux distributions)

scp is used for file transfers and should be unnecessary for this course.

  1. Download wrapper into the directory you want.

  2. chmod +x wrapper
  3. Usage

    <path to wrapper>/wrapper <stu password> <plab password> <stu server> <plab server>
  4. Create alias in ~/.bashrc or ~/.zshrc file

    alias plab="./wrapper pass1 pass2 e1234567@stu.comp.nus.edu.sg plab1234@123.456.78.900"

    Use absolute path to wrapper instead of ./

  5. Restart terminal or source your configuration file.

Login to plab

plab

Download Point.java from plab server into your current folder

plab -d ~/Point.java .

Upload your local Point.java into plab (why are you using this function?)

plab -u Point.java ~

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks