小编Upg*_*ave的帖子

深度第一个树遍历积累在clojure

我想采取像这样的树状结构:

{"foo" {"bar" "1" "baz" "2"}}
Run Code Online (Sandbox Code Playgroud)

并且在记住来自根的路径时递归遍历以生成如下内容:

["foo/bar/1", "foo/baz/2"]
Run Code Online (Sandbox Code Playgroud)

关于如何在没有拉链或clojure.walk的情况下如何做到这一点的任何建议?

tree recursion clojure clojurescript

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

关于Object.create()和属性继承的困惑

在下面的片段中,为什么boat.calls在我打电话时递增sailboat.getHasEngine()?另外,为什么sailboat.calls在只调用一次getHasEngine()之后设置为2?

let vehicle = {
  calls: 0,
  hasEngine: null,
  getHasEngine: function() {
    vehicle.calls = vehicle.calls + 1;
    this.calls = this.calls + 1;
    return this.hasEngine;
  },
  canFly: null,
  getCanFly: function() { 
    vehicle.calls = vehicle.calls + 1;
    this.calls = this.calls + 1;
    return this.canFly; 
  }
}

let boat = Object.create(vehicle);
boat.canFly = false;

let sailboat = Object.create(boat);
sailboat.hasEngine = false;

let fishingBoat = Object.create(boat);
fishingBoat.hasEngine = true;

console.log(vehicle.calls);
// 0
console.log(boat.calls);
// 0
console.log(sailboat.calls);
// 0 …
Run Code Online (Sandbox Code Playgroud)

javascript

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

使用java按需创建缩略图图像的成功案例

我在服务器上有一堆图像.当客户端请求URL为图像时,客户端可以指定接收完整图像或获取图像的缩略图.所以,我正在寻求实现一个处理请求的servlet类型解决方案,并在需要时根据需要生成缩略图.它需要支持jpg,gif,tif,png.

看起来像使用BufferedImage,JAI和/或ImageMagick是java的最佳选择(来自这篇文章).还有我可能错过的其他人吗?

还有,有没有人在java中实现类似的东西?如果是这样,对解决方案的任何建议给出(1)相当下降的质量缩略图,(2)在处理图像时不会占用大量内存,(3)可接受的响应时间?

java image imagemagick jai

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

elisp新手问题:在org.el中找不到'filename'函数定义?

我真的很喜欢emacs中的org-mode并希望自定义一些东西.在通过org.el阅读时,我发现了几个引用,filename但找不到filename使用describe-function

我确信这是一个简单的答案,但我只是在学习elisp而且这并不明显.任何洞察到哪里filename定义?和/或如果它不是一个功能,它是什么?

例如,filename在第25502行:

         (filename (if to-buffer 
         (expand-file-name
          (concat
           (file-name-sans-extension
        (or (and subtree-p
             (org-entry-get (region-beginning)
                    "EXPORT_FILE_NAME" t))
            (file-name-nondirectory buffer-file-name)))
           "." html-extension)
          (file-name-as-directory
           (or pub-dir (org-export-directory :html opt-plist))))))
Run Code Online (Sandbox Code Playgroud)

emacs elisp org-mode

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

这个Haskell函数需要什么类型的签名或注释?

我是Haskell的新手,我无法确切地了解需要哪种类型的注释或哪种类型的签名才能使其工作.这个test函数本身没用,但如果我能理解如何让它工作,我认为这有助于我更好地理解haskell类型.

test 0 = -1
test n = test (floor (n / 10))
Run Code Online (Sandbox Code Playgroud)

这个问题似乎是相关的: Haskell:为什么RealFrac并不意味着分数?

但我无法弄清楚如何让我的榜样发挥作用.这是我跑步时看到的错误test 0:

<interactive>:470:1:
Could not deduce (Integral a10) arising from a use of ‘test’
from the context (Num a)
  bound by the inferred type of it :: Num a => a
  at <interactive>:470:1-6
The type variable ‘a10’ is ambiguous
Note: there are several potential instances:
  instance Integral Foreign.C.Types.CChar
    -- Defined in ‘Foreign.C.Types’
  instance Integral Foreign.C.Types.CInt
    -- Defined in ‘Foreign.C.Types’
  instance Integral …
Run Code Online (Sandbox Code Playgroud)

haskell

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

使用番石榴缓存减少样板的方法

我有几十个像PersonDao这样的数据访问对象,方法如下:

Person findById(String id) {}
List<Person> search(String firstName, LastName, Page) {}
int searchCount(String firstName, LastName) {}
Run Code Online (Sandbox Code Playgroud)

我已经通过添加guava缓存与其中一个类进行了实验,这非常好,但是有很多样板.

这是一个让findById首先在缓存中查看的示例:

private final LoadingCache<String, Person> cacheById = CacheBuilder.newBuilder()
  .maximumSize(maxItemsInCache)
  .expireAfterWrite(cacheExpireAfterMinutes, TimeUnit.MINUTES)
  .build(new CacheLoader<String, Person>() {
    public Person load(String key) {
      return findByIdNoCache(key);
  });
//.... and update findById to call the cache ...
@Override
public Person findById(String id) {
  return cacheById.getUnchecked(id);
}
Run Code Online (Sandbox Code Playgroud)

因此,因为每个方法都有不同的参数和返回类型,所以我最终为每个方法创建了一个单独的cacheLoader!

我想一切都整合到一个返回对象类型和接受Map对象的一个​​缓存加载器,但后来我结束了大丑的if/else弄清楚打电话加载缓存哪种方法.

我正在努力寻找一种优雅的方法来为这些数据访问对象添加缓存,任何建议?也许guava缓存不适用于这个用例?

java caching guava

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