小编Sid*_*tha的帖子

使用URL获取标题,元描述内容

我试图从URL中提取标题和元标记的描述内容,这就是我所拥有的:

fin[] //urls in a string array

for (int f = 0; f < fin.length; f++)
{
Document finaldoc = Jsoup.connect(fin[f]).get(); //fin[f] contains url at each instance
Elements finallink1 = finaldoc.select("title");
out.println(finallink1);
Elements finallink2 = finaldoc.select("meta");
out.println(finallink2.attr("name"));
out.println(fin[f]); //printing url at last
}
Run Code Online (Sandbox Code Playgroud)

但它不打印标题,只是将描述打印为"描述"并打印网址.

结果:

description plus.google.com generator en.wikipedia.org/wiki/google description earth.google.com

java url jsoup

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

编译器如何区分<?当它们在类型擦除后看起来都被编译成同一个东西时,从<Number>扩展Number>?

我正在尝试理解java通用的covariancy,我理解为什么

List<Number> list = new ArrayList<Integer>();
Integer = list.get(0);
Run Code Online (Sandbox Code Playgroud)

不允许使用float,因此不会将float放入列表中,从而导致问题.我相信类型擦除会将其编译为:

List list = new ArrayList();
Integer = (Integer) list.get(0);
Run Code Online (Sandbox Code Playgroud)

这是允许的:

List<? extends Number> list = new ArrayList<Integer>();
Integer = list.get(0);
Run Code Online (Sandbox Code Playgroud)

类型擦除后,这不会编译成同样的东西吗?通配符如何帮助编译器强制执行浮点数在保存整数时不会放入列表中?

java covariance type-erasure

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

Strtol 第二个参数

第二个论点如何运作strtol

这是我尝试过的:

strtol(str, &ptr, 10)
Run Code Online (Sandbox Code Playgroud)

其中ptr是 achar *并且str是一个字符串。现在,如果我传入stras'34EF'和 print *ptr,它会正确地给我E, 并*(ptr+1)给我F,但是如果我 print ptr,它会给我EF!打印不应该ptr导致像十六进制地址之类的垃圾值吗?

c++ string parsing strtol

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

对'和'关键字感到困惑

为什么这两段代码产生不同的输出?

    $a = 3;
    ($a == 4) and print "But I wanted apple, cherry, or blueberry!\n" ;
Run Code Online (Sandbox Code Playgroud)

没有节目输出但是

    $a = 3;
    print "But I wanted apple, cherry, or blueberry!\n" and ($a == 4);
Run Code Online (Sandbox Code Playgroud)

给:但我想要苹果,樱桃或蓝莓!

perl

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

为什么浮点运算被认为是昂贵的?

我读到gprof(函数分析)和其他分析方法可以返回执行程序时发生的浮点运算的数量,因此想知道Flops如何比常规运算贵得多?

profiling flops

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

从函数指针列表中获取函数的索引

我有一个函数列表,所有这些函数都扩展了Consumer接口.我需要提取出函数的索引.这样做的原因是我正在实现循环工作流,其中用户按顺序调用列表中的函数.因此,当用户使用foo完成时,foo调用一个调度程序函数,该函数在列表中的foo之后调度该函数.为此,foo需要知道列表中自己的索引.我不想硬编码数字,这就是我试图检索foo索引的原因.这就是我所拥有的:

import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.function.Consumer;

public class Experiment {

  private List<Consumer<String>> activities = ImmutableList.of(
  this::bar,
  this::foo
  );

  public void bar(String x) {
    System.out.println();
  }

  public void foo(String x) {
    System.out.println();
  }

  public void print() {
    System.out.println(activities.indexOf((Consumer<String>)this::foo));
  }

  public static void main(String []args) {
    Experiment e = new Experiment();
    e.print();
  }
}
Run Code Online (Sandbox Code Playgroud)

这打印-1给我,所以它无法在列表中找到它.有没有办法从这个列表中提取出函数的索引?

java java-8 method-reference

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

低通高斯滤波器,具有指定的截止频率

我正在玩混合图像,并希望使用高斯滤波器对图像进行低通滤波.然而,为了制作混合图像,假设在2个图像上使用2个滤波器与不同的截止频率组合.

fspecial()当我们用它来制作高斯滤波器时,是否允许我们指定截止频率?(我知道我们可以指定滤波器大小和sigma,并且sigma和截止频率之间存在某种关系).如果我们只能使用sigma指定截止频率,那么我需要设置什么sigma来获得0.2 Hz的截止频率.

matlab image-processing gaussian

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

如何使用Python替换本文中的冒号?

我有一个看起来像的文件

1::12::33::1555
1::412::1245::23444
Run Code Online (Sandbox Code Playgroud)

等等.我需要摆脱最后一个参数,并用逗号替换冒号.我试过了:

  myfile = open('words.txt', 'r')
  content = myfile.read()
  content = re.sub(r'(.+)::(.+)::(.+)::(.+)', "\1,\2,\3", content)
  myfile = open('words.txt', 'w')
  myfile.write(content)   
  # Close the file
  myfile.close()
Run Code Online (Sandbox Code Playgroud)

但后面的引用不起作用,我最后得到一个带逗号的文件.

我希望实现的目标是:

1,12,33
1,412,1245
Run Code Online (Sandbox Code Playgroud)

python regex

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

在Java中,如何创建一个函数指针列表,每个参数都带一个参数?

我已经看过这里,它适用于包含Runnables的参数减少方法列表.我需要Consumer在我的情况下.这是我到目前为止:

import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.function.Consumer;

public class experiment {

 private static List<Consumer<String>> activities;

 public experiment (){
 activities = ImmutableList.of(
     (userId) -> this::bar,        // throws error
     (userId) -> this::foo);
 }

 public void bar(String x) {
   System.out.println(x);
 }

 public void foo(String x) {
   System.out.println(x);
 }

 public static void main(String []args) {

  for (int i=0; i<2; i++) {
    activities.get(i).accept("activity #" + i);
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

我看到的错误是void is not a functional interface.

我不明白为什么我会这样做,barfoo …

java function-pointers

0
推荐指数
1
解决办法
415
查看次数

touchesBegan函数从不输入

我正在尝试为我的应用弹出一个弹出窗口。到目前为止,弹出窗口以固定的坐标弹出,我试图将其弹出到用户点击的位置。这就是我所拥有的:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    print("touchesbegan")
    for touch in touches{
        //Handle touch
        let location = touch.locationInView(self.view)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)

        let vc = storyboard.instantiateViewControllerWithIdentifier("ColonyPopoverController") as! ColonyPopoverController
        vc.modalPresentationStyle = .Popover
        vc.preferredContentSize = CGSizeMake(200, 150)

        if let popoverController = vc.popoverPresentationController {
            popoverController.delegate = self
            popoverController.sourceRect = CGRectMake(location.x, location.y, 20, 10)
            popoverController.sourceView = self.view
            self.presentViewController(vc, animated: true, completion: nil)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我注意到当我点击模拟器时,打印语句永远不会打印。

我认为interaction并已multi-touch启用。我知道这种方法很好用,因为我也将其与Google Maps集成在一起,因此当我点击时,会出现一个google pin:

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) …
Run Code Online (Sandbox Code Playgroud)

touchesbegan gmsmapview swift

0
推荐指数
1
解决办法
7682
查看次数