我正在为我当地的电影中心写一个粉丝应用程序,它显示了接下来几天的筛选日历.使用来自网站的参数化HTTP调用来检索每日电影列表(答案包含希伯来语,因此如果您点击链接并获得一些Gibberish,则可能是正常的).
该应用程序显示接下来八天的日程安排,因此它会针对每日日程安排请求进行8次调用.
private class GetMoviesTask extends AsyncTask<Integer, Void, List<Film>>
Run Code Online (Sandbox Code Playgroud)
doInBackground()每天检索电影列表,并onPostExecute()更新界面.
从MainActivity.onCreate()以下位置调用AsyncTask :
for (int i=0; i<NUMBER_OF_DAYS_TO_VIEW; i++){
new GetMoviesTask().execute(i);
}
Run Code Online (Sandbox Code Playgroud)
问题是AsyncTask不是并发执行的.这些日子一个接一个地缓慢加载,这是非常缓慢的:



同时启动这些AsyncCalls的最佳方法是什么?
在我的一个JUnit测试中,我正在初始化一个对象:
MyObject myObject = new MyObject(220, 120, 0.05, true);
Run Code Online (Sandbox Code Playgroud)
构造函数的签名是:
public MyObject(int minLength, int maxLength,
double onBitsRatio, boolean forceAtLeastOneBitOn)
Run Code Online (Sandbox Code Playgroud)
其次是:
assert(onBitsRatio >= 0.0 && onBitsRatio <= 1.0);
assert(maxLength>=minLength);
assert(false);
Run Code Online (Sandbox Code Playgroud)
奇怪的是,断言不会像我期望的那样停止执行.
为什么JUnit会忽略这些断言?
考虑以下TestNG配置,它运行com.example.functional.*pacakge中的所有测试:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Functional1" verbose="1" >
<test name="FunctionalTest" >
<packages>
<package name="com.example.functional.*">
</package>
</packages>
</test>
</suite>
Run Code Online (Sandbox Code Playgroud)
为了拆分测试作业,添加了一些排除规则:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Functional1" verbose="1" >
<test name="FunctionalTest" >
<packages>
<package name="com.example.functional.*">
<exclude name="com.example.functional.services.courier.*"></exclude>
<exclude name="com.example.functional.optimization.*"></exclude>
<exclude name="com.example.functional.initialization"></exclude>
<exclude name="com.example.functional.tasks"></exclude>
</package>
</packages>
</test>
</suite>
Run Code Online (Sandbox Code Playgroud)
被排除的包仍在执行 - 任何想法为什么忽略排除?
考虑以下多行字符串:
>> print s
shall i compare thee to a summer's day?
thou art more lovely and more temperate
rough winds do shake the darling buds of may,
and summer's lease hath all too short a date.
Run Code Online (Sandbox Code Playgroud)
re.sub()替换所有的发生and有AND:
>>> print re.sub("and", "AND", s)
shall i compare thee to a summer's day?
thou art more lovely AND more temperate
rough winds do shake the darling buds of may,
AND summer's lease hath all too short a …Run Code Online (Sandbox Code Playgroud) 如何并行运行一系列命令,并将其输出存储在变量中?
我试过了:
output=`(echo -n "started "; sleep 2; echo "stopped") &`
echo "output before=$output"
wait
echo "output after=$output"
Run Code Online (Sandbox Code Playgroud)
暂停了两秒钟,接着是:
output before=started stopped
output after=started stopped
Run Code Online (Sandbox Code Playgroud)
我期望:
output before=
<2 seconds pause>
output after=started stopped
Run Code Online (Sandbox Code Playgroud)
如何在后台运行一系列命令,并将其输出存储在变量中?
Pythonsetuptools可以创建一个源代码分发:
python setup.py sdist # create a source distribution (tarball, zip file, etc.)
Run Code Online (Sandbox Code Playgroud)
或者二进制分布:
python setup.py bdist # create a built (binary) distribution
Run Code Online (Sandbox Code Playgroud)
据我了解,不应该有任何性能差异:
bdist.pyc从二进制包安装已经编译的文件。sdist将.py文件编译为.pyc文件,并安装它们。执行时,.pyc文件的编译方式无关紧要- 它们应该具有相同的性能。
dist和sdistpython包之间有什么性能差异吗?
Flask提供了方便的jsonify()功能,它从Python变量返回一个JSON对象:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def json_hello():
return jsonify({x:x*x for x in range(5)}), 200
if __name__ == "__main__":
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
哪个回报:
{
"0": 0,
"1": 1,
"2": 4,
"3": 9,
"4": 16
}
Run Code Online (Sandbox Code Playgroud)
(PS - 注意从int到string的转换以符合JSON).
这种缩进的格式对于长输出是浪费的,我更喜欢缩小版本:
{"1": 1, "0": 0, "3": 9, "2": 4, "4": 16}
Run Code Online (Sandbox Code Playgroud)
如何从Flask中获得缩小版本的JSON jsonify()?
请考虑以下SQL查询和响应:
CREATE TEMPORARY TABLE dreams (name text, type text);
INSERT INTO dreams VALUES ('Monkey', 'nice');
INSERT INTO dreams VALUES ('Snake', 'Not nice');
INSERT INTO dreams VALUES ('Donkey', 'nice');
INSERT INTO dreams VALUES ('Bird', 'nice');
SELECT name from dreams WHERE type='nice' ORDER BY name;
name
--------
Bird
Donkey
Monkey
(3 rows)
Run Code Online (Sandbox Code Playgroud)
为方便起见,我想按照外观的顺序列举结果,而不管任何现有的ID.预期的结果应该是a-la:
SELECT <magic_enumeration>, name from dreams WHERE type='nice' ORDER BY name;
magic_enumeration | name
-------------------+--------
1 | Bird
2 | Donkey
3 | Monkey
(3 rows)
Run Code Online (Sandbox Code Playgroud)
有关如何按外观顺序枚举查询结果的任何想法?
考虑一个包含以下行的表:
id | bigint
polygons | geometry(Polygon,4326)[]
Run Code Online (Sandbox Code Playgroud)
SELECT-ing 该polygons行返回一个不可读的二进制数据数组:
SELECT polygons FROM some_table WHERE id=405;
{0103000020E61000000100000006000000B84F039E5AC0E375243935C13F402...}
Run Code Online (Sandbox Code Playgroud)
st_AsText在第一个元素上使用会返回一个可读的输出:
SELECT st_AsText(polygons[1]) FROM some_table WHERE id=405;
POLYGON((-106.4689521119 31.7547183717742 ...)
Run Code Online (Sandbox Code Playgroud)
不出所料,该函数仅适用于元素,不适用于数组:
SELECT st_AsText(polygons) FROM some_table WHERE id=405;
ERROR: function st_astext(geometry[]) does not exist
Run Code Online (Sandbox Code Playgroud)
用 Python 术语来说,我正在寻找print [st_AsText(p) for i in polygons]PostgreSQL 中的等价物。
如何在 SELECT 语句中对数组的所有元素运行 PostgreSQL 函数,就像 Python 的列表理解一样?
附录
我认为这不是严格的重复,因为How to apply a function to each element of an array column in Postgres?处理内联数组(例如FROM unnest(ARRAY[1.53224,0.23411234]) …
要从服务器发送Android推送消息,需要两条信息:
共同的智慧说发件人ID应该在我的项目页面中显而易见,但我似乎无法找到它 - 任何想法在哪里?
python ×3
postgresql ×2
android ×1
arrays ×1
assert ×1
bash ×1
concurrency ×1
eclipse ×1
enumeration ×1
flask ×1
java ×1
java-package ×1
json ×1
junit ×1
minify ×1
performance ×1
postgis ×1
regex ×1
replace ×1
sender-id ×1
setuptools ×1
sql ×1
sql-function ×1
string ×1
testng ×1
xml ×1