读《长安的荔枝》

  • 为什么李善德想放弃这个任务而去逃命
  • 杜甫是怎么安慰李善德的
  • 到了岭南之后,李善德是怎么找到钱的
  • 李善德是怎么找到最会种荔枝的人的
  • 李善德是怎么记录荔枝运输情况与荔枝味道变化情况的
  • 为什么岭南的官想要杀害李善德
  • 李善德是怎么认识杨国忠的
  • 为什么完成了任务,李善德没有获得奖赏反而被发配到岭南
  • 被发配到了岭南,反而避免了长安失守的影响,是福是祸

小爹教我的知识

  • 小爹是我们老家对奶奶的称呼
  • 算盘口诀
  • 小爹版本的鸡兔同笼

鸡蛋

  • 有一次和小爹一起在中百仓储卖菜的区域逛,看到标着土鸡蛋的鸡蛋,奶奶说这不是土鸡蛋,我纠正说这里写着是土鸡蛋,后来想到奶奶每天和鸡打交道,不用看字直接看鸡蛋就能知道是不是土鸡蛋

前端知识体系

前端知识体系

javascript基础语法

Angular中使用到的Observable和RxJS

TypeScript

UI

visual studio code

leetcode733图像渲染刷题笔记

图像渲染

有一幅以 m x n 的二维整数数组表示的图画 image ,其中 image[i][j] 表示该图画的像素值大小。
你也被给予三个整数 sr , sc 和 newColor 。你应该从像素 image[sr][sc] 开始对图像进行 上色填充 。
为了完成 上色工作 ,从初始像素开始,记录初始坐标的 上下左右四个方向上 像素值与初始坐标相同的相连像素点,接着再记录这四个方向上符合条件的像素点与他们对应 四个方向上 像素值与初始坐标相同的相连像素点,……,重复该过程。将所有有记录的像素点的颜色值改为 newColor 。
最后返回 经过上色渲染后的图像 。

题目分析

列出自己想到的线索

  • 维护一个存储要检查的点的集合,toBeChecked

根据题解进行分析

  • 题解里看到这道题的最佳解法是使用DFS(深度优先搜索)
  • 搜索了一下DFS,DFS里可以通过自己调用自己的方法,也就是递归来实现

递归

  • 递归的特点就是自己调用自己
  • 递归由两部分组成:(1)递归操作 (2)递归终止条件

一个最简单的递归

  • 计算从1,2,3公差为1的等差数列前n项和的程序
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    /**
    * 递归操作,进行一次加法操作
    * 递归终止条件,当前的数字等于1
    */
    public int sum(int n) {
    int sum = 0;
    if (n == 1) {
    sum += 1;
    } else {
    sum = sum(n - 1) + n;
    }
    return sum;
    }

递归增加

  • 计算从1,7,13公差为6的等差数列前n项和的程序
    1
    2
    3
    4
    5
    6
    7
    8
    9
    public int sum6(int n){
    int sum = 0;
    if(n == 1){
    sum += n;
    }else{
    sum = sum6(n - 6) + n;
    }
    return sum;
    }

使用递归来解决这道题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @param image 二维数组来代表原始的图片
* @param sr 目标点的行号
* @param sc 目标点的列号
* @param color 目标点的新颜色
* @return 上好色的图片
*/
public int[][] floodFill(int[][] image, int sr, int sc, int color) {
int oldColor = image[sr][sc];
dfs(image, oldColor, sr, sc, color);
return image;
}

/**
* 递归
* 递归操作:
* 1. dfs 行号 - 1
* 2. dfs 行号 + 1
* 3. dfs 列号 - 1
* 4. dfs 列号 + 1
* 递归终止条件:
* 1. 当前的行号<0
* 2. 当前的列号<0
* 3. 当前的行号>行长
* 4. 当前的列号>行宽
* 5. 当前的颜色不等于oldColor
* 6. 当前的颜色等于新颜色
* return;
*/
public void dfs(int[][] image, int oldColor, int sr, int sc, int newColor) {
int rLength = image.length;
int cLength = image[0].length;
if(sr < 0 || sc < 0 || sr >= rLength || sc >= cLength || image[sr][sc] != oldColor || image[sr][sc] == newColor){
return;
}
image[sr][sc] = newColor;

dfs(image, oldColor, sr - 1, sc, newColor);
dfs(image, oldColor, sr + 1, sc, newColor);
dfs(image, oldColor, sr, sc - 1, newColor);
dfs(image, oldColor, sr, sc + 1, newColor);
}

二叉树的前序遍历、中序遍历、后续遍历

  • dfs深度优先搜索最基础的应用应该就是用在二叉树的前中后序遍历上
  • 如下为通过递归实现二叉树前序遍历的代码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    /**
    * Definition for a binary tree node.
    * public class TreeNode {
    * int val;
    * TreeNode left;
    * TreeNode right;
    * TreeNode() {}
    * TreeNode(int val) { this.val = val; }
    * TreeNode(int val, TreeNode left, TreeNode right) {
    * this.val = val;
    * this.left = left;
    * this.right = right;
    * }
    * }
    */
    class Solution {
    private List<Integer> list = new ArrayList<>();

    public List<Integer> preorderTraversal(TreeNode root) {
    if(root != null){
    list.add(root.val);
    }

    if (root != null && root.left != null) {
    preorderTraversal(root.left);
    }

    if (root != null && root.right != null) {
    preorderTraversal(root.right);
    }
    return list;
    }
    }

八皇后问题

  • 题目
    1
    2
    3
    4
    5
    class Solution {
    public List<List<String>> solveNQueens(int n) {

    }
    }

题意

  • 入参n代表棋盘行的个数,列的个数,要摆放的皇后的个数
  • 输出字符串集合,点表示不放置棋子,Q表示放置皇后

解题思路

  • 定义属性,二维数组board[n][n], 解法编号count
  • 定义行为,isValid(), printBoard

spring framework中进行AOP编程

通过注解实现面向切片编程的核心步骤

  • 定义注解
  • 实现解析注解的代码
  • 使用注解

定义注解

声明的方式

  • 对于JavaType.java文件,我们常用的是用来声明类(class)或接口(interface)
    1
    2
    public class JavaType{
    }
    或者
    1
    2
    public interface JavaType{
    }
    这里我们使用@interface来定义一个annnotation注解
    1
    2
    public @interface JavaType{
    }

在@interface上使用注解

@Target注解
  • 用来声明注解的使用目标,常见@Target的值有:ElementType.Method用于方法,ElementType.Type用于类型(包括java类、接口、注解), ElementType.Parameter用于方法参数,还有更多枚举可以从ElementType中找到具体定义
    1
    2
    @Target(ElementType.METHOD)
    public interface JavaType{}
@Retention注解
  • 使用有道词典翻译是保持力的名词意思,此注解的@Target声明的是ANNOTATION_TYPE,用于为注解类型提供声明
  • @Retention配置的值从RetentionPolicy.java枚举中选择,可选值为SOURCE,CLASS,RUNTIME
  • SOURCE定义的注解保留在源代码中,不编译到Class中去,如@Override和@SuppressWarnings注解使用本策略
  • CLASS定义的注解会保留到class文件,但是运行期间不会识别此注解
  • RUNTIME定义的注解会被保留到class文件中,同时运行期间也会被识别,AOP中使用的注解一般情况下使用本策略
@Documented
  • 用于javadoc的一个注解,声明注解时使用了本注解时,在到处javadoc时,在javadoc中就能看到目标的注解声明

在一个注解中定义方法

  • 定义一:基本使用,使用default关键字
    1
    2
    3
    4
    5
    6
    7
    8
    import java.lang.annotation.*;

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface JavaType {
    String value() default "";
    }
  • 使用一
    1
    2
    3
    4
    public class Test{
    @JavaType("value")
    public void typeA(){}
    }
  • 关键字default指定默认值,默认值必须是与元素的数据类型兼容的类型
  • 定义二: 使用枚举
    1
    2
    3
    4
    5
    6
    7
    8
    import java.lang.annotation.*;

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface JavaType {
    RetentionPolicy value() default RetentionPolicy.RUNTIME;
    }
  • 使用二
    1
    2
    3
    4
    5
    6
    7
    import java.lang.annotation.RetentionPolicy;

    public class Test {
    @JavaType(RetentionPolicy.CLASS)
    public void typeA() {
    }
    }
  • 定义三:使用数组
    1
    2
    3
    4
    5
    6
    7
    8
    import java.lang.annotation.*;

    @Target(ElementType.ANNOTATION_TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface Target {
    ElementType[] value();
    }
  • 使用三
1
2
3
4
5
6
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target({ElementType.METHOD, ElementType.TYPE})
public @interface JavaType {
}

webgoat环境搭建

芹菜炒香肠

为什么想写研究webgoat,想写这篇文章

  • 最近听到一个词,叫“bounty hacker”,赏金黑客,通过提交安全漏洞获得赏金的人,这种挣钱方式看起来很酷,webgoat又是开源的由java开发的web靶场,所以就开始了

环境搭建

  • webgoat就是一个java web工程,用启动java web的方式启动就可以

Git教程

git知识

Git快速上手

  • git的仓库:Github、gitee、腾讯云Coding等等
  • 【fork按钮】fork代码到自己的namespace
  • 【git clone】从仓库下载代码到本地:git clone https://github.com/JavaProgrammerLB/spring-framework.git
  • 【git status】查看未修改的代码
  • 【git add -A】添加修改
  • 【git commit -m “修改处理逻辑”】提交
  • 【git push】推送

.gitignore

1
2
3
4
5
6
7
# 忽略单个文件
HELP.md
# 忽略文件夹
.idea
target
# 忽略后缀特征的文件
*.iml

Git分支相关命令

  • 【列出本地分支】git branch
  • 【列出所有分支】git branch -a
  • 【创建分支】git branch dev
  • 【切换分支】git checkout dev
  • 【创建并切换到分支】git checkout -b bug_fix
  • 【把本地新建分支推送到远程的新分支】git push origin bug_fix
  • 【分支合并】git merge master

工作区、暂存区、分支

  • 【工作区】本地
  • 【暂存区】git add readme.txt
  • 【分支】git commit -m “新增readme”

将暂存区文件恢复到工作区

  • git add a.txt
  • git add b.txt
  • git reset HEAD
  • 【或】git reset HEAD a.txt

Git远程仓库

  • 【查看远程仓库】git remote
  • 【查看远程仓库和url】 git remote -v
  • 【增加远程仓库】git remote add upstream https://github.com/spring-projects/spring-framework.git
  • 【从远程仓库拉代码】git pull upstream main
  • 【把本地代码push到origin仓库】git push origin

从git init命令开始的流程

  • 【本地创建】init
    1
    2
    3
    mkdir git_repo
    cd git_repo
    git init
  • 【创建空远程仓库】https://github.com/JavaProgrammerLB/git_repo.git
  • 【绑定】
    1
    2
    git remote add origin https://github.com/JavaProgrammerLB/git_repo.git
    git remote -v
  • 【本地提交】写代码、创建好.gitignore文件
    1
    2
    3
    4
    git add .gitignore
    git add 1.txt
    git commit -m "【初始化】init"
    git push origin master

Kubernetes教程

关键词

  • pods、label、annotation、namespace

kubectl get

  • kubectl get pods
1
kubectl get pods --show-labels
  • kubectl get pods -L creation_method, env
  • kubectl get pods -l creation_method=manual
  • kubectl get pods -l env
  • kubectl get pods -l ‘!env’
  • kubectl get pods -l creation_method!=manual
  • kubectl get pods -l env in (prod, dev)
  • kubectl get pods -l env notin (prod, dev)
  • kubectl get pods -l app=pc, rel=dev
  • kubectl get nodes
  • kubectl get services
  • kubectl get secrets
  • kubectl get namespaces
  • kubectl get pods –namespace kube-system

kubectl run

  • kubectl run nginx –image=nginx
  • kubectl run k8s-tutorial-node –image yitianyigexiangfa/k8s_node_hello_world:1.0
  • kubectl run k8s-tutorial-node –image yitianyigexiangfa/k8s_node_hello_world:1.0 –port=8080

kubectl delete

  • kubectl delete pods k8s-tutorial-node
  • kubectl delete pods -l creation_method=manual
  • kubectl delete namespaces custom-namespaces
  • kubectl delete secrets regsecret
  • kubectl delete rs kubia –cascade=false

kubectl create

  • kubectl create deployment demo –image=yitianyigexiangfa/springboot-k8s-tutorial –dry-run=client -o=yaml > deployment.yaml
  • kubectl create service clusterip demo –tcp=8080:8080 –dry-run=client -o=yaml >> deployment.yaml
  • kubectl create namespace custom-namespace

kubectl apply

  • kubectl apply -f deployment.yaml

kubectl port-forward

1
2
kubectl port-forward svc/demo --address=0.0.0.0  8080:8080
kubectl port-forward k8s-tutorial-fortune --address=0.0.0.0 8080:80

kubectl config

  • kubectl config set-context kube-system-ctx –cluster=k8s-cluster1 –user=kubectl –namespace=kube-system

kubectl logs

  • kubectl logs k8s-tutorial-node
  • kubectl logs k8s-tutorial-node -c redis

kubectl label

  • kubectl label pods k8s-tutorial-node creation_method=manual
  • kubectl label pods k8s-tutorial-node env=prod –overwrite

kubectl annotation

  • kubectl annotation pods k8s-tutorial-node myCompany.com/someAnnotaion=”foo bar”

kubectl edit

  • kubectl edit replicationcontroller kubia

kubectl scale

  • kubectl scale rc kubia –replicas=3

kubectl exec

1
kubectl exec k8s-tutorial-fortune -c html-generator -- cat /var/htdocs/index.html