小编Asg*_*and的帖子

为什么每次迭代 putStrLn 都会变慢?

我制作了一个小型的生命游戏程序,它自己迭代几代。问题是每次迭代时, putStrLn 函数都会显着减慢,我无法弄清楚原因。这是代码:

import Control.Concurrent

data CellState = Dead | Alive

data Position = Position Integer Integer

type Generation = Position -> CellState

is_alive :: CellState -> Bool
is_alive Alive = True
is_alive Dead = False

neighbors :: Position -> [Position]
neighbors (Position x y) =
  [(Position (x-1) (y-1)), (Position x (y-1)),  (Position (x+1) (y-1)), (Position (x+1) y),
  (Position (x+1) (y+1)), (Position x (y+1)), (Position (x-1) (y+1)), (Position (x-1) y)]

alive_neighbors :: Generation -> Position -> Int
alive_neighbors generation position …
Run Code Online (Sandbox Code Playgroud)

haskell conways-game-of-life

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

为什么即使我更改了输入文件,Sharp 仍输出相同的文件?

使用 Sharp 对 JPG 进行缩放和着色后,我立即删除输入文件。当我上传同名的新文件时,Sharp 将输出旧文件。我在 Ubuntu 16.04 上运行 NodeJS。

这是编辑文件的代码:

sampleFile.mv(__dirname + "/" + name + "." + ext, function(err) {
    if (err)
      return res.status(500).send(err);

    res.send('File uploaded!');

    if (ext != "xlsx") {
      // This will attempt to resize the images
      console.log("Sharpening image")
      sharp(__dirname + "/" + name + "." + ext).resize({ height: 27 }).flatten( { background: '#ffffff' } ).toFile("/var/www/my_ip/file.jpg")
        .then(function(newFileInfo) {
          // newFileInfo holds the output file properties
          console.log("Success")
          try {
            fileSystem.unlinkSync(__dirname + "/" + name + "." + …
Run Code Online (Sandbox Code Playgroud)

javascript ubuntu node.js sharp

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