小编ken*_*ntz的帖子

你如何给当前用户环境变量su

我有一个设置的变量.bashrc.

~/.bashrc:

PROJ_HOME=~/Projects/stable
Run Code Online (Sandbox Code Playgroud)

从bash shell,我想做这样的事情:

$ su -l kenneth -c 'echo $PROJ_HOME'
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时,预期/home/kenneth/Projects/stable不会打印出来.

有关如何做到这一点的任何想法?

linux bash ubuntu

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

理解javascript继承和node.js util继承函数的例子

我有两个模块:apirequest.jsfeed.js. 当我打电话feed.start()apirequest,我得到的,TypeError: Object #<Feed> has no method 'start'.为什么是这样?不util.inherits(Feed, APIRequest);继承APIRequest的属性?

apirequest.js

var EventEmitter = require('events').EventEmitter;
var util = require('util');

function APIRequest(endpoint) { } 

APIRequest.prototype.start = function() { }

util.inherits(APIRequest, EventEmitter);

module.exports = APIRequest;
Run Code Online (Sandbox Code Playgroud)

feed.js

var util = require('util');
var APIRequest = require('../lib/api_request');

function Feed(endpoint) {
  APIRequest.call(this, endpoint);
}

util.inherits(Feed, APIRequest);

var feed = new Feed(endpoint);

feed.start();
Run Code Online (Sandbox Code Playgroud)

javascript oop inheritance node.js

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

为什么Chrome调试程序会跳过删除语句?

为什么Chrome调试程序会跳过删除语句?如果在控制台中运行,以下代码将演示观察结果.

(function () {
  var foo = { bar: true };
  debugger;
  delete foo.bar;
})();
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome

9
推荐指数
1
解决办法
334
查看次数

扭曲反应器在一个程序中多次启动?

是否可以在同一程序中多次启动反应堆?假设您希望将扭曲的功能封装在方法中,以用于API目的.

例如,mymodule.py看起来像这样:

  1 from twisted.web.client import getPage
  2 from twisted.internet import reactor
  3 
  4 def _result(r):
  5     print r
  6     reactor.stop()
  7 
  8 def _error(e):
  9     print e
 10     reactor.stop()
 11 
 12 def getGoogle():
 13     d = getPage('http://www.google.com')
 14     d.addCallbacks(_result, _error)
 15     reactor.run()
 16 
 17 def getYahoo():
 18     d = getPage('http://www.yahoo.com')
 19     d.addCallbacks(_result, _error)
 20     reactor.run()
 21 
Run Code Online (Sandbox Code Playgroud)

main.py看起来像这样:

  1 import mymodule
  2 
  3 getGoogle()
  4 getYahoo()
Run Code Online (Sandbox Code Playgroud)

python twisted reactor

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

在python中,如何确定局部范围中变量的值

出于调试目的,我发现如果我可以打印局部作用域中的变量并且只打印局部作用域中的变量,那将是有益的.

样品:

def showAuthUser(self):
    """Make a request to the campfire server. 

    Returns a getPage object which is deferred.
    """
    u = self.uri + self._resource['showAuthUser']
    m = 'GET'
    n = self.username
    p = self.password
    b = base64.encodestring('{0}:{1}'.format(n, p)) 
    h = {'Authorization': 'Basic ' + b.strip()}
    return self._getPage(u, m, h)
Run Code Online (Sandbox Code Playgroud)

有没有办法在h之后找到局部范围内的所有变量的值?

python

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

在页面初始加载后加载jQuery库

我有一个案例,我需要检查页面上是否存在jQuery,如果没有,我需要加载它.我创建一个脚本标记并引用外部jQuery库.在继续使用脚本的其余部分之前,如何等待在页面上加载库?

更新:

继祗园的建议后,看起来是什么样的:

if (typeof jQuery === 'undefined') {
    var j = document.createElement('SCRIPT');
    j.type = 'text/javascript';
    j.src = '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
    document.getElementsByTagName('head')[0].appendChild(j);
    j.onload = function () {
        var section = document.createElement('DIV');
        section.setAttribute('style', 'height:300px; width:250px; position: fixed; right: 0px; top: 100px;z-index: 9999; border-style:solid;border-width:1px;');
        section.innerHTML = '<p>steps</p><textarea name="steps"></textarea><p>expected results</p><textarea name="results"></textarea><p><input type="button" name="submit" value="add test case" /></p>';

        document.getElementsByTagName('body')[0].appendChild(section);
    };  
} 
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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