我想得到一个AudioInputStream的延迟(以微秒为单位).我怎么能轻松做到这一点?我发现如何获得音频文件的持续时间:但由于封装,不能这样做.我看到的唯一对象是AudioInputStream类的实例.
我打算写基于终端的游戏.这将是实时的,所以我需要同时显示动画和阅读键盘事件.我怎样才能做到这一点?在JavaScript中,我会创建一个循环来显示游戏状态并将事件附加到自定义键.但我不知道如何在Perl和终端中做类似的事情.它必须是非阻塞的,并且必须允许同时对多个键做出反应.
我编写了这段代码,它在系统中安装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)
我尝试了其他模块,但也有错误.如何使用严格模式执行我想要的操作?
问题是已知的,但我找不到任何简单的解决方案:
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事件的实现,但我找不到任何东西.你能帮忙吗?
我有一个标题和粘性页脚的布局.两者都是40px高.现在我需要添加一个scroolbar,它将填充自由空间(verticaly).看起来应该是这样的:

有两个限制:
这个问题有没有严格的CSS解决方案?
我尝试编写一个函数,它接受一个子列表列表,反转子列表并返回连接的反向子列表.这是我的尝试:
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) 我尝试在测试之前创建一些目录树,然后删除它:
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) 我想用两个对象制作一个合成.我可以用对象嵌套来做到这一点:
object Composition {
object SomePartOfComposition {
// some body
}
}
Run Code Online (Sandbox Code Playgroud)
但是SomePartOfComposition的主体是如此之长,我希望它在一个单独的文件中.我怎样才能做到这一点?
//编辑
我知道,我可以使用特质.但我想要严格的一对一关系 - 它是一个单身人士.
我有一个带浮点数的文件,这是一个例子:
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.怎么了?
我试着在考试前学习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) events ×2
file ×2
haskell ×2
javascript ×2
lines ×2
perl ×2
audio ×1
bareword ×1
bdd ×1
c ×1
composition ×1
css ×1
detect ×1
dom-events ×1
duration ×1
invert ×1
io ×1
java ×1
keydown ×1
keypress ×1
list ×1
mocha.js ×1
module ×1
numbers ×1
object ×1
onload ×1
reverse ×1
rmdir ×1
scala ×1
signature ×1
stream ×1
strict ×1
terminal ×1
testing ×1