我正在尝试在Chrome扩展程序中编写更好的书签管理器.问题是没有关于如何实际使用bookmarksAPI的简单示例(我可以找到).
我查看了示例源代码(当我将其导入并安装在我的计算机上时,除了提供搜索框之外它没有做任何事情.键入/输入并按返回无法执行任何操作)并且找不到任何有用的内容.
我的最终目标是制作一个扩展程序,允许我保存页面以便稍后阅读,而无需在某个地方注册某个服务的帐户.所以我计划在根文件夹/其他书签中创建一个或两个书签文件夹 - 至少是"未读页面"文件夹.在该文件夹中,我将创建未读书签.当用户将项目标记为已读时,它将从该文件夹中删除.
所以这就是我想要做的......任何帮助都会非常感激,即使它只是指向一些好的例子.
更新:
...<script>
function display(tree){
document.getElementById("Output").innerHTML = tree;
}
function start(){
chrome.bookmarks.getTree(display);
}
</script>
</head>
<body>
<h4 id="Output"></h4>
<script>
start();
</script>
...
Run Code Online (Sandbox Code Playgroud)
这[object Object]表明,这表明(至少对我有限的JavaScript经验)对象存在.但是如何访问该对象的成员?
更改tree为tree.id或将显示为参数的任何其他内容undefined.
我刚刚开始使用Django编写我的第一个应用程序 - 我的家人的家务管理经理.在本教程中,它将向您展示如何以表格形式添加相关对象.我不关心相关的对象,我只想以表格形式添加常规对象.这就是我在admin.py中的内容
from chores.models import Chore
from django.contrib import admin
class ChoreAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['description', 'frequency', 'person']})
]
admin.site.register(Chore, ChoreAdmin)
Run Code Online (Sandbox Code Playgroud)
我想点击"添加家务"而不是看到:
Description: _____
Frequency: ______
Person: _____
Run Code Online (Sandbox Code Playgroud)
我想要它显示:
Description: __________ | Frequency: _______ | Person: _____
Run Code Online (Sandbox Code Playgroud)
这是微不足道的,还是需要大量的定制工作?如果这很容易,我该怎么做?
谢谢!
显然我可以从中获取日期和时间datetime.datetime.now(),但我实际上并不关心秒或特别是微秒.
有什么地方我可以轻松获得日期+小时+分钟?
此图片是Font Awesome 示例的屏幕截图

在我的屏幕上(我甚至在Paint中旋转以确保它确实模糊而不仅仅是一些魔法)90度和270度旋转显得模糊.垂直和水平翻转都很好.我的问题是为什么?什么是Chrome或Font Awesome机制导致这种情况发生?
当然,IE 9中的情况要糟糕得多

我可以去
http://myjenkins:8080/job/Project/42/changes
Run Code Online (Sandbox Code Playgroud)
并查看触发特定Jenkins构建的提交消息.
但是,我想通过REST API或其他东西来获取它.我在搜索中没有运气.是否有捷径可寻?
不知道这有多可能,但这里有:
我正在尝试用一些稍微微妙的行为来写一个对象 - 这可能是也可能不是一个好主意,我还没有确定.
我有这个方法:
def __getattr__(self, attr):
try:
return self.props[attr].value
except KeyError:
pass #to hide the keyerror exception
msg = "'{}' object has no attribute '{}'"
raise AttributeError(msg.format(self.__dict__['type'], attr))
Run Code Online (Sandbox Code Playgroud)
现在,当我像这样创建一个这样的实例时:
t = Thing()
t.foo
Run Code Online (Sandbox Code Playgroud)
我得到一个包含我的函数的stacktrace :
Traceback (most recent call last):
File "attrfun.py", line 23, in <module>
t.foo
File "attrfun.py", line 15, in __getattr__
raise AttributeError(msg.format(self._type, attr))
AttributeError: 'Thing' object has no attribute 'foo'
Run Code Online (Sandbox Code Playgroud)
我不希望这样 - 我希望堆栈跟踪读取:
Traceback (most recent call last):
File "attrfun.py", line 23, in …Run Code Online (Sandbox Code Playgroud) 我使用https://github.com/dockerfile/haproxy中的默认 HAProxy Docker 映像
不幸的是我无法让它正确地重新加载我的配置。
如果我跑
$ sudo docker exec haprox haproxy -f /etc/haproxy/haproxy.cfg -p '$(</var/run/haproxy.pid)' -st '$(</var/run/haproxy.pid)'
Run Code Online (Sandbox Code Playgroud)
它只是转储帮助文件。如果我跑
$ sudo docker exec haprox 'haproxy -f /etc/haproxy/haproxy.cfg -p $(</var/run/haproxy.pid) -st $(</var/run/haproxy.pid)'
Run Code Online (Sandbox Code Playgroud)
我明白了
2014/12/30 00:03:23 docker-exec: failed to exec: exec: "haproxy -f /etc/haproxy/haproxy.cfg -p $(</var/run/haproxy.pid) -st $(</var/run/haproxy.pid)": stat haproxy -f /etc/haproxy/haproxy.cfg -p $(</var/run/haproxy.pid) -st $(</var/run/haproxy.pid): no such file or directory
Run Code Online (Sandbox Code Playgroud)
嘘。这些都不是我想要的。我可以运行docker exec haprox service haproxy reload- 但这最终会产生几个 haproxy 进程,因此当我通过 unix 套接字连接时,我从中获得一组信息,show stat但从 http 统计页面获得一组完全不同的信息。 …
我有一个遗留数据库,它使用各种存储过程为多个列创建默认值.尝试追踪名称并向我的代码添加查询会更加或更不容易,更不用说维护噩梦了.
我会想是能够告诉SQLAlchemy的忽略,我真的不关心列.不幸的是,事实并非如此.相反,它提供null违反数据库约束的值.
这是我的意思的一个例子:
import sqlalchemy as sa
import logging
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
l = logging.getLogger('sqlalchemy.engine')
l.setLevel(logging.INFO)
l.addHandler(logging.StreamHandler())
engine = sa.create_engine('postgresql+psycopg2://user@host:port/dbname')
Session = sessionmaker(bind=engine)
session = Session()
temp_metadata = sa.MetaData(schema='pg_temp')
TempBase = declarative_base(metadata=temp_metadata)
with session.begin(subtransactions=True):
session.execute('''
CREATE TABLE pg_temp.whatevs (
id serial
, fnord text not null default 'fnord'
, value text not null
);
INSERT INTO pg_temp.whatevs (value) VALUES ('something cool');
''')
class Whatever(TempBase):
__tablename__ = 'whatevs'
id = sa.Column('id', sa.Integer, …Run Code Online (Sandbox Code Playgroud) 大多数情况下,当我使用 pytest 时,输出非常非常长。一百多行。很多时候我想要这个输出,我真的想要。--tb=short是不是真的一个很好的办法。但是我不想在我的 tmux 窗口中向后滚动 200 行来找到我的测试输出,因为这也很烦人。
我想要的是这样的:
______________________ >>test_my_test_with_a_lot_of_output _______________________
# imagine lots of test output here
______________________ <<test_my_test_with_a_lot_of_output _______________________
Run Code Online (Sandbox Code Playgroud)
我可以在 py.test 中使用一些标志或设置来实现这种输出吗?
我正在使用嘲笑API unittest.mock.我的界面是一个requests在场景后面使用的类.所以我做的是这样的:
@pytest.fixture
def mocked_api_and_requests():
with mock.patch('my.thing.requests') as mock_requests:
mock_requests.post.return_value = good_credentials
api = MyApi(some='values', that='are defaults')
yield api, mock_requests
def test_my_thing_one(mocked_api_and_requests):
api, mocked_requests = mocked_api_and_requests
... # some assertion or another
def test_my_thing_two(mocked_api_and_requests):
api, mocked_requests = mocked_api_and_requests
... # some other assertions that are different
Run Code Online (Sandbox Code Playgroud)
正如你可能看到的那样,我在这两个测试中都有相同的第一行,并且闻起来对我来说不够干净.
我希望能够做到这样的事情:
def test_my_thing_one(mock_requests, logged_in_api):
mock_requests.get.return_value = ...
Run Code Online (Sandbox Code Playgroud)
而不是必须解压缩这些值,但我不确定是否有办法使用pytest可靠地执行此操作.如果它在夹具的文档中我完全错过了它.但它确实感觉应该有一个正确的方法来做我想做的事情.
有任何想法吗?class TestGivenLoggedInApiAndMockRequests: ...如果我需要走这条路,我愿意使用.我只是不太清楚这里适当的模式是什么.
python ×6
pytest ×2
bookmarks ×1
css ×1
datetime ×1
django ×1
docker ×1
exception ×1
font-awesome ×1
haproxy ×1
html ×1
javascript ×1
jenkins ×1
mocking ×1
postgresql ×1
sqlalchemy ×1