例如,假设我需要在收到两个事件"eventA"和"eventB"后运行一个函数.我通常做的是为每个事件声明一个布尔变量,在接收到事件时将变量设置为true,并询问另一个变量是否为true来运行该函数:
var a = false,
b = false;
$scope.$on("eventA", function(){
a = true;
if (b)
performTask();
});
$scope.$on("eventB", function(){
b = true;
if (a)
performTask();
});
var performTask = function() {
/* do something... */
};
Run Code Online (Sandbox Code Playgroud)
如果有三个或更多事件,这会变得更复杂.是否有设计模式来处理这些情况?
给定一个字符串,其中可能包含一个或多个以";"分隔的SQL语句,例如:
String sql = "select * from table1 where col1 = 'abc;de'; select * from table2;";
Run Code Online (Sandbox Code Playgroud)
我需要在一个字符串数组中获取语句:
array[0] = "select * from table1 where col1 = 'abc;de';"
array[1] = "select * from table2;"
Run Code Online (Sandbox Code Playgroud)
请注意,分号可能出现在撇号之间.
例如,使用正则表达式:
String regex = "???"; // <--- I can't figure out this one
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(sql);
Run Code Online (Sandbox Code Playgroud)
什么是正则表达式来实现这一目标?
我正在尝试在Play Scala程序中读取Json数据.Json在某些字段中可能包含空值,所以这就是我定义Reads对象的方式:
implicit val readObj: Reads[ApplyRequest] = (
(JsPath \ "a").read[String] and
(JsPath \ "b").read[Option[String]] and
(JsPath \ "c").read[Option[String]] and
(JsPath \ "d").read[Option[Int]]
) (ApplyRequest.apply _)
Run Code Online (Sandbox Code Playgroud)
和ApplyRequest案例类:
case class ApplyRequest ( a: String,
b: Option[String],
c: Option[String],
d: Option[Int],
)
Run Code Online (Sandbox Code Playgroud)
这不能编译,我明白了 No Json deserializer found for type Option[String]. Try to implement an implicit Reads or Format for this type.
如何声明Reads对象接受可能的null?
在这个 Jasmine 测试中,我比较了两个几乎相同的对象,唯一的区别是第二个对象有一个额外的未定义成员。
describe('Testing', function () {
it('should compare two objects', function () {
var obj1 = {a: 1, b: 2 };
var obj2 = {a: 1, b: 2, c: undefined };
console.log(JSON.stringify(obj1));
console.log(JSON.stringify(obj2));
expect(obj1).toEqual(obj2);
});
Run Code Online (Sandbox Code Playgroud)
测试失败,但是打印两个对象会JSON.stringify产生两个相同的输出。
{"a":1,"b":2}
{"a":1,"b":2}
Run Code Online (Sandbox Code Playgroud)
浏览物体可以发现差异,但在复杂的物体中这并不容易。关于如何解决这个问题有什么建议吗?
我在 Pentaho PDI 中有以下转换(注意 SQL 语句中的问号):
转换是从工作中调用的。我需要的是在作业运行时从用户那里获取值并将其传递给转换,以便替换问号。
我的问题是有参数、参数和变量,我不知道该使用哪一个。如何使这项工作有效?
在这个插件中,我有一个Angular UI Modal包装在一个指令中.从控制器,我调用一个方法来打开模态,但为此我需要使用$timeout,否则,DOM还没有完成渲染指令.
这似乎有效,但是如果需要完成的任何事情在$timeout到期后还没有完成,会发生什么?该$timeout可以在开发环境中工作,但在生产中可能会失败.使用是不好的做法$timeout?如何在这个例子中避免使用它?
HTML
<div modal control="modalCtl"></div>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
var app = angular.module('app', ['ui.bootstrap']);
app.controller('myCtl', function($scope,$timeout) {
$scope.modalCtl = {};
$timeout(function(){
$scope.modalCtl.openModal();
},100);
})
.directive('modal', function ($uibModal) {
var directive = {};
directive.restrict = 'EA';
directive.scope = {
control: '='
};
directive.link = function (scope, element, attrs) {
scope.control = scope.control || {};
scope.control.openModal = function() {
scope.modalInstance = $uibModal.open({
template: '<button ng-click="close()">Close</button>',
scope: scope
})
};
scope.close = function () …Run Code Online (Sandbox Code Playgroud) angularjs angular-ui angularjs-directive angular-ui-bootstrap
在这个 jsfiddle 中,我创建了一个 Fabric.js 文本lockRotation: true以避免旋转。线不见了,但是要旋转的框控件还在,怎么去掉?
HTML
<canvas id="c" width="300" height="300"></canvas>
Run Code Online (Sandbox Code Playgroud)
Javascript
var canvas = new fabric.Canvas('c');
var text = new fabric.IText('This is the text',{
left: 50,
top: 50,
fontFamily: 'Arial',
fontWeight: 'normal',
fontSize: 18,
lockRotation: true,
stroke: 'black',
fill: 'black'
});
Run Code Online (Sandbox Code Playgroud) 在这个插件中,我有一个Angular 6模块,它包含一个相关的服务HttpClient.模块由应用程序模块导入,主应用程序组件调用该服务.
问题是我收到以下错误:
模块'CoreServiceModule'声明的意外值'MyHttpService'.请添加@ Pipe/@ Directive/@ Component注释
我检查了所有的导入和声明,但找不到问题.哪里出错?
模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { MyHttpService } from './http.service';
@NgModule({
imports: [
CommonModule,
HttpClientModule
],
declarations: [
MyHttpService
],
exports: [
MyHttpService
]
})
export class CoreServiceModule {}
Run Code Online (Sandbox Code Playgroud)
和服务:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable({
providedIn: 'root'
})
export class …Run Code Online (Sandbox Code Playgroud) 我有以下尝试操作堆栈的代码window.history:
console.log("before:" + window.history.length);
window.history.pushState(null, null, '/page1');
console.log("after:" + window.history.length);
Run Code Online (Sandbox Code Playgroud)
尽管我添加了一个状态,但在beforeand中总是打印相同的内容:after
before:50
after:50
Run Code Online (Sandbox Code Playgroud)
为什么pushState不增加历史长度?顺便说一句,50即使我刷新页面,长度也总是如此。
我有一个 Docker 应用程序,它在 Windows 上的笔记本电脑中运行良好,使用组合和启动容器的多个实例作为 Dask 集群。
服务的名称是“worker”,我启动了两个容器实例,如下所示:
docker compose up --scale worker=2
Run Code Online (Sandbox Code Playgroud)
我在 Azure 上部署了映像,当我运行 docker compose(使用我在 Windows 中使用的相同命令)时,只启动了一个容器。
如何在 Azure 中部署容器集群?我可以使用 docker compose 还是我需要采用不同的方法,例如使用模板或 Kubernetes 进行部署?
这是docker-compose.yml文件:
version: "3.0"
services:
web:
image: sofacr.azurecr.io/pablo:job2_v1
volumes:
- daskvol:/code/defaults_prediction
ports:
- "5000:5000"
environment:
- SCHEDULER_ADDRESS=scheduler
- SCHEDULER_PORT=8786
working_dir: /code
entrypoint:
- /opt/conda/bin/waitress-serve
command:
- --port=5000
- defaults_prediction:app
scheduler:
image: sofacr.azurecr.io/pablo:job2_v1
ports:
- "8787:8787"
entrypoint:
- /opt/conda/bin/dask-scheduler
worker:
image: sofacr.azurecr.io/pablo:job2_v1
depends_on:
- scheduler
environment:
- PYTHONPATH=/code
- SCHEDULER_ADDRESS=scheduler …Run Code Online (Sandbox Code Playgroud) angularjs ×2
javascript ×2
angular ×1
angular-ui ×1
azure ×1
dask ×1
docker ×1
fabricjs ×1
jasmine ×1
jasmine2.0 ×1
java ×1
pentaho ×1
pentaho-cde ×1
regex ×1
scala ×1