如何向我登录mongo shell的当前用户显示?这很有用,因为可以db.auth("newuser", "password")在交互式shell中更改您登录的用户.人们很容易失去踪迹.
使用接受的答案作为基础,我将提示更改为包括用户,连接和数据库:
.mongorc.js在主目录中编辑.
function prompt() {
var username = "anon";
var user = db.runCommand({connectionStatus : 1}).authInfo.authenticatedUsers[0];
var host = db.getMongo().toString().split(" ")[2];
var current_db = db.getName();
if (!!user) {
username = user.user;
}
return username + "@" + host + ":" + current_db + "> ";
}
Run Code Online (Sandbox Code Playgroud)
结果:
MongoDB shell version: 2.4.8
connecting to: test
anon@127.0.0.1:test> use admin
switched to db admin
anon@127.0.0.1:admin> db.auth("a_user", "a_password")
1
a_user@127.0.0.1:admin>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用django-debug-toolbar和我的django应用程序,它适用于django v1.5.但是,我正在尝试将系统迁移到django v1.6,并且当我尝试加载任何页面时它会生成以下错误.
python manage.py runserver
Validating models...
0 errors found
December 21, 2013 - 22:53:18
Django version 1.6.1, using settings 'MySite.settings'
Starting development server at http://XXX.XXX.XXX.XXX:XXXX/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
File "/home/user/django-env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 90, in get_response
response = middleware_method(request)
File "/home/user/django-env/local/lib/python2.7/site-packages/debug_toolbar/middleware.py", line 45, in process_request
mod_path, func_name = func_path.rsplit('.', 1)
AttributeError: 'function' object has no attribute 'rsplit'
[21/Dec/2013 22:53:21] "GET / HTTP/1.1" 500 58172
Run Code Online (Sandbox Code Playgroud)
源代码有这个注释,但我不确定它们的含义是什么(import_by_path):
def process_request(self, …Run Code Online (Sandbox Code Playgroud) Python 3.x,Celery 4.x ......
我有一个基于类的任务.
myproj/celery.py
from celery import Celery
# django settings stuff...
app = Celery('myproj')
app.autodiscover_tasks()
Run Code Online (Sandbox Code Playgroud)
app1/tasks.py
import celery
class EmailTask(celery.Task):
def run(self, *args, **kwargs):
self.do_something()
Run Code Online (Sandbox Code Playgroud)
如果我做:
$ celery worker -A myproj -l info
[tasks]
. app2.tasks.debug_task
. app2.tasks.test
Run Code Online (Sandbox Code Playgroud)
因此,芹菜装饰器用于注册任务,但基于类的任务未注册.
更新1:
如果我添加以下行 app1/tasks.py
from myproj.celery import app
email_task = app.tasks[EmailTask.name]
Run Code Online (Sandbox Code Playgroud)
.
$ celery worker -A myproj -l info
File "myproj/app1/tasks.py", line 405, in <module>
email_task = app.tasks[EmailTask.name]
File "/usr/local/lib/python3.5/site-packages/celery/app/registry.py", line 19, in __missing__
raise self.NotRegistered(key)
celery.exceptions.NotRegistered
Run Code Online (Sandbox Code Playgroud)
更新2: …
需要提前道歉:长度和我的无知.我正在尝试自学新概念:d3.js和精灵表.精灵表概念很容易理解,但我很困惑如何将它整合到d3中.基本上我想要做的是从精灵表中选择我想用作图像的精灵,然后使用d3在页面上的其他地方显示这个选定的精灵,并且很可能是同一精灵的多个副本.
实际的精灵表供参考(见下文免责声明):

以下是问题:1)我将精灵表添加到我的html中,硬编码<clipPath>现在,这显示了我想要的特定精灵,但是,精灵的尺寸/位置就像显示整个精灵表一样.我怎样才能"捕捉"精灵本身,而不仅仅是隐藏未使用的精灵?在下图中,我想在d3鼠标悬停事件中使用单个"图标"(第2部分).
修改此示例:SO:在不使用foreignObject的情况下在SVG中显示CSS图像精灵
HTML
<svg id="mySvg1" width="100%" height="100%">
<defs>
<clipPath id="c">
<rect x="135" y="0" width="150" height="150"/>
</clipPath>
</defs>
<image transform="scale(1.0)" x="0" y="0" width="550" height="420" xlink:href="static/img/iconSheet.png" clip-path="url(#c)"/>
<svg>
Run Code Online (Sandbox Code Playgroud)
结果

2)我可以<pattern>用来确定要在d3对象/事件中显示的图像.就像在矩形中显示图形一样.但这似乎不适用于大型图像(精灵表)?如果我尝试使用精灵表本身及其在模式中的原生尺寸,它会变得奇怪和模糊.如果我们解决第1部分,我们可能会忽略第2部分,但是对于一般知识/将来的使用,这将是很好的理解.
修改此示例:SO:在d3 javascript中在圆形对象中添加图像?
HTML
<svg id="mySvg" width="550" height="420">
<defs id="mdef">
<pattern id="image" x="0" y="0" height="550" width="420">
<image transform="scale(1.0)" x="0" y="0" width="550" height="420" xlink:href="static/img/iconSheet.png"></image>
</pattern>
</defs>
</svg>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var svgContainer = d3.select("div#content-main").append("svg")
.attr("width", 740)
.attr("height", 760)
.attr("class", "mySvg")
.style("border", "none");
svgContainer.append("rect")
.attr("class", "logo")
.attr("x", 0)
.attr("y", …Run Code Online (Sandbox Code Playgroud) 一位同事声称这是向Angular注入纯ES6 JavaScript类的错误方法.我很好奇是否有更好的方法(更正确)?
顺便说一句,将注入的依赖项($timeout在此示例中)附加到实例是否更好(以及为什么更好); 例如,this._$timeout = $timeout在构造函数中.我个人认为在这种情况下做这件事没有任何好处.
class.factory.js
let ClassFactory = function($timeout) {
// Factory function that simply returns class constructor.
class MyClass {
constructor(a, b) {
// contrived class
this.a = a;
this.b = b;
this.c = null;
}
applyChange() {
// contrived class method
const SELF = this;
$timeout(() => {
SELF.c = SELF.a + SELF.b;
});
}
}
return MyClass ;
};
ClassFactory.$inject = ['$timeout'];
export default ClassFactory;
Run Code Online (Sandbox Code Playgroud)
app.module.js
import ClassFactory from './factories/class.factory';
import …Run Code Online (Sandbox Code Playgroud) 请耐心等待,我是GUI编程,IronPython,WPF和.NET的新手.但是,我对Python非常熟悉.我浏览了很多在线教程,但似乎没有人能解决我面临的确切问题.(也许这是微不足道的?但对像我这样的人来说这并不是微不足道的!)
问题:我想知道如何从Windows.System.Application中将新的WPF窗口(XAML)作为新窗口启动.基本上,我想从我的应用程序的帮助菜单中启动一个"关于"对话框.我知道这可以通过使用System.Windows.Forms.Form来实现,但从长远来看,我希望能够通过使用XAML标记加载更复杂的窗口安排.
目前,当我单击关于菜单(mnuAboutClick)时,这会加载XAML窗口,但在此过程中替换/销毁原始主窗口(WpfMainWindow).我希望两个窗户都保持打开状态.
编辑:或者,有没有办法将xaml加载到System.Windows.Forms.Form?这将适合我的需要.
这是我的代码示例:
import wpf
from System.Windows import Application, Window
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, 'WpfMainWindow.xaml')
def mnuAboutClick(self, sender, e):
print 'About Menu Click'
wpf.LoadComponent(self, 'WpfAboutWindow.xaml') # How to launch "About Dialog", This works, but destroys "WpfMainWindow"!
if __name__ == '__main__':
Application().Run(MyWindow())
Run Code Online (Sandbox Code Playgroud) 我正在使用docker python:3.5-alpine3.4image并尝试安装,lapack-dev但是它一直失败。它抱怨找不到libgfortran.so.5。但是,我尝试安装libgfortran,但这似乎无法解决问题。
(1/1) Installing libgfortran (5.3.0-r0)
OK: 33 MiB in 37 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
fetch http://dl-8.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-8.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
WARNING: This apk-tools is OLD! Some packages might not function properly.
ERROR: unsatisfiable constraints:
so:libgfortran.so.5 (missing):
required by:
lapack-3.8.0-r1[so:libgfortran.so.5]
Run Code Online (Sandbox Code Playgroud)
有什么想法我可以解决这个问题吗?这是相关的RUN步骤。
FROM python:3.5-alpine3.4
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& apk update \
&& apk add --update-cache --no-cache libgcc libquadmath musl \
&& apk add --update-cache --no-cache libgfortran \
&& …Run Code Online (Sandbox Code Playgroud) 看到这篇博客文章 ...它已经很老了,所以也许情况发生了变化.但在我的实验中他们没有.为了upload_to动态更改模型字段FileField 路径,您必须求助于使用signals和创建自定义model fields.讨厌.我无法想象拥有动态上传路径是一个特殊的用例,标准的Django框架无法解决这个问题.我错过了什么吗?有没有其他方法可以实现这一目标?
本质上我想这样做:
def MyModel(models.Model):
fileUpload = models.FileField(upload_to='media/', null=True, blank=True)
def save(self, **kwargs):
# Retrieve the user's id/pk from their profile
up = UserProfile.objects.get(email=self.email)
# All their uploads go into their own directory
self.file_image.upload_to = up.id
super(MyModel, self).save()
Run Code Online (Sandbox Code Playgroud)
然而,在我尝试的10种不同的实现中,Django讨厌所有这些.特别是对于这个,文件被上传到默认路径'media/'.
我已经尝试抓取参数的模型表并将这些参数传递到dict对象,创建MyModel对象,设置MyModel.fileUpload.upload_to参数,然后将dict复制到模型中并保存.不行.
我也试图覆盖这个__init__方法,但猜猜是什么?那是在对象创建的早期,它实际上还没有self.email定义!所以这不起作用.
任何想法或我必须遵循原始链接中概述的神秘解决方案?
我无法通过virtualenv(和virtualenvwrapper)获取apache来为我的网站服务.我尝试了这里的演练.值得注意的是,我使用的是Ubuntu Server v13.10,我读过它还没有对Apache v2.2的本机支持,因此在演练中我无法安装apache2.2-common.但是,我不认为这是问题,因为apache错误日志表示存在权限问题.
在我的设置中,虚拟环境位于非root用户的主目录中,而apache服务器以root身份运行(我认为这是正常的).我试图跟踪权限使用namei,我已确保chmod +rw路径为root.有任何想法吗?
[Thu Mar 06 14:16:37.639031 2014] [mpm_event:notice] [pid 8771:tid 140338386122624] AH00489: Apache/2.4.6 (Ubuntu) mod_wsgi/3.4 Python/2.7.5+ configured -- resuming normal operations
[Thu Mar 06 14:16:37.639144 2014] [core:notice] [pid 8771:tid 140338386122624] AH00094: Command line: '/usr/sbin/apache2'
[Thu Mar 06 14:16:53.456622 2014] [:error] [pid 8775:tid 140338291197696] [client 192.168.XXX.XXX:50742] mod_wsgi (pid=8775): Target WSGI script '/var/www/www.mysite.org/index.wsgi' cannot be loaded as Python module.
[Thu Mar 06 14:16:53.456735 2014] [:error] [pid 8775:tid 140338291197696] [client 192.168.XXX.XXX:50742] …Run Code Online (Sandbox Code Playgroud) 有没有办法强制执行except块,以便我可以通过单元测试验证错误消息/处理?例如:
def get_books(request):
...
try:
book = Books.objects.get_or_create(user=request.user)
except:
messages.error(request, 'Unable to create new book!')
return HttpResponseRedirect(reverse('my_books'))
# more try/except cases
Run Code Online (Sandbox Code Playgroud)
所以在这个例子中,我可以尝试模拟ORM失败,或者我可以尝试在这种情况下发送无效用户.但是有一种抛出异常的一般方法(我愿意使用库)吗?Mock例如.或者是否有其他方法可用于unittest强制例外?显然在整个代码中会有很多try/except块,所以我正在寻找任何帮助.
这里发生了什么?
头文件:
// .h file
public:
typedef size_t size_type;
static const size_type CAPACITY = 3;
private:
value_type data[CAPACITY];
size_type cursor;
Run Code Online (Sandbox Code Playgroud)
实施文件:
// .cpp file
for (cursor = 0; cursor <= CAPACITY; ++cursor)
{
data[cursor] = -1;
std::cout << "cursorPos: " << cursor << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
输出:
cursorPos: 0
cursorPos: 1
cursorPos: 2
cursorPos: 3220176896
Run Code Online (Sandbox Code Playgroud) django ×4
python ×4
javascript ×2
alpine-linux ×1
angularjs ×1
apache ×1
apk ×1
c++ ×1
celery ×1
d3.js ×1
django-1.6 ×1
ecmascript-6 ×1
es6-class ×1
installation ×1
ironpython ×1
lapack ×1
mongodb ×1
python-2.7 ×1
python-3.x ×1
sprite-sheet ×1
svg ×1
unit-testing ×1
virtualenv ×1
windows ×1
wpf ×1