可爱小蛇

可爱可爱小小蛇

【持续更新】PAT甲级Advanced Level

2021-11-16

题目集网址: https://pintia.cn/problem-sets/994805342720868352/problems/type/7

我的代码网址,附尽量详细的英文注释: https://github.com/suchacutesnake/pat

2021-11-16 16:44:21 星期二 这两天饭也吃不香,觉也睡不好,都是因为这道傻逼题目(指1026),也不讲讲清楚,就tm纯靠猜是吧

![]( https://cutesnaketop.oss-cn-beijing.aliyuncs.com/image/gitee-img/Screen Shot 2021-11-16 at 4.40.48 PM.jpg)

做一题8小时,真心累,这题目多少有点大病。我还以为我代码有问题,结果网上一搜才知道全是题目没讲清楚的地方case不过,我真的是醉了,我写的代码从一开始就一点问题都没有……这考的是编程能力还是猜出题人意思的能力?

2021-11-21 21:28:59 星期日 今天打算19:3021:30做个pat甲级的模拟考,正好10351038的分值加起来是100.结果我93分钟就全ac了,前3题每题都刚好只用13分钟。太兴奋了,信心一下就来了,我直接膨胀起来了。今早力扣周赛只做出两题的阴霾一扫而光,我甚至开始考虑是否在今年12月9日前报名12月19日的pat甲级测试了。

2021-11-23 19:09:13 星期二 今天模拟了2020春季的PAT真题,得分83/100,排名396/1588。还挺失望的。比较有趣的是我模拟考时正好赶上服务器迁移,看不到实时排名,最后钱就退回给我了,相当于我白嫖了一次考试。 ![]( https://cutesnaketop.oss-cn-beijing.aliyuncs.com/image/gitee-img/Screen Shot 2021-11-23 at 7.10.56 PM.jpg) 本来在用Windows考试的,结果vs2019一个更新以后直接开机五分钟必卡崩,只好切回Mac,这里大概浪费了半个小时。真气死我了。这里心态就已经不太好了。或许开考前认真一点做好准备会有更好的结果吧。 这次考试一三题ac了,第二题tle,第四题两个tle一个wa。考试过程中我以为会有更高端的算法,就想到别处去了。结果看了看别人的解析,我的想法是没问题,但第二题是没用数组存路径导致速度慢了,第四题则至今不明白哪里有问题。两个题都是模拟,我恨模拟!上周力扣周赛也是第二题模拟卡了我50分钟,直接后面就没时间思考了。感觉今年冬季PAT可以一战,高分应该没问题,满分就看运气了。

2021-11-25 20:11:19 星期四 昨晚做了套真题,才47分,排名985/2701,直接锐气都没了。今晚又花了一小时做了https://pintia.cn/problem-sets/1263308065769611264 PAT 520 钻石争霸赛真题(2020-05-20),结果得分55/120,排名1351/7951,直接自信给干崩溃了。。。其实要说我真不会吗,倒不是,问题就在于很难一次写出bug-free的代码,浪费时间太多了。也许以后做题要开始限时了,把熟练度提上来。我还是很缺练习,自己之前对自己的定位或许过高了。

基于srs, node.js, express, socket.io搭建https实时聊天室直播间

2021-10-11

2021-10-11 15:20:01 星期一 demo

重要参考

https://ivampiresp.com/2020/04/05/use-the-rtmp-module-of-nginx-to-build-a-streaming-media 基本对着来就行。由于我是在网站上部署,而2021年新版本Chrome对HTTPS的执念非常之强,文中http localhost的方法在HTTPS的环境下常常就不管用了,在GitHub上翻看了很多配置文档才搞定HTTPS的配置,坑实在是太多了。

一些配置文件及常用命令

推流部分

srs配置

centos编译安装 https://github.com/ossrs/srs/wiki/v4_CN_Home#getting-started

Debian(Ubuntu应该差不多,我是用的Debian,按步骤做一点问题没有) https://www.cnblogs.com/surplus/p/15319061.html

./srs/trunk/conf/https.hls.conf

# the config for srs to delivery hls
# @see https://github.com/ossrs/srs/issues/1657#issuecomment-722971676
# @see full.conf for detail config.

listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;
http_server {
    enabled         on;
    listen          8080;
    dir             ./objs/nginx/html;
    https {
        enabled on;
        listen 8088;
        key /root/.acme.sh/binaryenfold.xyz/binaryenfold.xyz.key;
        cert /root/.acme.sh/binaryenfold.xyz/binaryenfold.xyz.cer;
    }
}
vhost __defaultVhost__ {
    hls {
        enabled         on;
        hls_fragment    10;
        hls_window      60;
        hls_path        ./objs/nginx/html;
        hls_m3u8_file   [app]/[stream].m3u8;
        hls_ts_file     [app]/[stream]-[seq].ts;
    }
}

常用命令

高分子化学

2021-10-08

不知道为什么这篇文章的图片全部显示不出来了…… 2022.4.20更新:换阿里云OSS以后全都没问题了。高分子化学也低分飘过,及格万岁!笔记懒得补了。

1 绪论

2 缩聚与逐步聚合

![]( https://cutesnaketop.oss-cn-beijing.aliyuncs.com/image/gitee-img/Screen Shot 2021-11-09 at 7.05.34 PM.jpg) ![]( https://cutesnaketop.oss-cn-beijing.aliyuncs.com/image/gitee-img/Screen Shot 2021-11-09 at 7.05.58 PM.jpg)

3 自由基聚合

![]( https://cutesnaketop.oss-cn-beijing.aliyuncs.com/image/gitee-img/Screen Shot 2021-11-09 at 7.03.05 PM.jpg)

4 自由基共聚合

![]( https://cutesnaketop.oss-cn-beijing.aliyuncs.com/image/gitee-img/Screen Shot 2021-11-09 at 7.04.55 PM.jpg)

如何为Mac新增词典

2021-10-01

2022.4.22更新:本文配图已全挂,致歉。

已经看了两个多月英文原版的csapp了,过程中深感Macbook触控板用力按压直接出翻译的方便: 但是Mac内置的词典十分鸡肋,老查不到词,因此搜索了一番,找到了方法,记录一番。

1 下载词典

以下是词典链接: http://download.huzheng.org/zh_CN/ 下好以后不要动,下一步里面原封不动拖进去。

2 导入词典

需要下载app。 旧版的DictUnifier已不再维护,升级至Catalina或big sur后拖入字典后会闪退。以下是macOS Catalina和big sur都能用的版本(注意只能用拖入的方式导入新词典,拖完以后默认即可): https://github.com/jjgod/mac-dictionary-kit/files/4176459/DictUnifier.zip 如果有兴趣或者问题的话,可以看GitHub上的讨论: https://github.com/jjgod/mac-dictionary-kit/pull/4

3 设置词典

在启动台(Launchpad)里面找到字典应用(当然cmd+space 输入 dictionary也可),打开,cmd+,打开系统偏好设置, 把需要的词典拖动至最上方即可。

4 总结

会看GitHub能解决非常多的问题。参考链接底下好多人都因为不会看GitHub就卡住了。

参考链接:https://www.jianshu.com/p/c57be986589b

CMU15-213 cache lab

2021-09-23

#part A 2021-09-23 22:18:42 星期四

#include <stdio.h>  //printf()
#include <time.h>  //clock_t
#include <stdlib.h>  //atoi()
#include <getopt.h>  //getopt()
#include "cachelab.h"

typedef struct 
{
    unsigned tag;    /* tag bits per line */
    _Bool valid;     /* 1 valid bit per line */
    clock_t stamp;   /* time stamp, to implement LRU algorithm */
}cache_line;

cache_line** init_cache(int s, int E) {
    /* cache size = S(=2^s sets per cache) * E(lines per set) * B(=2^b bytes per block)
     * we use cache_line_size here instead of B
     */
    int sets_cnt = 1<<s, cache_line_size = sizeof(cache_line);
    
    /* cache_line** cache is a two dimensional array, and cache[i] means
     * the ith set in the cache.
     */
    cache_line** cache = (cache_line**) malloc(cache_line_size * sets_cnt);
    
    for(int i = 0; i < sets_cnt; ++i) {
        int set_size = cache_line_size * E;
        //initial the ith set
        cache[i] = (cache_line*) malloc(set_size);
        //the for loop can be replaced by
        //memset(cache[i], 0, set_size)  //#include <string.h>
        for(int j = 0; j < E; ++j) {
            cache[i][j].tag = 0;
            cache[i][j].valid = 0;
            cache[i][j].stamp = 0;
        }
    }
    return cache;
}

void free_cache(cache_line** cache, int s) {
    int sets_cnt = 1<<s;
    for(int i = 0; i < sets_cnt; ++i) {
        free(cache[i]);
    }
    free(cache);
}

_Bool set_insert(cache_line* set, unsigned long tag, int E) {
    int old_stamp_index = 0;
    for(int i = 0; i < E; ++i) {
        if(set[i].stamp < set[old_stamp_index].stamp) old_stamp_index = i;
        if(!set[i].valid) {
            set[i].valid = 1;
            set[i].tag = tag;
            set[i].stamp = clock();
            return 0;
        }
    }
    //all lines valid, evict the Least-Recent-Used
    set[old_stamp_index].tag = tag;
    set[old_stamp_index].stamp = clock();
    return 1;
}

//hit=1, miss=0
_Bool set_inspect(cache_line* set, unsigned tag, int E) {
    for(int i = 0; i < E; ++i) {
        if(set[i].valid && set[i].tag == tag) {
            //hit, renew time stamp
            set[i].stamp = clock();
            return 1;
        }
    }
    //miss
    return 0;
}

void cache_simulate(cache_line** cache, char type, unsigned address,
                    int bytes, int s, int E, int b, int v, 
                    int* hits, int* misses, int* evictions) {
    //address = tag + set index + block offset
    //unsigned int has 32 bits
    unsigned tag = address>>s>>b, set_index = address<<(32-b-s)>>(32-s);
    cache_line* set = cache[set_index];
    _Bool hit_or_not = set_inspect(set, tag, E), eviction_or_not = 0;
    if(!hit_or_not) {
        eviction_or_not = set_insert(set, tag, E);
    }

    //print detailed info
    if(v) {
        printf("%c %x,%d", type, address, bytes);
        if(hit_or_not) {
            printf(" hit");
        } else {
            if(eviction_or_not) printf(" eviction");
            printf(" miss");
        }
        if(type == 'M') printf(" hit");
        printf("\n");
    }

    //summary
    if(type == 'M') ++*hits;
    if(hit_or_not) ++*hits;
    else ++*misses;
    if(eviction_or_not) ++*evictions;
}

void print_usage(){
    printf(
        "Usage: ./csim [-hv] -s <num> -E <num> -b <num> -t <file>\n"
        "Options\n"
        "  -h        Print this help message.\n"
        "  -v        Optional verbose flag.\n"
        "  -s <num>: Number of set index bits.\n"
        "  -E <num>: Number of lines per set.\n"
        "  -b <num>: Number of block offset bits.\n"
        "  -t <file>: Trace file.\n"
        "\n"
        "Exampes:\n"
        "  linux> ./csim -s 4 -E 1 -b 4 -t traces/yi.trace\n"
        "  linux> ./csim -v -s 8 -E 2 -b 4 -t traces/yi.trace\n"
    );
}

int main(int argc, char** argv) {
    //no arg
    if(argc == 1) {
        printf("./csim-ref: Missing required command line argument\n");
        print_usage();
        return 0;
    }

    /* access command line */
    int s, E, b, v = 0;
    char ch;
    char* file_path;
    while((ch = getopt(argc, argv, "s:E:b:t:vh")) != -1) {
        switch(ch) {
            case 's':
                s = atoi(optarg);
                break;
            case 'E':
                E = atoi(optarg);
                break;
            case 'b':
                b = atoi(optarg);
                break;
            case 't':
                file_path = optarg;
                break;
            case 'v':
                v = 1;
                break;
            case 'h':
                print_usage();
                return 0;
            default:
                break;
        }
    }

    //initialize cache
    cache_line** cache = init_cache(s, E);

    //open file
    FILE* fp = fopen(file_path, "r");//r: read only
    if(!fp) {
        printf("%s: No such file or directory\n", file_path);
        return 1;
    }

    //file format: S 7ff000398,8

    /* read file */
    char type;
    unsigned address;
    int bytes, hits = 0, misses = 0, evictions = 0;
    while(fscanf(fp, " %c %x,%d", &type, &address, &bytes) != EOF) {
        if(type == 'I') continue;
        //enter core function
        cache_simulate(cache, type, address, bytes, s, E, b, v,
                        &hits, &misses, &evictions);
    }
    fclose(fp);
    printSummary(hits, misses, evictions);

    free_cache(cache, s);
    return 0;
}

运行结果:

化工传质与分离过程

2021-09-22

1 传质过程基础

费克第一定律,传质微分方程(略),做题:求摩尔通量,摩尔平均速度,质量通量,扩散通量 典型题 其中,质量衡算方程相等两边分别是从左向右积分和从管壁向中心积分。

2 气体吸收

气膜阻力/总阻力=(1/KG)/(1/kG)

2021-10-22 15:40:27 星期五

2021-10-23 20:00:04 星期六

csapp notes, chapter 6, Memory Hierarchy

2021-09-21

2021-09-21 11:58:26 星期二

这块不是很懂其意义所在,就算文中说把set index bits放在前面是“inefficient use of the cache”,但两者hit,miss,eviction次数是一样的,用时也是一样的。我能想象到体现区别的情况是按顺序读完前4个地址后后面全部随机跳着读,这样middle bits才能体现出速度上的优势,不过真的有这种读法存在的可能性吗

csapp notes, chapter4: Processor Architecture

2021-09-13

Sequential Y86-64 Implementations

Organizing Processing into Stages

Fetch. The fetch stage reads the bytes of an instruction from memory, using the program counter (PC) as the memory address. From the instruction it extracts the two 4-bit portions of the instruction specifier byte, referred to as icode (the instruction code) and ifun (the instruction function). It possibly fetches a register specifier byte, giving one or both of the register operand specifiers rA and rB. It also possibly fetches an 8-byte constant word valC. It computes valP to be the address of the instruction following the current one in sequential order. That is, valP equals the value of the PC plus the length of the fetched instruction.

CMU15-213 Architecture Lab

2021-09-10

2021-09-10 21:15:08 星期五 这是csapp里面关于callee-saved registers怎么用的讲解。当时看得还是不明就里,现在已经做了2个汇编相关的lab,才明白它确实讲得非常清楚。

题外话,图床改从这里传的了,现在看到图片的网址是https://s.pc.qq.com/tousu/img/20210910/8986371_1631279936.jpg 我的内心:@&¥%……&@#¥……&*(qq投诉emmmmmmmmm希望不会挂掉……)

part A

基础不牢,地动山摇。今晚在用Y86-64汇编语言实现以下c代码的时候,

long rsum_list(list_ptr ls)
{
    if (!ls)
	return 0;
    else {
	long val = ls->val;
	long rest = rsum_list(ls->next);
	return val + rest;
    }
}

因为搞不明白callee saved register怎么用,还有push和pop还有一点模糊的地方,到最后还是参考了别人的代码才能写对,唉。

rsum_list:
        pushq %rbp
	    irmovq $0,%rax
        andq %rdi,%rdi
	    je return
        mrmovq 0(%rdi),%rbp  #ls->val
        mrmovq 8(%rdi),%rdi  #ls->next
        call rsum_list
        addq %rbp,%rax
return:
        popq %rbp
        ret

再次题外话,别人做这个lab是

我趁着考完期中的空闲时间,花了近一天时间啃了下第四章,并顺便做了个下这个 Architecture Lab。

而我光是配环境就是2个小时,到现在6.5h了才做完part A(一共3个part)的前两个函数(一共3个函数),还全是抄的自己完全做不出来,真是差距巨大啊orz

cs自学路径

2021-09-01

DONE

学习

程序设计基础

南开大学大一上学期通识必修课,学习C++基础,考试基本是C++语法。大作业做了个简单的struct存储各种物质的化学能量信息,通过输入化学式可以计算各种反应的熵变焓变等信息。在什么也不会的时候,助教提出我们可以用结构体来存数据,在当时的我看来宛如变魔法一般。这个助教后来去了北大化院直博,是真牛人。

数据结构与算法

南开大学大一下学期通识必修课,学习C++继承多态等特性以及链表、栈等数据结构。内容非常多,难度非常大,当时学得完全是一知半解。大作业用paddlepaddle平台调用百度的api做了个视频抠图换背景,参加中国大学生计算机设计大赛(好像是这个名)拿了天津二等奖,老师也大笔一挥给了大作业一个满分。

Stanford CS106B: Programming Abstractions

大二下学期自学课程。本来该从CS106A学起的,但前面两门课的基础让我觉得CS106A太过简单了。CS106B这门课我主要的时间都花在读懂作业题目和做作业上,算是数据结构比较进阶一点的课程,会介绍字典、压缩等知识,同时会介绍一点点dfs之类的算法,作业还是非常有趣的。

CMU15-213

大二升大三暑假开始。配套教材是大名鼎鼎的csapp(Computer Systems: A Programmer’s Perspective)。同时啃英文原版的书同时做lab,进展缓慢。

刷题

LeetCode

大二升大三暑假开始接触,大三上开学以后基本保持每天两题的频率。先刷hot100.

TODO

学习

15213结束之后,

  1. Stanford cs144计算机网络
  2. mit6.s081操作系统
  3. mit18.06线性代数
  4. cmu15445数据库系统设计。

刷题

力扣hot100结束后,

  1. 刷力扣top100
  2. 刷pat155题