快乐冲浪与生活

多体验、多体会、多体悟

0%

本文主要介绍如何基于 Docker 生成容器化应用以及配置 Nginx 来实现 Web 服务的负载均衡,包含以下内容:

  1. Go 简易 Web 程序(hello world)
  2. 通过 Dockerfile 生成镜像
  3. Nginx 配置
  4. Docker Compose 多容器启动

Go Web 程序

本次配置使用 Go Web 程序作为后端服务,其作用是接收请求并返回“hello-world”,代码如下:

Series 和 DataFrame 是 Pandas 中两种重要的数据结构,也是我们操作和分析的主要对象。其中 Series 是一种类似于数组、列表或表格中一列的 一维数据对象,DataFrame 则可以表示表格化的数据对象,可由多个 Series 对象组成。

本文主要摘录 Series 和 DataFrame 两种数据结结构的创建方法以及一些注意事项。

django.forms 包提供了 HTML 表单验证的功能,在没有使用 DRF 的情况下,无法合理地处理 API 传参的验证,其中传参验证中就缺少了参数默认值的设置。

层次结构

django.forms 包提供的 Field 类如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
__all__ = (
    'Field', 'CharField', 'IntegerField',
    'DateField', 'TimeField', 'DateTimeField', 'DurationField',
    'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField',
    'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField',
    'ComboField', 'MultiValueField', 'FloatField', 'DecimalField',
    'SplitDateTimeField', 'GenericIPAddressField', 'FilePathField',
    'JSONField', 'SlugField', 'TypedChoiceField', 'TypedMultipleChoiceField',
    'UUIDField',
)

继承关系如下图:

原文: Error handling and Go

介绍

如果你写过 Go 的代码,就一定遇到过 Go 的内置类型 error。一个 error 类型的值可用于指明程序的某种不正常的状态,比如,当打开文件失败时,os.Open 函数会返回一个非 nil 的 error 值。

PAT 甲级 1003 。

 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
# -*- coding:utf-8 -*-

if __name__ == '__main__':
    # n 树中节点个数
    # m 非叶子节点个数
    n, m = list(map(int, input().strip().split(' ')))
    # 二维数组
    # 元素的下标表示节点的 ID
    # 第 1 个元素不使用
    tree = [[] for _ in range(n+1)]
    while m != 0:
        tokens = list(map(int, input().split(' ')))
        _id = tokens[0]
        children = tokens[2:]
        tree[_id] = children
        m = m - 1

    # 记录每一层叶子节点的数量
    counts = [0 for _ in range(n+1)]
    # 记录最大深度
    max_depth = 0

    def dfs(i, depth):
        global max_depth, counts, tree

        if len(tree[i]) == 0:  # 节点 i 为叶子节点
            counts[depth] = counts[depth] + 1
            max_depth = max(depth, max_depth)
            return
        for j in tree[i]:
            dfs(j, depth + 1)

    dfs(1, 0)

    print(' '.join([str(count) for count in counts[:max_depth+1]]))

测试点 4 没过,应该是没有理解 The input ends with N being 0. That case must NOT be processed. 的原因,因为不知道要输出什么。