小编Bul*_*ula的帖子

斐波纳契封闭了

我正在他们的官方网站上进行巡回演出,我被要求写一个斐波纳契发电机.这里是:

 package main

import "fmt"

// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
    first := 0
    second := 0
    return func() int{
        if(first == 0) {
         first = 1
         second = 1
         return 0
        }else {
            current := first   
            firstc := second
            second = first + second
            first = firstc
            return current
        }



    }
}

func main() {
    f := fibonacci()
    for i := 0; i < 10; i++ …
Run Code Online (Sandbox Code Playgroud)

closures fibonacci go

11
推荐指数
4
解决办法
6724
查看次数

Reader接口和golang中的Read方法

我跟随golang之旅,我被要求:

实现一个实现io.Reader的rot13Reader并从io.Reader读取,通过将ROT13替换密码应用于所有字母字符来修改流.

我首先将方法实现到*rot13Reader

   type rot13Reader struct {
    r io.Reader
}

func (r *rot13Reader) Read(p []byte) (n int, e error){


}
Run Code Online (Sandbox Code Playgroud)

但是我无法理解这种Read方法.

是否p包含所有字节?因此,我应该做的就是迭代它们并应用ROT13替换?

我知道它应该返回读取的字节数和文件末尾的EOF错误但是我不确定何时以及如何调用此方法.所以回到我原来的问题是否p包含所有读取的数据?如果没有,那么我该怎么做呢?

io byte go

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

由于缺少bean,Webserver无法启动

我正在尝试启动一个简单的spring应用程序

我在这里有main.java文件:

    package main;

import javafx.application.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;


@ComponentScan
@EnableAutoConfiguration
public class Main {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的libs: 在此输入图像描述

这是pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>blog</groupId>
    <artifactId>blog</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.0.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>1.0.0.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>1.0.0.BUILD-SNAPSHOT</version>
        </dependency>
    </dependencies>


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

最后错误就是这个:

      .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \ …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

滤波器算法中缺少逻辑

我正在尝试从课程scala课程中解决第三项任务.我已经完成了一些但是我认为在某个特定功能方面我忽略了这一点.我必须实现过滤器函数,该函数将返回给定满足给定谓词的推文集中的所有推文的子集.我已经实现了一些我认为可以帮助我的功能,但测试失败了

注意请不要给我烘焙代码,因为这将违反课程荣誉代码.我想要的只是帮助我调试逻辑并帮助我查看我搞砸的地方以及测试失败的原因.

  abstract class TweetSet {

  def isEmpty: Boolean
  /**
   * This method takes a predicate and returns a subset of all the elements
   * in the original set for which the predicate is true.
   *
   * Question: Can we implment this method here, or should it remain abstract
   * and be implemented in the subclasses?
   */
  def filter(p: Tweet => Boolean): TweetSet

  /**
   * This is a helper method for `filter` that propagetes the accumulated tweets.
   */
  def …
Run Code Online (Sandbox Code Playgroud)

algorithm recursion scala

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

Go Tour Slices练习逻辑

我正试图完成Exercise: SlicesGo Go之旅.
但是我真的不明白我被要求做什么.

实施Pic.它应该返回一个长度为dy的片段,其中每个元素都是一个dx 8位无符号整数片.运行程序时,它将显示您的图片,将整数解释为灰度(井,蓝光)值.

我有以下代码

package main

import "golang.org/x/tour/pic"

func Pic(dx, dy int) [][]uint8 {
    a := make([][]uint8, dy)
    return a
}

func main() {
    pic.Show(Pic)
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经创建了dy长度的切片.但是我不明白下一步.我是否需要创建一个for循环,在其中我将切片的每个元素分配给dx范围内的值?我不是要求代码,而是要求解释/澄清

go slice

8
推荐指数
2
解决办法
1837
查看次数

Spring Starting抛出一个异常

我正在尝试在春天构建最简单的应用程序,我的单个控制器有以下代码

    package User;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by Bula on 14/02/14.
 */
@Controller
public class UsersController {

    @RequestMapping("/user")
    public String index()
    {
        return "user_index";
    }

}
Run Code Online (Sandbox Code Playgroud)

这是Main.java.引导一切的那个:

  package main;

import javafx.application.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;


@ComponentScan
@EnableAutoConfiguration
public class Main {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

这也是pom.xml

  <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>blog</groupId>
    <artifactId>blog</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.0.0.RELEASE</version>
        </dependency> …
Run Code Online (Sandbox Code Playgroud)

java spring maven spring-boot

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

Martin Odersky:努力保持简单

我正在观看马丁·奥德斯基(Martin Odersky)在斯卡拉课程中自己推荐的演讲,我很好奇它的一个方面

var x = 0
async { x = x + 1 }
async { x = x * 2 }
Run Code Online (Sandbox Code Playgroud)

所以我得到它,如果第一个语句首先执行然后第二个执行,它可以给2:

x = 0;
x = x + 1;
x = x * 2; // this will be x = 2
Run Code Online (Sandbox Code Playgroud)

我得到它如何给1:

x = 0;
x = x * 2;
x = x + 1 // this will be x = 1
Run Code Online (Sandbox Code Playgroud)

但是怎么能得到0呢?声明是否可能根本不执行?

很抱歉这么简单的问题,但我真的很困惑

logic asynchronous scala

6
推荐指数
2
解决办法
652
查看次数

goroutines如何运作?

我正在关注Go Tour,当涉及到goroutines时我有点卡住了.我知道他们非常轻量级,每次goroutine阻止,另一个将开始,但我无法理解这个例子实际如何工作:

package main

import (
    "fmt"
    "time"
)

func say(s string) {
    for i := 0; i < 5; i++ {
        time.Sleep(1000 * time.Millisecond)
        fmt.Println(s)
    }
}

func main() {
    go say("world")
    say("hello")
}
Run Code Online (Sandbox Code Playgroud)

Playground

据我所知,一个goroutine是针对具有参数"world"的say函数启动的,但据我所知,应该打印"world"五次并且"hello"一次.但是我不明白为什么输出是这样的:

hello
world
hello
world
hello
world
hello
world
hello
Run Code Online (Sandbox Code Playgroud)

从我对其他语言的线程的有限理解,输出应该是这样的:

hello
world
world
world
world
world
Run Code Online (Sandbox Code Playgroud)

或者像这样:

world 
world
world
hello
world
world
Run Code Online (Sandbox Code Playgroud)

为什么第二行也执行五次?go语句下面的任何内容都会归类为go例程的一部分吗?

下一张幻灯片还显示了我无法再次回头看的内容:

package main

import "fmt"

func sum(a []int, c chan int) {
    sum := 0 …
Run Code Online (Sandbox Code Playgroud)

concurrency go goroutine

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

CUDA 初始化:CUDA 未知错误 - 这可能是由于环境设置不正确

我正在尝试安装具有 CUDA 支持的手电筒。

这是我的collect_env.py脚本的结果:

PyTorch version: 1.7.1+cu101
Is debug build: False
CUDA used to build PyTorch: 10.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.1 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: Could not collect

Python version: 3.9 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: 10.1.243
GPU models and configuration: GPU 0: GeForce GTX 1080
Nvidia driver version: 460.39
cuDNN version: Could not collect
HIP runtime version: N/A …
Run Code Online (Sandbox Code Playgroud)

python pytorch

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

使用nodeJS的跨浏览器画布没有找到该功能的签名

我正在尝试在页面上构建一个画布,只要用户在其上绘制内容就会自动更新.但是看起来好像下面的一段代码(来自index.html)导致错误

  socket.on("drawn_complete",function(data){
    ctx.putImageData(data.image,0,0);
    console.log("Everthing worked technically");
});
Run Code Online (Sandbox Code Playgroud)

这是在我的控制台中输出的错误:

Uncaught TypeError: Failed to execute 'putImageData' on 'CanvasRenderingContext2D': No function was found that matched the signature provided
Run Code Online (Sandbox Code Playgroud)

我的data.image是从以下代码返回的内容:

ctx.getImageData(0,0,200,100); // ctx is canvas.getContext("2d")
Run Code Online (Sandbox Code Playgroud)

这是我的html中的画布:

 <canvas id="myCanvas" width="200" height="100"
style="border:1px solid #000000;">
</canvas>
Run Code Online (Sandbox Code Playgroud)

这是完整的nodeJS:

    var http = require("http")
var server = http.createServer(handler).listen(1337);
console.log("Server created at 127.0.0.1:1337");
var io = require("socket.io").listen(server);


function handler(req,res)
{
    console.log("Client Connected");
    res.writeHead(200,{"Content-type": "text/plain"});
    res.end("Hello World");
}


io.sockets.on("connection",function(socket){
    socket.on("drawing",function(data){
        var image = data["image"];
        io.sockets.emit("drawn_complete",image);
    });
});
Run Code Online (Sandbox Code Playgroud)

当用户握住并在我的画布中移动鼠标时,绘图就会被触发:

这是代码:

  c.onmousedown = …
Run Code Online (Sandbox Code Playgroud)

javascript html5 canvas node.js

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