我正在尝试做一个非常基本的网络套接字,但我不明白为什么我没有得到一个字符串。
我正在使用wsnpm 的模块作为服务器。https://github.com/websockets/ws
客户:
let socket = new WebSocket('wss://upload.lospec.com');
socket.addEventListener('open', function (event) {
socket.send('test');
});
Run Code Online (Sandbox Code Playgroud)
服务器:
const wss = new WebSocket.Server({ server });
wss.on("connection", function (ws) {
ws.on("message", function (asdfasdf) {
console.log("got new id from client",asdfasdf);
});
Run Code Online (Sandbox Code Playgroud)
服务器结果:
got new id from client <Buffer 74 65 73 74>
Run Code Online (Sandbox Code Playgroud)
尝试遵循文档上的示例以及本教程:https://ously.com/blog/web-app-websockets-nodejs
但它并没有像两个地方所承诺的那样像一条线一样出来。
为什么这不以字符串形式出现?
我把我的程序简化为这个,但它仍然行为不端:
var grid = [0, 1, 2, 3];
function moveUp(moveDir) {
for (var row in grid) {
console.log('row:');
console.log(row + 5);
}
}
Run Code Online (Sandbox Code Playgroud)
它似乎row是一个字符串而不是整数,例如输出
row:
05
row:
15
row:
25
row:
35
Run Code Online (Sandbox Code Playgroud)
而不是5,6,7,8,这是我想要的.for循环中的计数器不应该是一个字符串吗?
当我的flexbox容器有超过一定数量的元素时,我希望它使用多行.这是我目前的解决方案:
.container {
display: flex;
width: 400px;
background: black;
padding: 6px;
margin: 10px;
flex-wrap: wrap;
}
.box {
flex: 1 1 0;
height: 32px;
flex-grow: 1;
min-width: 15%;
border: solid 1px black;
}
.box:nth-child(even) {
background: blue;
}
.box:nth-child(odd) {
background: red;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div …Run Code Online (Sandbox Code Playgroud)我想存储的用户计算机上的图像,所以我想,这应该存储在用户数据文件夹,如所描述这里.
app.getPath(name)
name.返回String - 指向与name关联的特殊目录或文件的路径.失败时会抛出错误.您可以通过名称请求以下路径:
home用户的主目录
appData每用户应用程序数据目录,默认情况下指向:Windows $ XDG_CONFIG_HOME上的%APPDATA%或Linux上的〜/ .config~/macOS上的应用程序支持
userData用于存储应用程序配置文件的目录,默认情况下,它是附加了应用程序名称的appData目录.- ...
这就是我认为你应该做的事情:
const app = require('electron');
alert(app.getPath('userData'));
Run Code Online (Sandbox Code Playgroud)
但我得到"getPath不是一个函数".我不知道该把它放在哪里.它不能从我的html文件或渲染器文件中工作,我不知道如何从主文件中使用它,因为它没有链接到网页.
我正在尝试制作一个插入特殊类型元素的编辑器。我发现,如果您在其中的元素上将 contenteditable 设置为 false,它不会让您在其中键入内容(这很好),但它不会将光标放在任何一个之前或之后,光标就会消失。
有没有办法阻止用户在元素内键入内容,但在单击它时保留光标焦点,就像它是普通的文本符号一样?
div div {
width: 30px;
height: 30px;
background: red;
display: inline-block;
}
div {background: #ccc}Run Code Online (Sandbox Code Playgroud)
<div contenteditable="true">
this one will let you type<div></div>inside the red box
</div>
<div contenteditable="true">
this one wont, <div contenteditable="false"></div> but the cursor does nothing when you click inside it now
</div>
<div contenteditable="true">
cant place cursor after this box <div contenteditable="false"></div>
</div>Run Code Online (Sandbox Code Playgroud)
如果文本块是最后一个,您也无法单击该文本块的末尾。
可用性的大问题,真的很想解决这个问题。
Facebook已经解决了这个问题,但我不知道是用js还是css:
编辑:我发现fb将caret-color属性更改为黑色,但在您键入后它似乎跳转到span之外的位置,这必须使用js完成。还在想办法。
编辑:尝试了很多事情,以为我可以正常工作,但它仍然引起其他奇怪的问题。我建议您不要尝试这样做,而只使用图像元素或表情符号。
我所做的一切都不起作用,而且我不断收到可笑的 CORS 错误和其他问题。我只想做一个正常的宣誓,通过浏览器登录用户。我想使用 snowrap,但我什至无法使用它,因为我需要刷新令牌。
\n\n我已经授权该应用程序并从 API 获取“代码”,然后我应该通过向https://www.reddit.com/api/v1/access_token发出发布请求来使用该代码。
\n\n但我每次都会收到 CORS 错误。
\n\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.reddit.com/api/v1/access_token. (Reason: missing token \xe2\x80\x98access-control-allow-headers\xe2\x80\x99 in CORS header \xe2\x80\x98Access-Control-Allow-Headers\xe2\x80\x99 from CORS preflight channel).\n\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.reddit.com/api/v1/access_token. (Reason: CORS request did not succeed).\nRun Code Online (Sandbox Code Playgroud)\n\n代码:
\n\nconst redirect_uri = \'https://EXAMPLE.com/reddit/\';\nconst client_id = \'xxxxxxxxxxxxx\';\nconst queryString = window.location.search;\nconst urlParams = new URLSearchParams(queryString); /*global URLSearchParams*/\nconst code …Run Code Online (Sandbox Code Playgroud) 我尝试使用 git 目录进行 npm install,每次都会得到这个。
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\User\AppData\Local\npm-cache\_cacache\tmp\git-clone-4622a2ff/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\User\AppData\Local\npm-cache\_cacache\tmp\git-clone-4622a2ff\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
Run Code Online (Sandbox Code Playgroud)
我试过:
npm cache clean -fnpm cache verifynpm install npm@latest -g我将 css 上传到 github,然后转到网站上的文件并单击 raw 选项。我尝试将其添加到网页中,但 chrome 给出以下错误:
资源解释为样式表,但使用 MIME 类型 text/plain 进行传输:“https://raw.githubusercontent.com/me/my-repo/master/style.css”。
和
跨源读取阻止 (CORB) 阻止了 MIME 类型为 text/plain 的跨源响应https://raw.githubusercontent.com/me/my-repo/master/style.css。有关更多详细信息,请参阅https://www.chromestatus.com/feature/5629709824032768 。
我该怎么做才能成功添加此 CSS?我也用 javascript 添加它:
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', 'https://raw.githubusercontent.com/me/my-repo/master/style.css');
document.getElementsByTagName('head')[0].appendChild(link);
Run Code Online (Sandbox Code Playgroud) 我有一个像素艺术字体(在 ttf 文件中),我发现它的原始分辨率为 8 像素 ( CTX.font = '8px mainfont';)
当我执行 fillText 时,字体在 Firefox 中显示完美,但在 chrome 中显示模糊:
我尝试将 X 坐标偏移不同的量(例如 0.5),但它变得更加模糊。通常它始终是一个舍入整数。
我尝试CTX.translate(0.5, 0);过并且CTX.imageSmoothingEnabled = true;
我尝试过CSSfont-smooth: none; font-smooth: never; -webkit-font-smoothing : none;
过去,我必须将字体转换为特殊格式,并使用库在画布上绘制它们。只是希望 5 年后他们添加一个官方方法来解决这个问题吗?
我正在尝试将记录上自动添加的createdAt日期更新为现在。
这是我正在使用的代码:
Document.findOneAndUpdate({_id: docId}, {createdAt: new Date()}, function(err, updated) {});
Run Code Online (Sandbox Code Playgroud)
它适用于我的开发环境,但不适用于服务器。它不返回错误,但不更新记录,只返回未更改的记录。
我尝试使用 new Date().toISOnew Date().toISOString() 或 .toGMTString() 对其进行格式化,但两者仍然仅适用于开发环境。两者都有节点 6.10,但服务器有 mongo 3.4.4,开发人员有 mongo 3.2.10。
如果我添加另一个要更新的字段(第二个参数),该字段会很好地更新,但createdAt保持不变。
'https://twitter.com/pixelhenk/status/891303699204714496'.match(/\/status\/(\d+)/g)
Run Code Online (Sandbox Code Playgroud)
给我
[ "/status/891303699204714496" ]
Run Code Online (Sandbox Code Playgroud)
我如何得到这个数字?我想把它放在括号中做了这个,但显然没有.