小编cie*_*bor的帖子

如何获得AudioInputStream的持续时间?

我想得到一个AudioInputStream的延迟(以微秒为单位).我怎么能轻松做到这一点?我发现如何获得音频文件的持续时间:但由于封装,不能这样做.我看到的唯一对象是AudioInputStream类的实例.

java audio duration stream

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

终端中的键盘事件

我打算写基于终端的游戏.这将是实时的,所以我需要同时显示动画和阅读键盘事件.我怎样才能做到这一点?在JavaScript中,我会创建一个循环来显示游戏状态并将事件附加到自定义键.但我不知道如何在Perl和终端中做类似的事情.它必须是非阻塞的,并且必须允许同时对多个键做出反应.

terminal perl events keypress keydown

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

评估和使用的问题

我编写了这段代码,它在系统中安装POE模块时有效.

#!/usr/bin/perl

use strict;
use warnings;
use POE;

...
Run Code Online (Sandbox Code Playgroud)

但是我想确定这个模块是否存在:

#!/usr/bin/perl

use strict;
use warnings;
eval("use POE; 1") or die ('Please, install POE module. \n');

...
Run Code Online (Sandbox Code Playgroud)

它返回:

Bareword "KERNEL" not allowed while "strict subs" in use at ./terminalhero.perl line 58.
Bareword "HEAP" not allowed while "strict subs" in use at ./terminalhero.perl line 60.
Execution of ./terminalhero.perl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

我尝试了其他模块,但也有错误.如何使用严格模式执行我想要的操作?

perl module strict detect bareword

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

寻找图像onLoad的替代方案

可能重复:
jQuery或JavaScript:确定何时完成图像加载

问题是已知的,但我找不到任何简单的解决方案:

var img = new Image();

img.onLoad = function() {
  console.log("load");         // this event doesn't fire
};

img.src = "img/domino/21.png";

console.log(img.complete);     // false

setTimeout(function() {
  console.log(img.complete);   // sometimes true, sometimes false
}, 10);
Run Code Online (Sandbox Code Playgroud)

我正在寻找onComplete事件的实现,但我找不到任何东西.你能帮忙吗?

javascript events onload dom-events

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

使用粘性页脚时,CSS高度为100%

我有一个标题和粘性页脚的布局.两者都是40px高.现在我需要添加一个scroolbar,它将填充自由空间(verticaly).看起来应该是这样的:

预习

有两个限制:

  • 没有JavaScript
  • 没有CSS3 calc()函数

这个问题有没有严格的CSS解决方案?

css cross-browser sticky-footer

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

无法演绎(a〜[a])

我尝试编写一个函数,它接受一个子列表列表,反转子列表并返回连接的反向子列表.这是我的尝试:

conrev :: Ord a => [[a]] -> [a]
conrev [[]] = []
conrev [[a]] = reverse [a]
conrev [(x:xs)] = reverse x ++ conrev [xs]

main = putStrLn (show (conrev [[1,2],[],[3,4]]))
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

3.hs:4:27:
    Could not deduce (a ~ [a])
    from the context (Ord a)
      bound by the type signature for conrev :: Ord a => [[a]] -> [a]
      at 3.hs:1:11-31
      `a' is a rigid type variable bound by
      the type signature for conrev :: Ord a => [[a]] -> …
Run Code Online (Sandbox Code Playgroud)

reverse haskell list signature type-deduction

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

Mocha不会在after()函数中调用rmdir

我尝试在测试之前创建一些目录树,然后删除它:

require('should');
var fs = require('fs');
var rmdir = require('rmdir');

describe('FsWatcher', function() {
  before(function(done) {
    console.log("before");
    fs.mkdir('tmp');
    fs.mkdir('tmp/css');
    fs.mkdir('tmp/js');
    fs.mkdir('tmp/lib');
    fs.open('tmp/index.htm', 'w');
    // (...)
    console.log("after_before");
    done();
  });

  describe('single file', function() {
    it('should succed', function(done) {
      (1).should.equal(1);
      done();
    });
  });

  after(function() {
    console.log("after");
    rmdir('tmp', function() {
        console.log("rmdir!");
    });
    console.log("after_end");
  });
});
Run Code Online (Sandbox Code Playgroud)

console.logs 的顺序没问题:

mocha `find tests -name '*.js'`

  before
after_before
?after
after_end


  ? 1 test complete (6 ms)
Run Code Online (Sandbox Code Playgroud)

但它不会调用rmdir().同样的rmdir在它结束时起作用before():

describe('FsWatcher', function() {
  before(function(done) {
    console.log("before");
    fs.mkdir('tmp');
    fs.mkdir('tmp/css');
    fs.mkdir('tmp/js'); …
Run Code Online (Sandbox Code Playgroud)

javascript testing bdd mocha.js rmdir

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

Scala中的组合,基于对象(单例)

我想用两个对象制作一个合成.我可以用对象嵌套来做到这一点:

object Composition {
  object SomePartOfComposition {
    // some body
  }
}
Run Code Online (Sandbox Code Playgroud)

但是SomePartOfComposition的主体是如此之长,我希望它在一个单独的文件中.我怎样才能做到这一点?

//编辑

我知道,我可以使用特质.但我想要严格的一对一关系 - 它是一个单身人士.

scala object composition

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

如何获取文件中的浮点数?

我有一个带浮点数的文件,这是一个例子:

0.01
0.24
0.08
0.15
0.7
0.22
0.05
0.28
0.4
0.44
0.8
0.55
Run Code Online (Sandbox Code Playgroud)

现在我需要获得所有浮动的数量(在这种情况下为12).应避免空行.

我这样做了:

  FILE *f, *junk;
  if (MYTHREAD == 0) {
    f = fopen ("dane.dat", "r");    
    junk = fopen ("/dev/null", "w");    

    for(size = 0; fscanf(f, "%f\n", junk) != EOF; ++size);

    fclose(junk);
    fclose(f);
  }
Run Code Online (Sandbox Code Playgroud)

它返回128 O_o.怎么了?

c floating-point numbers file lines

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

反转文件中的行

我试着在考试前学习Haskell,这对我来说仍然很神奇.今天我尝试编写一个程序,它读取一个文件,然后按顺序将它的行写入另一个文件.结果?很多错误:(.这是我的代码:

import IO

readLines :: Handle -> [String] -> [String]
readLines handler list = do
    eof <- hIsEOF handler
    if eof then list
        else do
            line <- hGetLine handler
            readLines handler (list ++ [line])

writeLines :: Handle -> [String] -> [String]
writeLines handler list = if length list == 0 then list
    else do
        line <- head list
        hPutStrLn handler line
        writeLines tail list

fileToList :: FilePath -> [String]
fileToList filename = do
    handler <- openFile filename ReadMode
    list <- …
Run Code Online (Sandbox Code Playgroud)

io haskell file lines invert

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