Lecture 3:
Bash Recap + Intro to Version Control
Fall 2025
Announcements
Outline
Outline
Shell / Bash Review
Editing your .zshrc or .bashrc file
Exercise 1: Common Bash Commands
Let’s try doing these exercises together (Windows users: please use WSL + Ubuntu):�
Using the Command Line Cheat Sheet…
Answers Exercise 1: (Try it before you look)...
Answers Exercise 1: (Try it before you look)...
Exercise: Bash + VIM Practice
Open a terminal | For Windows: Activate WSL using the command prompt PowerShell |
Open a file called init-app.sh using nano | Command: vi init-app.sh |
Create a script that:
| Use the course command line cheat sheet to help you. Hints:
|
Save your file and exit | Ctrl+O – Saves changes�Crtl+X – Exit editor |
Test the bash script you just made: | bash init-app.sh |
Answers: Bash + VIM Practice
cd ~/Desktop/csci338 # should be a different path for you
echo "Hello world!" > readme.txt
cat readme.txt # should print "Hello world!" to the screen
vi init-app.sh
Within vim, go into edit mode by pressing the i key.
Then add the following lines to test.sh:
mkdir my-app
touch my-app/index.html
touch my-app/style.css
Save and quit vim by first pressing the Escape key and � then typing :wq to save and quit
bash init-app.sh # should have created a my-app directory + HTML/CSS file within your current directory
Outline
Reminder of the Problem
Write a function – using any programming language you want – that takes in a list of integers. The function returns true if the list contains two or more of the same integer, false otherwise.
// Java
public static boolean containsPair(List<Integer> l) {
return false;
}
Suggested Approach
Also: You probably won’t be allowed to use a code editor when you’re doing coding interviews. Whiteboarding only!
containsPair: Approach #1
public static boolean containsPair(List<Integer> l) {
for (int i = 0; i < l.size() - 1; i++) {
if (l.get(i).equals(l.get(i + 1))) {
return true;
}
}
return false;
}
Q: Does this work? If not, what is the problem? Can you think of a scenario where this could work and a code enhancement you might make?
containsPair: Approach #2
public static boolean containsPair(List<Integer> l) {
for (int i = 0; i < (l.size() - 1); i++) {
for (int j = i + 1; j < l.size(); j++) {
if (l.get(i).equals(l.get(j))) {
return true;
}
}
}
return false;
}
Q: Does this work? Is it efficient? What’s the worst case scenario?
containsPair: Approach #2 with bug
public static boolean containsPair(List<Integer> l) {
for (int i = 0; i < (l.size() - 1); i++) {
for (int j = 0; j < l.size(); j++) {
if (l.get(i).equals(l.get(j))) {
return true;
}
}
}
return false;
}
Q: Can you find the bug? Why is it a bug?
containsPair: Approach #3
public static boolean containsPair(List<Integer> l) {
List<Integer> unique = new ArrayList<Integer>();
for (int i = 0; i < l.size(); i++) {
if (unique.contains(l.get(i))) {
return true;
}
unique.add(l.get(i));
}
return false;
}
Q: Does this work? Is it efficient? What’s the worst case scenario?
containsPair: Approach #4
public static boolean containsPair(List<Integer> l) {
Map<Integer, Integer> s = new HashMap<Integer, Integer>();
for(int i = 0; i < l.size(); i++) {
if (s.containsKey(l.get(i))) {
return true;
}
s.put(l.get(i), 1);
}
return false;
}
Q: Does this work? Is it efficient? Do you think this is different than approach 3? Why or why not? What’s the worst case scenario?
containsPair: Approach #5
public static boolean containsPair(List<Integer> l) {
Set<Integer> s = new HashSet<Integer>(l);
return s.size() != l.size();
}
Q: Does this work? Is it efficient? What’s the worst case scenario?
Good Work!
Thinking like this takes lots of practice. Keep at it. We’ll keep doing these problems all semester.
URL Shortener
Your boss asks you to implement a URL shortener. Specifically:
What steps would you take to implement this system?
Let’s draw this out on the whiteboard…
Outline
Why is Code History important?
Why is Version Control Important?
What is the difference between centralized and distributed version control?
What is the problem with having long-running dev branches? What is the solution?
What is the one version rule?
What are the tradeoffs of having a Monorepo versus multiple repos?
Pros of Monorepos:
Cons of Monorepos:
What files do you check into version control? What files do you NOT check in?