小编CES*_*SCO的帖子

如何使用typescript检查Angular2版本

我用angular2@2.0.0-alpha.11写了一个简单的应用程序,效果很好.现在我正在测试它的最新版本的alpha和beta avaible在npm,我一直想知道我是否真的真的改变了或者我正在缓存一些东西.

我想在我的根组件上执行类似下面的操作

export class ChromeComponent {

  ngOnInit() {
    console.log('angular version');
  }
}
Run Code Online (Sandbox Code Playgroud)

angular.version 在控制台上返回 undefined

typescript angular

24
推荐指数
2
解决办法
3万
查看次数

从包中导入所有函数:"from.*import*"

目标

我希望能够__init__.py从我的包中的每个文件导入(在)所有函数.

用法

例如在此文件夹结构中.

manage.py
- scripts/
   -- __init__.py
   -- tests.py
   -- deploy.py
Run Code Online (Sandbox Code Playgroud)

我目前正在做以下事情:

manage.py:

from scripts import *
Run Code Online (Sandbox Code Playgroud)

script/init .py:

from .tests import *
from .deploy import *
Run Code Online (Sandbox Code Playgroud)

但是,每次我在包中添加另一个文件时,我都要添加一个导入行script/__init__.py,这有点烦人.

python python-import

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

Cobra + Viper Golang如何测试子命令?

我正在使用Go开发一个Web应用程序.到目前为止一切顺利,但现在我正在将Wercker整合为CI工具并开始关注测试.但我的应用程序在很大程度上依赖于Cobra/Viper配置/ flags/environment_variables方案,我不知道在运行我的测试套件之前如何正确初始化Viper值.任何帮助将非常感激.

tdd go viper-go

10
推荐指数
1
解决办法
5859
查看次数

如何从源Python编译安装Pip

我正在运行最新的Debian的树莓派.默认情况下它配备了2.7.3,但是我买了它来运行一个大型的Flask家庭自动化应用程序,这个应用程序都是在2.7.9上编写的,我希望以后没有问题(我知道它是次要版本,但我是一个完美主义者).

所以我下载了最新的Python 2.7.10.并且做到了

./configure && make && make altinstall
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.它/usr/local/bin按照我的预期安装了解释器 .现在我需要能够运行pip install -r requirements.txt,然后我需要pip.所以我从Python网站下载了get-pip.py并尝试了

/usr/local/bin/Python2.7 get-pip.py
Run Code Online (Sandbox Code Playgroud)

没有运气.我也尝试使用不同的编译Python解释器来创建virtualenv

virtualenv -p /usr/local/Python2.7 venv
Run Code Online (Sandbox Code Playgroud)

也没有运气.我能够在我编译的Python上安装easy_install,但是当我尝试时它也会抛出一个错误

/usr/local/bin/easy_install pip
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我已经阅读了关于首先配置Python的--ensurepip标志,但我是否需要删除Python并重新安装它只是为了让我的编译解释器?

python debian pip python-2.7 raspberry-pi2

9
推荐指数
1
解决办法
5691
查看次数

使用Flask动态安排Celery Beat任务

我希望能够让我的应用程序的用户启动/停止Celery beat定期的crontab样式任务.现在我用Celery运行

venv/bin/celery worker -A celery_worker.celery --loglevel=info
Run Code Online (Sandbox Code Playgroud)

我用这个简单的例子运行了Celery Beat:

@celery.task
def add(x, y):
    return x + y
Run Code Online (Sandbox Code Playgroud)

在我的配置文件中:

CELERYBEAT_SCHEDULE = {
    'add-every-30-seconds': {
        'task': 'app.email.add',
        'schedule': timedelta(seconds=30),
        'args': (16, 16)
    },
}
CELERY_TIMEZONE = 'UTC'
Run Code Online (Sandbox Code Playgroud)

然后我用Celery击败了Celery

celery -A celery_worker.celery beat -s ~/Documents/cesco-automation/power/celerybeat-schedule
Run Code Online (Sandbox Code Playgroud)

而且效果很好!但我需要更多地控制时间表.

同样在我的app shell上,我能够做到这一点.

>>>add.apply_async([80,800],countdown=30)

>>> from datetime import datetime, timedelta     
>>> tomorrow = datetime.now() + timedelta(days=1)
>>> add.apply_async(args=[10, 10], eta=tomorrow)
Run Code Online (Sandbox Code Playgroud)

这很棒,但我正在开发一个家庭自动化应用程序,所以我还需要停止任务.我该怎么做呢??

我还发现这个链接提及有关Django的自定义调度类.这正是我需要的.在Celery文档中,它提到了-S标志,但我不知道如何正确地将类添加到我的Flask应用程序中.我怎样才能和Flask一起使用?

我真的需要Celery Beat吗?除了crontab还有其他选择吗?Crontab似乎不够锐利.

django celery flask python-2.7 celerybeat

8
推荐指数
1
解决办法
3875
查看次数

如何判断我的容器是否在Kubernetes集群中运行?

如何判断我是否在kubernetes集群中运行?使用泊坞窗,我可以检查是否/.dockerinit存在。有等同的吗?

kubernetes

8
推荐指数
3
解决办法
4565
查看次数

如何在Typescript中使用React useRef钩子?

使用新的useRef钩子创建引用

const anchorEl = React.useRef<HTMLDivElement>(null)

并使用像

<div style={{ width: "15%", ...flexer, justifyContent: "flex-end" }}>
    <Popover
        id="simple-popper"
        open={open}
        anchorEl={anchorEl}
        onClose={() => {
          setOpen(false)
        }}
        anchorOrigin={{
          vertical: 'bottom',
          horizontal: 'center',
        }}
        transformOrigin={{
          vertical: 'top',
          horizontal: 'center',
        }}
    >
        <Typography>The content of the Popover.</Typography>
    </Popover>
</div>
<div ref={anchorEl} >
      ...
Run Code Online (Sandbox Code Playgroud)

但是我得到这个错误

TS2322: Type 'MutableRefObject<HTMLDivElement>' is not assignable to type 'HTMLElement | ((element: HTMLElement) => HTMLElement)'.
  Type 'MutableRefObject<HTMLDivElement>' is not assignable to type '(element: HTMLElement) => HTMLElement'.
    Type 'MutableRefObject<HTMLDivElement>' provides no match for the …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs typescript-typings react-hooks

8
推荐指数
2
解决办法
4437
查看次数

Webpack 2代码分割与服务器端渲染和React-Router-v4

使用webpack2.2.0-rc1并对routerv4做出反应,并使用此要点使代码拆分工作,其中说明以下内容

function asyncComponent(getComponent) {
  return class AsyncComponent extends React.Component {
    static Component = null;
    state = { Component: AsyncComponent.Component };

    componentWillMount() {
      if (!this.state.Component) {
        getComponent().then(Component => {
          AsyncComponent.Component = Component
          this.setState({ Component })
        })
      }
    }
    render() {
      const { Component } = this.state
      if (Component) {
        return <Component {...this.props} />
      }
      return null
    }
  }
}

const Foo = asyncComponent(() =>
  System.import('./Foo').then(module => module.default)
)
Run Code Online (Sandbox Code Playgroud)

它确实有效,但我正在使用服务器端渲染.所以在服务器上我需要组件A,然后在客户端I System.import组件A.当我访问延迟加载的路由时,我得到这个反应重用标记警告,因为客户端呈现最初从https://gist.github加载null .com/acdlite/a68433004f9d6b4cbc83b5cc3990c194#file-app-js-L21 加载组件A. Warning: React attempted to reuse …

javascript node.js universal reactjs code-splitting

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

如何为 Azure 服务编写 MassTransit Json 解串器

这是我将对象发布到事件网格的方式。我希望能够使用azure服务总线来收听它。

        public void Publicar<T>(T model, string operation, string entity)
    {
        _nomeEvento = entity + operation;

        Boolean.TryParse(Configuration["EventGridConfig:Enabled"], out var eventGridIsActive);
        if (!eventGridIsActive)
            return;

        var primaryTopicKey = Configuration["EventGridConfig:AcessKey"];
        var primaryTopic = Configuration["EventGridConfig:Endpoint"];

        var primaryTopicHostname = new Uri(primaryTopic).Host;

        var topicCredentials = new TopicCredentials(primaryTopicKey);
        var client = new EventGridClient(topicCredentials);

        client.PublishEventsAsync(primaryTopicHostname, GetEventsList(model)).GetAwaiter().GetResult();
    }

    private List<EventGridEvent> GetEventsList<T>(T model)
    {
        return new List<EventGridEvent>
        {
            new EventGridEvent()
            {
                Id = Guid.NewGuid().ToString(),
                EventType = _nomeEvento,
                Data = model,
                EventTime = DateTime.Now,
                Subject = "MS_Clientes",
                DataVersion = "1.0",
            }
        }; …
Run Code Online (Sandbox Code Playgroud)

json azure azureservicebus json-deserialization azure-eventgrid

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

使用 Nginx 在 Docker 容器内使用路由器部署 Angular2

我正在尝试部署一个使用框架的路由器功能的 Angular 2,但我在使用 docker 容器内的 nginx 为其提供服务时遇到了一些问题。

由 angular-cli 构建的 angular 应用程序具有如下文件结构:

./dist
??? 08c42df75dd2c636f46f3c564b3ddaa5.ttf
??? 8eab7754b320d3562a2deff1ca81bb6f.woff2
??? assets
?   ??? fonts
?   ?   ??? Avenir_Next_New_Regular.otf
?   ?   ??? Avenir_Next_New_Regular.ttf
?   ?   ??? material.woff2
?   ??? img
?       ??? angular-2.svg
??? index.html
??? inline.js
??? main.dc3f8a76e21296ab1f32.bundle.js
??? main.dc3f8a76e21296ab1f32.bundle.js.gz
??? styles.771fbb659c3d6c4edd71.bundle.js
??? styles.771fbb659c3d6c4edd71.bundle.js.gz
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下 dockerfile 进行部署

FROM nginx:1.10-alpine
COPY dist/ /var/www
COPY ng2.conf /etc/nginx/conf.d/default.conf
CMD 'nginx'
Run Code Online (Sandbox Code Playgroud)

棘手的部分是如何设置以下default.conf文件:

server {
  listen 80;

  root /var/www/;

  // The question is how do …
Run Code Online (Sandbox Code Playgroud)

nginx docker angular

4
推荐指数
1
解决办法
1803
查看次数