小编Pet*_*Guo的帖子

如何在防火墙后面的Windows上使用rustup安装Rust?

下载了rustup-init.exe.当我在家里运行时,一切都很顺利,但当我通过代理从我的办公室运行时,我遇到了一个问题:

info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
error: could not download file from 'https://static.rust-lang.org/dist/channel-rust-stable.toml.sha256' to 'C:\Users\350627\.rustup\tmp\l3ogei4e89gnb1df_file
info: caused by: error during download
info: caused by: [6] Couldn't resolve host name (Couldn't resolve host 'static.rust-lang.org')
Run Code Online (Sandbox Code Playgroud)

我在Windows上并且http_proxy环境变量已正确设置.

我试图"自定义安装",但它没有给我手动提供IP地址的选项:

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
Run Code Online (Sandbox Code Playgroud)

有没有人知道解决方法?

proxy rust

12
推荐指数
2
解决办法
4622
查看次数

具有水平对齐的UICollectionView水平滚动

我想要一个分页UICollectionView,每个页面从左到右显示单元格.我现在可以通过经典UICollectionViewFlowLayout和现实来实现

layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
Run Code Online (Sandbox Code Playgroud)

结果如下:

      page 1             page 2
 cell 1 | cell 3 || cell 5 | cell 7
 cell 2 | cell 4 || cell 6 | cell 8
Run Code Online (Sandbox Code Playgroud)

我现在想要达到的目标是:

      page 1             page 2
 cell 1 | cell 2 || cell 5 | cell 6
 cell 3 | cell 4 || cell 7 | cell 8
Run Code Online (Sandbox Code Playgroud)

我想知道是否有比创建自己的流量控制器更简单的解决方案?或者如果没有,是否有一些地方我可以看到源代码UICollectionViewFlowLayout与我想要的不同?

objective-c ios uicollectionviewlayout

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

num crate中的大整数实现是否缓慢?

我在Rust中实现了Miller-Rabin Strong Pseudoprime测试,BigUint用于支持任意大质数.要通过5到10 ^ 6之间的数字,它需要大约40秒cargo run --release.

我用Java实现了相同的算法,BigInteger同样的测试需要10秒才能完成.Rust似乎慢了4倍.我认为这是由实施引起的num::bigint.

这只是当前的状态num::bigint,还是有人能发现我的代码有任何明显的改进?(主要是关于我如何使用该语言.无论我的算法实现是好还是坏,它在两种语言中的实现几乎完全相同 - 因此不会导致性能上的差异.)

我注意到clone()由于Rust的所有权模型,有很多需要,这可能会很快影响速度到某种程度.但我想没有办法解决这个问题,对不对?

这是代码:

extern crate rand;
extern crate num;
extern crate core;
extern crate time;

use std::time::{Duration};
use time::{now, Tm};

use rand::Rng;
use num::{Zero, One};
use num::bigint::{RandBigInt, BigUint, ToBigUint};
use num::traits::{ToPrimitive};
use num::integer::Integer;
use core::ops::{Add, Sub, Mul, Div, Rem, Shr};

fn find_r_and_d(i: BigUint) -> (u64, BigUint) {
    let mut d = i;
    let mut r = 0;
    loop …
Run Code Online (Sandbox Code Playgroud)

performance biginteger performance-testing rust

10
推荐指数
1
解决办法
2386
查看次数

Xcode 6的最低iOS部署目标

维基百科说,6的最低iOS部署目标XcodeiOS7.我刚刚检查过,XCode现在页面上列出了6个GM,最低iOS部署目标已经改为iOS5.1.1.

我确实需要支持iOS6.0,并希望通过官方Xcode文档进行确认.我搜索过,找不到这个特定的信息.有人可以分享一个提到这个的官方文件的链接吗?谢谢.

xcode ios ios6 xcode6

9
推荐指数
1
解决办法
6602
查看次数

为什么Xcode的调试器会使用Swift以这种方式跳转?

我用F6in 调试了下面的代码Xcode 6,执行的顺序非常有趣.

这是代码--7行,在第1行设置断点:

    let request = AWSDynamoDBPutItemInput()
    request.tableName = "blah"

    let card = AWSDynamoDBAttributeValue()
    card.S = "1234"
    let email = AWSDynamoDBAttributeValue()
    email.S = "notset"

    request.item = ["card_number" : card, "email" : email]
Run Code Online (Sandbox Code Playgroud)

当我通过代码F6时,它显示以下序列(数字是行号):

1,2,4,2,3,4,6,4,5,6,7,6,7
Run Code Online (Sandbox Code Playgroud)

为什么是这样?这是Xcode还是语言?这些类是在亚马逊的AWS SDK中定义的,不确定是否重要,它们是通过swift-objective-c桥接访问的,这可能与桥接有关.

顺便说一下,执行的最终结果是正确的.

debugging xcode objective-c swift

9
推荐指数
2
解决办法
1536
查看次数

如何使用angular2/http进行ajax调用?

我正在使用Angular 2.0.0-beta.0和typescript.我能够在没有任何问题的情况下使用window ['fetch']开启ajax调用(我不需要使用早期版本中所需的任何变通方法.)

但我无法使用angular2的http进行相同的ajax调用.

这是演示该问题的代码.项目文件夹中有三个文件index.html,以及名为app的子文件夹中的boot.ts和app.component.ts.

app.component.ts:

import {Http, HTTP_PROVIDERS} from 'angular2/http';
import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    providers: [HTTP_PROVIDERS],
    template: '<h1>My First Angular 2 App</h1><button (click)="getTasks()">click</button>{{tasks}}'
})
export class AppComponent { 
    http: Http;
    tasks = [];

    constructor(http: Http) {
        alert(http == null);
        this.http = http;
    }

    getTasks(): void {
        this.http.get('http://localhost:3000/tasks/norender');
            //.map((res: Response) => res.json())

            //it is important to have this subscribe call, since the 
            //request is only made if there is a subscriber 
            .subscribe(res => this.tasks = res);
    } …
Run Code Online (Sandbox Code Playgroud)

dependency-injection http typescript angular

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

如何绑定Angular 2表达式和TypeScript方法?

我想要做的是在输入名字和姓氏时显示全名.

这有效:

<h1 [hidden]="!firstName || !lastName">Hello {{lastName + ', ' + firstName}}!</h1>
Run Code Online (Sandbox Code Playgroud)

这不起作用(调用类中定义的方法的正确方法是什么?):

<!--h1 [hidden]="!firstName || !lastName">Hello {{fullName()}}!</h1!-->
Run Code Online (Sandbox Code Playgroud)

这也不起作用:

<button ng-click="alertFullName()">show full name</button>
Run Code Online (Sandbox Code Playgroud)

以下是文件:index.html:

<!DOCTYPE html>
<html>

  <head>
    <title>Angular 2 QuickStart</title>

    <!-- 1. Load libraries -->
    <script src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script>
    <script src="https://code.angularjs.org/tools/typescript.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.0/Rx.js"></script>
    <script src="https://code.angularjs.org/2.0.0-beta.0/angular2.dev.js"></script>

    <!-- 2. Configure SystemJS -->
    <script>
      System.config({
        transpiler: 'typescript', 
        typescriptOptions: { emitDecoratorMetadata: true }, 
        packages: {'src': {defaultExtension: 'ts'}} 
      });
    </script>

    <!-- 3. Bootstrap -->
    <script>
      System.import('angular2/platform/browser').then(function(ng){
        System.import('src/hello_world').then(function(src) {
          ng.bootstrap(src.HelloWorld);
        });
      });
    </script>

  </head>

  <!-- …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

如何在angular2中注入位置?

我认为注入位置就像注入Http一样.然而,如果我在最后一行取消注释"公共位置:位置",我的应用程序会中断 - 页面无法呈现.据我所知,我有正确的import和providers数组:

import {Component} from 'angular2/core';
import {
    ROUTER_DIRECTIVES,
    ROUTER_PROVIDERS,
    RouteConfig,
    Location,
    LocationStrategy,
    HashLocationStrategy
} from 'angular2/router';

import {TaskForm} from './task_form';
import {TaskList} from './task_list';
import {AboutUs} from './about_us';

@Component({
    selector: 'task-app',
    templateUrl: 'app/task_app.html',
    providers: [ROUTER_PROVIDERS],
    directives: [TaskForm, TaskList, ROUTER_DIRECTIVES]
})
@RouteConfig([
    {path: '/', component: TaskApp, as: 'Home'},
    {path: '/about_us', component: AboutUs, as: 'aboutUs'}
])
export class TaskApp {  
    constructor(/*public location: Location*/) { 
Run Code Online (Sandbox Code Playgroud)

在我的index.html中,我有以下行:

<script src="https://code.angularjs.org/2.0.0-beta.0/router.dev.js"></script>
Run Code Online (Sandbox Code Playgroud)

在我的引导代码中,我有:

import {bootstrap} from 'angular2/platform/browser';
import {HTTP_PROVIDERS} from 'angular2/http';
import {provide} from 'angular2/core'; …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

6
推荐指数
1
解决办法
3227
查看次数

NSJSONSerialization和NSNull

有时我会遇到JSON结构,例如“'data':null”。NSJSONSerialization将它们转换为NSNull,老实说,这很烦人。

我了解其背后的原因-诸如NSDictionary之类的内容不能包含nil值。

很好,但是在那种情况下,我宁愿看到反序列化数据结构中缺少的元素,这在许多情况下实际上简化了处理。是否有可以传递给NSJSONSerialization的选项或配置,并要求它完全做到这一点-只是错过了反序列化数据结构中的那些nil?

null json objective-c nsdictionary nsnull

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

在主线程上执行NSURLConnection sendAsynchronousRequest完成块吗?

我想知道completionHandler在我使用时是否在主线程上调用了块NSURLConnection sendAsynchronousRequest.我主要担心的是我是否需要UIKit自己在主线程上发出呼叫.

该文件NSURLConnection没有提到这个细节,除非我错过了.

我描述了我的代码,没有内存泄漏,这表明该块是在主线程上执行的.

有没有给出明确答案的文件?

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    [self.progress stopAnimating];
    if (data != nil) {
        ...
    } else {
        [self showMessageIgnoreAcknowledgement:@"Error" message:@"blah"];
    }
}];
Run Code Online (Sandbox Code Playgroud)

objective-c uikit nsurlconnection ios objective-c-blocks

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