我HttpsConnection
在Android上遇到了麻烦.
首先,不,它不是重复.我在SO上尝试了几乎所有的解决方案,比如更改keep-alive
选项或者timeout
(其中一些确实优化了我的代码的一部分)但是它在Android上比在iOS上慢5到10倍(可能更多).
在Android上发送请求到我的服务器需要几秒钟,而在iOS和浏览器上它几乎是即时的.我确信服务器没有原因.但似乎获得输入流非常慢!
这一行:
in=conn.getInputStream();
Run Code Online (Sandbox Code Playgroud)
是最拖延的,它本身需要几秒钟.
我的目标是从我的服务器获取JSON.我的代码应该在技术上尽可能地优化(并且它可能可以帮助一些人HttpsConnection
在同一时间):
protected String getContentUrl(String apiURL)
{
StringBuilder builder = new StringBuilder();
String line=null;
String result="";
HttpsURLConnection conn= null;
InputStream in= null;
try {
URL url;
// get URL content
url = new URL(apiURL);
System.setProperty("http.keepAlive", "false");
trustAllHosts();
conn = (HttpsURLConnection) url.openConnection();
conn.setHostnameVerifier(DO_NOT_VERIFY);
conn.setRequestMethod("GET");
conn.setRequestProperty(MainActivity.API_TOKEN, MainActivity.ENCRYPTED_TOKEN);
conn.setRequestProperty("Connection", "close");
conn.setConnectTimeout(1000);
in=conn.getInputStream();
// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while ((line=br.readLine())!= …
Run Code Online (Sandbox Code Playgroud) 我有模型用户。有两个管理器,过滤由 is_active 设置的查询的 UserManager 和 AllUserManager。默认管理器设置为 UserManager。
用户有另一个模型的外键,名为 Address,具有related_name='users'。
问题是下一个。当 User is_active 为 False 时,Address 不会在 users 集合中显示非活动用户。
是否有可能以某种方式将 AllUserManager 设置为某些 FK 的默认管理器?我希望能够列出地址中的所有用户,而不管他们的活动如何。
我想在运行时将文本框添加到我的用户表单中。目前我正在使用此代码执行此操作:
Dim edtBox_n As Control
Set edtBox_n = usrFrm.Controls.Add("Forms.TextBox.1", "edtBox_n", True)
With edtBox_n
.Top = 20
.Left = 20
End With
Run Code Online (Sandbox Code Playgroud)
但是,我无法操作文本框特定的属性,例如多行、最大文本长度等。
是否有另一个选项向不缺乏此要求的用户添加运行时控件?
我正在使用球衣2
我有一个抽象类,用于构建我的请求.现在,我还有一些抽象的客户端类,我用它们作为代理类和实际实现.这些工作得很好,但未经测试.
我的问题是如何测试它,而不必运行它连接的Web服务?
public abstract class AbstractRestProxy {
private Client client;
private WebTarget service;
/**
* Get the base {@link Client} and {@link WebTarget}
*/
@PostConstruct
public void base() {
this.client = ClientBuilder.newClient();
this.service = this.client.target(this.getBaseUri());
}
/**
* close the connection before destroy
*/
@PreDestroy
protected void close() {
if (this.client != null) {
this.client.close();
}
}
/**
*
* @return get the basePath
*/
protected abstract String getBasePath();
/**
*
* @return get the baseUri
*/
protected abstract …
Run Code Online (Sandbox Code Playgroud) 我正在学习迅速并试图理解词典.我已经习惯了PHP,你可能会写下以下内容......
$dataPoints = Array("A"=>1,"B"=>2,"C"=>3);
foreach($dataPoints as $value) {
echo($value);
}
Run Code Online (Sandbox Code Playgroud)
在此示例中,值将按顺序输出 - 1,2,3
我的快速代码看起来像这样......
var dataPoints: Dictionary<String,Int> = ["A":1,"B":2,"C":3]
for (key, value) in dataPoints {
print(value)
}
Run Code Online (Sandbox Code Playgroud)
但是,这些值会以意想不到的顺序出现.有什么东西可以做,以保持值的创建顺序,或者一个快速的字典永远不会被排序?
我正在开发一个Java项目,其中有一个HTML编辑器,用户可以在html编辑器(ckeditor)中输入文本,实际的HTML文本保存在数据库中.
现在,当用户下次再来,并编辑相同的文本时,我想通过比较它与数据库来显示两者之间的差异.
我面临的最重要的问题是,即使任何比较器工具知道Italic的样式已经变为Bold,比较器的输出也strike-throughs
就是单词Italic
和节目Bold
插入代替它.
但这并不能解释实际编辑的意图或行动.意图/行动是用户从Italic到Bold.我正在寻找的是一个工具,它不是显示Italic这个词被删除而Bold被添加而不是代替那个,它会向我显示Italic
首先是删除的Bold
单词/句子以及用单词/句子替换.
我希望我的意思很明确.我一直在努力实现这一目标.我试过diff_match_patch,daisydiff等,没有任何帮助.
我的试验:
/*
String oldTextHtml = mnotes1.getMnotetext();
String newTextHTML = mnotes.getMnotetext();
oldTextHtml = oldTextHtml.replace("<br>","\n");
oldTextHtml = Jsoup.clean(oldTextHtml, Whitelist.basic());
oldTextHtml = Jsoup.parse(oldTextHtml).text();
newTextHTML = newTextHTML.replace("<br>","\n");
newTextHTML = Jsoup.clean(newTextHTML,Whitelist.basic());
newTextHTML = Jsoup.parse(newTextHTML).text();
diff_match_patch diffMatchPatch = new diff_match_patch();
LinkedList<diff_match_patch.Diff> deltas = diffMatchPatch.diff_main(oldTextHtml, newTextHTML);
diffMatchPatch.diff_cleanupSemantic(deltas);
newText += diffMatchPatch.diff_prettyHtml(deltas);
groupNoteHistory.setWhatHasChanged("textchange");
groupNoteHistory.setNewNoteText(newText);
noEdit = true;
*/
List<String> oldTextList = Arrays.asList(mnotes1.getMnotetext().split("(\\.|\\n)"));
List<String> newTextList = Arrays.asList(mnotes.getMnotetext().split("(\\.|\\n)"));
if (oldTextList.size() == newTextList.size()) …
Run Code Online (Sandbox Code Playgroud) 我有一个数据库的备份,我将恢复到在docker容器内运行的postgres数据库.
我在OS X上使用的是docker-
machine.Postgres图像是postgres:9.4
.
这是我到目前为止提出的脚本:
pg_restore --verbose --clean --no-acl --no-owner \
-h tcp://`docker-machine ip default`:5432 \
-U postgres \
-d tonsser-api_development latest.dump
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我收到错误:
pg_restore: connecting to database for restore
pg_restore: [archiver (db)] connection to database "tonsser-api_development" failed: could not translate host name "tcp://192.168.99.100:5432" to address: nodename nor servname provided, or not known
Run Code Online (Sandbox Code Playgroud) 我尝试更新其他字段,效果很好。
我在 API 中使用的命令:
User.update({ email: targetUser.email }, { $set: { isAdmin: true }, $push: { 'log.updated': new Date() } }, function (err, user) {
if (err) {
responseObject.err = err;
responseObject.data = null;
responseObject.code = 422;
return res.json(responseObject);
}
return res.json(responseObject);
});
Run Code Online (Sandbox Code Playgroud)
澄清一下,当我尝试运行它时,API 返回代码 200,这意味着一切正常,但是当我检查数据库时,isAdmin 值没有改变。
任何建议都会有所帮助,这里的想法不多了!
请求的用户架构:
var UserSchema = new Schema({
name: { type: String, default: "", index: 'text' },
email: { type: String, lowercase: true },
role: { type: String, default: "" },
meta: {
skills: …
Run Code Online (Sandbox Code Playgroud) 我正在渲染高阶组件,Application
我需要在渲染之前从服务器获取一些数据.我做的,在Application
我发出loadApplicationState()
行动的构造函数中,执行服务器调用并准备初始状态.
一些简化的代码,
class Application extends Component {
constructor(props) {
super(props);
const { dispatch } = this.props;
dispatch(loadApplicationState());
}
render() {
const { stateLoaded } = this.props.state;
render (
<div>
{ stateLoaded ? renderApp() : renderProgress() }
</div>
)
}
}
function loadApplicationState() {
return (dispatch) => {
// fetch data and once ready,
applicationStateLoaded(data);
}
}
Run Code Online (Sandbox Code Playgroud)
我在练习上尝试过,它运行正常.但不确定这是一种正确的方法吗?特别是为此目的使用构造函数.
在Visual Studio 2015 Enterprise Edition中,如果我在代码中放置断点,并将代码编入IF语句,则会出现致命错误:
尝试应用代码更改并且需要终止调试时发生了致命错误.操作不受支持.未知错误:0x800004005.
Visual Studio然后崩溃.
我不确定是什么原因导致问题或在哪里看.有任何想法吗?
java ×2
android ×1
dictionary ×1
django ×1
docker ×1
excel ×1
express ×1
html ×1
javascript ×1
jersey-2.0 ×1
json ×1
junit ×1
mongodb ×1
node.js ×1
pg-restore ×1
postgresql ×1
reactjs ×1
redux ×1
string ×1
swift ×1
vba ×1