小编Max*_*mov的帖子

mongodb调试 - ReferenceError:未定义控制台

我有js文件mongodb在我得到console.log调试表达式的地方运行:

use test;
db.city.find().snapshot().forEach(function(city){
    var Pos = city.Pos;

    if (Pos) 
    {
        longLat = Pos.split(" ");
        console.log("longLat");  // for debugging ----------------------------  
        console.log(longLat);

        lon = longLat[0];
        lat = longLat[1];

        if (lon && lat)
        {
            lon = parseFloat(lon);
            lat = parseFloat(lat);
            longLat = [lon, lat];
            city.longLat = longLat;

        }

    }
    db.orgs.save(city);

})
Run Code Online (Sandbox Code Playgroud)

当我运行它...

mongo < /path/to/this/js/file.js
Run Code Online (Sandbox Code Playgroud)

...输出中出错:

ReferenceError: console is not defined
Run Code Online (Sandbox Code Playgroud)

有没有办法记录中间结果以进行调试?

javascript mongodb mongodb-shell

7
推荐指数
1
解决办法
3290
查看次数

mmonit golang重启慢和状态不存在

我创建了必须在崩溃时重启的monit应用程序golang site

$ cd /etc/monit/conf.d 
$ vim checkSite 
Run Code Online (Sandbox Code Playgroud)

它启动程序nohup并将其保存pid到文件:

check process site with pidfile /root/go/path/to/goSite/run.pid
    start program = "/bin/bash -c 'cd /root/go/path/to/goSitePath; nohup ./goSite > /dev/null 2>&1 & echo $! > run.pid'" with timeout 5 seconds
    stop program = "/bin/kill -9 `cat /root/go/path/to/goSitePath/run.pid`"
Run Code Online (Sandbox Code Playgroud)

它开始了.

Process 'site'
  status                            Running
  monitoring status                 Monitored
  pid                               29723
  parent pid                        1
  uptime                            2m 
  children                          0
  memory kilobytes                  8592
  memory kilobytes total            8592
  memory percent                    0.4%
  memory percent total …
Run Code Online (Sandbox Code Playgroud)

go monit

7
推荐指数
1
解决办法
1537
查看次数

调试模式,用于记录sublime控制台中的任何命令

我使用了那个命令,但忘了怎么打开它:

在sublime控制台中,由ctrl+ `我调用类似于...

turn_on_debug_mode
Run Code Online (Sandbox Code Playgroud)

...和sublime控制台开始记录我运行的每个命令.例如,如果我在视图上按下鼠标右键,Copy file path然后在sublime控制台中单击,我发现此操作的日志记录与调用命令的名称一样copy_file_path.

所以这是一个简单的方法来获取我可以在自编的sublime插件中使用的命令名称.

问题是我不记得如何打开调试模式.

sublimetext sublimetext2 sublimetext3 sublime-text-plugin

7
推荐指数
1
解决办法
4464
查看次数

从一个nodeunit文件中按名称运行一个测试

是否可以通过多次测试从nodeunit测试文件中仅运行一个测试.我的tests.js档案:

module.exports = {
    test2: function (test) {
        console.log ("test2")
        test.done();
    },
    test1: function (test) {
        console.log ("test1")
        test.done();
    }
};
Run Code Online (Sandbox Code Playgroud)

我可以运行所有测试:

$ nodeunit tests.js
Run Code Online (Sandbox Code Playgroud)

但是我想只运行test2:

$ nodeunit tests.js test2
Run Code Online (Sandbox Code Playgroud)

是否可以不将文件tests.js拆分为2个单独的文件?

nodeunit

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

改变elasticsearch.yml后重新加载elasticsearch

如何elasticsearch申请新配置?我在文件中更改了一个字符串~ES_HOME/config/elasticsearch.yml:

# Disable HTTP completely:
#
http.enabled: false
Run Code Online (Sandbox Code Playgroud)

然后尝试重新加载elasticsearch:

elasticsearch reload
Run Code Online (Sandbox Code Playgroud)

然后尝试重新启动elasticsearch:

elasticsearch restart
Run Code Online (Sandbox Code Playgroud)

然后检查并查看http请求仍然可以接受弹性搜索.

所以我的设置不适用.

我的操作系统是os X.ElasticSearch版本是1.2.0

elasticsearch

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

在golang中缩小html以删除多余的空格和下一行字符

如何创建html minifier?

package main

import (
    "fmt"
)

func HtmlMinify(html string) string {
    // todo: minify html
    return html
}

func main() {

    htmlExample := `<li>
                        <a>Hello</a>
                    </li>`
    minifiedHtml := HtmlMinify(htmlExample)
    fmt.Println(minifiedHtml) //  `<li><a>Hello</a></li>` is wanted
}
Run Code Online (Sandbox Code Playgroud)

输出:

<li>
                        <a>Hello</a>
                    </li>
Run Code Online (Sandbox Code Playgroud)

但我希望它是

<li><a>Hello</a></li>
Run Code Online (Sandbox Code Playgroud)

操场

go

6
推荐指数
2
解决办法
3874
查看次数

无法通过密钥获得大猩猩会话值

我无法通过这种方式从会话中获得价值,它是nil:

session := initSession(r)
valWithOutType := session.Values[key]
Run Code Online (Sandbox Code Playgroud)

完整代码:

package main

import (
    "fmt"
    "github.com/gorilla/mux"
    "github.com/gorilla/sessions"
    "log"
    "net/http"
)

func main() {
    rtr := mux.NewRouter()
    rtr.HandleFunc("/setSession", handler1).Methods("GET")
    rtr.HandleFunc("/getSession", handler2).Methods("GET")
    http.Handle("/", rtr)
    log.Println("Listening...")
    http.ListenAndServe(":3000", http.DefaultServeMux)
}

func handler1(w http.ResponseWriter, r *http.Request) {
    SetSessionValue(w, r, "key", "value")
    w.Write([]byte("setSession"))
}

func handler2(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("getSession"))
    value := GetSessionValue(w, r, "key")
    fmt.Println("value from session")
    fmt.Println(value)
}

var authKey = []byte("secret") // Authorization Key

var encKey = []byte("encKey") // Encryption Key

var …
Run Code Online (Sandbox Code Playgroud)

go gorilla

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

Go中的光标键终端输入

我正在创建一个Go应用程序,以便在终端中使用.以下代码要求用户向终端输入文本.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    for {
        fmt.Println("Please input something and use arrows to move along the text left and right")
        in := bufio.NewReader(os.Stdin)
        _, err := in.ReadString('\n')
        if err != nil {
            fmt.Println(err)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是用户不能使用左箭头和右箭头沿着刚输入的文本进行修改.当他按下箭头时,控制台会打印 ^[[D^[[C^[[A^[[B标志.

输出:

Please input something and use arrows to move along the text left and right
hello^[[D^[[C^[[A^[[B
Run Code Online (Sandbox Code Playgroud)

如何使箭头键表现得更加用户友好,让人类使用左右箭头沿着刚刚输入的文本导航?

我想,我应该关注像termbox-gogocui这样的库, 但是如何正确地将它们用于此目的,我不知道.

terminal go

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

将cmd stdout和stderr作为字符串返回,而不是在golang中打印到控制台

我正在从golang应用程序执行bash命令.现在,stdoutstderr直接进入控制台:

cmd.Stdout = os.Stdout 
cmd.Stderr = os.Stderr
Run Code Online (Sandbox Code Playgroud)

但我希望stdoutstderrrunBashCommandAndKillIfTooSlow函数返回为字符串变量而不立即打印到控制台.怎么实现这个?

代码:

package main

import (
    "fmt"
    "log"
    "os"
    "os/exec"
    "time"
)

func main() {
    ok, outString, errString := runBashCommandAndKillIfTooSlow("ls -la", 2000)
    fmt.Println("ok")
    fmt.Println(ok)
    fmt.Println("outString")
    fmt.Println(outString)
    fmt.Println("errString")
    fmt.Println(errString)
}

/*
run bash command and kill it if it works longer than "killInMilliSeconds" milliseconds
*/
func runBashCommandAndKillIfTooSlow(command string, killInMilliSeconds time.Duration) (okResult bool, stdout, stderr string) {
    fmt.Println("running bash command...")
    fmt.Println(command)
    cmd := …
Run Code Online (Sandbox Code Playgroud)

go

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

缓存存储[]未定义

我正在尝试运行 laravel 应用程序。我有一个错误:

In CacheManager.php line 98:

  Cache store [] is not defined.


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Run Code Online (Sandbox Code Playgroud)

当我跑步时:

composer install --optimize-autoloader --no-dev
Run Code Online (Sandbox Code Playgroud)

我的缓存.php:

<?php

use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Cache Store
    |--------------------------------------------------------------------------
    |
    | This option controls the default cache connection that gets used while
    | using this caching library. This connection is used when another is
    | not explicitly specified when executing a given caching function. …
Run Code Online (Sandbox Code Playgroud)

php laravel

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