小编dem*_*lem的帖子

sizeWithAttributes 返回带有换行符的错误大小 \n

我正在使用 NSString 的 sizeWithAttributes 方法来获取 NSString 的动态高度。

我的字符串是 @“这是地址行 1 \n 这是地址行 2”

但该方法仅返回 line1 的大小(在 \n 字符之前)

有没有办法在字符串大小中包含 \n ?

objective-c nsstring ios

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

计算给定列表的欧几里德距离

def distance(alist, blist):
    sum_of = 0
    for x in alist:
        for y in blist:
            ans = (x - y)**2
            sum_of += ans
    return (sum_of)**(1/2)
print(distance([1, 1, 3], [2, 2, 3])) #1.4142135623730951
print(distance([1, 2, 3], [2, 2, 3])) #1.0
print(distance([2, 2, 3], [2, 2, 3])) #0.0
print(distance([1, 1], [2, 2])) #1.4142135623730951
Run Code Online (Sandbox Code Playgroud)

所以我有一组测试用例,它们给了我两个带有数字的列表。我的任务是计算给定列表的欧几里德距离。但是,我没有得到正确的结果。相反,我得到的是 3.7416573867739413、3.0、2.0 和 2.0。这就是我到目前为止所拥有的,我不确定我做错了什么。

python euclidean-distance

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

reactjs - 必须返回有效的React元素(或null)

我有以下简单的代码:

var data = [{ email: "bob@gmail.com" },{ email: "toto@gmail.com" }];
var User = React.createClass({
render: function ()
{
    return
    (
        <li>
            {this.props.email}
        </li>
    );
}});

var UserList = React.createClass({        
render: function ()
{            
    var userNodes = this.props.data.map(function (user)
    {
        console.log(user.email);
        return
        (
            <User email={user.email} ></User>
        );
    });            
    return
    (
        <ul>{userNodes}</ul>
    );
}});


ReactDOM.render(<UserList data={data} />, document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

"必须返回一个有效的React元素(或null).您可能已经返回了undefined,一个数组或一些其他无效对象."

reactjs

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

使用适用于iOS 10的UNUserNotificationCenter

尝试使用Firebase注册远程通知,但是在实现以下代码时,我收到错误:

UNUserNotificationCenter仅适用于iOS 10.0或更高版本

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        var soundID: SystemSoundID = 0
        let soundFile: String = NSBundle.mainBundle().pathForResource("symphony", ofType: "wav")!
        let soundURL: NSURL = NSURL(fileURLWithPath: soundFile)
        AudioServicesCreateSystemSoundID(soundURL, &soundID)
        AudioServicesPlayAlertSound(soundID)
        Fabric.with([Twitter.self])


        //Firebase configuration
        FIRApp.configure()

        //Resource code from stackoverflow to create UNUserNotificationCenter
        let center = UNUserNotificationCenter.current()
        center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
            // Enable or disable features based on authorization.
        }
        application.registerForRemoteNotifications()
        return true
    }
Run Code Online (Sandbox Code Playgroud)

通过简单的"修复它"不能通过基于操作系统版本号创建if语句来解决我的问题.对于UserNotifications框架,我应该做什么或想到这个解决方案?

apple-push-notifications swift firebase-cloud-messaging

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

Docker上的状态应用程序

我正在学习Docker。读一本Docker书,上面写着“不建议在Docker上运行有状态的应用程序(即数据库引擎)”。我还从我的一个朋友那里听说他在Docker上使用MySQL没问题。

在Docker上运行有状态应用程序是一种好习惯吗?Docker最适合的情况是什么?

docker

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

执行上一个命令行的输出

我需要执行上一个命令的结果,但我不知道如何处理。

我有第一个命令返回登录服务器的指令,然后我想在之后执行它。

我的第一个命令返回: docker 登录 ...

例如:

> my-first-comnand | execute the result of my-first-command

linux shell

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

来自守护进程 i/o 超时的 Docker 注册表错误响应

来自守护进程的错误响应:Get https://registry.xxx.com:5000/v1/users/ : dial tcp: lookup registry.xxx.com on 192.168.65.1:53: read udp 192.168.65.2:42307->192.168。 65.1:53:I/O 超时

我已经设置了一个在 Ubuntu 服务器上运行的私有 docker 注册表,但是当我执行“docker login https://registry.xxx.com:5000 ”时不断收到上述错误。

当我从我的手机网络运行“curl -v https://registry.xxx.com:5000 ”时,我可以解析主机并成功登录到注册表。但是当我从注册表所在的同一网络运行“curl -v https://registry.xxx.com:5000 ”时,我不能这样做并得到“无法解析主机”错误。

似乎无法解析域。我有一个draytek路由器。

有任何想法吗?

docker docker-registry

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

将MATLAB工作空间变量显示为GUI功能

我在MATLAB工作区中有一个变量,我想将这个变量传递给我的GUI中的一个函数.

我该如何完成这项任务?

matlab user-interface

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

如何声明一个泛型函数返回满足F#中多个约束的类型?

我想写的是:

type A() =
    interface IX with ...
    interface IY with ...

type B() =
    interface IX with ...
    interface IY with ...

let mk t : 'T when 'T :> IX and 'T :> IY =
    match t with
    | Choice1 -> new A()
    | Choice2 -> new B()
Run Code Online (Sandbox Code Playgroud)

注意mk的返回类型的类型约束.虽然它没有编译,编译器抱怨它不能将A和B转换为'T.

generics f#

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

Javascript:按div内的内容排序链接

我有一个包含一组链接的div,我的目标是按内容自动对这些链接进行排序,请按照下面的示例进行更好的理解:

之前

<div id="sort-this-div">
<a href="http://something45yer.com">Content3</a>
<a href="http://somethingeyerty.com">Content1</a>
<a href="http://somethingfwegrw.com">Content2</a>
<a href="http://somethingt43rwer.com">Content4</a>
</div>
Run Code Online (Sandbox Code Playgroud)

<div id="sort-this-div">
<a href="http://somethingeyerty.com">Content1</a>
<a href="http://somethingfwegrw.com">Content2</a>
<a href="http://something45yer.com">Content3</a>
<a href="http://somethingt43rwer.com">Content4</a>
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript

3
推荐指数
1
解决办法
1585
查看次数