Hw01 of CS61A of UCB(2021-Fall)
hw01. Control
Q1. Welcome Forms
Skip :)
Q2. A Plus Abs B
Fill in the blanks in the following function for adding
ato the absolute value ofb, without callingabs. You may not modify any of the provided code other than the two blanks.
This problem is easy if we know that we can bind names to functions. In this problem:
- When
b < 0,a + abs(b) = a - b, so we should usesub - When
b > 0,a + abs(b) = a + b, so we should useadd
The solutions for exercise09 of Missingsemester(2020)
Lecture 09. Security and Cryptography
Entropy
Suppose a password is chosen as a concatenation of four lower-case dictionary words, where each word is selected uniformly at random from a dictionary of size 100,000. An example of such a password is
correcthorsebatterystaple. How many bits of entropy does this have?
In order to calculate the bits of entropy, we need to know how many possibilites there.
We can easily know the combinations count are $100000^4$ and the bits of entropy are $log_2 (100000^4)\approx 66\ bit$ 🤗
The solutions for exercise08 of Missingsemester(2020)
Lecture 08. Metaprogramming
Most makefiles provide a target called
clean. This isn’t intended to produce a file calledclean, but instead to clean up any files that can be re-built by make. Think of it as a way to “undo” all of the build steps. Implement acleantarget for thepaper.pdfMakefileabove. You will have to make the target phony. You may find thegit ls-filessubcommand useful. A number of other very common make targets are listed here.
How to Use Logging in Python
Intro
Recently I was fine-tuning my deep learning model, and I habitually started to use print to print some key information on the terminal. So my workflow is like:
- I type some hyperparameters to train my model.
- I manually opened an Excel to record the hyperparameters used and the model evaluation results. And I will go back to step 1. If I am not satisfied with results.
Soon, I became bored with this workflow (In fact, I kept this for quite a long time.). However, I suddenly forgot to record key information manually. As a result, I had to navigate in the history output of the the terminal slowly.
The solutions for exercise07 of Missingsemester(2020)
debugging
Use
journalctlon Linux orlog showon macOS to get the super user accesses and commands in the last day. If there aren’t any you can execute some harmless commands such assudo lsand check again.
When I run log show --last 1d, it keeps running for along time. I don’t know how long it make take, so I will just execute harmless sudo ls to check the log.
The solutions for exercise 05&06 of MIT.Missing-semester(2020)
Lecture05. Command-line Environment
Job control
From what we have seen, we can use some
ps aux | grepcommands to get our jobs’ pids and then kill them, but there are better ways to do it. Start asleep 10000job in a terminal, background it withCtrl-Zand continue its execution withbg. Now usepgrepto find its pid andpkillto kill it without ever typing the pid itself. (Hint: use the-afflags).
The solutions for exercise 03&04 of MIT.Missing-semester(2020)
Lecture 03. Editors (Vim)
Complete
vimtutor. Note: it looks best in a 80x24 (80 columns by 24 lines) terminal window.
It is a tutorial for beginners of vim. I will just put some notes which are not mentioned in course here.
-
Ucommand: When we pressuin normal mode, we can undo the last command. WhatUdoes is fixing a whole line. -
Ctrl + G: show your location in the file and the file status. Type the linenumber you want to go, then pressG, then you are there.
How to draw a simple relation graph in Python
Intro
The process of drawing a simple relation graph in python can be broken down into 2 steps.
- Define a graph.
- Draw a graph.
Step 1. Define a graph
In this step, we will use the networkx package.
Install tutorial
If you are using conda, you can just type conda install networkx
If you are using pip, you can just type pip install networkx
Nodes
First of all, you need to create a graph.