我正在使用React和Typescript.我有一个反应组件充当包装器,我希望将其属性复制到其子组件.我遵循React的使用clone元素的指南:https://facebook.github.io/react/blog/2015/03/03/react-v0.13-rc2.html#react.cloneelement.但是在使用时React.cloneElement我从Typescript中得到以下错误:
Argument of type 'ReactChild' is not assignable to parameter of type 'ReactElement<any>'.at line 27 col 39
Type 'string' is not assignable to type 'ReactElement<any>'.
Run Code Online (Sandbox Code Playgroud)
如何为react.cloneElement分配正确的输入?
这是一个复制上述错误的示例:
import * as React from 'react';
interface AnimationProperties {
width: number;
height: number;
}
/**
* the svg html element which serves as a wrapper for the entire animation
*/
export class Animation extends React.Component<AnimationProperties, undefined>{
/**
* render all children with properties from parent
*
* …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装Meteor-Up(mup),用于将应用程序从我的Ubuntu 14.04笔记本电脑部署到Ubuntu 14.04服务器,但它似乎没有正确安装.如何正确安装mup?
我知道我需要npm才能安装mup.所以,我已经成功安装了npm:
$ sudo apt-get install npm
Run Code Online (Sandbox Code Playgroud)
然后,我尝试安装mup:
$ sudo npm install -g mup
Run Code Online (Sandbox Code Playgroud)
安装日志:
npm http GET https://registry.npmjs.org/mup
npm http 304 https://registry.npmjs.org/mup
npm http GET https://registry.npmjs.org/nodemiral
npm http GET https://registry.npmjs.org/cjson
npm http GET https://registry.npmjs.org/colors
npm http GET https://registry.npmjs.org/uuid
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/underscore/1.7.0
npm http 304 https://registry.npmjs.org/colors
npm http 304 https://registry.npmjs.org/uuid
npm http 304 https://registry.npmjs.org/rimraf
npm http 304 https://registry.npmjs.org/nodemiral
npm http 304 https://registry.npmjs.org/cjson
npm http 304 https://registry.npmjs.org/underscore/1.7.0
npm http GET https://registry.npmjs.org/jsonlint/1.6.0
npm http GET …Run Code Online (Sandbox Code Playgroud) 我正在使用atom with atom-beautify和uncrustify来格式化我的java文件.我希望lambda表达式的缩进仅在打开大括号后缩进一个级别() -> {.我试过调整indent_continue属性,但是当我将它设置为零时会发疯.(使用4个空格进行缩进)
何时indent_continue = 0发生这种情况:
public class Test {
public static void runTest(Runnable code) { code.run(); }
public static void main(String[] args) {
runTest(() -> {
System.out.println("hello"); // <-- look at this line
}); // <-- this one too
}
}
Run Code Online (Sandbox Code Playgroud)
什么时候indent_continue = 4,它双倍缩进:
public class Test {
public static void runTest(Runnable code) { code.run(); }
public static void main(String[] args) {
runTest(() -> {
System.out.println("hello"); // <-- look …Run Code Online (Sandbox Code Playgroud) 我正在创建一个生成范围(0,限制+ 1)中的素数列表的快速方法.在函数中,我最终从名为primes的列表中删除名为removable的列表中的所有整数.我正在寻找一种快速和pythonic的方法去除整数,知道两个列表总是排序.
我可能错了,但我相信list.remove(n)遍历列表,将每个元素与n进行比较.意味着以下代码在O(n ^ 2)时间内运行.
# removable and primes are both sorted lists of integers
for composite in removable:
primes.remove(composite)
Run Code Online (Sandbox Code Playgroud)
基于我的假设(这可能是错误的并且请确认这是否正确)以及两个列表总是排序的事实,我认为以下代码运行得更快,因为它只在O列表上循环一次(n)时间.然而,它根本不是pythonic或干净.
i = 0
j = 0
while i < len(primes) and j < len(removable):
if primes[i] == removable[j]:
primes = primes[:i] + primes[i+1:]
j += 1
else:
i += 1
Run Code Online (Sandbox Code Playgroud)
是否有内置函数或更简单的方法?什么是最快的方式?
附注:我实际上没有计时上面的函数或代码.此外,如果在过程中更改/销毁可移除列表也无关紧要.
对于任何感兴趣的人,全部功能如下:
import math
# returns a list of primes in range(0, limit+1)
def fastPrimeList(limit):
if limit < 2:
return list()
sqrtLimit = int(math.ceil(math.sqrt(limit)))
primes = [2] + …Run Code Online (Sandbox Code Playgroud) 我正在使用 webpack,它采用正则表达式将文件送入加载器。我想从构建中排除测试文件,测试文件以.test.js. 所以,我正在寻找一个匹配index.js但不匹配的正则表达式index.test.js。
我尝试使用否定回顾断言
/(?<!\.test)\.js$/
Run Code Online (Sandbox Code Playgroud)
但它说该表达式无效。
SyntaxError: Invalid regular expression: /(?<!\.test)\.js$/: Invalid group
Run Code Online (Sandbox Code Playgroud)
示例文件名:
index.js // <-- should match
index.test.js // <-- should not match
component.js // <-- should match
component.test.js // <-- should not match
Run Code Online (Sandbox Code Playgroud) 我想要一个我的流星应用程序连接到远程数据库.我以为我可以部署两个应用程序,一个用于在服务器上设置数据库,另一个用于托管应用程序但连接到另一个服务器上的数据库.我无法让这个工作,但我也想知道这是否是推荐的?我应该在没有mup/meteor的服务器上设置mongodb数据库,还是可以使用mup为我设置?
我尝试过但无法开展工作:
我正在使用两个亚马逊ec2实例(ubuntu 14.04).我为这两个实例制定了以下安全入站规则:
Custom TCP Port: 27017 Source: instance-public-ip-1/32
Custom TCP Port: 27017 Source: instance-public-ip-2/32
HTTP Port: 80 Source: All Addresses
SSH Port: 22 Source: My IP
Run Code Online (Sandbox Code Playgroud)
在尝试访问远程数据库的应用程序的mup.json文件中,我在"env"下添加了"MONGO_URL":"mongodb:// db-instance-public-ip:27017/db",db是该实例上的应用程序.
托管数据库的流星应用程序成功部署,但托管应用程序的流星应用程序没有.在"调用部署过程"期间部署失败,这里是STDERR/STDOUT :( XXX.XXX.XXX.XXX是实例的公共IP地址)
x调用部署过程:FAILED
-----------------------------------STDERR-----------------------------------
npm WARN package.json meteor-dev-bundle@0.0.0 No description
npm WARN package.json meteor-dev-bundle@0.0.0 No repository field.
npm WARN package.json meteor-dev-bundle@0.0.0 No README data
/usr/lib/node_modules/wait-for-mongo/bin/wait-for-mongo:14
throw err;
^
Error: TIMEOUTED_WAIT_FOR_MONGO
at null._onTimeout (/usr/lib/node_modules/wait-for-mongo/lib/waitForMongo.js:20:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
-----------------------------------STDOUT-----------------------------------
56.145:27017]
wait-for-mongo: failed to connect to [XXX.XXX.XXX.XXX:27017]
wait-for-mongo: failed to …Run Code Online (Sandbox Code Playgroud) 我有一个有几个不同价值观的课程.我希望能够通过不同的值对这些对象的列表进行排序,但我不知道该怎么做.我希望能够为任何值和两个方向(最少到最大,反之亦然)对它们进行排序.
例如,下面是一个示例类,以及一个示例对象列表:
class Sample(object):
def __init__(self, name, sampleValue1, sampleValue2):
self.name
self.value1 = sampleValue1
self.value2 = sampleValue2
def __repr__(self):
return self.name
# creating sample objects for clarification
objectNames = ['A','B','C','D']
values1 = [3,4,1,2]
values2 = [1,4,2,3]
sampleObjects = list()
for i in xrange(4):
obj = Sample(objectNames[i], values1[i], values2[i])
sampleObjects.append(obj)
Run Code Online (Sandbox Code Playgroud)
从每个对象值中对sampleObject进行排序应该产生以下内容.排序应按指定的顺序返回对象列表(下面使用对象名称).
value1: [C,D,A,B]
value1 reversed: [B,A,D,C]
value2: [A,C,D,B]
value2 reversed: [B,D,C,A]
Run Code Online (Sandbox Code Playgroud) 我希望能够在元素小于或等于某个限制时迭代列表.我自己创建了一个函数来生成我想要的结果,但我想知道是否有一个函数可以为我做这个,或者如果结果可以像列表理解那样重现,所以我不必单独编写功能调用?基本上,我想知道是否有更短/更快的迭代方式,因为我需要在多个python文件和大型迭代中使用它.
我查看了python 2.7的itertools文档https://docs.python.org/2/library/itertools.html,我认为它会有我想要的东西(它可能有,但我错过了,因为我不知道了解itertools中的几个函数.
这是我拥有的一个例子和我想要的结果:
def iterList(iList, limit):
index = 0
while index < len(iList) and iList[index] <= limit:
yield iList[index]
index += 1
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
smallPrimes = list()
for p in iterList(primes, 19):
smallPrimes.append(p)
print smallPrimes
# now smallPrimes == [2, 3, 5, 7, 11, 13, 17, 19]
Run Code Online (Sandbox Code Playgroud) 我有一个带有 mongodb(称为 ec2-mongo)的 ec2 实例,其安全组为 sg-mongodb-server。我正在尝试通过另一个具有安全组 sg-connect 的 ec2 实例(称为 ec2-connect)连接到 mongodb。我想设置规则以允许两个安全组之间的流量,而无需参考特定的 IP 地址。我怎样才能做到这一点?
当我的安全组设置如下时,我可以连接到 mongo(所以据我所知,服务器没有任何问题)。出站设置为所有:
sg-mongodb-服务器:
Inbound:
Port Source
22 my_ip
27017 ip_of_ec2-connect
Run Code Online (Sandbox Code Playgroud)
SG连接:
Inbound:
Port Source
22 my_ip
27017 ip_of_ec2-mongo
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用安全组而不是 IP 地址时,我无法连接到 mongodb。
sg-mongodb-服务器:
Inbound:
Port Source
22 my_ip
27017 sg-connect
Run Code Online (Sandbox Code Playgroud)
SG连接:
Inbound:
Port Source
22 my_ip
27017 sg-mongodb-server
Run Code Online (Sandbox Code Playgroud)
尝试连接时的错误消息:
MongoDB shell version: 3.2.3
connecting to: XXX.XXX.XXX.XXX/test
2016-02-19T18:24:09.245+0000 W NETWORK [thread1] Failed to connect to XXX.XXX.XXX.XXX:27017 after 5000 milliseconds, giving up.
2016-02-19T18:24:09.245+0000 E …Run Code Online (Sandbox Code Playgroud) python ×3
python-2.7 ×3
meteor ×2
meteor-up ×2
mongodb ×2
amazon-ec2 ×1
atom-editor ×1
class ×1
ecmascript-6 ×1
install ×1
iterator ×1
java ×1
javascript ×1
list ×1
npm ×1
object ×1
reactjs ×1
regex ×1
security ×1
sortedlist ×1
sorting ×1
typescript ×1
ubuntu-14.04 ×1
uncrustify ×1
webpack ×1