当链接函数应用于一个参数时,是否有一种有效/简单的方法,只应用满足其要求的函数才能应用?例如:
我有1个参数'Obj'和3个函数:func1,func2,func3.每个都有自己的要求,需要满足这些要求,以便将函数应用于参数.例如伪代码:
(if condition1 then func1) . (if condition2 then func2) . (if condition3 then func3) Obj
Run Code Online (Sandbox Code Playgroud)
因此,如果所有条件都合格,则所有3个函数都将应用于Obj.
有什么方法可以做到这一点吗?
每次我们对后端进行更改,需要更改客户端 DNS 设置时,我们都必须通过电子邮件、电话、电子邮件提醒等漫长的过程,以便让每个人都实施必要的更改。
为了一劳永逸地简化这一点,我完成了以下操作:我为 dns.ourdomain.com 设置了一个带有 Cloud DNS 区域的 Google Cloud 项目
通过这种方式,我可以指导我们的客户设置:
www.client.com CNAME client.dns.ourdomain.com
Run Code Online (Sandbox Code Playgroud)
在 Cloud DNS 控制台中,我们添加:
client.dns.ourdomain.com CNAME client.backendserver.com
Run Code Online (Sandbox Code Playgroud)
现在,将来如果我们需要进行更改,我们可以在一次批量操作中完成所有操作,而无需涉及客户。
我已经测试了这个设置并且它工作得很好,但似乎有一个共识认为这是不好的做法。如果有,潜在的陷阱是什么?
使用带有'.then'的链条有什么好处,如果它不像预期的那样工作:
new Promise(function(resolve, reject) {
// A mock async action using setTimeout
setTimeout(function() { resolve(10); }, 3000);
})
.then(function(num) {
console.log('first then: ', num); return num * 2; })
.then(function(num) {
setTimeout(function() {
console.log('second then: ', num); return num * 2; }, 500);
})
.then(function(num) {
console.log('last then: ', num);
});
// RESULT!
// From the console:
// first then: 10
// last then: undefined
// second then: 20
Run Code Online (Sandbox Code Playgroud)
我期待以下结果:
// RESULT!
// From the console:
// first then: 10 …Run Code Online (Sandbox Code Playgroud) 我有一个由 8 亿条记录聚合而成的频率表,我想知道是否可以使用包从频率表中计算一阶转移矩阵,这是不对称的,因为某些状态再也没有发生过。频率表的一个示例是:
library(data.table)
model.data <- data.table(state1 = c(3, 1, 2, 3), state2 = c(1, 2, 1, 2), Freq = c(1,2,3,4))
Run Code Online (Sandbox Code Playgroud)
model.data 看起来像这样:
| 状态 1 | 状态2 | n |
|---|---|---|
| 3 | 1 | 1 |
| 1 | 2 | 2 |
| 2 | 1 | 3 |
| 3 | 2 | 4 |
使用包 pollster,我可以计算比例表:
library(pollster)
crosstab(model.data, state1, state2, Freq)
Run Code Online (Sandbox Code Playgroud)
| 状态 1 | 1 | 2 | n |
|---|---|---|---|
| 1 | 0 | 100 | 2 |
| 2 | 100 | 0 | 3 |
| 3 | 20 | 80 | 5 |
但是,我正在寻找的对称转移矩阵是:
| 状态 1 | 1 | 2 | 3 | n |
|---|---|---|---|---|
| 1 | 0 | 100 | 0 | 2 |
| 2 | 100 | 0 | 0 | 3 … |
我是一个jQuery新手,也许我想问一个非常基本的问题,但我真的很挣扎,同时弄清楚为什么jQuery链在我的情况下不起作用.
var container = $('#container'),
items = container.find('ul.items'),
moreItems = items.children('li.moreItems');
var config = {
container : container,
items : items,
moreItems : moreItems
}
var app = myApp(config);
function MyApp(config) {
this.container = config.container;
this.items = config.items;
this.moreItems = config.moreItems;
this.current = 0;
}
MyApp.prototype.myUsefulFunction() {
this.moreItems[this.current].fadeIn();
}
Run Code Online (Sandbox Code Playgroud)
假设我有一个div#container,其中包含每个都有多个li的ul元素.我想访问第n个li并淡化元素,但是控制台抛出了一个错误,说明fadeIn没有这样的方法.你能帮我解决一下吗?
我想在两个过滤器链之间切换,如案例1和案例2所示,代码如下.当我最初选择两种情况时,输出显示正确.但是,当我切换到另一个过滤器链时,输出在当前和先前过滤器链之间闪烁.切换过滤链的推荐方法是什么?
-(void) updateFilter:(NSInteger) style {
switch (style) {
case 1:
[kuwahara setRadius:5];
[videoCamera addTarget:kuwahara];
[kuwahara addTarget:grayscale];
[grayscale addTarget:filteredVideoView];
break;
case 2:
[videoCamera addTarget:grayscale];
[blur setBlurSize:3];
[grayscale addTarget:blur];
[blur addTarget:colorinvert];
[colorinvert addTarget:filteredVideoView];
break;
default:
[videoCamera addTarget:filteredVideoView];
break;
}
[videoCamera startCameraCapture];
}
Run Code Online (Sandbox Code Playgroud) 我经常发现自己编写的ruby代码如下所示:
b = f1(a)
c = f2(b)
d = f3(c)
...
Run Code Online (Sandbox Code Playgroud)
有没有一种方法,以连锁f1,f2,f3一起不分类型A,B和C的?例如,像
a.send_to(&:f1)
.sent_to(&:f2)
.sent_to(&:f3)
Run Code Online (Sandbox Code Playgroud)
它不一定是那个,但我喜欢可以按顺序读取的代码,如"开始a,现在应用f1,然后应用f2,......"
在我看来,我在这里真正要求的是一种map在单个对象而不是列表上使用的方法.我可以这样做:
[a].map(&:f1)
.map(&:f2)
.map(&:f3)
.first
Run Code Online (Sandbox Code Playgroud)
以下(有点)工作,虽然猴子修补Object似乎是一个坏主意:
class Object
def send_to(&block)
block.call(self)
end
end
Run Code Online (Sandbox Code Playgroud)
我说"(有点)有效"因为
1.send_to{|x| x+1}
#=> 2
Run Code Online (Sandbox Code Playgroud)
但
def add_1(x); x+1; end
1.send_to(&:add_1)
#=> NoMethodError: private method `add_1' called for 0:Fixnum
Run Code Online (Sandbox Code Playgroud)
注意:这个问题有类似之处,但建议是在每个对象的特定类上定义一个方法.
我想做一些非常简单的事,但我不懂一点......
var Q = require('q');
var funcs = ["first", "second", "third", "fourth"];
function main(){
// really don't know how to chain sequentially here ...
var result = Q();
funcs.forEach(function (f) {
result = treat(f).then(f);
});
}
function treat(t){
var deferred = Q.defer();
setTimeout(function(){
deferred.resolve("treated "+ t);
},2000);
return deferred.promise;
}
main();
Run Code Online (Sandbox Code Playgroud)
我希望我的funcs数组的每个元素按顺序"处理",输出将是这样的:
treated first
//2 seconds later
treated second
//2 seconds later
treated third
//2 seconds later
treated fourth
Run Code Online (Sandbox Code Playgroud)
我无法做到这一点:(它应该很简单,我没有抓到的东西:(
我需要在许多设备中拥有最新的证书信任存储,所以我希望能够将它们组合到证书上,然后我可以只推送那个文件.我只想捆绑许多CA的公钥,但我不想添加私有文件,因为我想要一个我推送到我所有设备的证书.我以为这个功能被称为链,但openssl不会在没有私有文件的情况下接受命令.可以这样做吗?我尝试了几种不同的东西,我在这里看了很多线程,但我不知道我在做什么.
我试图使用的命令是:
openssl -export -pkcs12 -out output.pem -cafile intermediate.pem
Run Code Online (Sandbox Code Playgroud)
我试过"openssl crl2pkcs7 -certfile bundle.pem -out p7.pem",但它产生了一个错误:
openssl crl2pkcs7 -certfile bundle.pem -out p7.pem
unable to load CRL
9460:error:0906D06C:PEM routines:PEM_read_bio:no start line:.\crypto\pem\pem_lib.c:701:Expecting: X509 CRL
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
openssl pkcs7 -in bundle.pem -out p7.pem
unable to load PKCS7 object
3676:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:.\crypto\asn1\tasn_dec.c:1201:
3676:error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error:.\crypto\asn1\tasn_dec.c:765:
3676:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:.\crypto\asn1\tasn_dec.c:697:Field=type, Type=PKCS7
3676:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:.\crypto\pem\pem_oth.c:83:
Run Code Online (Sandbox Code Playgroud) 我最近一直在研究区块链,我遇到了以太坊和chain.com
这两个平台似乎都有助于开发和部署区块链应用程序,其中chain.com专门针对金融公司.
但是,这两者之间究竟有什么区别?
chain ×10
promise ×2
blockchain ×1
cname ×1
dns ×1
ecmascript-6 ×1
es6-promise ×1
ethereum ×1
filter ×1
function ×1
gpuimage ×1
haskell ×1
javascript ×1
jquery ×1
markov ×1
matrix ×1
node.js ×1
openssl ×1
q ×1
r ×1
ruby ×1
sequence ×1
transition ×1