小编Dav*_*idL的帖子

Ansible - procesor_count vs processor_cores vs processor_vcpus

我对使用以下cpu事实设置服务器感到困惑:

"ansible_processor": [
    "GenuineIntel", 
    "Intel(R) Xeon(R) CPU E5-2650L v3 @ 1.80GHz", 
    "GenuineIntel", 
    "Intel(R) Xeon(R) CPU E5-2650L v3 @ 1.80GHz"
], 
"ansible_processor_cores": 1, 
"ansible_processor_count": 2, 
"ansible_processor_threads_per_core": 1, 
"ansible_processor_vcpus": 2, 
Run Code Online (Sandbox Code Playgroud)

它似乎正确地报告了CPU的数量,但我应该将我的工作者(线程)数量作为基础?我确信我会使用,ansible_processor_cores但它似乎只报告一个(1 - sic!)尽管报告了两个处理器!如何获得工作进程可用的线程数?

multithreading ansible

12
推荐指数
1
解决办法
6691
查看次数

Angular2:如何正确使用bootstrap-tagsinput

我正在尝试在Angular2项目中使用bootstrap-tagsinput库.使用package.jsonfile 安装库:

  "dependencies": {
    ...
    "bootstrap-tagsinput": "^0.7.1",
    ...
  }
Run Code Online (Sandbox Code Playgroud)

现在我有一个bootstrap-tagsinput文件夹node_modules.我想在特定组件中使用tagsinput.我看到目录中有一个bootstrap-tagsinput-angular.js文件node_modules/bootstrap-tagsinput/dist,但我无法正常使用它.

我应该在index.html中添加JS文件,以便bootstrap-tagsinput可用于所有组件吗?或者有没有办法在需要的地方导入它?

换句话说,有没有办法做这样的事情:

mycomponent.component.html:

<input type="text" value="Amsterdam,Washington,Sydney,Beijing,Cairo" data-role="tagsinput"/>
Run Code Online (Sandbox Code Playgroud)

mycomponent.component.ts:

import {Component, AfterViewInit} from '@angular/core';
import {TagsInputComponents} from 'bootstrap-tagsinput'; // Something like that?!?

@Component({
    ...
})

export class MyComponentComponent implements AfterViewInit {

    ngAfterViewInit():any {
        $('input').tagsinput('refresh');
    }
}
Run Code Online (Sandbox Code Playgroud)

非常感谢你的帮助!

javascript angularjs systemjs bootstrap-tags-input angular

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

应用启动时预加载一些片段

我有一个带有导航抽屉的 Android 应用程序。我的问题是某些片段需要几秒钟才能加载(解析器、Map API)。我想在应用程序启动时加载我的所有片段。

我不确定是否有可能或一种好的方法来做到这一点,但我正在考虑在主要活动的 onCreate 方法中为我的每个片段创建一个实例。然后,当用户在导航抽屉中选择一个片段时,我使用现有实例而不是创建一个新实例。

问题是它不能防止我第一次显示特定片段时出现延迟。在我看来,原因是片段构造函数没有做很多操作。

在网上搜索后,我找不到在应用程序启动时(而不是在用户选择抽屉中的项目时)“预加载”片段的优雅方式。

一些帖子谈到了 AsyncTask,但看起来 MapFragment 操作除了在主线程中无法执行(我尝试时出现异常:java.lang.IllegalStateException: Not on the main thread)。

这是我到目前为止尝试过的:

mFragments = new Fragment[BasicFragment.FRAGMENT_NUMBER];
mFragments[BasicFragment.HOMEFRAGMENT_ID] = new HomeFragment();
mFragments[BasicFragment.CAFEFRAGMENT_ID] = new CafeFragment();
mFragments[BasicFragment.SERVICEFRAGMENT_ID] = new ServiceFragment();
mFragments[BasicFragment.GOOGLEMAPFRAGMENT_ID] = new GoogleMapFragment();
Run Code Online (Sandbox Code Playgroud)

当在导航抽屉中选择一个项目时:

private void selectItem(int position) {

    Fragment fragment = mFragments[position];

    // here, I check if the fragment is null and instanciate it if needed

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.content_frame, fragment);
    ft.commit();

    mDrawerList.setItemChecked(position,true);
    mDrawerLayout.closeDrawer(mDrawerList);
}
Run Code Online (Sandbox Code Playgroud)

我也试过 …

android fragment navigation-drawer

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

使用Node Js服务器运行Angular2应用程序

我正在使用Angular2(客户端)和Node JS(服务器端)技术开始一个新项目.

我已经设法使用node和创建RESTful API express.输入特定URL时,将显示匹配的Json响应.到现在为止还挺好.

现在我正在尝试将Angular 2集成到这个过程中.我已经创建了app.component.显示页面时,组件未加载,我得到了一些404代码:

Failed to load resource: 404 (not found) http://localhost:3000/node_modules/core-js/client/shim.min.js
...
Failed to load resource: 404 (not found) http://localhost:3000/systemjs.config.js
Run Code Online (Sandbox Code Playgroud)

这是我的项目结构:

??? App
|    ??? app.component.ts                //copied from Angular2/get-started
|    ??? main.ts                         // copied from Angular2/get-started
??? dist                                 //contains generated JS files
??? node_modules
??? server                               // contains Server Typescript files
??? index.html                           // copied from Angular2/get-started
??? index.ts                             // server entry point
??? package.json
??? systemjs.config.js
??? tsconfig.json
??? typings.json …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express angular

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

使用函数中止 bash 脚本

我尝试创建一个可以中断脚本执行的函数(由于致命错误):

quit() {
  echo -e "[ERROR]" | log
  exit 1
}
Run Code Online (Sandbox Code Playgroud)

调用示例:

if [ "$#" -eq 1 ]; then
    # Do stuff
else
    echo -e "function getValue: wrong parameters" | log
    quit
fi
Run Code Online (Sandbox Code Playgroud)

函数quit被调用(在日志文件中回显)但脚本继续运行。我读过exit只终止子shell(这是真的吗?)这意味着它终止了quit函数而不是整个脚本。

目前,我不喜欢在quit方法中使用返回码,因为它意味着很多代码重构。

有没有办法从quit函数中停止脚本?

编辑: 出现错误的情况的完整示例:

#!/bin/bash

logfile="./testQuit_log"

quit() {
  echo "quit" | log
  exit 1
}

log() {
  read data
  echo -e "$data" | tee -a "$logfile"
}


foo() {
  if [ "$#" -ne 1 ]; then …
Run Code Online (Sandbox Code Playgroud)

bash shell

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

Symfony - 以生成的形式添加文本

我想做一些非常简单的事情,但我不知道如何管理它。我有一个表格:

{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
Run Code Online (Sandbox Code Playgroud)

其中有几个文本字段。我想<p>my Text</p>在两个文本字段之间“插入”一些文本(如)(假设在name文本字段和description文本字段之间)。表单是使用表单构建器工具生成的。我试过这样的事情:

$builder
    ->add('stuffName') // works well (text field 1)
    ->add('addedText', 'text', array('label' => 'my Text')) // Trouble here!
    ->add('stuffDescription'); // works well (text field 2)
Run Code Online (Sandbox Code Playgroud)

但它会生成一个文本字段(而不是简单的文本)。我不在乎文本是在表单构建器中设置还是直接在树枝模板中设置......只要它在我的两个文本字段之间。任何的想法?

非常感谢!

forms symfony twig

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

Angular 2使用AfterViewInit从文件执行JS

非常新的Angular 2,在环顾了几个小时后,我想得到一些帮助.

我有一个带有一些通用函数的JS文件.例如:

$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip(); 
});
Run Code Online (Sandbox Code Playgroud)

该文件实际上包含更多代码.您可以想象,我想启用所有组件的工具提示.我不能简单地包含此文件,index.html因为在加载文件时(尚未)存在子组件.

经过一番挖掘,afterViewInit()上来了.这篇文章建议将JS代码复制/粘贴到ngAfterViewInit().这是丑陋的方式(在我看来)......

所以我在这里提出了两个相关的问题:

1#有没有办法在加载子组件时执行JS代码?例如,类似于:

// In app.component.ts
ngAfterChildComponentLoaded(){
   // JS code here
}
Run Code Online (Sandbox Code Playgroud)

这个解决方案非常有趣,因为我没有被强制ngAfterViewInit()在所有组件中使用相同的内容.但这可能吗?

2#有没有办法导入JS代码instrad的复制/粘贴到ngAfterViewInit()?我不想将300行JS代码复制/粘贴到15个不同的组件中(原因很明显).

非常感谢你的帮助!

javascript angularjs angular

4
推荐指数
2
解决办法
4574
查看次数