小编tro*_*gne的帖子

node.js stdout clearline()和cursorTo()函数

从node.js教程中,我看到了这两个process.stdout函数:

process.stdout.clearLine();
process.stdout.cursorTo(0);
Run Code Online (Sandbox Code Playgroud)

但我使用的是更新的node.js版本(4.2.4),并且这些功能不存在.我得到的process.stdout.clearLine is not a functionprocess.stdout.cursorTo is not a function.

node.js版本4.2.4上clearLine和cursorTo的等价物是什么?

编辑:

这些都不起作用:

process.readline.clearLine();
process.readline.cursorTo(0);

function writeWaitingPercent(p) {
    process.readline.clearLine();
    process.readline.cursorTo(0);
    process.stdout.write(`waiting ... ${p}%`);
}
Run Code Online (Sandbox Code Playgroud)

我明白了 Cannot read property 'clearLine' of undefined

node.js

26
推荐指数
3
解决办法
2万
查看次数

vagrant无法连接到虚拟框

当我vagrant up使用基本的Vagrantfile时,只配置了这两行:

config.vm.box = "ubuntu/trusty32"
config.vm.network "forwarded_port", guest: 80, host: 8080
Run Code Online (Sandbox Code Playgroud)

我看到我的虚拟框打开了,但是我的流浪日志多次显示此行,直到超时:

default: Warning: Connection timeout. Retrying...
Run Code Online (Sandbox Code Playgroud)

然后,在超时后的一段时间,虚拟框框最终要求我登录,但这太长了!

所以我记录了流浪汉/流浪汉.然后在我的物理机器上,如果我"流浪汉ssh".没有任何事情发生,直到这个:

ssh_exchange_identification: read: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)

怎么了 ?任何的想法 ?

(顺便说一句,我的8080端口是免费的,我也尝试过vb.gui = true,

它正在与盒子一起工作hashicorp/precise32)

ubuntu virtual-machine vagrant

12
推荐指数
2
解决办法
7776
查看次数

加载所有图像时的jquery div

通过执行以下操作,我可以在加载图像时加载图像:

<img style="display:none;" src="big3.jpg">
<script type="text/javascript">
    $('img').load(function(){
        $(this).css({'display':'block'})
    });
</script>
Run Code Online (Sandbox Code Playgroud)

但我想要的是在加载所有img时加载div,但这不起作用,为什么?:

<div style="display:none;">
    <img src="big3.jpg">
</div>
<script type="text/javascript">
    $('div').load(function(){
        $(this).css({'display':'block'})
    });
</script>
Run Code Online (Sandbox Code Playgroud)

jquery load image

11
推荐指数
1
解决办法
9520
查看次数

laravel - 为什么函数调用没有括号?

我在一个laravel教程中看到了这个:

Auth::user()->item;
Run Code Online (Sandbox Code Playgroud)

其中item是一个函数,在models\User.php中:

function item() { return $this->hasMany('Item', 'owner_id'); }
Run Code Online (Sandbox Code Playgroud)

其中Item是models\Item.php

那么为什么在调用item函数时不需要括号?喜欢:Auth::user()->item(); 如果我把括号括起来,浏览器会变得疯狂并崩溃.

此外,如果我将Item.php重命名为Item2.php,将类Item重命名为Item2,我这样做hasMany('Item2', 'owner_id'),它将无法工作.但为什么 ?'Item'来自哪里?

谢谢,

帕特里克

function foreign-key-relationship parentheses laravel

10
推荐指数
1
解决办法
1680
查看次数

cygwin:vagrant ssh,空命令提示符

如果我vagrant ssh使用windows cmd,我会得到一个很好的命令提示符,就像那样:

vagrant@homestead:~$ echo foo
vagrant@homestead:~$ foo
Run Code Online (Sandbox Code Playgroud)

但是对于cygwin和mintty,我根本没有提示:

echo foo
foo
Run Code Online (Sandbox Code Playgroud)

我认为它与"伪tty分配"有关.

有了cygwin和mintty,我可以得到我的提示:

vagrant ssh -- -t -t
Run Code Online (Sandbox Code Playgroud)

我如何改变cygwin和mintty以便我不必告诉它-t

关于ssh -t选项:

"强制伪tty分配.这可以用来在远程机器上执行任意基于屏幕的程序,这在实现菜单服务时非常有用.多个-t选项强制tty分配,即使ssh有没有当地人."

cygwin vagrant

6
推荐指数
1
解决办法
1952
查看次数

不能用薄荷键入一些字符

使用mintty作为终端,像这样运行:

C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -
Run Code Online (Sandbox Code Playgroud)

我不能输入像〜,[,{...这样的字符

但我可以在windows cmd终端上键入所有这些字符,在cygwin默认终端上运行cygwin.bat:

@echo off
C:
chdir C:\cygwin64\bin
bash --login -i
Run Code Online (Sandbox Code Playgroud)

什么在我的键盘上做薄荷?

*仅在使用Teamviewer*远程记录时才会发生这种情况

cygwin mintty teamviewer

5
推荐指数
0
解决办法
221
查看次数

multiprocessing.pool.MaybeEncodingError: 'TypeError("cannot serialize '_io.BufferedReader' object",)'

为什么下面的代码只适用于multiprocessing.dummy,而不适用于 simple multiprocessing

import urllib.request
#from multiprocessing.dummy import Pool #this works
from multiprocessing import Pool

urls = ['http://www.python.org', 'http://www.yahoo.com','http://www.scala.org', 'http://www.google.com']

if __name__ == '__main__':
    with Pool(5) as p:
        results = p.map(urllib.request.urlopen, urls)
Run Code Online (Sandbox Code Playgroud)

错误 :

Traceback (most recent call last):
  File "urlthreads.py", line 31, in <module>
    results = p.map(urllib.request.urlopen, urls)
  File "C:\Users\patri\Anaconda3\lib\multiprocessing\pool.py", line 268, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "C:\Users\patri\Anaconda3\lib\multiprocessing\pool.py", line 657, in get
    raise self._value
multiprocessing.pool.MaybeEncodingError: Error sending result: '[<http.client.HTTPResponse object at 0x0000016AEF204198>]'. Reason: …
Run Code Online (Sandbox Code Playgroud)

python urllib multiprocessing python-multithreading python-multiprocessing

4
推荐指数
1
解决办法
2526
查看次数

little information about snippets

When trying to insert a snippet, be it custom or provided by vscode, I don't have enough info to choose from the suggestions.

For example, I have custom snippet for "template" :

    "template js": {
        "prefix": "template",
        "body": ["<template>", "    $0", "</template>"],
        "description": "template js description"
    }
Run Code Online (Sandbox Code Playgroud)

If I enter "templ" (for "template"), I will see 3 suggestions : my custum snippet, and 2 by vscode.

But next to each suggestions I see this :

Snippet 1 :

Provider: snippetCompletions …
Run Code Online (Sandbox Code Playgroud)

code-snippets visual-studio-code

3
推荐指数
1
解决办法
197
查看次数

javascript setInterval - 倒计时滞后

我使用下面的代码在几秒钟内倒计时.问题是,当使用jquery .load再次加载包含倒计时的页面部分时,新的倒计时会出错:每隔一秒,我们会看到快速的2秒,如下所示:9-8 ... 7-6. ..5-4 ......就好像它与时钟不同步......在那里看到:aorbaroquethrash.com/test(为了解决问题,我必须在你那里换歌)

知道如何解决这个问题吗?

<script type = "text/javascript">
/*author Philip M. 2010*/

var timeInSecs;
var ticker;

function startTimer(secs){
timeInSecs = parseInt(secs)-1;
ticker = setInterval("tick()",1000);   // every second
}

function tick() {
var secs = timeInSecs;
if (secs>0) {
timeInSecs--;
}
else {
clearInterval(ticker); // stop counting at zero
}

document.getElementById("countdown").innerHTML = secs;
} 
startTimer(<?php echo $stream['info']['length'];?>);

</script>
Run Code Online (Sandbox Code Playgroud)

帕特里克

javascript setinterval countdown

2
推荐指数
1
解决办法
4766
查看次数

无法使用heroku将cookie发送到后端

我正在向我的后端发出 axios 请求,并设置一个 cookie :

axios.get(`http://mybackend/somepage`)
     .then((response) => {
        res.cookie('token', response.data.token)
        res.send(`click here <a href="http://mybackend/profile">profile</a>`)
})
Run Code Online (Sandbox Code Playgroud)

在我的后端,我使用带有“cookie-parser”的express。

单击后端的链接,我得到以下内容console.log(req.cookies):“[Object: null prototype] {}”。

查看请求标头,cookie 甚至没有发送。

我在本地主机上测试时没有这个问题。

是因为无法在两个域(在本例中是 2 个 heroku 应用程序)之间交换 cookie 吗?

heroku node.js express

2
推荐指数
1
解决办法
1161
查看次数

反应路由器4并表达:无法获取

我正在尝试对Express服务器使用React Router 4。

如果我将路径设置为“ /”,它将起作用。但是,如果我将路径设置为“ / test”,并访问测试,则会得到“ Cannot GET / test”。是因为React Router 4与Express不兼容吗?

app-client.js:

import { BrowserRouter, Route, Switch } from 'react-router-dom';
import Board from './components/Board';

ReactDOM.render(
    <BrowserRouter>
        <div>
            <Route path="/test" component={Board} />
        </div>
    </BrowserRouter>
    , document.getElementById('react-container'));
Run Code Online (Sandbox Code Playgroud)

Board.js:

var React = require('react');
var createReactClass = require('create-react-class');

var Board = createReactClass({
    render(){
        return (<h1>Board</h1>)
    }    
});

export default Board;
Run Code Online (Sandbox Code Playgroud)

express reactjs react-router

0
推荐指数
1
解决办法
1554
查看次数