The Framework of Backtracking Algorithm Problems (DFS)

This paper addresses several questions.

What is the backtracking algorithm? What are the techniques for solving problems related to backtracking algorithms? How do I learn backtracking algorithms? Is there a pattern to the backtracking algorithm code?

The backtracking algorithm is actually what we often call the DFS algorithm, which is essentially a violent exhaustive enumeration algorithm.

Read more...

The Framework of Solving Dynamic Programming Problems

Dynamic Programming is a problem for many people, but it is also one of the most skillful and interesting strategies. This article gives a partial overview of these problems, plus a framework for solving dynamic programming.

This paper addresses several questions.

What is dynamic programming?

What are the techniques for solving dynamic programming problems?

How can I learn dynamic programming?

Read more...

The difference between this.\$store.dispatch() and this.\$store.commit() in vuex

Difference

The difference between this.$store.dispatch() and this.$store.commit() methods is that in general they are only different in the way values are accessed, both methods pass the value to vuex’s mutation to change the state.

  • this.$store.dispatch(): contains asynchronous operations, such as submitting data to the background, written: this.$store.dispatch('action method name', value)
  • this.$store.commit(): synchronous operation, written: this.$store.commit('mutations method name', value)
Read more...

Deploy Github Actions

Sometimes automated deployment projects or timed tasks need to be deployed online, but these are for temporary use or these lightweight applications do not warrant the additional purchase of a cloud server for deployment. This is when you might consider using Github Actions for automated deployments.

GitHub Actions[1] is GitHub’s continuous integration service[2], launched in October 2018[3]. It is very powerful in that each action is used to perform an action, such as grabbing code, running tests, logging into a remote server, publishing to a third-party service, and so on. Combining these actions is a process of continuous integration. Of course, these actions are shared in the GitHub code repository, so we can refer to them directly.

Github Actions provides a complete server environment with the following server specifications

  • 2-core CPU
  • 7 GB RAM memory
  • 84 GB of SSD hard disk space

Detailed system environment information is shown in the following figure:


System environment information

Of course, you can use Windows Server 2019 and macOS X Catalina 10.15 in addition to Ubuntu.

Read more...

Hexo的云服务器部署

部署hexo博客到云服务器上的教程

环境部署

环境部署环节应该不需要多说,遇到问题了google之即可。

相关环境表

本地 远端欧拉 备注
nodejs nodejs node -v以及npm -v检查安装情况
git git
hexo-cli npm i hexo-cli -g安装

部署hexo

在本地安装完hexo-cli之后使用hexo检查安装成功与否。如果失败,先重新起一个命令行再尝试。

  1. 在自定义位置初始化blog文件夹:
1
2
mkdir hexo-blog
cd hexo-blog && npm init -y

公司的网执行npm i可能会失败,因为其本质是从github拉取仓库,可以直接从github下载压缩包后解压到该目录:GitHub - hexojs/hexo-starter: Hexo Starter site)

  1. 下载主题

    同以上一样,从Themes | Hexo选择合适主题下载,大部分主题都有教程如何安装。同理,如果直接使用npm无法拉取的话可以直接去github下载后放在theme文件夹下。

    在本地配置文件_config.yml文件中修改:

    1
    2
    # 这里修改为自定义主题
    theme: redefine

    注意有的主体需要新建形如_config.redefine.yml的文件进行主题的配置

  2. 本地执行hexo项目,添加start脚本

    先在package.json文件中修改:

    1
    2
    3
    4
    5
    6
    7
    "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo clean && hexo g -d",
    "server": "hexo server",
    "start": "hexo clean && hexo g && hexo s"
    },

    再使用npm start启动项目,可以在 http://localhost:4000 验证效果了

部署远端git

git的安装与配置不再详述,包括ssh认证的问题请自行解决。主要记录远端git私库的配置。

  1. ssh登录到远端服务器后,创建用户并配置其仓库:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    useradd git
    # 设置密码
    passwd git
    # 这步很重要,不切换用户后面会很麻烦
    su git
    cd /home/git/
    # 项目存在的真实目录
    mkdir -p projects/hexo-blog
    mkdir repos && cd repos
    # 创建一个裸露的仓库
    git init --bare blog.git
  2. 创建裸露仓库并配置hook

    1
    2
    3
    cd blog.git/hooks
    # 创建 hook 钩子函数,输入了内容如下
    vi post-receive
    1
    2
    #!/bin/bash
    git --work-tree=/home/git/projects/hexo-blog --git-dir=/home/git/repos/blog.git checkout -f
  3. 修改权限

    1
    2
    3
    4
    5
    chmod +x post-receive
    # 退出到 root 登录
    exit
    # 添加权限
    chown -R git:git /home/git/repos/blog.git
  4. 在本地测试git仓是否可用,在空白文件夹下发送以下命令,如果有空仓库下拉,说明git私库搭建成功:

    1
    git clone git@server_ip:/home/git/repos/blog.git
  5. 建立ssh信任关系,用于免密登录,在本地:

    1
    2
    3
    ssh-copy-id -i C:/Users/yourname/.ssh/id_rsa.pub git@server_ip
    # 测试能否登录
    ssh git@server_ip

    如果windows无法使用ssh-copy-id,参考windows无法使用ssh-copy-id解决方案

  6. (可选)安全起见禁用git用户的shell登录权限,只能通过git clonegit push等登录:

    1
    2
    3
    4
    5
    # 查看 git-shell 是否在登录方式里面
    cat /etc/shells
    # 查看是否安装
    which git-shell
    vi /etc/shells

    添加上两步显示出来的路径,通常在 /usr/bin/git-shell,随后修改/etc/passwd中的权限:

    1
    2
    3
    4
    # 将原来的
    git:x:1000:1000::/home/git:/bin/bash
    # 修改为
    git:x:1000:1000:,,,:/home/git:/usr/bin/git-shell

搭建nginx服务器

nginx的安装与配置不再赘述

  1. 配置nginx文件

    1
    2
    3
    4
    5
    6
    7
    # 先启动检查是否安装成功,浏览器查看 server_ip,默认是 80 端口
    nginx
    # 先停止nginx
    nginx -s stop
    # 可以使用nginx -t查看配置文件位置
    cd /etc/nginx/
    vim nginx.conf

    修改 root解析路径,同时将 user改为 root ,不然nginx无法访问/home/git/projects/hexo-blog。此外配置location为/的部分,自定义监听端口号。修改部分参考如下:

    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
    43
    44
    user root;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;

    include /usr/share/nginx/modules/*.conf;

    events {
    worker_connections 1024;
    }

    http {
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    client_max_body_size 100m;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
    listen 800 default_server;
    listen [::]:800 default_server;
    server_name localhost;
    root /usr/share/nginx/html;
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

        location / {
        root /home/git/projects/hexo-blog;
        index index.html index.html;
        }
    }
    }

    然后使用nginx -s reload重加载nginx配置

发布

至此我们就把本地和服务器的环境全部搭建完成,现在利用 hexo 配置文件进行链接

  1. 配置_config.yml文件中的deploy
1
2
3
4
deploy:
type: git
repo: git@server_ip:/home/git/repos/blog.git
branch: master
  1. package.json 中添加 npm 脚本

    1
    2
    3
    4
    "scripts": {
    "deploy": "hexo clean && hexo g -d",
    "start": "hexo clean && hexo g && hexo s"
    },
  2. 这下在本地调试就用npm start,调试好了就使用npm run deploy部署到服务器。即可通过server_ip:port/location进行访问了

    如果遇到上传不上的情况,在远端先rm删除分支,再创建_config.yml中配置的分支即可。

  • Copyrights © 2019-2024 鞠桥丹-QIAODAN JU
  • 访问人数: | 浏览次数:

请我喝杯蓝莓汁吧~

支付宝
微信