这一行有什么区别:
var a = parseInt("1", 10); // a === 1
Run Code Online (Sandbox Code Playgroud)
这条线
var a = +"1"; // a === 1
Run Code Online (Sandbox Code Playgroud)
这个jsperf测试显示,当前的chrome版本中的一元运算符要快得多,假设它是针对node.js的!
如果我尝试转换不是数字的字符串都返回NaN:
var b = parseInt("test" 10); // b === NaN
var b = +"test"; // b === NaN
Run Code Online (Sandbox Code Playgroud)
那么我什么时候应该优先使用parseInt一元加(尤其是在node.js中)???
编辑:双波浪运算符的区别是什么~~?
所以我想要做的是从网址流式传输图像,使用graphicsmagick处理它并将其上传到s3.我只是不让它工作.
将处理后的图像流式传输到本地磁盘(使用fs.createWriteStream)可以正常工作.
当我缓冲我的流时,s3中的最终图像至少具有预期的大小(kb-wise),但我无法打开该图像.
这就是我目前的进步:
var request = require('request');
var gm = require("gm");
var AWS = require('aws-sdk');
var mime = require('mime');
var s3 = new AWS.S3();
gm(request('http://www.some-domain.com/some-image.jpg'), "my-image.jpg")
.resize("100^", "100^")
.stream(function(err, stdout, stderr) {
var str = '';
stdout.on('data', function(data) {
str += data;
});
stdout.on('end', function(data) {
var data = {
Bucket: "my-bucket",
Key: "my-image.jpg",
Body: new Buffer(str, 'binary'), // thats where im probably wrong
ContentType: mime.lookup("my-image.jpg")
};
s3.client.putObject(data, function(err, res) {
console.log("done");
});
});
});
Run Code Online (Sandbox Code Playgroud)
我确实尝试了一些像创建filewritestream和filereadstream的东西,但我认为应该有一些更清洁的解决方案来解决这个问题......
编辑:我尝试的第一件事是将Body设置为stdout(来自@AndyD的建议答案):
var data …Run Code Online (Sandbox Code Playgroud) 使用twig 将类添加到knp_menu'sroot元素的正确方法是什么<ul>?
我尝试了很多东西:
1.
{{ knp_menu_render('main', {'class': 'foo'}) }}
Run Code Online (Sandbox Code Playgroud)
2.
{{ knp_menu_render('main', {'attributes': {'class': 'foo'}}) }}
Run Code Online (Sandbox Code Playgroud)
3.
{{ knp_menu_render('main', {'listAttributes': {'class': 'foo'}}) }}
Run Code Online (Sandbox Code Playgroud)
4.
{{ knp_menu_render('main', {'attributes': {'listAttributes': {'class': 'foo'}}}) }}
Run Code Online (Sandbox Code Playgroud)
他们都没有工作
在节点控制台中测试:
var moment = require('moment');
// create a new Date-Object
var now = new Date(2013, 02, 28, 11, 11, 11);
// create the native timestamp
var native = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());
// create the timestamp with moment
var withMoment = moment.utc(now).valueOf()
// it doesnt matter if i use moment(now).utc().valueOf() or moment().utc(now).valueOf()
// native: 1364469071000
// withMoment: 1364465471000
native === withMoment // false!?!?!
// this returns true!!!
withMoment === now.getTime()
Run Code Online (Sandbox Code Playgroud)
为什么本机的时间戳与withMoment相同?为什么withMoment返回从当前本地时间计算的时间戳?我怎么能实现那个moment.utc()返回与Date.UTC()相同的?
我有一个给定的文件:
{
"foo": {}
}
Run Code Online (Sandbox Code Playgroud)
哪里foo可以有任意数量的属性.假设我将数百万个文档导入到我的索引中,其中每个foo属性都有其他值.
这意味着我将动态构建的映射将变得非常庞大.有什么方法我可以告诉弹性搜索的东西
拿走你所拥有的一切
foo,只是接受它(或字符串化foo),而不必产生百万行映射?
或者在索引文档之前我是否必须自己照顾?
如果是这样,我认为有2个解决方案
JSON.stringify foo
将每个属性映射foo到键/值对,并创建一个对象数组:
// object
{
"foo": [
{"key": "bar1", "value": "bar1's value"},
{"key": "bar2", "value": "bar2's value"}
]
}
// resulting mapping
{
"type": {
"properties": {
"foo": {
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)你更喜欢解决方案1还是2,为什么?
感谢您的帮助!
对于paginate我有一个很大的问题.
我在我的模型中将查询定义为范围:
scope :published_and_valid, joins(...).where(...)
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我有时只想拥有前20名.
.limit(20)
Run Code Online (Sandbox Code Playgroud)
现在我希望能够对这20个结果进行分页(每页5个)
我试着这样做:
@articles = Article.published_and_valid.limit(20).paginate(:page => params[:page])
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为我认为结果是所有文章的分页结果
node.js ×3
javascript ×2
amazon-s3 ×1
file-upload ×1
momentjs ×1
php ×1
streaming ×1
symfony ×1
twig ×1
utc ×1