小编Mon*_*oya的帖子

Android - 轻扫以删除RecyclerView

我正在尝试实施滑动以删除与Gmail应用"滑动到存档"相同的内容:

gmail滑动删除 gmail滑动删除

我已经尝试了很多教程,但没有一个像gmail一样快,我更喜欢不在外部库上工作.我该怎么做?

编辑:

我的代码到目前为止 -

  ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
                public boolean onMove(RecyclerView recyclerView,
                                               RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
//                    final int fromPos = viewHolder.getAdapterPosition();
//                    final int toPos = viewHolder.getAdapterPosition();
//                    // move item in `fromPos` to `toPos` in adapter.
                    return true;// true if moved, false otherwise
                }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
                //Remove swiped item from list and notify the RecyclerView
                mAdapter.notifyItemRemoved(viewHolder.getLayoutPosition());
            }
        };
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
        itemTouchHelper.attachToRecyclerView(mRecyclerView);
Run Code Online (Sandbox Code Playgroud)

我已设法启用滑动手势,但 …

android android-recyclerview

35
推荐指数
3
解决办法
5万
查看次数

Linux python3 - 无法打开lib'SQL Server'

我正在尝试连接到Microsoft Azure SQL Server数据库.

这是我试图连接的方式:

 conn = pyodbc.connect('DRIVER={SQL Server};SERVER=%s' % (self.config.get("Sql", "DataSource")),
                        user= self.config.get("Sql", "UserId"),
                        password=self.config.get("Sql", "Password"),
                        database=self.config.get("Sql", "Catalog"))
Run Code Online (Sandbox Code Playgroud)

我在排除这一行时遇到错误.错误:

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")
Run Code Online (Sandbox Code Playgroud)

想不通为什么会这样,有什么想法吗?

linux sql-server azure python-3.x azure-sql-database

15
推荐指数
3
解决办法
3万
查看次数

Keras Tensorflow - 从多个线程预测时的异常

我正在使用keras 2.0.8和tensorflow 1.3.0后端.

我在类init中加载一个模型,然后用它来预测多线程.

import tensorflow as tf
from keras import backend as K
from keras.models import load_model


class CNN:
    def __init__(self, model_path):
        self.cnn_model = load_model(model_path)
        self.session = K.get_session()
        self.graph = tf.get_default_graph()

    def query_cnn(self, data):
        X = self.preproccesing(data)
        with self.session.as_default():
            with self.graph.as_default():
                return self.cnn_model.predict(X)
Run Code Online (Sandbox Code Playgroud)

我初始化CNN一次,query_cnn方法从多个线程发生.

我在日志中得到的例外是:

  File "/home/*/Similarity/CNN.py", line 43, in query_cnn
    return self.cnn_model.predict(X)
  File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 913, in predict
    return self.model.predict(x, batch_size=batch_size, verbose=verbose)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 1713, in predict
    verbose=verbose, steps=steps)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 1269, in _predict_loop
    batch_outs = …
Run Code Online (Sandbox Code Playgroud)

multithreading keras tensorflow

10
推荐指数
1
解决办法
6045
查看次数

Android - 外部库更改整个应用程序名称

我已经为我的项目添加了一个外部库,因为它在其values文件中有一个@ string/app_name标记,它会更改我的整个应用程序名称.我无法编辑此值文件.并且不知何故,android studio更喜欢使用外部库app_name资源.我该如何解决?

解:

正如Nicholas Tee所说:

在标记下的AndroidManifest.XML中更改应用名称.您应该看到android:label = @ string/app_name资源.在string.xml中,创建另一个标记,比如@ string/app_name_mine.将android:label = @ string/app_name更改为android:label = @ string/app_name_mine

我还需要添加一个:

tools:replace="label"
Run Code Online (Sandbox Code Playgroud)

到我的应用程序标签.

android

9
推荐指数
1
解决办法
1599
查看次数

GKE - 使用自定义指标的 HPA - 无法获取指标

我有自定义指标导出到Google Cloud Monitoring,我想根据它扩展我的部署。

这是我的 HPA:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: <DEPLOYMENT>-hpa
  namespace: production
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: <DEPLOYMENT>
  minReplicas: 5
  maxReplicas: 100
  metrics:
  - type: External
    external:
      metricName: "custom.googleapis.com|rabbit_mq|test|messages_count"
      metricSelector:
        matchLabels:
          metric.labels.name: production
      targetValue: 1
Run Code Online (Sandbox Code Playgroud)

在描述 hpa 时,我看到:

 Warning  FailedComputeMetricsReplicas  4m23s (x12 over 7m23s)  horizontal-pod-autoscaler  Invalid metrics (1 invalid out of 1), last error was: failed to get externa
l metric custom.googleapis.com|rabbit_mq|test|messages_count: unable to get external metric production/custom.googleapis.com|rabbit_mq|test|messages_count/&LabelSelect
or{MatchLabels:map[string]string{metric.labels.name: production,},MatchExpressions:[],}: unable to fetch metrics …
Run Code Online (Sandbox Code Playgroud)

kubernetes google-kubernetes-engine google-cloud-monitoring hpa

8
推荐指数
1
解决办法
1857
查看次数

Microsoft Knowledge API - 在数据库中搜索句子

我正在尝试将新的Microsoft Knowledge API集成到我的应用程序中.我需要在数据库中搜索以查找类似于google/bing搜索的结果.

到目前为止,我已经提出了这个要求 - 并且它运作良好:

https://westus.api.cognitive.microsoft.com/academic/v1.0/evaluate?expr=And(W=%27bandwidth%27)&attributes=Id,Ti,Y,D,CC,E&subscription-key=MY -API-KEY

根据文档 W论证仅在标题和摘要中搜索,我需要在整篇论文中进行搜索.

我怎样才能从数据库中查询一个句子?

azure microsoft-cognitive

5
推荐指数
1
解决办法
520
查看次数

pdf2HtmlEX - html 上的文本与源 pdf 不同

我正在使用 topdf2htmlEX将 pdf 文件转换为 html。之后我也从文件中提取文本。

问题:

我遇到一个文件,转换后的 html 中的文本不可读:https : //dspace.mit.edu/openaccess-disseminate/1721.1/101159

我使用的命令:

pdf2htmlEX --tounicode 1 ./file.pdf
Run Code Online (Sandbox Code Playgroud)

html 上的文本有很多空格和很多引号 - 在此处输入图片说明

[2]"M."Ha hn,"O."Barbie ri,"FP."Campa na,"R."Kötz,"R."Gallay,"App l."Ph ys ."A :"M a te r."S ci."过程"8 2 "(2 00 6 )"

--tounicodearg设置其他值会使文本变得乱七八糟。

有一个使用这个库的在线工具,在那里生成的 html 很好,这使它不是 pdf2htmlEX 错误,而是配置或版本问题。可能与 poppler 或 fontforge 有关。

版本:

pdf2htmlEX version 0.14.6
Copyright 2012-2015 Lu Wang <coolwanglu@gmail.com> and other contributors
Libraries: 
  poppler 0.54.0
  libfontforge 20180906
  cairo 1.14.6
Default data-dir: /usr/local/share/pdf2htmlEX
Supported image format: png jpg svg
Run Code Online (Sandbox Code Playgroud)

还尝试使用支持该项目的新存储库并获得相同的结果,请参阅问题: …

poppler fontforge pdf2htmlex

5
推荐指数
1
解决办法
900
查看次数

android - httpsurlconnection'get'405 - 不允许使用方法

我在HttpsUrlConnection上使用'get'方法.当我在eclipse(Windows)上测试我的代码时,它运行正常.当我将它压缩到jar文件并在android studio上使用它时,它给了我'405 - 方法不允许'.这是什么意思,我用不好的动词(预期的GET)运行方法.

这是我设置http方法类型的方式:

        conn.setRequestMethod("GET");
Run Code Online (Sandbox Code Playgroud)

我将http方法设置为'get',当我调试它时 - conn.getRequestMethod = GET和conn.delegate.getRequestMethod = POST.

错误响应是 - {"消息":"请求的资源不支持http方法'POST'."}

委托方法类型

主要的conn方法类型

已编辑 - 已添加代码:

 public static HttpsURLConnection getClient(URL url, LoginToken securityToken, RequestMethod methodType, String requestFormat, String responseFormat) throws IOException, SecurityTokenException {
    HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
    conn.addRequestProperty("Accept-Charset", "UTF-8");
    conn.addRequestProperty("Content-Type", requestFormat);
    conn.addRequestProperty("Accept", responseFormat);
    conn.addRequestProperty("User-Agent", "***SDK/1.0");
    conn.setRequestProperty("Cache-Control", "no-cache");
    if(securityToken != null) {
        LoginToken.ValidateToken(securityToken);
        conn.addRequestProperty("Authorization", String.format("Bearer %1$s", new Object[]{securityToken.getTemporarySecurityCode()}));
    }

    conn.setRequestMethod(methodType.toString());
    conn.setUseCaches(false);
    conn.setDoOutput(true);
    return conn;
}

  public Boolean IsCompleted() throws SecurityTokenException, CommandFailedException {
    LoginToken.ValidateToken(this.getSecurityToken());
    HttpsURLConnection conn = null;
    Gson …
Run Code Online (Sandbox Code Playgroud)

java https android http httpsurlconnection

4
推荐指数
1
解决办法
3242
查看次数

Python-按页面拆分pdf

PyPdf2用来拆分大PDF页面。问题在于此过程非常缓慢。

这是我使用的代码:

import os
from PyPDF2 import PdfFileWriter, PdfFileReader

with open(input_pdf_path, "rb") as input_file:
    input_pdf = PdfFileReader(input_file)
    directory = "%s/paging/" % os.path.dirname(input_pdf_path)
    if not os.path.exists(directory):
        os.makedirs(directory)

    page_files = []
    for i in range(0, input_pdf.numPages):
        output = PdfFileWriter()
        output.addPage(input_pdf.getPage(i))
        file_name = "%s/#*#*#*##-%s.pdf" % (directory, i)
        page_files.append(file_name)
        with open(file_name, "wb") as outputStream:
            output.write(outputStream)
Run Code Online (Sandbox Code Playgroud)

使用此代码分割177页pdf大约需要35到55秒。有没有办法可以改善此代码?还有其他更适合此工作的图书馆吗?

python pdf pypdf python-3.x pypdf2

4
推荐指数
1
解决办法
5512
查看次数

Pytorch - 在特定维度上应用池化

我有一个 3 维向量。我想在第二个维度上执行一维最大池。

根据 pytorch 的文档,池化总是在最后一个维度上执行。

https://pytorch.org/docs/stable/nn.html#maxpool1d

例如:

>>> x = torch.rand(5, 64, 32)
>>> pool = nn.MaxPool1d(2, 2)
>>> pool(x).shape
torch.Size([5, 64, 16])
Run Code Online (Sandbox Code Playgroud)

我想要的输出:

torch.Size([5, 32, 32])
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python pytorch

4
推荐指数
1
解决办法
2413
查看次数