我尝试在 package.json 中设置 git 依赖项:
"dependencies": {
"myLib": "git+ssh://git@domain.com:user/myLib.git"
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,sudo npm install我收到错误:
Warning: Permanently added the RSA host key for IP address 'myIp' to the list of known hosts.
Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)
尽管我可以成功地将相同的库克隆到该机器:
git clone git@domain.com:user/myLib.git
Run Code Online (Sandbox Code Playgroud)
所以我有有效的 ssh 密钥。
我的操作系统是OSX ,但我在Linux上也有同样的问题。
有时当我在Sublime text2中编辑coffeescript文件时,我将它编译为js时出错:
error: unexpected INDENT
$.post url,
Run Code Online (Sandbox Code Playgroud)
在sublime text2编辑器中,我看到有效的缩进:

但是,如果我在普通编辑器中复制粘贴此代码,我会看到错误的缩进:
click: ->
debugger;
# delete org here
$.post url,
Run Code Online (Sandbox Code Playgroud)
debugger; 字符串有错误的额外缩进.
那么如何高兴地编辑sublime text 2中的coffeescript文件呢?我在sublime中安装了coffeescript包.
我的Preferences.sublime-settings文件如下:
{
"auto_indent": true,
"auto_match_enabled": true,
"detect_indentation": true,
"draw_centered": false,
"font_size": 11.0,
"ignored_packages":
[
"Better CoffeeScript",
"Vintage"
],
"indent_guide_options":
[
"draw_active"
],
"indent_subsequent_lines": true,
"indent_to_bracket": true,
"smart_indent": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"use_tab_stops": true,
"word_wrap": "auto",
"wrap_width": 0
}
Run Code Online (Sandbox Code Playgroud) 我用一个方法及其别名创建了一个coffeeScript类:
class Class1
method1 : (param1)=>
console.log param1
aliasForMethod1: @method1
module.exports = Class1
Run Code Online (Sandbox Code Playgroud)
它输出javascript:
// Generated by CoffeeScript 1.6.2
(function() {
var Class1,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Class1 = (function() {
function Class1() {
this.method1 = __bind(this.method1, this);
}
Class1.prototype.method1 = function(param1) {
return console.log(param1);
};
Class1.prototype.aliasForMethod1 = Class1.method1;
return Class1;
})();
module.exports = Class1;
}).call(this);
Run Code Online (Sandbox Code Playgroud)
尝试使用这个类:
Class1 = require './class1'
instanceOfClass1 = new Class1()
instanceOfClass1.method1()
instanceOfClass1.aliasForMethod1()
Run Code Online (Sandbox Code Playgroud)
但得到错误:
$ node /pathToMyClassUser/class1_user.js
undefined
/pathToMyClassUser/class1_user.js:11 …Run Code Online (Sandbox Code Playgroud) 我想使用正则表达式来显示错误消息......
try {
throw new Error("Foo 'bar'");
} catch (err) {
console.log(getInQuotes(err));
}
Run Code Online (Sandbox Code Playgroud)
...其中 getInQuotes 是字符串函数:
var getInQuotes = function(str) {
var re;
re = /'([^']+)'/g;
return str.match(re);
};
Run Code Online (Sandbox Code Playgroud)
...但出现错误:
Object Error: Foo 'bar' has no method 'match'
Run Code Online (Sandbox Code Playgroud)
虽然它适用于普通字符串:
console.log(getInQuotes("Hello 'world'"));
Run Code Online (Sandbox Code Playgroud)
结果:
[ '\'world\'' ]
Run Code Online (Sandbox Code Playgroud)
尝试将错误对象字符串化...
console.log("stringify: " + JSON.stringify(err));
Run Code Online (Sandbox Code Playgroud)
...但它是空的:
stringify: {}
Run Code Online (Sandbox Code Playgroud) 如何在sublime text 3插件中获取所选文本:
import sublime, sublime_plugin
class plugin_window__go_to_relative_plugin__Command(sublime_plugin.WindowCommand):
def run(self):
window = self.window
view = window.active_view()
sel = view.sel()
sublime.status_message("selection: "+sel)
Run Code Online (Sandbox Code Playgroud)
我的代码抛出错误:
sublime.status_message("selection: "+sel)
TypeError: Can't convert 'Selection' object to str implicitly
Run Code Online (Sandbox Code Playgroud)
view.sel()返回sublime.Selection对象.但我不知道如何从那里获取选定的文本.
这个插件必须如下工作:当我在视图上调用它时...

...它应该将文本设置"dow = self.w"为变量sel
当我这样做str(sel)时返回<sublime.Selection object at 0x1047fd8d0>
对我来说,文档不是很清楚.
几天后我面临服务器磁盘溢出.在它充满10%之前.原因是文件newrelic_agent.log大小为5 - 30千兆字节.我在应用程序的文件nginx夹site-enabled和主目录中找到了这么大的文件node.js express.
{"name":"newrelic","hostname":"hostname","pid":355,"component":"redis","level":10,"msg":"Adding Redis command trace segment transaction 2769.","time":"2014-01-02T06:20:11.894Z","v":0}
{"name":"newrelic","hostname":"hostname","pid":355,"component":"redis","level":10,"msg":"Adding Redis command trace segment transaction 2769.","time":"2014-01-02T06:20:11.894Z","v":0}
{"name":"newrelic","hostname":"hostname","pid":355,"component":"redis","level":10,"msg":"Adding Redis command trace segment transaction 2769.","time":"2014-01-02T06:20:11.895Z","v":0}
Run Code Online (Sandbox Code Playgroud)
在我删除这些文件后,我在一天中发现它们的规模如此糟糕.
如何在服务器上禁用此日志记录?我认为这是因为newrelic redis的关键插件.或者唯一的方法是关闭这个插件?
我想配置supervisord有golang web app根据的文章.但是当我运行命令时出错sudo supervisord -c /etc/supervisor/supervisord.conf:
Error: Invalid username deploy user # the user your app should run as (i.e. *not* root!)
Run Code Online (Sandbox Code Playgroud)
我创建了用户deployuser并将其添加到组中supervisor
sudo adduser deployser supervisor
Run Code Online (Sandbox Code Playgroud)
Supervisord配置文件是
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0770 ; sockef file mode (default 0700)
chown=root:supervisor ; add our group
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) …Run Code Online (Sandbox Code Playgroud) 我试图从golang测试重复示例
package main
import (
"testing"
)
func TestSomeTest(t *testing.T) {}
func TestMain(m *testing.M) { // cleaning after each test}
Run Code Online (Sandbox Code Playgroud)
我想TestMain在每次测试后运行函数.
运行命令 go test
而编译器说
./testingM_test.go:9: undefined: testing.M
Run Code Online (Sandbox Code Playgroud)
那么在执行每个测试后如何清理?
我有一个以上的IP去互联网.我正在请求选择界面.在这种情况下,我应该如何设置标题?
tcpAddr := &net.TCPAddr{
IP: addrs[3].(*net.IPNet).IP, // Choosing ip address number 3
}
d := net.Dialer{LocalAddr: tcpAddr}
conn, err2 := d.Dial("tcp", "www.whatismyip.com:80")
if err2 != nil {
log.Fatal(err2)
}
defer conn.Close()
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{LocalAddr: tcpAddr}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
}
client := &http.Client{
Transport: transport,
}
response, err := client.Get("https://www.whatismyip.com/")
Run Code Online (Sandbox Code Playgroud)
通常标头以这种方式设置:
req.Header.Set("name", "value")
Run Code Online (Sandbox Code Playgroud)
但无法弄清楚如何将它们设置为我的代码.
我想他们必须设置在某处http.Transport或http.Client.但到底怎么样?
我的完整代码:
package main
import (
"bytes"
"fmt"
"github.com/PuerkitoBio/goquery"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"time"
) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在docker中运行chromedp。我的main.go:
package main
import (
"context"
"log"
"time"
"github.com/chromedp/chromedp"
)
func main() {
log.SetFlags(log.LstdFlags | log.Llongfile)
ctx, cancel := chromedp.NewContext(
context.Background(),
chromedp.WithLogf(log.Printf),
)
defer cancel()
// create a timeout
ctx, cancel = context.WithTimeout(ctx, 15 * time.Second)
defer cancel()
u := `https://www.whatismybrowser.com/detect/what-is-my-user-agent`
selector := `#detected_value`
log.Println("requesting", u)
log.Println("selector", selector)
var result string
err := chromedp.Run(ctx,
chromedp.Navigate(u),
chromedp.WaitReady(selector),
chromedp.OuterHTML(selector, &result),
)
if err != nil {
log.Fatal(err)
}
log.Printf("result:\n%s", result)
}
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM golang:latest as build-env …Run Code Online (Sandbox Code Playgroud) coffeescript ×2
go ×2
node.js ×2
sublimetext2 ×2
chromedp ×1
docker ×1
javascript ×1
logging ×1
newrelic ×1
plugins ×1
python ×1
sublimetext ×1
sublimetext3 ×1
supervisord ×1