Gradescope Autograder

Spring 2018

44个Assn,偏向数据结构
邀请码:MNXYKX
学校:UC Berkeley
直接输入,不要选择2U-UC Berkeley,否则将提示COURSE ENTRY CODE IS INVALID

Spring 2021

19个Assn,偏向软件工程
邀请码:MB7ZPY

文章收录

The Law of the Broken Futon 浮沙筑高台法则

“Since I’m fine now, can’t I add that missing piece later, when it’s actually needed?” Sometimes, yes. But it’s much harder.
Adding the missing piece later means waiting until the damage is already underway, and hellishly difficult to undo.

A Response to “Why Most Unit Testing is Waste”

(Unit Tests) They are based on programmers’ fantasies about how the function should work. But programmers break down requirements into smaller components all the time – this is how you program. Sometimes there are misunderstandings, but that is the exception, not the rule, in my opinion.

2.1 Mystery of Java Restore

When instantiate an Object, obj = new Object(), obj stores the address of the Object, not the specific data struction.

(That is why all type of variables create memory boxes of 64 bits. It is just the memory of the address.)

Therefore, When we use obj2 = obj, Java simply copy the addr of obj and assign it to obj2 (They are pointing to the same Object), that is why when we change obj2.weight it effects obj.weight too.

2.2 SLList

Static

if you don’t use any instance members of the outer class, make the nested class static.

Overloaded

// Share the same name but have different parameters.
private static int size(IntNode p) {
if (p.next == null) {
return 1;
}
return 1 + size(p.next);
}

public int size() {
return size(first);
}

Sentinel Node

public SLList() {
first = null;
size = 0;
}

public void addLast(int x) {
if (size == 0) {
addFirst(x);
return;
}
// This solution works, but special case code like that shown above should be avoided when necessary.
IntNode p = first;
while (p.next != null) {
p = p.next;
}
p.next = new IntNode(x, null);
size++;
}

We can do this by creating a special node that is always there, which we will call a sentinel node. The sentinel node will hold a value, which we won’t care about.

public void addLast(int x) {
IntNode p = sentinel;
while (p.next != null) {
p = p.next;
}
p.next = new IntNode(x, null);
size++;
}

3.0 Testing

The == operator

== operator simply compares the literal bits in the memory boxes. (e.g., for objects it only compares their address.)

Private Recursive Helper

/** Sorts strings destructively starting from item start. */
private static void sort(String[] x, int start) {
int smallestIndex = findSmallest(x);
swap(x, start, smallestIndex);
sort(x, start + 1);
}

/** Sorts strings destructively. */
public static void sort(String[] x) {
sort(x, 0);
}

This approach is quite common when trying to use recursion on a data structure that is not inherently recursive, e.g. arrays.

JUnit

import org.junit.Test;
import static org.junit.Assert.*;

@Test
public void test() {
// your test code
assertEquals(actual, expected);
}

Autograder vs JUnit

Rely on an Autograder, there is plenty of time that you’re not in control of neither your workflow or your code.

Test-Driven Development (TDD)

TDD is a development process in which we write tests for code before writing the code itself. The steps are as follows:

  1. Identify a new feature.
  2. Write a unit test for that feature.
  3. Run the test. It should fail.
  4. Write code that passes the test. Yay!
  5. Optional: refactor code to make it faster, cleaner, etc. Except now we have a reference to tests that should pass.

You should definitely write tests but only when they might be useful!

4.1 Overload

public static String longest(SLList<String> list);
public static String longest(AList<String> list);

Java will choose the right method according to the parameter you pass in.

However, it is ugly, repetitive and hard to maintain.

@Override

Override is something like a proofreader. It will remind you when you make a typo and named method in error.

4.2 Interface

Summary:

  • All methods must be public.
  • All variables must be public static final.
  • Cannot be instantiated
  • All methods are by default abstract unless specified to be default
  • Can implement more than one interface per class

Default

// Use `default` to define a method in `interface`
default public void print() {
// your code
}

Extends

The extends keyword defines “is-a”.

By using the extends keyword, subclasses inherit all members of the parent class. “Members” includes:

  1. All instance and static variables
  2. All methods
  3. All nested classes

Note that constructors are not inherited, and private members cannot be directly accessed by subclasses.

Subclass Constructor

A subclass is firstly its parentclass. Using the super keyword.

public VengefulSLList() {
super();
deletedItems = new SLList<Item>();
}

Or, if we choose not to, Java will automatically make a call to the superclass’s no-argument constructor for us.

Compile-time Error

VengefulSLList<Integer> vsl = new VengefulSLList<Integer>(9);
SLList<Integer> sl = vsl;

sl.addLast(50);
sl.removeLast();

sl.printLostItems(); // 会出错
VengefulSLList<Integer> vsl2 = sl; // 会出错

尽管运行时sl是动态的VengefulSLList类型,Java编译器将对象看作静态类型;SLList没有printLostItems方法,因此会报错;最后一句也是一样。

4.3 Polymorphism

public interface OurComparable {
public int compareTo(Object o);

public static OurComparable max(OurComparable[] items) {
int maxDex = 0;
for (int i = 0; i < items.length; i += 1) {
int cmp = items[i].compareTo(items[maxDex]);
if (cmp > 0) {
maxDex = i;
}
}
return items[maxDex];
}
}

public class Dog {
public int compareTo(Object o) {
Dog uddaDog = (Dog) o;
return this.size - uddaDog.size;
}
}

使用多态,就可以写出一个统一的max()方法,而不需要考虑各个类的数据结构

Final

The final keyword prevents the variable from being changed after its first assignment.

Notice: it doesn’t work for reference!

public final ArrayDeque<String>() deque = new ArrayDeque<String>();

deque不可改变,然而deque指向的ArrayDeque可变

Assn

Proj0

[!NOTE]
注意严格按照讲义要求编程,不要有讲义以外的函数或方法,否则Gradescope OJ会扣掉API的10分!

计算ForceExertedByX/Y,不要使用Math.abs()或者a < 0 ? -a : a来通过本地测试,否则OJ会报错。力的方向(正负)需要根据行星的相对位置来定。

Proj1

  • 注意构造空的Deque时,确保哨兵正确指向自己。
  • add()需要更改4个指针的方向。修改指针指向时,注意备份原指针指向位置。
  • 对于循环Deque,注意print()的迭代条件。
  • remove()方法需要检查isEmpty(),否则不应该执行。
  • get()方法,index从0开始,LinkedList和ArrayList的对应关系是一样的。

Array Deque

  • 先设计,再编码。好好想想要设计怎样的ArrayDeque。分离传入index和实际index。
  • 取模!!!一定要注意-1 % size = -1是取余数,Math.floorMod(-1, size) = size-1才是取模!(当Gradescope出现index=-1一般就是取模问题)
  • addFirst()后调用removeLast()时,size变回0,但是没有调整下标的话head和end不会连在一起(错误状态)
  • 考虑resize()的实现方法。浮点数运算比整数运算慢很多!

1.0 第一件事git config

  • git config --list --show-origin查看所有git配置以及所在文件
  • 使用git config --global可以设置git的基本信息(如用户名、邮箱),使用--unset取消设置
    1. 配置你的名称、邮箱以及编辑器
git config --global user.name "191220000-Zhang San" 
# 全局设置名称
git config --global user.email "zhang3@email.com"
git config --global core.editor vim

2.0 初始化仓库

  1. 本地仓库:git init创建一个新的 git 仓库,其数据会存放在一个名为 .git 的目录下
    删除仓库:删除 .git 文件夹
git add <文件名字,*表示全部>
git commit -m 'initial project version'
# 提交到暂存区,并附上注释
  1. 远程仓库:git clone克隆远端仓库
git clone <网址> <仓库存放文件夹名>
# 使用http克隆
阅读全文 »

Chapter3 操作系统结构

复杂度管理方法 M.A.L.H

Modularity: 模块化,分而治之
Abstraction: 抽象,接口与实现分离,遵循宽进严出原则。例如虚拟内存、文件系统

对于大型系统,只有模块化和抽象,可能导致划分模块太多,交互关系复杂,因此还需要引入分层和层次结构控制复杂度。

Layering: 分层,每个层级是一套完整机制。通常一个模块只能与本层和上下层交互,不能跨层。例如OSI、TCP/IP
Hierarchy: 层次结构,大的子系统由多个小的子系统组织成。即同级模块的分层

宽进严出原则:容忍各种输入(包括恶意输入),严格控制模块的对外输出

微内核

宏内核架构:单点bug使整个系统崩溃。
微内核:解耦单个功能/模块(如文件系统、设备驱动)作为独立服务隔离运行,使内核成为一个最小功能集。

微内核架构服务隔离,单点出问题系统不会崩溃

内核态部分,称为μkernel\mu kernel

微内核优势:

  1. 弹性硬件拓展能力
  2. 硬件异构实现
  3. 功能安全
  4. 信息安全
  5. 时延确定

现代操作系统特征:1)虚拟内存;2)用户态、内核态隔离。

阅读全文 »

笔记

命令

hexo new "postName" # 新建文章
hexo new page "pageName" # 新建页面
hexo generate # 生成静态页面至public目录
hexo server # 开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy # 部署到GitHub
hexo help # 查看帮助
hexo version # 查看Hexo的版本

按文章更新时间排序

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -updated # 默认是-date

背景设置

把你挑选的背景图片命名为:background.jpg,放在blog\themes\next\source\images里,在blog\themes\next\source\css_custom文件的custom.styl首部添加

body {
background:url(/images/background.jpg);
background-attachment: fixed;
}

符号链接

# Windows,有些文件需要文件名相同才能打开
# -d 目录符号链接
mklink /d C:\file\path\Target C:\file\path\Source

安装主题

  1. npm安装在modules下
cd hexo-site
npm install hexo-theme-next
  1. git clone安装
cd hexo-site
git clone https://github.com/next-theme/hexo-theme-next themes/next
# Upgrade
cd themes/next
git pull origin master
# Configuration
cp themes/next/_config.yml _config.next.yml

Hexo

我的配置

# 设置英文字体
global:
family: Source Serif Pro

# layout\_partials\head\head.njk 设置中文字体
{{ next_font() }}
{{ next_vendors('fontawesome') }}
<link href="https://fonts.googleapis.com/css?family=Noto+Serif+SC&display=swap" rel="stylesheet">
# source\css\_variables 添加中文字体
$font-family-chinese = "Noto Serif SC"

codes:
family: IBM Plex Mono

codeblock:
theme:
light: stackoverflow-light

Quick Start

npm install hexo-cli -g
hexo init blogFolderName
cd blog
npm install
hexo server

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Create a new post

$ hexo new "My New Post"

More info: Writing

Run server

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment

PA1-1 24.5.30

又开始了ICS之旅,这次又给自己下了一个难度,找到了汪亮老师讲解的ICS 5!

target

第一课的目标是修正一个register错误声明

insteresting

  • 中途网易源Bad Gateway 502了,更换清华源,学会了:%s/163/tuna/g非常爽!
  • 又学了几个终端快捷键
  • 想到了用 ccache 加速我的PA

problems

  1. unionstruct 的区别?
    unioin 在同一个内存空间中存储不同的数据类型。
    struct 则是同时存储不同的数据类型。
  2. 为什么要用 union?阅读i386手册
    2.3.1 General Registers
    As Figure 2-5 shows, the low-order word of each of these eight registers has a separate name and can be treated as a unit. This feature is useful for handling 16-bit data items and for compatibility with the 8086 and 80286 processors. The word registers are named AX, BX, CX, DX, BP, SP, SI, and DI.
    对于CPU来说,可以把AH AX AL看成单独的单元,拆分成小块。所以它们是共用关系。

PA1-2 ALU 24.6.5

target

实现ALU中的各类运算,包括设置标志位

knowledge

Appendix C

Name Function
CF Carry Flag ── Set on high-order bit carry or borrow; cleared otherwise.
PF Parity Flag ── Set if low-order eight bits of result contain an even number of 1 bits; cleared otherwise.
ZF Zero Flag ── Set if result is zero; cleared otherwise.
SF Sign Flag ── Set equal to high-order bit of result (0 is positive, 1 if negative).
OF
Overflow Flag ── Set if result is too large a positive number or too small a negative number (excluding sign-bit) to fit in destination operand; cleared otherwise.
阅读全文 »

Tight Coupling 紧耦合

在Spring框架以前,使用排序算法需要将算法实例化

public class ComplexBusinessService {
SortAlgorithm sortAlgorithm = new BubbleSortAlgorithm;
}
public class BubbleSortAlgorithm implements SortAlgorithm {...}

Good code has loose coupling.

移除依赖项的实例化可以移除紧耦合

public class ComplexBusinessService {
SortAlgorithm sortAlgorithm; // = new BubbleSortAlgorithm();

public ComplexBusinessService(SortAlgorithm sortAlgorithm) { // 创建构造函数
this.sortAlgorithm = sortAlgorithm;
}

public classBubbleSortAlgorithm implements SortAlgorithm {...}

Spring Framework instantiates objects and populates the dependencies.

阅读全文 »

一号标题

Title 2

三号标题

Title 4

五号标题
Title 6

标题 标题 标题
左对齐 两端对齐 右对齐
  • Unordered List
    • Unordered List
  1. Ordered List
    2. Ordered List
  • [x] TO-DO List
  • [] TO-DO List

Delete Line
Blod
Italic
Code
E=MC2E = MC^2
Link

[1]Hello, World!

public static void main(String[] args) {
System.out.println("Hello World!");
}
--- auto_detect: ture
+++ auto_detect: false

No Silver Bullet

By Brooks

[!NOTE]
Note that it is a note.

[!WARNING]
WARNING!

[!DANGER]
Notice the DANGER!

[!SUCCESS]
Now it is SUCCESS.

[!INFO]
Here is some INFO.


  1. Hello World! ↩︎

Git配置

远程仓库 - 廖雪峰的官方网站 (liaoxuefeng.com)

  1. 创建ssh key,在c盘用户目录.git文件夹中
    ssh-keygen -t rsa -C "youremail@example.com"
    ssh-keygen -l -f ~/.ssh/id_rsa 可以查看秘钥的配置信息,包括邮箱
  2. 在GitHub账号设置页面,添加ssh key,复制.ssh/id_rsa.pub的信息,点击创建即可
  3. 测试是否成功:ssh -T git@github.com
    注意:如果测试不成功,可能是反向代理的问题

Github 远程仓库

  1. 在github上新建一个仓库
  2. git remote add origin git@github.com:github账号名称/仓库名称.git 关联仓库,origin是远程库的名字
  3. git push -u origin master把本地库内容(master分支)推送到远程库(oringin),-u 参数表示会把本地master分支和远程master分支关联起来,方便后面简化命令
  • git remote set-url origin <URL>更改仓库地址

github trending 热门软件

  • 项目含金量 stars 1k+
  • fork 拷贝项目到自己的仓库
  • pull request 合并分支

NJU

  • 学习编程语言如C、Rust
  • 精选精读论文
  • STFW:比百度更高效的办法

网络搜索

网站 URL 备注
哔哩哔哩 https://search.bilibili.com/all?keyword={query}
知乎 https://www.zhihu.com/search?type=content&q={query}
百度贴吧 https://tieba.baidu.com/f?ie=utf-8&kw={query}&fr=search 优先搜索吧名
小红书 https://www.xiaohongshu.com/search_result?keyword={query}&source=web_search_result_notes 需要登录
淘宝 https://s.taobao.com/search?q={query}&commend=all&search_type=item&sourceId=tb.index&ie=utf8
京东 https://search.jd.com/Search?keyword={query}&enc=utf-8
Yandex https://yandex.com/search/?text={query}
GitHub https://github.com/search?q={query}&type=repositories
tldr https://tldr.inbrowser.app/pages/common/{query} mannual查Linux命令
必应翻译 https://cn.bing.com/translator?ref=TThis&text={query}&from=en&to=zh-Hant 英译中
DeepL翻译 https://www.deepl.com/translator#en/zh/{query} 英译中
  • 有时候站内搜索没有搜索引擎准确,可以使用搜索引擎过滤网站
    过滤站点:
http://<ENGINE.URL>/search?text=site%3A<SITE.URL>%20{query}

0.0 规范

我要编写一个名为“学习笔记”的 Web 应用程序,让用户能够记录感兴趣的主题,并在学习每个主题的过程中添加日志条目。“学习笔记”的主页对这个网站进行描述,并邀请用户注册或登录。用户登录后,可以创建新主题、添加新条目以及阅读既有的条目。

目录 ll_project 包含 4 个文件, 其中最重要的是 settings.pyurls.pywsgi.py。文件 settings.py 指定 Django 如何与系统交互以及如何管理项目。
在开发项目的过程中,我们将修改其中的一些设置,并添加一些设置。
文件 urls.py 告诉 Django,应创建哪些网页来响应浏览器请求。
文件 wsgi.py 帮助 Django 提供它创建的文件,名称是 web server gateway interface(Web 服务器网关接口)的首字母缩写。

1.0 创建环境

1.1 创建虚拟环境

在独立的项目文件夹下运行

python -m venv ll_env

python -m ensurepip --default-pip # 重装pip

将会创造一个ll_env文件夹
可以使用下面的命令激活虚拟环境。激活虚拟环境后,安装的模组将只在虚拟环境中生效,而不干扰到电脑上Python的模组

source ll_env/bin/activate # Linux系统
source ll_env/Scripts/activate # Windows系统

(ll_env)
work_directory$ # 命令提示符前会显示(ll_env)

使用deactive取消激活虚拟环境

1.2 安装配置Django

pip install --upgrade pip # 更新pip
pip install django # 安装Django
django-admin startproject ll_project . # 初始化Django
python manage.py migrate # 生成数据库
python manage.py runserver # 生成预览,可以在本地8000端口看到网页
Django手册: https://docs.djangoproject.com/en/4.1/ref/models/fields/
阅读全文 »
0%