我在Scala中遇到了一个小问题.在Haskell中,我可以这样做:
add :: (Num a) => (a,a) -> (a,a) -> (a,a)
Run Code Online (Sandbox Code Playgroud)
这样,我可以投入add任何类型的数字和支持+等.我希望Scala类相同,如下所示:
case class NumPair[A <: Numeric](x: A, y: A)
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.但是由于Scala Docs,它Numeric[T]是允许这些操作的唯一特征,并且似乎被扩展Int,Float等等.
有小费吗?
假设我有一个这样的文档:
{
_id: "cow",
comments: [
{user: "karl", comment: "I like cows.", at: /*a date*/},
{user: "harry", comment: "Cows are the best.", at: /*a date*/}
]
}
Run Code Online (Sandbox Code Playgroud)
现在我想收集"karl"我的数据库中留下的所有注释.或者只是特定日期的那些."comments"已编制索引,我该如何查询?
我正在尝试从 URL 加载音频缓冲区,然后播放它。我从这个HTML5 Rocks 教程中得到了大部分代码。
var request = new XMLHttpRequest();
request.open('GET', $(this).attr('data-url'), true);
request.responseType = 'arraybuffer';
request.onload = function() {
console.log(request);
context.decodeAudioData(request.response, function(buffer) {
console.log(buffer);
$('#play').click(function() {
var source = context.createBufferSource();
source.connect(context.destination);
source.noteOn(0);
}).removeAttr('disabled');
}, function(err) { console.log(err); });
};
request.send();
Run Code Online (Sandbox Code Playgroud)
但是,然后我按下#play按钮,没有任何反应。source.noteOn(0)被调用,我使用调试器检查了它。并且所有对象都已正确加载和创建,但我听不到声音。
此外,看起来,当我使用这种方法时,我需要重建一个具有所有控件的完整播放器。我今天准备这样做,保存工作,并更好地保证这个作品,是把buffer成<audio/>,因此它可以在那里玩。
我知道audio.src将文件名放在那里,但我需要使用音频缓冲区。我试过了
audio.src = buffer;
audio.load()
Run Code Online (Sandbox Code Playgroud)
但这没有用。
有什么资料吗?
我对Python一点都不熟悉,我经常做Ruby或JS.但我需要在运行Python的系统上编写基准测试脚本.我要做的是创建一个小脚本,获取文件大小和线程数,并写一个随机缓冲区.这是我在摆弄2个小时后得到的:
from multiprocessing import Pool
import os, sys
def writeBuf(buf):
def write(n):
f = open(os.path.join(directory, 'n' + str(n)), 'w')
try:
f.write(buf)
f.flush()
os.fsync(f.fileno)
finally:
f.close()
return write
if __name__ == '__main__':
targetDir = sys.argv[1]
numThreads = int(sys.argv[2])
numKiloBytes = int(sys.argv[3])
numFiles = int(102400 / numKiloBytes)
buf = os.urandom(numKiloBytes * 1024)
directory = os.path.join(targetDir, str(numKiloBytes) + 'k')
if not os.path.exists(directory):
os.makedirs(directory)
with Pool(processes=numThreads) as pool:
pool.map(writeBuf(buf), range(numFiles))
Run Code Online (Sandbox Code Playgroud)
但它抛出了错误: AttributeError: Can't pickle local object 'writeBuf.<locals>.write'
我之前尝试过write没有闭包,但是当我尝试在__name__ == '__main__'部件内部定义函数时出现错误.省略这 …
在Lift中,整个ProtoUser构造非常棒,令人惊叹的是它为你做了什么,大部分优点(很遗憾,很多东西都没有)没有记录.
只有一个问题:它包含我不需要的数据,甚至包含我不想要的数据.例如,我希望我的用户通过昵称登录,而我不需要知道他的位置,区域设置或名/姓.但在注册时,我需要标准注册页面上未显示的信息.
我的第一个想法是重写我自己的用户特征,但后来我必须重新编写所有的会话代码,授权等.是否已有替代方案?或者是否可以改变ProtoUser我自己的注册和登录页面,以及只有我需要的数据?
谢谢收听.
简单的问题:GTK是否有Linux风格的终端小部件?对于Haskell也是如此,因为我想使用gtk2hs
我终于在Windows上安装了Haskell SDL绑定.使用这个:
> $env:Path += ";C:\SDL;C:\SDL\bin;C:\SDL\include;C:\SDL\lib"
> cabal install SDL --extra-include-dirs="C:\SDL\include" --extra-lib-dirs="C:\SDL\lib"
Run Code Online (Sandbox Code Playgroud)
只要为configure脚本安装了Cygwin,这就可以工作.但是,我写了一个很小的测试脚本:
import Graphics.UI.SDL as SDL
import Control.Monad (void)
import Control.Exception (bracket_)
main = bracket_ (SDL.init [InitEverything]) quit $ do
screen <- setVideoMode 800 600 0 []
SDL.flip screen
void $ waitEvent
Run Code Online (Sandbox Code Playgroud)
现在尝试这个给我这个错误信息:
*Main> :main
Loading package SDL-0.6.4 ... <interactive>: mingw32: Cannot find specified module.
can't load .so/.DLL for: mingw32.dll (addDLL: could not load DLL)
Run Code Online (Sandbox Code Playgroud)
现在我正在寻找,mingw32.dll但我在我的电脑上找不到它,虽然我安装了MinGW32.有人有过这方面的经验吗?
使用SDL-0.6.4,GHC 7.4.2来自Haskell Platform 2012.4.0.0 …
这个查询有问题,我不知道它是什么.我相信这很简单:
db.foo.insert({
'created at': new Date(),
ooc: false,
body: '<p>Moo</p>\n',
keywords: [ 'Moo' ],
mentioned: [],
tags: [],
sender: {
_id: 'stuff',
name: 'lambdadusk',
'display name': 'Lambda'
}
});
Run Code Online (Sandbox Code Playgroud)
我从Mongo得到的错误很简单
!e.eoo()
Run Code Online (Sandbox Code Playgroud)
我正在使用MongoDB 2.0.5.谷歌搜索错误并没有告诉我太多.
基于这篇文章,我试图弄清楚如何在Haskell中使用VBO.我试着填写那里没有覆盖的位:
data Sprite = Sprite { spriteImage :: Image
, spritePosition :: Position
} deriving (Show, Eq)
spriteBatch :: [Sprite] -> [(TextureObject, [Sprite])]
spriteBatch = (map f) . toList . (groupedBy (imageTexture . spriteImage))
where f (t, s) = (t, s)
offset = plusPtr nullPtr
renderSprites :: [Sprite] -> IO ()
renderSprites l = (flip mapM_) (spriteBatch l) $ \(t, sps) -> do
textureBinding Texture2D $= Just t
let l = concat $ map sprToList sps
vbo <- …Run Code Online (Sandbox Code Playgroud) 我做了一个简单的文件字段:
<input type="file" name="pictures_array[]" multiple accept="image/*" id="page_pictures_array" />
Run Code Online (Sandbox Code Playgroud)
和一些 HTML5 文件 API 代码来列出文件:
$('.page-form #page_pictures_array').change(function(evt) {
var file, files, reader, _i, _len;
files = evt.target.files;
console.log(files);
$('#file-list').empty();
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
reader = new window.FileReader;
reader.onload = (function(file) {
return function(e) {
var src;
src = e.target.result;
return $("<li>" + file.name + " - " + file.size + " bytes</li>").prepend($('<img/>', {
src: src,
"class": 'thumb'
})).appendTo($('#file-list'));
};
})(file);
reader.readAsDataURL(file); …Run Code Online (Sandbox Code Playgroud) haskell ×3
html ×2
json ×2
mongodb ×2
scala ×2
bson ×1
cabal ×1
file-upload ×1
fileapi ×1
forms ×1
gtk ×1
gtk2hs ×1
html5-audio ×1
javascript ×1
lift ×1
mingw32 ×1
opengl ×1
python ×1
python-pool ×1
querying ×1
sdl ×1
terminal ×1
types ×1
vertex-array ×1
widget ×1