小编Reb*_*375的帖子

S3亚马逊静态网站与React?

我使用ReactJs构建了一个网站,为了查看网站,我通常会在npm开始并通过浏览器转到localhost:3000.

我现在想在S3上托管这个网站,但没有EC2实例.我的理解是npm是一个进程,所以它是服务器端的,因此,我需要购买计算才能实际部署我的网站.

我发现本教程没有提到支付EC2实例计算时间:https://www.fullstackreact.com/articles/deploying-a-react-app-to-s3/

然而,他们仍然使用NPM让我感到困惑.

我的问题是:如果我只使用静态S3网站,没有计算,是否可以使用React,如果是这样 - 我如何绕过NPM流程?

React - 单独脚本中的组件不起作用

在上面的帖子中,用户尝试制作一个hello-world应用程序,但所有答案都指向了使服务器提供内容的方向.我认为react是一个前端的东西,可以在没有服务器端进程的情况下运行.这是真的?有人可以解释为什么node.js是必要的或者与react配对,以及是否可以在没有ec2计算的情况下使用s3做出反应?

amazon-s3 amazon-ec2 reactjs

6
推荐指数
1
解决办法
1517
查看次数

联合作为 C 中函数的参数

我想知道是否可以使用联合作为函数的参数:

假设我有两个结构:

struct complex_attribute{
    struct generic_attribute *sub_attributes[20];
};

struct generic_attribute{
    int current_value;
};
Run Code Online (Sandbox Code Playgroud)

以及这两者的结合:

union union_attribute{
    struct complex_attribute *complex;
    struct generic_attribute *generic;
};
Run Code Online (Sandbox Code Playgroud)

我想创建一个接受 complex_attribute 或 generic_attribute 的函数:

struct tagged_attribute* prepare_tagged_attribute(int code, union union_attribute *attribute)
Run Code Online (Sandbox Code Playgroud)

但是,当我调用此函数时

prepare_tagged_attribute(2, pointer_to_complex_structure);
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

 passing argument 2 of ‘prepare_tagged_attribute’ from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)

所以我认为指向复杂结构的指针不一定是联合类型的指针(这是有道理的)……但是有可能以这种方式使用联合吗?

c structure function unions

5
推荐指数
2
解决办法
5034
查看次数

将整数与在 python 中的单元测试中不起作用的 MagicMock 进行比较

我有一个类,它使用类变量来选择要执行的逻辑。

#in file1:

class SomeHelper():
    def __init__(self):
        self.my_var = 0

#in file2: 
import file1
class MyClass():
    ...
    ...
    def calculate():
        inst = file1.SomeHelper()
        if x > inst.my_var:
           etc etc
Run Code Online (Sandbox Code Playgroud)

我正在编写一个单元测试并在另一个文件中模拟 SomeHelper():

from file 2 import MyClass
# tried both
@patch('file2.file1') OR @patch('file2.file1.SomeHelper')
def test_calculate(self, mock_helper):
    mock_helper.my_var = 0
    to_test = MyClass.calculate()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

类型错误:“MagicMock”和“int”的实例之间不支持“>”。

我以为我是my_var在修补模块后定义的。

python mocking python-unittest magicmock

5
推荐指数
1
解决办法
7776
查看次数

基于列数据生成列描述的优雅方法

我有一个pandas数据帧:

index    data1    data2
1        30       20
2        20       10  
3        40       90
Run Code Online (Sandbox Code Playgroud)

我想生成一个描述数组,每行一个,指示数据是否重要.

我定义重要值超过25,所以我想要以下数组:

['data1 was significant', '',  'data1 was significant\ndata2was significant']
Run Code Online (Sandbox Code Playgroud)

我知道我可以遍历每一行并检查每一列并构建一个数组,但我想知道是否有一种优雅的方法来使用pandas来做到这一点.

python list dataframe pandas

3
推荐指数
1
解决办法
103
查看次数

C中的双到int转换

我有一个结构变量运行状况,可以作为disk-> health访问,它是double类型.我试图将其打印为double,然后将其转换为int并再次打印.

printf("The disk health in loop is: %lf\n", disk_ptr->health);
//result is: 13230000014.560297
printf("The disk health in loop is: %i\n", (int) floor(disk_ptr->health));
//result is: -2147483648
printf("The disk health in loop is: %d\n", (int) floor(disk_ptr->health));
//result is: -2147483648
Run Code Online (Sandbox Code Playgroud)

上面的代码是我正在使用的.我希望输出第二个结果:13230000014,但它给了我一个奇怪的负数.

c double int type-conversion

0
推荐指数
2
解决办法
88
查看次数

在C中读取文件:"r"和"a +"标志的不同行为

我想打开一个文件,读取其内容,然后在文件中附加一行.我以为我应该使用"a +"标志来完成任务.

我有一个打开文件并返回指向该文件的指针的函数.

FILE* open_weekly_disk_file(char* filename){
    FILE* weekly_log;

    weekly_log = fopen(filename, "a+");
    //weekly_log = fopen(filename, "r");

    if(! weekly_log){
        printf("The attempt to open the weekly log failed!\n");
        return NULL;
    } else{
        return weekly_log;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我有一个函数调用上面的函数并使用scanf从文件中读取内容:

void sample_function(char* filename){
    FILE* log;
    char token[100], current_read[100];
    int limit;

    log = opened_weekly_disk_file(filename);
    // The problem happens here
    for(limit=0; limit < TOKEN_NUMBER; limit++){
        if(fscanf(log, "%s%s", &token, &current_read) == 2){
            printf("%s %s\n", token, current_read);
        }
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

我使用时此代码有效:

weekly_log = fopen(filename, "r");
Run Code Online (Sandbox Code Playgroud)

但是当我将"r"标志更改为"a +"时不起作用.我在for循环之前得到了一个Segmentation错误.

c file append readfile

0
推荐指数
2
解决办法
318
查看次数