小编Mat*_*zuk的帖子

如何在Swift中捕获"索引超出范围"?

我真的想在我的Swift代码中使用更简单的经典try catch块,但我找不到任何可以做到的东西.

我只需要:

try {
// some code that causes a crash.
}
catch {
// okay well that crashed, so lets ignore this block and move on.
}  
Run Code Online (Sandbox Code Playgroud)

这是我的困境,当TableView重新加载新数据时,一些信息仍然存在于RAM中,它调用didEndDisplayingCell一个带有新空数据源的tableView崩溃.

所以我经常抛出异常 Index out of range

我试过这个:

func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    do {
        let imageMessageBody = msgSections[indexPath.section].msg[indexPath.row] as? ImageMessageBody
        let cell = tableView.dequeueReusableCellWithIdentifier("ImageUploadCell", forIndexPath: indexPath) as! ImageCell
        cell.willEndDisplayingCell()
    } catch {
        print("Swift try catch is confusing...")
    }
}
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

func tableView(tableView: UITableView, didEndDisplayingCell …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

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

scrollTo函数jQuery无法正常工作

我需要Jquery的scrollTo函数来为这个网站工作:http://cinicraft.com/Silverman/index.html

我尝试了以下内容

$(document).ready(function()
{
    $("div.btnLp3").click(function(){
        $('body,html').scrollTo('#target-examples', 800, {easing:'elasout'});
    });
});
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个:

$(document).ready(function()
{
    $("div.btnLp3").click(function(){
        $('html, body').animate({ scrollTop: $(window.location.hash).offset().top}, 1000);
    });
});
Run Code Online (Sandbox Code Playgroud)

我似乎无法开始scrollTo工作.有没有人有任何想法?这是我导入的内容:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">  </script>    
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js">  </script>
Run Code Online (Sandbox Code Playgroud)

jquery scrollto

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

安装 uwsgi 后,python 仍然会报错:No module named 'uwsgi'

我不确定在 python3 中导入 uwsgi 需要什么。这个问题最近开始发生。我的整个应用程序都有网络套接字方法import uwsgi,这听起来像是一个相当常见的模块。

但在验证它已正确安装后:

pip install uwsgi
DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429).
Requirement already satisfied: uwsgi in /usr/local/lib/python3.4/site-packages (2.0.18)
Run Code Online (Sandbox Code Playgroud)

好像我不能在任何地方使用这个模块:

root@4a4d65e514ba:/usr/src# python 
Python 3.4.5 (default, Dec 14 2016, 18:54:20) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import uwsgi
Traceback (most recent …
Run Code Online (Sandbox Code Playgroud)

python uwsgi python-3.x

7
推荐指数
1
解决办法
1042
查看次数

递归因子方法返回一些负数

这是我的阶乘方法:

public static long factorial(int num1) {
    if (num1 <= 1) 
        return 1; 
    else
        return num1 * factorial(num1 - 1);
}
Run Code Online (Sandbox Code Playgroud)

这就是所谓的递归因子方法:

for (i = 0; i <= 25; i++)
    System.out.printf  ("%d !=  %,d\n", i, factorial (i));
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利,输出看起来似乎是正确的,但是一些因子是负的而不是正的:

OUTPUT:
0 !=  1
1 !=  1
2 !=  2
3 !=  6
4 !=  24
5 !=  120
6 !=  720
7 !=  5,040
8 !=  40,320
9 !=  362,880
10 !=  3,628,800
11 !=  39,916,800
12 !=  479,001,600
13 != …
Run Code Online (Sandbox Code Playgroud)

java factorial

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

递归指数法

public static int exponent(int baseNum) {
    int temp = baseNum *= baseNum;                

        return temp * exponent(baseNum);             
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我调试它,上面的方法会 n * n 变成无穷大,所以它仍然有效,但我需要这个递归方法在 10 次后停止,因为我的老师要求我们找到给定 10 次幂的指数。

该方法必须只有一个参数,以下是调用指数的一些示例:

                System.out.println ("The power of 10 in " + n + " is " + 
                    exponent(n));
Run Code Online (Sandbox Code Playgroud)

所以输出应该是:

The power of 10 in 2 is 1024
Run Code Online (Sandbox Code Playgroud)

或者

The power of 10 in 5 is 9765625
Run Code Online (Sandbox Code Playgroud)

java methods recursion exponent

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

通过 PHPMailer 发送带有附件的电子邮件

我正准备为一个网站创建一个表单页面,该页面需要用户填写许多字段,并将其发送到指定的电子邮件。

到目前为止,我已经创建了一个虚拟的 php 电子邮件页面,该页面使用 Google 的 SMTP 获取您的消息、1 个附件和收件人电子邮件地址。

这是我的 uploadtest.html 代码:

<body>

<h1>Test Upload</h1>

<form action="email.php" method="get">
Message: <input type="text" name="message">
Email: <input type="text" name="email"><br>
Attach File: <input type="file" name="file" id="file">
<input type="submit">
</form>


</body>
Run Code Online (Sandbox Code Playgroud)

uploadtest.html 是用户将看到的内容

这是 email.php 的代码:

<?php
    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $recipiant = $_GET["email"];
    $message = $_GET["message"];

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->Host       = "smtp.gmail.com"; // SMTP server
    $mail->Port       = 465; // SMTP Port
    $mail->SMTPSecure …
Run Code Online (Sandbox Code Playgroud)

php

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

SSL证书添加失败,错误:1312

我正在构建一个C#控制台应用程序,它将:

[1.]生成自签名证书.

[2.]将其添加到个人(本地计算机商店)

[3.]最后使用netsh命令将该证书分配给计算机上的端口号.

到目前为止,我有部分[1.][2.]完美地工作,但在[3.]我受到无用且非正式的错误消息的困扰:

SSL证书添加失败,错误:1312指定的登录会话不存在.它可能已经被终止了.

当我查看微软有关此问题的官方网页时:https: //support.microsoft.com/en-us/kb/981506

它基本上告诉我这是一个Windows操作系统错误,我应该请求一个修补程序.

我的Hack解决这个问题的方法:

我能够最终绕过此错误的一种方法是打开IIS主页>打开"服务器证书"功能>然后导入我的.pfx证书.

通过将.pfx导入IIS,我似乎能够毫无困难地解决问题.我只需要按顺序运行这两个命令来生成.pfx

1.) C:\OpenSSL-Win32\bin>openssl req -x509 -sha256 -nodes -days 365 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -newkey rsa:2048 -keyout privateKey.key -out certificate.crt

2.) C:\OpenSSL-Win32\bin>openssl pkcs12 -export -out cert.pfx -inkey privateKey.key -in certificate.crt -passout pass:

因此,如果我现在将这两个命令运行到openssl,并通过IIS将它们导入我的个人本地计算机证书存储区,我就没有SSL Certificate add failed, Error: 1312问题了.

但是,如果我以编程方式将新生成的证书添加到我的个人本地计算机证书存储区,那么我确实会收到错误:1312问题.

这是我的代码:

using CERTENROLLLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

using System.IO;
using System.Text;
using System.Security.Cryptography;
using System.Diagnostics; …
Run Code Online (Sandbox Code Playgroud)

c# iis openssl http.sys

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

在 PyCharm 中为 Python 突出显示更复杂的语法?

Python 突出显示其过于通用。

我似乎在 PyCharm Pro 中根本找不到任何解决方案。我有以下几点:

  1. 局部变量

  2. 班级名称

  3. 类实例

  4. 类实例调用方法

  5. 全局变量

但是,无论范围有多大不同,一切都是白色的。有什么办法可以用插件改进这个吗?或者,自定义 Python 语法更复杂?

在自定义 JavaScript、HTML 或许多其他语言的语法高亮颜色时,我对此完全没有任何问题。只是对于 Python,我唯一需要自定义的是:

编辑器,配色方案,Python

如何在 PyCharm 中为 Python 的配色方案添加更多颜色?

python syntax-highlighting intellij-idea pycharm

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

阶乘函数产生21的错误结果!以上

for (int i = 0; i <= 25; i++)
    System.out.printf("%d! = %,d\n", i, factorial(i));
Run Code Online (Sandbox Code Playgroud)

上面的代码初始化了下面的阶乘方法:

public static long factorial(int num1)
{
    if (num1 == 0)
        return 1;
    else
        return Math.abs(num1 * factorial(num1 - 1));
}
Run Code Online (Sandbox Code Playgroud)

因此,创建了以下输出:

0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5,040
8! = 40,320
9! = 362,880
10! = 3,628,800
11! = 39,916,800
12! = 479,001,600
13! = 6,227,020,800
14! = …
Run Code Online (Sandbox Code Playgroud)

java integer-overflow factorial long-integer

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

如果我是采取旧的Windows 95 .EXE用C++写的,我想8位整数转换为16位整数,这将是困难的?

如果我有一个旧的PC游戏,某些变量不能超过255而不会崩溃,是否可以通过修改Windows 95可执行文件将所有8位整数转换为16位整数?

我正在谈论的游戏是1997年的Total Annihilation.虽然游戏本身远远超过它的时间并且有能力被改编成史诗般的体验,(地狱,游戏是如此领先于它的时间,数据文件使用类似JSON的语法...游戏也支持4K,看起来仍然很神奇.)不幸的是,游戏中的武器总数有限.所有武器都有ID,武器的最大ID为255,如下所示:

[NUCLEAR_MISSILE]
    {
    ID=122;
    name=Nuclear Missile;
    rendertype=1;
    lineofsight=1;
    vlaunch=1;

    model=ballmiss;

    range=32000;
    reloadtime=180;

    noautorange=1;
    weapontimer=5;
    flighttime=400;

    weaponvelocity=350;
    weaponacceleration=50;
    turnrate=32768;
    areaofeffect=512;
    edgeeffectiveness=0.25;

    energypershot=180000;
    metalpershot=2000;

    stockpile=1;
    targetable=1;
    commandfire=1;
    cruise=1;

    soundstart=misicbm1;
    soundhit=xplomed4;

    firestarter=100;
    smokedelay=.1;
    selfprop=1;
    smoketrail=1;
    propeller=1;

    twophase=1;
    guidance=1;
    tolerance=4000;

    shakemagnitude=24;
    shakeduration=1.5;

    explosiongaf=commboom;
    explosionart=commboom;

    waterexplosiongaf=fx;
    waterexplosionart=h2oboom2;

    lavaexplosiongaf=fx;
    lavaexplosionart=lavasplashlg;

    startsmoke=1;

    [DAMAGE]
        {
        default=5500;
        ARMCOM=2900;
        CORCOM=2900;
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是否值得尝试?我对汇编语言不是很熟悉,但我听说使用C++,你有时必须在某些情况下在当天编写自己的汇编语言.

我想做的就是通过编辑.EXE将所有8位Ints提升到16位,这有多难以实现?

c++ assembly assemblies

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