程序设计

专业和发烧友程序员的问答

10
自动更新package.json版本
在做一个小发布并将其标记之前,我想更新package.json以反映该程序的新版本。 有没有一种方法可以package.json自动编辑文件? 需要git pre-release hook帮助吗?
181 git  node.js  npm  githooks 

12
在ipython Notebook中测量单元执行时间的简单方法
除了单元的原始输出,我想花时间在单元执行上。 为此,我尝试了%%timeit -r1 -n1但它没有公开定义在单元格内的变量。 %%time 适用于仅包含1条语句的单元格。 In[1]: %%time 1 CPU times: user 4 µs, sys: 0 ns, total: 4 µs Wall time: 5.96 µs Out[1]: 1 In[2]: %%time # Notice there is no out result in this case. x = 1 x CPU times: user 3 µs, sys: 0 ns, …

1
如何在UITableViewCell之间添加间距
有什么办法可以增加两者之间的间隔UITableViewCell? 我创建了一个表格,每个单元格只包含一个图像。图像被分配给像这样的单元: cell.imageView.image = [myImages objectAtIndex:indexPath.row]; 但这会使图像放大并适合整个单元格,并且图像之间没有间距。 或者以这种方式说,图像的高度例如为50,我想在图像之间增加20个间距。有什么办法可以做到这一点?

13
javascript对对象的reduce()
有一个很好的Array方法reduce()可以从Array中获取一个值。例: [0,1,2,3,4].reduce(function(previousValue, currentValue, index, array){ return previousValue + currentValue; }); 用对象达到相同目的的最佳方法是什么?我想这样做: { a: {value:1}, b: {value:2}, c: {value:3} }.reduce(function(previous, current, index, array){ return previous.value + current.value; }); 但是,对象似乎没有reduce()实现任何方法。


10
在Python中记录未捕获的异常
您如何导致未捕获的异常通过logging模块而不是通过模块输出stderr? 我意识到最好的方法是: try: raise Exception, 'Throwing a boring exception' except Exception, e: logging.exception(e) 但是我的情况是,如果在没有捕获到异常的情况下自动调用它,那将非常好logging.exception(...)。

2
str.startswith带有要测试的字符串列表
我试图避免使用那么多的if语句和比较,而只使用一个列表,但不确定如何将其用于str.startswith: if link.lower().startswith("js/") or link.lower().startswith("catalog/") or link.lower().startswith("script/") or link.lower().startswith("scripts/") or link.lower().startswith("katalog/"): # then "do something" 我希望它是: if link.lower().startswith() in ["js","catalog","script","scripts","katalog"]: # then "do something" 任何帮助,将不胜感激。
181 python  string  list 

1
C ++中有最大数组长度限制吗?
C ++中的数组有最大长度吗? 是C ++限制还是取决于我的机器?可以调整吗?它是否取决于数组的类型? 我可以以某种方式打破该限制吗?还是我必须寻找一种更好的信息存储方式?而最简单的方法应该是什么? 我要做的是将长整型存储在数组中,我正在Linux环境中工作。我的问题是:如果我需要存储N个大于10位的N个长整型数组,该怎么办? 我需要这样做是因为我正在为学校编写一些加密算法(例如p-Pollard),并碰到了整数和数组表示长度的墙。
181 c++  arrays 

11
为什么函数可以修改调用者认为的某些自变量,而不能修改其他自变量?
我正在尝试了解Python的可变范围方法。在此示例中,为什么f()能够更改的值(x如在其中看到的)main(),但不能更改的值n? def f(n, x): n = 2 x.append(4) print('In f():', n, x) def main(): n = 1 x = [0,1,2,3] print('Before:', n, x) f(n, x) print('After: ', n, x) main() 输出: Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After: 1 [0, 1, 2, …
181 python 

10
Python中的SFTP?(与平台无关)
我正在使用一个简单的工具,该工具使用密码也将密码传输到文​​件的硬编码位置。我是python新手,但是多亏了ftplib,这很容易: import ftplib info= ('someuser', 'password') #hard-coded def putfile(file, site, dir, user=(), verbose=True): """ upload a file by ftp to a site/directory login hard-coded, binary transfer """ if verbose: print 'Uploading', file local = open(file, 'rb') remote = ftplib.FTP(site) remote.login(*user) remote.cwd(dir) remote.storbinary('STOR ' + file, local, 1024) remote.quit() local.close() if …
181 python  sftp 

3
REST API登录模式
我正在创建一个REST api,紧紧遵循apigee建议,使用名词而不是动词,url中烘焙的api版本,每个集合两个api路径,GET POST PUT DELETE用法等。 我正在使用登录系统,但是不确定用于登录用户的正确REST方式。我目前不在安全性方面,只是在登录模式或流程方面。(稍后,我们将添加2步oAuth,以及HMAC等) 可能的选择 张贴到类似的东西 https://api...com/v1/login.json 放置到类似 https://api...com/v1/users.json 我还没有... 用于登录用户的正确REST风格是什么?

9
django测试应用程序错误-创建测试数据库时出错:创建数据库的权限被拒绝
当我尝试使用命令测试任何应用程序时(当我尝试使用使用此命令的结构来部署myproject时,我注意到了它): python manage.py test appname 我收到此错误: Creating test database for alias 'default'... Got an error creating the test database: permission denied to create database Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel syncdb命令似乎起作用。我在settings.py中的数据库设置: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', # …


1
改造2-动态网址
使用Retrofit 2,您可以在服务方法的注释中设置完整的URL,例如: public interface APIService { @GET("http://api.mysite.com/user/list") Call<Users> getUsers(); } 但是,在我的应用程序中,我的Web服务的URL在编译时未知,该应用程序在下载的文件中检索它们,因此我想知道如何将Retrofit 2与完整的动态URL结合使用。 我试图设置一个完整的路径,如: public interface APIService { @GET("{fullUrl}") Call<Users> getUsers(@Path("fullUrl") fullUrl); } new Retrofit.Builder() .baseUrl("http://api.mysite.com/") .build() .create(APIService.class) .getUsers("http://api.mysite.com/user/list"); // this url should be dynamic .execute(); 但是在这里,Retrofit并未看到该路径实际上是完整的URL,而是试图下载 http://api.mysite.com/http%3A%2F%2Fapi.mysite.com%2Fuser%2Flist 关于如何将Retrofit与此类动态url一起使用的任何提示? 谢谢
181 android  retrofit 

6
elasticsearch bool查询必须与OR结合使用
我目前正在尝试将基于Solr的应用程序迁移到Elasticsearch。 我有这个lucene查询 (( name:(+foo +bar) OR info:(+foo +bar) )) AND state:(1) AND (has_image:(0) OR has_image:(1)^100) 据我了解,这是MUST子句与布尔OR的组合: “获取所有包含(名称中包含foo AND bar)或(信息中包含foo AND bar)的所有文档。在此之后,按条件state = 1过滤结果,并增强具有图像的文档。” 我一直在尝试将布尔查询与MUST一起使用,但是我无法将布尔OR放入must子句中。这是我所拥有的: GET /test/object/_search { "from": 0, "size": 20, "sort": { "_score": "desc" }, "query": { "bool": { "must": [ { "match": { "name": "foo" } }, { …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.