我知道还有一些关于同一主题的其他问题,但是这些问题都不等于我的具体问题。
HttpURLConnection在我的 Android 应用程序中,我通过一些 RESTful 端点发出 Http 请求。其中一些端点使用自签名证书,其他端点则不使用。因此,我需要一种方法将自定义 KeyStore 添加到默认 HttpURLConnection 行为。
这是我现在的代码:
try {
KeyStore keyStore = getKeyStore(context);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, "pasword".toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
} catch (KeyStoreException | IOException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException | KeyManagementException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
它可以工作,但仅适用于自签名证书,任何其他请求都会产生java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
因此,我正在寻找一种方法让 HttpURLConnection 识别自定义自签名证书而不破坏正常行为。
我正在尝试将NodeJS应用程序上传到Amazon AWS中的Elastic Beanstalk。但是,当执行npm install时,它会引起一些权限被拒绝,因此无法运行该应用程序。这是日志
Application update failed at 2018-10-02T15:18:14Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed.
+ /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN deprecated tar.gz@1.0.7: ?? WARNING ?? tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
npm WARN deprecated fs-promise@2.0.3: Use mz or fs-extra^3.0 with Promise Support
> scrypt@6.0.3 preinstall /tmp/deployment/application/node_modules/scrypt
> node node-scrypt-preinstall.js
Error: Error: Command failed: ./configure
./configure: line 1904: config.log: Permission denied
./configure: line 1914: config.log: Permission denied …Run Code Online (Sandbox Code Playgroud) permission-denied amazon-web-services node.js amazon-elastic-beanstalk npm-install
我想在矩形中随机放置一些点。
生成随机的 x, y 坐标不是一个好主意,因为很多时候这些点主要分布在同一区域而不是覆盖整个矩形。
我不需要非常快的算法或最佳覆盖位置,只需要可以在简单游戏中运行的算法,该游戏生成几乎覆盖整个矩形的随机 (x, y)。
在我的特殊情况下,我试图生成一个简单的天空,所以我的想法是在天空矩形中放置近 40/50 颗星星。
有人可以指出我一些常见的算法来做到这一点吗?
我将为一个社交网络风格的网站构建一个 MySQL 数据库,用户可以在其中关注其他用户,然后从他们关注的用户那里获取更新。
我的数据库由一张包含用户基本信息的表组成:
| ID | username | password | email | ... other few columns |
Run Code Online (Sandbox Code Playgroud)
'ID' 是主要的,'username' 和 'email' 是唯一的和索引。
然后我有一个包含用户提要的表,只有在其他用户关注它时才应该显示,“ID”始终是主要的:
| ID | feed_to_show_in_home |
Run Code Online (Sandbox Code Playgroud)
然后是一个包含关注者统计信息的表格,以加快用户个人资料页面的速度:
| ID | followers_count | following_count |
Run Code Online (Sandbox Code Playgroud)
并且至少存储了谁跟随谁的真实追随者网络表:
| ID | following |
Run Code Online (Sandbox Code Playgroud)
在此表中,“ID”和“关注”都是主要的,因为一个用户只能关注另一个用户一次。
现在我想问一下,从性能的角度来看,我的结构是否良好。我特别担心如何检查用户是否正在关注另一个用户、停止关注用户以及仅在我关注该特定用户时如何显示提要。
在任何一种情况下,我想到的解决方案是始终扫描完整的表长度,但我认为这不是一个好的选择,因为该数据库计划存储超过 10,000 个用户。
algorithm ×1
android ×1
database ×1
mysql ×1
node.js ×1
npm-install ×1
performance ×1
position ×1
random ×1
self-signed ×1
ssl ×1