我正在阅读该_.isFunction()函数的源代码,并看到了这一行:
if (typeof (/./) !== 'function') {
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会这样././是一个似乎总是有类型的正则表达式object.为什么不会_.isFunction被重新定义,如果/./类型是function?
ChannelBufferInputStream responseStream = (ChannelBufferInputStream) response.getBodyAsStream();
ArrayList<Byte> arrayList = new ArrayList<Byte>();
try {
while (responseStream.available() > 0) {
arrayList.add(responseStream.readByte());
}
} catch (IOException e) {
e.printStackTrace();
return internalServerError();
}
Iterator<Byte> iterator = arrayList.iterator();
byte[] bytes = new byte[arrayList.size()];
int i = 0;
while (iterator.hasNext()) {
bytes[i++] = iterator.next();
}
Run Code Online (Sandbox Code Playgroud)
在我的Web应用程序的每个页面加载时调用此代码.它似乎运行得非常快,但是有什么能让它运行得更快吗?
编辑 - 使用字节数组输出流更新
ChannelBufferInputStream responseStream = (ChannelBufferInputStream) response.getBodyAsStream();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
int read = responseStream.read();
while (read != -1) {
byteArrayOutputStream.write(read);
read = responseStream.read();
}
} catch …Run Code Online (Sandbox Code Playgroud) 我正在尝试编码和解码图像.我正在使用FileReader的readAsDataURL方法将图像转换为base64.然后将其转换回来我尝试过使用 readAsBinaryString()并且atob()没有运气.有没有另一种方法来保持图像没有base64编码吗?
readAsBinaryString()
开始读取指定Blob的内容,可能是文件.当读取操作完成时,readyState将变为DONE,并且将调用onloadend回调(如果有).那时,result属性包含文件中的原始二进制数据.
知道我在这里做错了吗?
示例代码 http://jsfiddle.net/qL86Z/3/
$("#base64Button").on("click", function () {
var file = $("#base64File")[0].files[0]
var reader = new FileReader();
// callback for readAsDataURL
reader.onload = function (encodedFile) {
console.log("reader.onload");
var base64Image = encodedFile.srcElement.result.split("data:image/jpeg;base64,")[1];
var blob = new Blob([base64Image],{type:"image/jpeg"});
var reader2 = new FileReader();
// callback for readAsBinaryString
reader2.onloadend = function(decoded) {
console.log("reader2.onloadend");
console.log(decoded); // this should contain binary format of the image
// console.log(URL.createObjectURL(decoded.binary)); // Doesn't work
};
reader2.readAsBinaryString(blob);
// console.log(URL.createObjectURL(atob(base64Image))); // Doesn't work
};
reader.readAsDataURL(file); …Run Code Online (Sandbox Code Playgroud) 我正在使用该inline-image函数来创建图标类.这是我目前的SCSS:
.folder {
background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
height: 30px;
width: 41px;
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个可以确定图像宽度和高度的函数,所以我可以这样做:
.folder {
background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
height: image-height("icons/home/folder.png", 'image/png');
width: image-width("icons/home/folder.png", 'image/png');
}
Run Code Online (Sandbox Code Playgroud)
有这样的事吗?
我一直在考虑将两种方法存储在cookie中.一种方法是对所有数据使用一个cookie并将其存储为JSON字符串.
另一种方法是为每个数据使用不同的cookie.
我在第一种方法中看到的负面影响是,由于cookie中有额外的JSON字符,它会在标题中占用更多空间.此外,我将不得不解析和字符串化JSON,这需要一点处理时间.积极的是只使用了一个cookie.我还缺少其他积极因素吗?
我在第二种方法中看到的负面影响是将使用更多的cookie密钥值对.
我将存储大约15-20个cookie.每个cookie的到期日期都是相同的.
根据我的理解,每个域的最大cookie数量约为4000.我们还没有接近这个数字.
我有什么问题可以忽略吗?哪种方法最好?
编辑 - 这些cookie由JavaScript管理.
我正在将 node.js 应用程序从 Heroku 迁移到在端口 80 上使用 WebSockets 的 AWS Elastic Beanstalk。WebSockets 在 AWS Elastic Beanstalk 上返回 301 错误,但在 Heroku 上没有。
要初始化 WebSocket 连接,请单击Create a new note。
AWS Beanstalk http://default-environment.psgekxtsbd.us-west-2.elasticbeanstalk.com/
Heroku https://murmuring-shelf-40601.herokuapp.com/
这就是我在服务器上设置 WebSockets 的方式。
const express = require('express');
const app = express();
require("express-ws")(app);
app.post("/service/create-account/", (req, res)=> {/*code in here*/});
app.ws('/:noteId/', function (ws, req) {/*code in here*/});
const port = process.env.PORT || 3000;
app.listen(port);
Run Code Online (Sandbox Code Playgroud)
我尝试在.ebextensions文件夹中添加不同的配置,例如,
files:
"/etc/nginx/conf.d/01_websockets.conf" :
mode: "000644"
owner: root
group: root
content : …Run Code Online (Sandbox Code Playgroud) heroku amazon-web-services websocket node.js amazon-elastic-beanstalk
Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol.
https://tools.ietf.org/html/rfc2616#section-15.1.3
根据该标准,https://google.com不应将引荐发送到非安全网站,但确实如此.其他HTTPS站点是否将引荐发送到HTTP站点?
所有这些测试都是使用Chrome v33.0.1750.117完成的
要运行测试,我转到第一页,然后打开控制台并手动执行重定向. location = "http://reddit.com";
防爆.
https://google.com - > http://www.reddit.com 保留推荐
https://startpage.com/ - > http://www.reddit.com推荐被剥夺
https://bankofamerica.com - > http://reddit.com推荐被剥夺
https://facebook.com - > http://reddit.com推荐被剥夺
谷歌是否做了一些特别的事情来保持推荐?是否有保留推荐的HTTPS站点列表?是否还有其他情况需要删除推荐?
谢谢!
javascript ×3
cookies ×1
css ×1
fileapi ×1
heroku ×1
http-headers ×1
inputstream ×1
java ×1
node.js ×1
referrals ×1
sass ×1
websocket ×1