问:
Multiple dependency issues during RedHat's yum update
As soon as I login I tried sudo yum update and it shows following errors. How do I solve this updates issue?

```<code>[ec2-user@ip-172-31-16-247 ~]$ sudo yum update
</code>```

Loaded plugins: priorities, update-motd, upgrade-helper

  amzn-main/latest
  | 2.1 kB  00:00

  amzn-updates/latest
  | 2.3 kB  00:00
   737 packages excluded due to
  repository priority protections
 Resolving Dependencies

  --> Running transaction check

  ---> Package aws-cfn-bootstrap.noarch 0:1.4-11.6.amzn1 will be updated

  ---> Package aws-cfn-bootstrap.noarch 0:1.4-12.7.amzn1 will be an update

  ---> Package aws-cli.noarch 0:1.10.46-1.40.amzn1 will be updated

  ---> Package aws-cli.noarch 0:1.10.56-1.41.amzn1 will be an update

  ---> Package bind-libs.x86_64 32:9.8.2-0.37.rc1.45.amzn1 will be updated

  ---> Package bind-libs.x86_64 32:9.8.2-0.37.rc1.47.amzn1 will be an update

  ---> Package bind-utils.x86_64 32:9.8.2-0.37.rc1.45.amzn1 will be updated

  ---> Package bind-utils.x86_64 32:9.8.2-0.37.rc1.47.amzn1 will be an update

  ---> Package curl.x86_64 0:7.40.0-8.58.amzn1 will be updated

  ---> Package curl.x86_64 0:7.40.0-8.59.amzn1 will be an update

  ---> Package db4.x86_64 0:4.7.25-18.11.amzn1 will be obsoleted

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: apr-util-
  1.4.1-4.17.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python27- libs-2.7.12-2.120.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: cyrus-sasl- lib-2.1.23-13.16.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-4.11.2-
  2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: ruby20-libs-
  2.0.0.648-1.29.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-build-
  4.11.2-2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: iproute-
  4.4.0-3.23.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: subversion- libs-1.9.4-2.55.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: pam-1.1.8-
  12.33.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: subversion-
  1.9.4-2.55.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: sendmail-
  8.14.4-8.12.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: pam_ccreds- 10-4.9.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: libserf-
  1.3.7-1.7.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-libs-
  4.11.2-2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: cyrus-sasl-
  2.1.23-13.16.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-python27-
  4.11.2-2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python26-
  2.6.9-2.88.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-build- libs-4.11.2-2.73.amzn1.x86_64

  ---> Package db4-utils.x86_64 0:4.7.25-18.11.amzn1 will be obsoleted

  ---> Package dracut.noarch 0:004-336.28.amzn1 will be updated

  ---> Package dracut.noarch 0:004-409.31.amzn1 will be an update

amzn-updates/latest/filelists_db       |
  3.3 MB  00:00
   epel/x86_64/filelists_db
  | 7.2 MB  00:00

  ---> Package kernel.x86_64 0:4.4.19-29.55.amzn1 will be installed

  ---> Package kernel-devel.x86_64 0:4.4.19-29.55.amzn1 will be installed

  ---> Package kernel-headers.x86_64 0:4.4.15-25.57.amzn1 will be updated

  ---> Package kernel-headers.x86_64 0:4.4.19-29.55.amzn1 will be an update

  ---> Package kernel-tools.x86_64 0:4.4.15-25.57.amzn1 will be updated

  ---> Package kernel-tools.x86_64 0:4.4.19-29.55.amzn1 will be an update

  ---> Package libcurl.x86_64 0:7.40.0-8.58.amzn1 will be updated

  ---> Package libcurl.x86_64 0:7.40.0-8.59.amzn1 will be an update

  ---> Package libdb4.x86_64 0:4.8.30-13.el7 will be obsoleting

  ---> Package libdb4-utils.x86_64 0:4.8.30-13.el7 will be obsoleting

  ---> Package libevent.x86_64 0:2.0.18-1.11.amzn1 will be updated

  ---> Package libevent.x86_64 0:2.0.21-4.19.amzn1 will be an update

  ---> Package libgcrypt.x86_64 0:1.5.3-12.18.amzn1 will be updated

  ---> Package libgcrypt.x86_64 0:1.5.3-12.19.amzn1 will be an update

  ---> Package mysql-config.x86_64 0:5.5.46-1.10.amzn1 will be updated

  ---> Package mysql-config.x86_64 0:5.5.51-1.11.amzn1 will be an update

  ---> Package python26.x86_64 0:2.6.9-2.86.amzn1 will be updated

  ---> Package python26.x86_64 0:2.6.9-2.88.amzn1 will be an update

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python26-
  2.6.9-2.88.amzn1.x86_64

  ---> Package python26-libs.x86_64 0:2.6.9-2.86.amzn1 will be updated

  ---> Package python26-libs.x86_64 0:2.6.9-2.88.amzn1 will be an update

  ---> Package python27.x86_64 0:2.7.10-4.122.amzn1 will be updated

  ---> Package python27.x86_64 0:2.7.12-2.120.amzn1 will be an update

  ---> Package python27-boto.noarch 0:2.39.0-1.0.amzn1 will be updated

  ---> Package python27-boto.noarch 0:2.42.0-1.1.amzn1 will be an update

  ---> Package python27-botocore.noarch 0:1.4.36-1.56.amzn1 will be updated

  ---> Package python27-botocore.noarch 0:1.4.46-1.58.amzn1 will be an update

  ---> Package python27-devel.x86_64 0:2.7.10-4.122.amzn1 will be updated

  ---> Package python27-devel.x86_64 0:2.7.12-2.120.amzn1 will be an update

  ---> Package python27-libs.x86_64 0:2.7.10-4.122.amzn1 will be updated

  ---> Package python27-libs.x86_64 0:2.7.12-2.120.amzn1 will be an update

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python27- libs-2.7.12-2.120.amzn1.x86_64

  --> Processing Dependency: /usr/bin/db_stat for package: rpm-4.11.2-
  2.73.amzn1.x86_64

  --> Processing Conflict: libdb4-4.8.30-13.el7.x86_64 conflicts filesystem <

3

  --> Finished Dependency Resolution

Error: Package: python26-2.6.9-2.88.amzn1.x86_64 (amzn-updates)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: /usr/bin/db_stat

  Removing: db4-utils-4.7.25-18.11.amzn1.x86_64 (installed)

       Not found
    Obsoleted By:
  libdb4-utils-4.8.30-13.el7.x86_64 (epel)

  Not found

Error: Package: iproute-4.4.0-3.23.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: ruby20-libs-2.0.0.648-1.29.amzn1.x86_64
  (installed)
     Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-build-4.11.2-2.73.amzn1.x86_64 (@amzn-main)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-python27-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: python27-libs-2.7.12-2.120.amzn1.x86_64
  (amzn-updates)
     Requires:
  libdb-4.7.so()(64bit)
     Removing:
  db4-4.7.25-18.11.amzn1.x86_64 (installed)

  libdb-4.7.so()(64bit)
     Obsoleted By:
  libdb4-4.8.30-13.el7.x86_64 (epel)

  ~libdb-4.8.so()(64bit)

Error: libdb4 conflicts with filesystem-2.4.30-3.8.amzn1.x86_64

Error: Package: rpm-build-libs-4.11.2-2.73.amzn1.x86_64
  (installed)
     Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: sendmail-8.14.4-8.12.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: cyrus-sasl-lib-2.1.23-13.16.amzn1.x86_64
  (installed)
     Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: pam-1.1.8-12.33.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: subversion-1.9.4-2.55.amzn1.x86_64 (@amzn-updates)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: apr-util-1.4.1-4.17.amzn1.x86_64 (@amzn-main)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-libs-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: pam_ccreds-10-4.9.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: subversion-libs-1.9.4-2.55.amzn1.x86_64
  (@amzn-updates)
     Requires:
  libdb-4.7.so()(64bit)
     Removing:
  db4-4.7.25-18.11.amzn1.x86_64 (installed)

  libdb-4.7.so()(64bit)
     Obsoleted By:
  libdb4-4.8.30-13.el7.x86_64 (epel)

  ~libdb-4.8.so()(64bit)

Error: Package: cyrus-sasl-2.1.23-13.16.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: libserf-1.3.7-1.7.amzn1.x86_64 (@amzn-main)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

You could try using --skip-broken to work around the problem
  You
  could try running: rpm -Va --nofiles --nodigest

[ec2-user@ip-172-31-16-247 ~]$

答:
There is a conflict between epel and ami packages. The thing to do (since you are on AMI) is to disable other repositories first, run clean + update, then renable them (for one-off install/upgrades on a per-package basis).</p>

```<code>yum-config-manager --disable epel
yum clean all
yum update
yum-config-manager --enable epel
</code>```

Body:
As soon as I login I tried sudo yum update and it shows following errors. How do I solve this updates issue?

[ec2-user@ip-172-31-16-247 ~]$ sudo yum update

Loaded plugins: priorities, update-motd, upgrade-helper

  amzn-main/latest
  | 2.1 kB  00:00

  amzn-updates/latest
  | 2.3 kB  00:00
   737 packages excluded due to
  repository priority protections
 Resolving Dependencies

  --> Running transaction check

  ---> Package aws-cfn-bootstrap.noarch 0:1.4-11.6.amzn1 will be updated

  ---> Package aws-cfn-bootstrap.noarch 0:1.4-12.7.amzn1 will be an update

  ---> Package aws-cli.noarch 0:1.10.46-1.40.amzn1 will be updated

  ---> Package aws-cli.noarch 0:1.10.56-1.41.amzn1 will be an update

  ---> Package bind-libs.x86_64 32:9.8.2-0.37.rc1.45.amzn1 will be updated

  ---> Package bind-libs.x86_64 32:9.8.2-0.37.rc1.47.amzn1 will be an update

  ---> Package bind-utils.x86_64 32:9.8.2-0.37.rc1.45.amzn1 will be updated

  ---> Package bind-utils.x86_64 32:9.8.2-0.37.rc1.47.amzn1 will be an update

  ---> Package curl.x86_64 0:7.40.0-8.58.amzn1 will be updated

  ---> Package curl.x86_64 0:7.40.0-8.59.amzn1 will be an update

  ---> Package db4.x86_64 0:4.7.25-18.11.amzn1 will be obsoleted

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: apr-util-
  1.4.1-4.17.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python27- libs-2.7.12-2.120.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: cyrus-sasl- lib-2.1.23-13.16.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-4.11.2-
  2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: ruby20-libs-
  2.0.0.648-1.29.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-build-
  4.11.2-2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: iproute-
  4.4.0-3.23.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: subversion- libs-1.9.4-2.55.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: pam-1.1.8-
  12.33.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: subversion-
  1.9.4-2.55.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: sendmail-
  8.14.4-8.12.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: pam_ccreds- 10-4.9.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: libserf-
  1.3.7-1.7.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-libs-
  4.11.2-2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: cyrus-sasl-
  2.1.23-13.16.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-python27-
  4.11.2-2.73.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python26-
  2.6.9-2.88.amzn1.x86_64

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: rpm-build- libs-4.11.2-2.73.amzn1.x86_64

  ---> Package db4-utils.x86_64 0:4.7.25-18.11.amzn1 will be obsoleted

  ---> Package dracut.noarch 0:004-336.28.amzn1 will be updated

  ---> Package dracut.noarch 0:004-409.31.amzn1 will be an update

amzn-updates/latest/filelists_db       |
  3.3 MB  00:00
   epel/x86_64/filelists_db
  | 7.2 MB  00:00

  ---> Package kernel.x86_64 0:4.4.19-29.55.amzn1 will be installed

  ---> Package kernel-devel.x86_64 0:4.4.19-29.55.amzn1 will be installed

  ---> Package kernel-headers.x86_64 0:4.4.15-25.57.amzn1 will be updated

  ---> Package kernel-headers.x86_64 0:4.4.19-29.55.amzn1 will be an update

  ---> Package kernel-tools.x86_64 0:4.4.15-25.57.amzn1 will be updated

  ---> Package kernel-tools.x86_64 0:4.4.19-29.55.amzn1 will be an update

  ---> Package libcurl.x86_64 0:7.40.0-8.58.amzn1 will be updated

  ---> Package libcurl.x86_64 0:7.40.0-8.59.amzn1 will be an update

  ---> Package libdb4.x86_64 0:4.8.30-13.el7 will be obsoleting

  ---> Package libdb4-utils.x86_64 0:4.8.30-13.el7 will be obsoleting

  ---> Package libevent.x86_64 0:2.0.18-1.11.amzn1 will be updated

  ---> Package libevent.x86_64 0:2.0.21-4.19.amzn1 will be an update

  ---> Package libgcrypt.x86_64 0:1.5.3-12.18.amzn1 will be updated

  ---> Package libgcrypt.x86_64 0:1.5.3-12.19.amzn1 will be an update

  ---> Package mysql-config.x86_64 0:5.5.46-1.10.amzn1 will be updated

  ---> Package mysql-config.x86_64 0:5.5.51-1.11.amzn1 will be an update

  ---> Package python26.x86_64 0:2.6.9-2.86.amzn1 will be updated

  ---> Package python26.x86_64 0:2.6.9-2.88.amzn1 will be an update

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python26-
  2.6.9-2.88.amzn1.x86_64

  ---> Package python26-libs.x86_64 0:2.6.9-2.86.amzn1 will be updated

  ---> Package python26-libs.x86_64 0:2.6.9-2.88.amzn1 will be an update

  ---> Package python27.x86_64 0:2.7.10-4.122.amzn1 will be updated

  ---> Package python27.x86_64 0:2.7.12-2.120.amzn1 will be an update

  ---> Package python27-boto.noarch 0:2.39.0-1.0.amzn1 will be updated

  ---> Package python27-boto.noarch 0:2.42.0-1.1.amzn1 will be an update

  ---> Package python27-botocore.noarch 0:1.4.36-1.56.amzn1 will be updated

  ---> Package python27-botocore.noarch 0:1.4.46-1.58.amzn1 will be an update

  ---> Package python27-devel.x86_64 0:2.7.10-4.122.amzn1 will be updated

  ---> Package python27-devel.x86_64 0:2.7.12-2.120.amzn1 will be an update

  ---> Package python27-libs.x86_64 0:2.7.10-4.122.amzn1 will be updated

  ---> Package python27-libs.x86_64 0:2.7.12-2.120.amzn1 will be an update

  --> Processing Dependency: libdb-4.7.so()(64bit) for package: python27- libs-2.7.12-2.120.amzn1.x86_64

  --> Processing Dependency: /usr/bin/db_stat for package: rpm-4.11.2-
  2.73.amzn1.x86_64

  --> Processing Conflict: libdb4-4.8.30-13.el7.x86_64 conflicts filesystem <

3

  --> Finished Dependency Resolution

Error: Package: python26-2.6.9-2.88.amzn1.x86_64 (amzn-updates)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: /usr/bin/db_stat

  Removing: db4-utils-4.7.25-18.11.amzn1.x86_64 (installed)

       Not found
    Obsoleted By:
  libdb4-utils-4.8.30-13.el7.x86_64 (epel)

  Not found

Error: Package: iproute-4.4.0-3.23.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: ruby20-libs-2.0.0.648-1.29.amzn1.x86_64
  (installed)
     Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-build-4.11.2-2.73.amzn1.x86_64 (@amzn-main)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-python27-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: python27-libs-2.7.12-2.120.amzn1.x86_64
  (amzn-updates)
     Requires:
  libdb-4.7.so()(64bit)
     Removing:
  db4-4.7.25-18.11.amzn1.x86_64 (installed)

  libdb-4.7.so()(64bit)
     Obsoleted By:
  libdb4-4.8.30-13.el7.x86_64 (epel)

  ~libdb-4.8.so()(64bit)

Error: libdb4 conflicts with filesystem-2.4.30-3.8.amzn1.x86_64

Error: Package: rpm-build-libs-4.11.2-2.73.amzn1.x86_64
  (installed)
     Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: sendmail-8.14.4-8.12.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: cyrus-sasl-lib-2.1.23-13.16.amzn1.x86_64
  (installed)
     Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: pam-1.1.8-12.33.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: subversion-1.9.4-2.55.amzn1.x86_64 (@amzn-updates)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: apr-util-1.4.1-4.17.amzn1.x86_64 (@amzn-main)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-libs-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: pam_ccreds-10-4.9.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: subversion-libs-1.9.4-2.55.amzn1.x86_64
  (@amzn-updates)
     Requires:
  libdb-4.7.so()(64bit)
     Removing:
  db4-4.7.25-18.11.amzn1.x86_64 (installed)

  libdb-4.7.so()(64bit)
     Obsoleted By:
  libdb4-4.8.30-13.el7.x86_64 (epel)

  ~libdb-4.8.so()(64bit)

Error: Package: cyrus-sasl-2.1.23-13.16.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: libserf-1.3.7-1.7.amzn1.x86_64 (@amzn-main)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

Error: Package: rpm-4.11.2-2.73.amzn1.x86_64 (installed)

      Requires: libdb-4.7.so()(64bit)

      Removing: db4-4.7.25-18.11.amzn1.x86_64
  (installed)
      libdb-4.7.so()(64bit)

      Obsoleted By: libdb4-4.8.30-13.el7.x86_64
  (epel)
      ~libdb-4.8.so()(64bit)

You could try using --skip-broken to work around the problem
  You
  could try running: rpm -Va --nofiles --nodigest

[ec2-user@ip-172-31-16-247 ~]$

Body:
There is a conflict between epel and ami packages. The thing to do (since you are on AMI) is to disable other repositories first, run clean + update, then renable them (for one-off install/upgrades on a per-package basis).

yum-config-manager --disable epel
yum clean all
yum update
yum-config-manager --enable epel


来源: stackexchange

问:
Print the smallest string that can be repeated to get the original string
Sample Input
abababab

Sample Output
ab

```<code>1 <= length of string <= 5000
</code>```

What I am doing is recording the number of occurrences of each character. Then I find the smallest non-zero occurrence and and divide all the others by this number. Then I add everything and this gives me the length up to which I need to print the original string to give me the answer.

In the sample input, a=4, b=4. So the smallest occurrence is 4 and after division I get a=1, b=1 and addition gives me 2. I will print first 2 from original string to get ab.

I even tried more complex examples and this algorithm seems to work flawlessly but I am still getting a few test cases wrong.

```<code>#include <cmath>
#include <cstdio>
#include <string.h>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    char str[5005];
    int letters[26] = {0}, min = 10000, len=0;
    cin>>str;
    int lent = strlen(str);
    if(lent==1)
    {
        cout<<str;
        return 0;
    }
    for(int i=0; i<lent; i++)
        letters[(int)str[i]-97]++;
    for(int i=0; i<26; i++)
    {
        if(letters[i]>0)
        {
            if(letters[i]<min)min=letters[i];
        }
    }
    for(int i=0; i<26; i++)
    {
        len+= letters[i]/min;
    }
    for(int i=0; i<len; i++)
        cout<<str[i];
    return 0;
}
</code>```

Please suggest the correct approach

答:
As pointed out by the sample inputs given by Ryan and  Hagen von Eitzen in the comments and using the hint given by WhozCraig I was finally able to get the right approach.</p>

```<code>#include <cmath>
#include <cstdio>
#include <string.h>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    string str;
    int letters[26] = {0}, min = 10000, len=0;
    cin>>str;
    int lent = str.size();
    len = lent;
    for(int i=1; i<=lent; i++)
    {
        string temp = "";
        string ans = "";
        if(lent%i == 0)
        {
            for(int j=0; j<i; j++)
                ans+=str[j];
            for(int j=0; j<(lent/i); j++)
                temp+=ans;
            if(str==temp)
            {
                cout<<ans;
                return 0;
            }
        }
    }
    return 0;
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Sample Input
abababab

Sample Output
ab

1 <= length of string <= 5000

What I am doing is recording the number of occurrences of each character. Then I find the smallest non-zero occurrence and and divide all the others by this number. Then I add everything and this gives me the length up to which I need to print the original string to give me the answer.

In the sample input, a=4, b=4. So the smallest occurrence is 4 and after division I get a=1, b=1 and addition gives me 2. I will print first 2 from original string to get ab.

I even tried more complex examples and this algorithm seems to work flawlessly but I am still getting a few test cases wrong.

#include <cmath>
#include <cstdio>
#include <string.h>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    char str[5005];
    int letters[26] = {0}, min = 10000, len=0;
    cin>>str;
    int lent = strlen(str);
    if(lent==1)
    {
        cout<<str;
        return 0;
    }
    for(int i=0; i<lent; i++)
        letters[(int)str[i]-97]++;
    for(int i=0; i<26; i++)
    {
        if(letters[i]>0)
        {
            if(letters[i]<min)min=letters[i];
        }
    }
    for(int i=0; i<26; i++)
    {
        len+= letters[i]/min;
    }
    for(int i=0; i<len; i++)
        cout<<str[i];
    return 0;
}

Please suggest the correct approach

Body:
As pointed out by the sample inputs given by Ryan and  Hagen von Eitzen in the comments and using the hint given by WhozCraig I was finally able to get the right approach.

#include <cmath>
#include <cstdio>
#include <string.h>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    string str;
    int letters[26] = {0}, min = 10000, len=0;
    cin>>str;
    int lent = str.size();
    len = lent;
    for(int i=1; i<=lent; i++)
    {
        string temp = "";
        string ans = "";
        if(lent%i == 0)
        {
            for(int j=0; j<i; j++)
                ans+=str[j];
            for(int j=0; j<(lent/i); j++)
                temp+=ans;
            if(str==temp)
            {
                cout<<ans;
                return 0;
            }
        }
    }
    return 0;
}


问:
Vectorization: matrix array multiplication element wise one by one
I have a matrix:

R = [0 -1;1 0];

```<code>array = 1:1:10;
</code>```

Also x0 = [2;1]

How can I obtain another array in the most efficient way without loop?

```<code>array2 = [expm(1*R) expm(2*R) expm(3*R) .... expm(10*R)];
</code>```

Then I want to obtain
array3 of dimension 2 by 10 such that:

```<code>array3 = [expm(1*R)*x0 expm(2*R)*x0 expm(3*R)*x0 .... expm(10*R)*x0];
</code>```

答:
Well I see that the matrix R that you have is 2x2. In case it is always 2x2, then you can use the following function (Wikipedia) to calculate the exponential:

```<code>function output = expm2d(A)
% Assuming t = 1 from Evaluation by Laurent series (https://en.wikipedia.org/wiki/Matrix_exponential#Evaluation_by_Laurent_series)
s = trace(A) / 2;
q = sqrt(-det(A - s*eye(size(A))));
output = exp(s) * ((cosh(q) - s * sinh(q) / q) * eye(size(A)) + (sinh(q) * A / q));
end
</code>```

Using the excellent comparison function provided by thewaywewalk, I got the following results:

When using expm:

```<code>>> bench
ans =
    0.0181 %// rahnema
    0.1075 %// thewaywewalk arrayfun
    0.1139 %// thewaywewalk accumarray
</code>```

When using expm2d:

```<code>>> bench
ans =
    0.0048 %// rahnema
    0.0161 %// thewaywewalk arrayfun
    0.0222 %// thewaywewalk accumarray
</code>```

As you can see, using the function for 2d matrices leads to a 10x decrease in the runtime. Of course, this cannot be used when R is not 2x2.

Edit:
When using expm2d for A = 1:100:

```<code>>> bench
ans =
    0.1379 %// rahnema
    0.1415 %// thewaywewalk arrayfun
    0.1756 %// thewaywewalk accumarray
</code>```

Body:
I have a matrix:

R = [0 -1;1 0];

array = 1:1:10;

Also x0 = [2;1]

How can I obtain another array in the most efficient way without loop?

array2 = [expm(1*R) expm(2*R) expm(3*R) .... expm(10*R)];

Then I want to obtain
array3 of dimension 2 by 10 such that:

array3 = [expm(1*R)*x0 expm(2*R)*x0 expm(3*R)*x0 .... expm(10*R)*x0];

Body:
Well I see that the matrix R that you have is 2x2. In case it is always 2x2, then you can use the following function (Wikipedia) to calculate the exponential:

function output = expm2d(A)
% Assuming t = 1 from Evaluation by Laurent series (https://en.wikipedia.org/wiki/Matrix_exponential#Evaluation_by_Laurent_series)
s = trace(A) / 2;
q = sqrt(-det(A - s*eye(size(A))));
output = exp(s) * ((cosh(q) - s * sinh(q) / q) * eye(size(A)) + (sinh(q) * A / q));
end

Using the excellent comparison function provided by thewaywewalk, I got the following results:

When using expm:

>> bench
ans =
    0.0181 %// rahnema
    0.1075 %// thewaywewalk arrayfun
    0.1139 %// thewaywewalk accumarray

When using expm2d:

>> bench
ans =
    0.0048 %// rahnema
    0.0161 %// thewaywewalk arrayfun
    0.0222 %// thewaywewalk accumarray

As you can see, using the function for 2d matrices leads to a 10x decrease in the runtime. Of course, this cannot be used when R is not 2x2.

Edit:
When using expm2d for A = 1:100:

>> bench
ans =
    0.1379 %// rahnema
    0.1415 %// thewaywewalk arrayfun
    0.1756 %// thewaywewalk accumarray


问:
Custom control binding doesn't update the model
I am using a custom WindowsFormsHost control to wrap FastColoredTextbox winforms control in a tab control whose tabs are dynamically created when user hits the new document button via a DataTemplate.

Because of the limitations of the tab control which is explained in this SO question, my Undo/Redo logic was holding the history of all the tabs for each tab, which was resulting in wrong text being displayed.

So I decided to modify the FastColoredTextbox control to expose history and the redo stack, and added them to my custom WindowsFormsHost wrapper control as dependency properties which is bound two ways to my DocumentModel.

XAML:

```<code><TabControl TabStripPlacement="Top" Margin="5" ItemsSource="{Binding Documents}" SelectedItem="{Binding CurrentDocument, Mode=TwoWay}" x:Name="TabDocuments">
    <TabControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="10" MaxWidth="10" MinWidth="10"/>
                    <ColumnDefinition Width="10" MaxWidth="10" MinWidth="10"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding Metadata.FileName}"/>
                <TextBlock Grid.Column="1" Text="*" Visibility="{Binding IsSaved, Converter={StaticResource VisibilityConverter}}"/>
                <Button Grid.Column="2" Width="10" Height="10" MaxWidth="10" MaxHeight="10" MinWidth="10" MinHeight="10" VerticalAlignment="Center" HorizontalAlignment="Right" Command="{Binding CloseDocumentButtonCommand}">
                    <TextBlock Text="X" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="8" FontWeight="Bold"/>
                </Button>
            </Grid>
        </DataTemplate>
    </TabControl.ItemTemplate>
    <TabControl.ContentTemplate>
        <DataTemplate x:Name="TabDocumentsDataTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border BorderBrush="Black" BorderThickness="1" Grid.Column="0" Margin="5">
                    <customControls:CodeTextboxHost Text="{Binding Markdown, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" History="{Binding History, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" RedoStack="{Binding RedoStack, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" WordWrap="True" x:Name="CodeTextboxHost"/>
                </Border>
                <Border BorderBrush="Black" BorderThickness="1" Grid.Column="1" Margin="5">
                    <wpf:ChromiumWebBrowser Address="{Binding Html, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name="ChromiumWebBrowser"/>
                </Border>
            </Grid>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>
</code>```

The relevant part of the model:

```<code>public ObservableCollection<UndoableCommand> History
{
    get { return _history; }
    set
    {
        _history = value;
        OnPropertyChanged();
    }
}

public ObservableCollection<UndoableCommand> RedoStack
{
    get { return _redoStack; }
    set
    {
        _redoStack = value;
        OnPropertyChanged();
    }
}
</code>```

The relevant parts of the custom control code:

```<code>public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CodeTextboxHost), new PropertyMetadata("", new PropertyChangedCallback(
(d, e) =>
{
    var textBoxHost = d as CodeTextboxHost;
    if (textBoxHost != null && textBoxHost._innerTextbox != null)
    {
        textBoxHost._innerTextbox.Text = textBoxHost.GetValue(e.Property) as string;
    }
}), null));

public static readonly DependencyProperty HistoryProperty = DependencyProperty.Register("History", typeof(LimitedStack<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new LimitedStack<UndoableCommand>(200), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var history = textBoxHost.GetValue(e.Property) as LimitedStack<UndoableCommand>;
            if (history != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.History = history;
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public static readonly DependencyProperty RedoStackProperty = DependencyProperty.Register("RedoStack", typeof(Stack<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new Stack<UndoableCommand>(), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var redoStack = textBoxHost.GetValue(e.Property) as Stack<UndoableCommand>;
            if (redoStack != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.RedoStack = redoStack;
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public LimitedStack<UndoableCommand> History
{
    get { return (LimitedStack<UndoableCommand>) GetValue(HistoryProperty);}
    set { SetValue(HistoryProperty, value);}
}

public Stack<UndoableCommand> RedoStack
{
    get { return (Stack<UndoableCommand>) GetValue(RedoStackProperty); }
    set { SetValue(RedoStackProperty, value);}
}

public CodeTextboxHost()
{
    Child = _innerTextbox;
    _innerTextbox.Language = FastColoredTextBoxNS.Language.Custom;
    _innerTextbox.DescriptionFile = AppDomain.CurrentDomain.BaseDirectory + "SyntaxConfig\\MarkdownSyntaxHighlighting.xml";
    _innerTextbox.HighlightingRangeType = HighlightingRangeType.AllTextRange;
    _innerTextbox.TextChanged += _innerTextbox_TextChanged;
}

private void _innerTextbox_TextChanged(object sender, TextChangedEventArgs e)
{
    Text = _innerTextbox.Text;
    History = _innerTextbox.TextSource.Manager.History;
    RedoStack = _innerTextbox.TextSource.Manager.RedoStack;
}
</code>```

My problem is when TextChanged event is triggered, History or RedoStack does not update on the model while Text perfectly updates.

I tried adding RelativeSource as this SO question suggests but it didn't work.

Any help/ideas would be appreciated. Thank you.

Edit 1:

As suggested I made all collections ObservableCollection, however it didn't make any change, as the model is again not updated.

```<code>public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CodeTextboxHost), new PropertyMetadata("", new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            textBoxHost._innerTextbox.Text = textBoxHost.GetValue(e.Property) as string;
        }
    }), null));

public static readonly DependencyProperty HistoryProperty = DependencyProperty.Register("History", typeof(ObservableCollection<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new ObservableCollection<UndoableCommand>(), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var history = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (history != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.History = history.ToLimitedStack(200);
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public static readonly DependencyProperty RedoStackProperty = DependencyProperty.Register("RedoStack", typeof(ObservableCollection<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new ObservableCollection<UndoableCommand>(), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var redoStack = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (redoStack != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.RedoStack = redoStack.ToStack();
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public ObservableCollection<UndoableCommand> History
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(HistoryProperty);}
    set { SetValue(HistoryProperty, value);}
}

public ObservableCollection<UndoableCommand> RedoStack
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(RedoStackProperty); }
    set { SetValue(RedoStackProperty, value);}
}

public string Text
{
    get { return (string)GetValue(TextProperty); }
    set { SetValue(TextProperty, value); }
}

public bool WordWrap
{
    get { return (bool)GetValue(WordWrapProperty); }
    set { SetValue(WordWrapProperty, value); }
}

public CodeTextboxHost()
{
    Child = _innerTextbox;
    _innerTextbox.Language = FastColoredTextBoxNS.Language.Custom;
    _innerTextbox.DescriptionFile = AppDomain.CurrentDomain.BaseDirectory + "SyntaxConfig\\MarkdownSyntaxHighlighting.xml";
    _innerTextbox.HighlightingRangeType = HighlightingRangeType.AllTextRange;
    _innerTextbox.TextChanged += _innerTextbox_TextChanged;
}

private void _innerTextbox_TextChanged(object sender, TextChangedEventArgs e)
{
    Text = _innerTextbox.Text;
    History = _innerTextbox.TextSource.Manager.History.ToOveObservableCollection();
    RedoStack = _innerTextbox.TextSource.Manager.RedoStack.ToObservableCollection();
}
</code>```

答:
I was able to make the UI change the Model by modifying the custom control code as follows:

```<code>public static readonly DependencyProperty HistoryProperty = DependencyProperty.Register("History", typeof(IEnumerable<UndoableCommand>), typeof(CodeTextboxHost), new FrameworkPropertyMetadata(new ObservableCollection<UndoableCommand>(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var history = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (history != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.History = history.ToLimitedStack(200);
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public static readonly DependencyProperty RedoStackProperty = DependencyProperty.Register("RedoStack", typeof(IEnumerable<UndoableCommand>), typeof(CodeTextboxHost), new FrameworkPropertyMetadata(new ObservableCollection<UndoableCommand>(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var redoStack = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (redoStack != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.RedoStack = redoStack.ToStack();
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public ObservableCollection<UndoableCommand> History
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(HistoryProperty);}
    set { SetCurrentValue(HistoryProperty, new ObservableCollection<UndoableCommand>(value));}
}

public ObservableCollection<UndoableCommand> RedoStack
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(RedoStackProperty); }
    set { SetCurrentValue(RedoStackProperty, new ObservableCollection<UndoableCommand>(value));}
}
</code>```

So instead of SetValue, I used SetCurrentValue on History and RedoStack to make the UI update the model correctly.

Body:
I am using a custom WindowsFormsHost control to wrap FastColoredTextbox winforms control in a tab control whose tabs are dynamically created when user hits the new document button via a DataTemplate.

Because of the limitations of the tab control which is explained in this SO question, my Undo/Redo logic was holding the history of all the tabs for each tab, which was resulting in wrong text being displayed.

So I decided to modify the FastColoredTextbox control to expose history and the redo stack, and added them to my custom WindowsFormsHost wrapper control as dependency properties which is bound two ways to my DocumentModel.

XAML:

<TabControl TabStripPlacement="Top" Margin="5" ItemsSource="{Binding Documents}" SelectedItem="{Binding CurrentDocument, Mode=TwoWay}" x:Name="TabDocuments">
    <TabControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="10" MaxWidth="10" MinWidth="10"/>
                    <ColumnDefinition Width="10" MaxWidth="10" MinWidth="10"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding Metadata.FileName}"/>
                <TextBlock Grid.Column="1" Text="*" Visibility="{Binding IsSaved, Converter={StaticResource VisibilityConverter}}"/>
                <Button Grid.Column="2" Width="10" Height="10" MaxWidth="10" MaxHeight="10" MinWidth="10" MinHeight="10" VerticalAlignment="Center" HorizontalAlignment="Right" Command="{Binding CloseDocumentButtonCommand}">
                    <TextBlock Text="X" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="8" FontWeight="Bold"/>
                </Button>
            </Grid>
        </DataTemplate>
    </TabControl.ItemTemplate>
    <TabControl.ContentTemplate>
        <DataTemplate x:Name="TabDocumentsDataTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border BorderBrush="Black" BorderThickness="1" Grid.Column="0" Margin="5">
                    <customControls:CodeTextboxHost Text="{Binding Markdown, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" History="{Binding History, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" RedoStack="{Binding RedoStack, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" WordWrap="True" x:Name="CodeTextboxHost"/>
                </Border>
                <Border BorderBrush="Black" BorderThickness="1" Grid.Column="1" Margin="5">
                    <wpf:ChromiumWebBrowser Address="{Binding Html, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name="ChromiumWebBrowser"/>
                </Border>
            </Grid>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

The relevant part of the model:

public ObservableCollection<UndoableCommand> History
{
    get { return _history; }
    set
    {
        _history = value;
        OnPropertyChanged();
    }
}

public ObservableCollection<UndoableCommand> RedoStack
{
    get { return _redoStack; }
    set
    {
        _redoStack = value;
        OnPropertyChanged();
    }
}

The relevant parts of the custom control code:

public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CodeTextboxHost), new PropertyMetadata("", new PropertyChangedCallback(
(d, e) =>
{
    var textBoxHost = d as CodeTextboxHost;
    if (textBoxHost != null && textBoxHost._innerTextbox != null)
    {
        textBoxHost._innerTextbox.Text = textBoxHost.GetValue(e.Property) as string;
    }
}), null));

public static readonly DependencyProperty HistoryProperty = DependencyProperty.Register("History", typeof(LimitedStack<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new LimitedStack<UndoableCommand>(200), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var history = textBoxHost.GetValue(e.Property) as LimitedStack<UndoableCommand>;
            if (history != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.History = history;
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public static readonly DependencyProperty RedoStackProperty = DependencyProperty.Register("RedoStack", typeof(Stack<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new Stack<UndoableCommand>(), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var redoStack = textBoxHost.GetValue(e.Property) as Stack<UndoableCommand>;
            if (redoStack != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.RedoStack = redoStack;
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public LimitedStack<UndoableCommand> History
{
    get { return (LimitedStack<UndoableCommand>) GetValue(HistoryProperty);}
    set { SetValue(HistoryProperty, value);}
}

public Stack<UndoableCommand> RedoStack
{
    get { return (Stack<UndoableCommand>) GetValue(RedoStackProperty); }
    set { SetValue(RedoStackProperty, value);}
}

public CodeTextboxHost()
{
    Child = _innerTextbox;
    _innerTextbox.Language = FastColoredTextBoxNS.Language.Custom;
    _innerTextbox.DescriptionFile = AppDomain.CurrentDomain.BaseDirectory + "SyntaxConfig\\MarkdownSyntaxHighlighting.xml";
    _innerTextbox.HighlightingRangeType = HighlightingRangeType.AllTextRange;
    _innerTextbox.TextChanged += _innerTextbox_TextChanged;
}

private void _innerTextbox_TextChanged(object sender, TextChangedEventArgs e)
{
    Text = _innerTextbox.Text;
    History = _innerTextbox.TextSource.Manager.History;
    RedoStack = _innerTextbox.TextSource.Manager.RedoStack;
}

My problem is when TextChanged event is triggered, History or RedoStack does not update on the model while Text perfectly updates.

I tried adding RelativeSource as this SO question suggests but it didn't work.

Any help/ideas would be appreciated. Thank you.

Edit 1:

As suggested I made all collections ObservableCollection, however it didn't make any change, as the model is again not updated.

public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CodeTextboxHost), new PropertyMetadata("", new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            textBoxHost._innerTextbox.Text = textBoxHost.GetValue(e.Property) as string;
        }
    }), null));

public static readonly DependencyProperty HistoryProperty = DependencyProperty.Register("History", typeof(ObservableCollection<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new ObservableCollection<UndoableCommand>(), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var history = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (history != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.History = history.ToLimitedStack(200);
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public static readonly DependencyProperty RedoStackProperty = DependencyProperty.Register("RedoStack", typeof(ObservableCollection<UndoableCommand>), typeof(CodeTextboxHost), new PropertyMetadata(new ObservableCollection<UndoableCommand>(), new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var redoStack = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (redoStack != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.RedoStack = redoStack.ToStack();
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public ObservableCollection<UndoableCommand> History
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(HistoryProperty);}
    set { SetValue(HistoryProperty, value);}
}

public ObservableCollection<UndoableCommand> RedoStack
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(RedoStackProperty); }
    set { SetValue(RedoStackProperty, value);}
}

public string Text
{
    get { return (string)GetValue(TextProperty); }
    set { SetValue(TextProperty, value); }
}

public bool WordWrap
{
    get { return (bool)GetValue(WordWrapProperty); }
    set { SetValue(WordWrapProperty, value); }
}

public CodeTextboxHost()
{
    Child = _innerTextbox;
    _innerTextbox.Language = FastColoredTextBoxNS.Language.Custom;
    _innerTextbox.DescriptionFile = AppDomain.CurrentDomain.BaseDirectory + "SyntaxConfig\\MarkdownSyntaxHighlighting.xml";
    _innerTextbox.HighlightingRangeType = HighlightingRangeType.AllTextRange;
    _innerTextbox.TextChanged += _innerTextbox_TextChanged;
}

private void _innerTextbox_TextChanged(object sender, TextChangedEventArgs e)
{
    Text = _innerTextbox.Text;
    History = _innerTextbox.TextSource.Manager.History.ToOveObservableCollection();
    RedoStack = _innerTextbox.TextSource.Manager.RedoStack.ToObservableCollection();
}

Body:
I was able to make the UI change the Model by modifying the custom control code as follows:

public static readonly DependencyProperty HistoryProperty = DependencyProperty.Register("History", typeof(IEnumerable<UndoableCommand>), typeof(CodeTextboxHost), new FrameworkPropertyMetadata(new ObservableCollection<UndoableCommand>(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var history = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (history != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.History = history.ToLimitedStack(200);
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public static readonly DependencyProperty RedoStackProperty = DependencyProperty.Register("RedoStack", typeof(IEnumerable<UndoableCommand>), typeof(CodeTextboxHost), new FrameworkPropertyMetadata(new ObservableCollection<UndoableCommand>(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(
    (d, e) =>
    {
        var textBoxHost = d as CodeTextboxHost;
        if (textBoxHost != null && textBoxHost._innerTextbox != null)
        {
            var redoStack = textBoxHost.GetValue(e.Property) as ObservableCollection<UndoableCommand>;
            if (redoStack != null)
            {
                textBoxHost._innerTextbox.TextSource.Manager.RedoStack = redoStack.ToStack();
                textBoxHost._innerTextbox.OnUndoRedoStateChanged();
            }
            else
            {
                textBoxHost._innerTextbox.ClearUndo();
            }
        }
    }), null));

public ObservableCollection<UndoableCommand> History
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(HistoryProperty);}
    set { SetCurrentValue(HistoryProperty, new ObservableCollection<UndoableCommand>(value));}
}

public ObservableCollection<UndoableCommand> RedoStack
{
    get { return (ObservableCollection<UndoableCommand>) GetValue(RedoStackProperty); }
    set { SetCurrentValue(RedoStackProperty, new ObservableCollection<UndoableCommand>(value));}
}

So instead of SetValue, I used SetCurrentValue on History and RedoStack to make the UI update the model correctly.


问:
Django list ordering by date
I want to display in the same page all the results of this 2 queries and ordering them by date. The goal is to mix both results to just display a unique list ordering by date.

```<code>articles = Articles.objects.all()

statut = Statut.objects.all()
</code>```

I have this idea but I don't know :

```<code>articles = list(Articles.objects.all())

statut = list(Statut.objects.all())

all = articles + statut
</code>```

So I have a unique list and it's working. It displays every results.

Now I wonder how to order by date for the template rendering?

May be there is a simpler way to do it ?

Thank you

答:
You may try to chain 2 querysets together and the apply sorted to them:

```<code>from itertools import chain
from operator import attrgetter

articles = list(Articles.objects.all())

statut = list(Statut.objects.all())

result_list = sorted(
    chain(articles, statut),
    key=attrgetter('date_created')) # date_created name may differ
</code>```

Title: Django list ordering by date

Body:
I want to display in the same page all the results of this 2 queries and ordering them by date. The goal is to mix both results to just display a unique list ordering by date.

articles = Articles.objects.all()

statut = Statut.objects.all()

I have this idea but I don't know :

articles = list(Articles.objects.all())

statut = list(Statut.objects.all())

all = articles + statut

So I have a unique list and it's working. It displays every results.

Now I wonder how to order by date for the template rendering?

May be there is a simpler way to do it ?

Thank you

Body:
You may try to chain 2 querysets together and the apply sorted to them:

from itertools import chain
from operator import attrgetter

articles = list(Articles.objects.all())

statut = list(Statut.objects.all())

result_list = sorted(
    chain(articles, statut),
    key=attrgetter('date_created')) # date_created name may differ


问:
LogCat error while running AutoCompleteTextView contacts android
I am using autoCompleteTextView to load the contacts. There is no errors and it doesnt crash too. But the autocompleteTextview doesn't seem to appear anything.I will post my codes and logcat.

Codes:-
       package com.droidnova.android.samples;

```<code>   import android.app.Activity;
   import android.content.ContentResolver;
   import android.content.Context;
   import android.database.Cursor;
   import android.net.Uri;
   import android.os.Bundle;
   import android.provider.Contacts;
   import android.provider.Contacts.People;
   import android.provider.SyncStateContract.Constants;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
  import android.widget.AutoCompleteTextView;
  import android.widget.CursorAdapter;
  import android.widget.Filterable;
  import android.widget.LinearLayout;
   import android.widget.TextView;

   public class AutoComplete extends Activity {

private static TextView mName;
private static TextView mNumber;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.button);

   ContentResolver content = getContentResolver();
    Cursor cursor = content.query(People.CONTENT_URI,
            PEOPLE_PROJECTION, People.NAME+"IS NOT NULL AND" +
            People.NUMBER_KEY+"IS NOT NULL",null,People.DEFAULT_SORT_ORDER);
    ContactListAdapter adapter = new ContactListAdapter(this, cursor);

    AutoCompleteTextView textView = (AutoCompleteTextView)
            findViewById(R.id.AutoCompleteTextView01);
    textView.setAdapter(adapter);
    textView.setHint("type name");
}

// XXX compiler bug in javac 1.5.0_07-164, we need to implement Filterable
// to make compilation work
   public static class ContactListAdapter extends CursorAdapter implements Filterable {
     public ContactListAdapter(Context context, Cursor c) {
        super(context, c);
        mContent = context.getContentResolver();
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final LinearLayout ret = new LinearLayout(context);
        final LayoutInflater inflater = LayoutInflater.from(context);
        mName = (TextView) inflater.inflate(
                android.R.layout.simple_dropdown_item_1line, parent, false);
        mNumber=(TextView) inflater.inflate(
                android.R.layout.simple_dropdown_item_1line, parent, false);
        int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
        int numberIdx = cursor.getColumnIndex(People.NUMBER);

        String name = cursor.getString(nameIdx);
        String number = cursor.getString(numberIdx);

        mName.setText(name);
        mNumber.setText(number);
        return ret;

    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
         int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
         int numberIdx = cursor.getColumnIndex(People.NUMBER);

         String name = cursor.getString(nameIdx);
         String number = cursor.getString(numberIdx);
         ((TextView) ((LinearLayout) view).getChildAt(0)).setText(name);
         LinearLayout horizontal = (LinearLayout) ((LinearLayout) view).getChildAt(1);
         ((TextView) horizontal.getChildAt(0)).setText(number);

    }

    @Override
    public String convertToString(Cursor cursor) {
        int numCol = cursor.getColumnIndexOrThrow(People.NUMBER);
        String number = cursor.getString(numCol);
        return number;

    }

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        if (getFilterQueryProvider() != null) { return getFilterQueryProvider().runQuery(constraint); }

        StringBuilder buffer = null;
        String[] args = null;
        if (constraint != null) {
            buffer = new StringBuilder();
            buffer.append(People.NAME + " IS NOT NULL AND " + People.NUMBER_KEY + " IS NOT NULL AND ");
            buffer.append("UPPER(");
            buffer.append(People.NAME);
            buffer.append(") GLOB ?");
            args = new String[] { constraint.toString().toUpperCase() + "*" };
        }

        return mContent.query(People.CONTENT_URI,PEOPLE_PROJECTION, buffer == null ? null : buffer
                .toString(), args, People.DEFAULT_SORT_ORDER);
    }

    private ContentResolver mContent;
}

  private static final String[] PEOPLE_PROJECTION = new String[] {
     People.NAME,
    People._ID,
    People.NUMBER,
};
</code>```

}

This is my logcat:

```<code>12-14 07:26:46.711: INFO/ActivityManager(59): Start proc com.droidnova.android.samples  for activity com.droidnova.android.samples/.SelectContact: pid=250 uid=10025 gids={1015}
  12-14 07:26:46.721: ERROR/AndroidRuntime(244): ERROR: thread attach failed
  12-14 07:26:46.761: DEBUG/dalvikvm(244): LinearAlloc 0x0 used 639500 of 5242880 (12%)
  12-14 07:26:46.941: DEBUG/ddm-heap(250): Got feature list request
12-14 07:26:47.091: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at [0x49e2e8:0x49e464] in 1288362 ns
12-14 07:26:47.111: WARN/ActivityThread(250): Application com.droidnova.android.samples is waiting for the debugger on port 8100...
12-14 07:26:47.141: INFO/System.out(250): Sending WAIT chunk
12-14 07:26:47.151: INFO/dalvikvm(250): Debugger is active
12-14 07:26:47.211: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x4a2798:0x4a28a4] in 571302 ns
12-14 07:26:47.351: INFO/System.out(250): Debugger has connected
12-14 07:26:47.361: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.561: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.761: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.781: INFO/ARMAssembler(59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x393188:0x393244] in 604406 ns
12-14 07:26:47.801: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x393dd0:0x393f98] in 666356 ns
12-14 07:26:47.961: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.161: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.371: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.571: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.782: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.981: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.181: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.391: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.593: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.791: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.996: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.201: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.401: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.601: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.801: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.012: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.216: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.421: INFO/System.out(250): debugger has settled (1459)
12-14 07:26:51.971: WARN/Resources(250): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f060000}
12-14 07:26:52.931: INFO/ActivityManager(59): Displayed activity com.droidnova.android.samples/.SelectContact: 6292 ms (total 6292 ms)
12-14 07:26:58.051: DEBUG/ViewFlipper(99): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
12-14 07:26:58.051: DEBUG/ViewFlipper(99): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
12-14 07:26:58.611: DEBUG/dalvikvm(105): GC freed 2632 objects / 154776 bytes in 515ms
12-14 07:27:02.341: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:02.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:02.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:06.391: DEBUG/dalvikvm(170): GC freed 726 objects / 53656 bytes in 106ms
12-14 07:27:26.941: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:26.951: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:26.951: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:30.351: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:30.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:30.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:33.401: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:33.401: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:33.401: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:37.211: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:37.211: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:37.211: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:38.371: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:38.371: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:38.381: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:39.351: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:39.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:39.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:39.931: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:39.931: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:39.941: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:49.261: DEBUG/AndroidRuntime(267): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-14 07:27:49.271: DEBUG/AndroidRuntime(267): CheckJNI is ON
12-14 07:27:49.491: DEBUG/AndroidRuntime(267): --- registering native functions ---
12-14 07:27:49.891: DEBUG/ddm-heap(267): Got feature list request
12-14 07:27:50.431: DEBUG/AndroidRuntime(267): Shutting down VM
12-14 07:27:50.431: DEBUG/dalvikvm(267): DestroyJavaVM waiting for non-daemon threads to exit
12-14 07:27:50.431: DEBUG/dalvikvm(267): DestroyJavaVM shutting VM down
12-14 07:27:50.441: DEBUG/dalvikvm(267): HeapWorker thread shutting down
12-14 07:27:50.441: DEBUG/dalvikvm(267): HeapWorker thread has shut down
12-14 07:27:50.451: ERROR/AndroidRuntime(267): ERROR: thread attach failed
12-14 07:27:50.451: DEBUG/jdwp(267): JDWP shutting down net...
12-14 07:27:50.451: INFO/dalvikvm(267): Debugger has detached; object registry had 1 entries
12-14 07:27:50.471: DEBUG/dalvikvm(267): VM cleaning up
12-14 07:27:50.491: DEBUG/dalvikvm(267): LinearAlloc 0x0 used 629532 of 5242880 (12%)
12-14 07:27:50.981: DEBUG/AndroidRuntime(275): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-14 07:27:50.981: DEBUG/AndroidRuntime(275): CheckJNI is ON
12-14 07:27:51.251: DEBUG/AndroidRuntime(275): --- registering native functions ---
12-14 07:27:51.641: DEBUG/ddm-heap(275): Got feature list request
12-14 07:27:52.222: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.droidnova.android.samples/.SelectContact }
12-14 07:27:52.242: DEBUG/AndroidRuntime(275): Shutting down VM
12-14 07:27:52.252: DEBUG/dalvikvm(275): DestroyJavaVM waiting for non-daemon threads to exit
12-14 07:27:52.252: DEBUG/dalvikvm(275): DestroyJavaVM shutting VM down
12-14 07:27:52.252: DEBUG/dalvikvm(275): HeapWorker thread shutting down
12-14 07:27:52.262: DEBUG/dalvikvm(275): HeapWorker thread has shut down
12-14 07:27:52.262: ERROR/AndroidRuntime(275): ERROR: thread attach failed
12-14 07:27:52.272: DEBUG/jdwp(275): JDWP shutting down net...
12-14 07:27:52.272: INFO/dalvikvm(275): Debugger has detached; object registry had 1 entries
12-14 07:27:52.292: DEBUG/dalvikvm(275): VM cleaning up
12-14 07:27:52.331: DEBUG/dalvikvm(275): LinearAlloc 0x0 used 639500 of 5242880 (12%)
</code>```

答:
The method you are using is looks to weird.  Have a look at previous question asked by me

How to implement MultiAutoCompeleteTextView like Android default SMS Application ?

ContentLicense: CC BY-SA 2.5

Body:
I am using autoCompleteTextView to load the contacts. There is no errors and it doesnt crash too. But the autocompleteTextview doesn't seem to appear anything.I will post my codes and logcat.

Codes:-
       package com.droidnova.android.samples;

   import android.app.Activity;
   import android.content.ContentResolver;
   import android.content.Context;
   import android.database.Cursor;
   import android.net.Uri;
   import android.os.Bundle;
   import android.provider.Contacts;
   import android.provider.Contacts.People;
   import android.provider.SyncStateContract.Constants;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
  import android.widget.AutoCompleteTextView;
  import android.widget.CursorAdapter;
  import android.widget.Filterable;
  import android.widget.LinearLayout;
   import android.widget.TextView;

   public class AutoComplete extends Activity {

private static TextView mName;
private static TextView mNumber;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.button);

   ContentResolver content = getContentResolver();
    Cursor cursor = content.query(People.CONTENT_URI,
            PEOPLE_PROJECTION, People.NAME+"IS NOT NULL AND" +
            People.NUMBER_KEY+"IS NOT NULL",null,People.DEFAULT_SORT_ORDER);
    ContactListAdapter adapter = new ContactListAdapter(this, cursor);

    AutoCompleteTextView textView = (AutoCompleteTextView)
            findViewById(R.id.AutoCompleteTextView01);
    textView.setAdapter(adapter);
    textView.setHint("type name");
}

// XXX compiler bug in javac 1.5.0_07-164, we need to implement Filterable
// to make compilation work
   public static class ContactListAdapter extends CursorAdapter implements Filterable {
     public ContactListAdapter(Context context, Cursor c) {
        super(context, c);
        mContent = context.getContentResolver();
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final LinearLayout ret = new LinearLayout(context);
        final LayoutInflater inflater = LayoutInflater.from(context);
        mName = (TextView) inflater.inflate(
                android.R.layout.simple_dropdown_item_1line, parent, false);
        mNumber=(TextView) inflater.inflate(
                android.R.layout.simple_dropdown_item_1line, parent, false);
        int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
        int numberIdx = cursor.getColumnIndex(People.NUMBER);

        String name = cursor.getString(nameIdx);
        String number = cursor.getString(numberIdx);

        mName.setText(name);
        mNumber.setText(number);
        return ret;

    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
         int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
         int numberIdx = cursor.getColumnIndex(People.NUMBER);

         String name = cursor.getString(nameIdx);
         String number = cursor.getString(numberIdx);
         ((TextView) ((LinearLayout) view).getChildAt(0)).setText(name);
         LinearLayout horizontal = (LinearLayout) ((LinearLayout) view).getChildAt(1);
         ((TextView) horizontal.getChildAt(0)).setText(number);

    }

    @Override
    public String convertToString(Cursor cursor) {
        int numCol = cursor.getColumnIndexOrThrow(People.NUMBER);
        String number = cursor.getString(numCol);
        return number;

    }

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        if (getFilterQueryProvider() != null) { return getFilterQueryProvider().runQuery(constraint); }

        StringBuilder buffer = null;
        String[] args = null;
        if (constraint != null) {
            buffer = new StringBuilder();
            buffer.append(People.NAME + " IS NOT NULL AND " + People.NUMBER_KEY + " IS NOT NULL AND ");
            buffer.append("UPPER(");
            buffer.append(People.NAME);
            buffer.append(") GLOB ?");
            args = new String[] { constraint.toString().toUpperCase() + "*" };
        }

        return mContent.query(People.CONTENT_URI,PEOPLE_PROJECTION, buffer == null ? null : buffer
                .toString(), args, People.DEFAULT_SORT_ORDER);
    }

    private ContentResolver mContent;
}

  private static final String[] PEOPLE_PROJECTION = new String[] {
     People.NAME,
    People._ID,
    People.NUMBER,
};

}

This is my logcat:

12-14 07:26:46.711: INFO/ActivityManager(59): Start proc com.droidnova.android.samples  for activity com.droidnova.android.samples/.SelectContact: pid=250 uid=10025 gids={1015}
  12-14 07:26:46.721: ERROR/AndroidRuntime(244): ERROR: thread attach failed
  12-14 07:26:46.761: DEBUG/dalvikvm(244): LinearAlloc 0x0 used 639500 of 5242880 (12%)
  12-14 07:26:46.941: DEBUG/ddm-heap(250): Got feature list request
12-14 07:26:47.091: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at [0x49e2e8:0x49e464] in 1288362 ns
12-14 07:26:47.111: WARN/ActivityThread(250): Application com.droidnova.android.samples is waiting for the debugger on port 8100...
12-14 07:26:47.141: INFO/System.out(250): Sending WAIT chunk
12-14 07:26:47.151: INFO/dalvikvm(250): Debugger is active
12-14 07:26:47.211: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x4a2798:0x4a28a4] in 571302 ns
12-14 07:26:47.351: INFO/System.out(250): Debugger has connected
12-14 07:26:47.361: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.561: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.761: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.781: INFO/ARMAssembler(59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x393188:0x393244] in 604406 ns
12-14 07:26:47.801: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x393dd0:0x393f98] in 666356 ns
12-14 07:26:47.961: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.161: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.371: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.571: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.782: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.981: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.181: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.391: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.593: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.791: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.996: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.201: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.401: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.601: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.801: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.012: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.216: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.421: INFO/System.out(250): debugger has settled (1459)
12-14 07:26:51.971: WARN/Resources(250): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f060000}
12-14 07:26:52.931: INFO/ActivityManager(59): Displayed activity com.droidnova.android.samples/.SelectContact: 6292 ms (total 6292 ms)
12-14 07:26:58.051: DEBUG/ViewFlipper(99): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
12-14 07:26:58.051: DEBUG/ViewFlipper(99): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
12-14 07:26:58.611: DEBUG/dalvikvm(105): GC freed 2632 objects / 154776 bytes in 515ms
12-14 07:27:02.341: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:02.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:02.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:06.391: DEBUG/dalvikvm(170): GC freed 726 objects / 53656 bytes in 106ms
12-14 07:27:26.941: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:26.951: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:26.951: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:30.351: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:30.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:30.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:33.401: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:33.401: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:33.401: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:37.211: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:37.211: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:37.211: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:38.371: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:38.371: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:38.381: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:39.351: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:39.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:39.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:39.931: ERROR/MediaPlayerService(30):   error: -2
12-14 07:27:39.931: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:39.941: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:49.261: DEBUG/AndroidRuntime(267): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-14 07:27:49.271: DEBUG/AndroidRuntime(267): CheckJNI is ON
12-14 07:27:49.491: DEBUG/AndroidRuntime(267): --- registering native functions ---
12-14 07:27:49.891: DEBUG/ddm-heap(267): Got feature list request
12-14 07:27:50.431: DEBUG/AndroidRuntime(267): Shutting down VM
12-14 07:27:50.431: DEBUG/dalvikvm(267): DestroyJavaVM waiting for non-daemon threads to exit
12-14 07:27:50.431: DEBUG/dalvikvm(267): DestroyJavaVM shutting VM down
12-14 07:27:50.441: DEBUG/dalvikvm(267): HeapWorker thread shutting down
12-14 07:27:50.441: DEBUG/dalvikvm(267): HeapWorker thread has shut down
12-14 07:27:50.451: ERROR/AndroidRuntime(267): ERROR: thread attach failed
12-14 07:27:50.451: DEBUG/jdwp(267): JDWP shutting down net...
12-14 07:27:50.451: INFO/dalvikvm(267): Debugger has detached; object registry had 1 entries
12-14 07:27:50.471: DEBUG/dalvikvm(267): VM cleaning up
12-14 07:27:50.491: DEBUG/dalvikvm(267): LinearAlloc 0x0 used 629532 of 5242880 (12%)
12-14 07:27:50.981: DEBUG/AndroidRuntime(275): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-14 07:27:50.981: DEBUG/AndroidRuntime(275): CheckJNI is ON
12-14 07:27:51.251: DEBUG/AndroidRuntime(275): --- registering native functions ---
12-14 07:27:51.641: DEBUG/ddm-heap(275): Got feature list request
12-14 07:27:52.222: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.droidnova.android.samples/.SelectContact }
12-14 07:27:52.242: DEBUG/AndroidRuntime(275): Shutting down VM
12-14 07:27:52.252: DEBUG/dalvikvm(275): DestroyJavaVM waiting for non-daemon threads to exit
12-14 07:27:52.252: DEBUG/dalvikvm(275): DestroyJavaVM shutting VM down
12-14 07:27:52.252: DEBUG/dalvikvm(275): HeapWorker thread shutting down
12-14 07:27:52.262: DEBUG/dalvikvm(275): HeapWorker thread has shut down
12-14 07:27:52.262: ERROR/AndroidRuntime(275): ERROR: thread attach failed
12-14 07:27:52.272: DEBUG/jdwp(275): JDWP shutting down net...
12-14 07:27:52.272: INFO/dalvikvm(275): Debugger has detached; object registry had 1 entries
12-14 07:27:52.292: DEBUG/dalvikvm(275): VM cleaning up
12-14 07:27:52.331: DEBUG/dalvikvm(275): LinearAlloc 0x0 used 639500 of 5242880 (12%)


问:
I have to add some rows for perticular records.. my project is on live.. so i cant redo the whole database
I have to add one row for records where it is not present.. i cant empty/change database, beacause its on live..

for example:

```<code>id  |  attribute_id | val

28  |  11           | a

28  |  12           | b

28  |  13           | c

28  |  14           | d
</code>```

suppose this is one record in table of same id, this records are already present in table.. i have to add one row for old records where it is not present..

It should be added like this..

```<code>id  |  attribute_id | val

28  |  11           | a

28  |  12           | b

28  |  13           | c

28  |  14           | d

28  |  15           | No
</code>```

see the last row.. i have add attribute 15 for records(ids) where its not present

please suggest me mysql query to add this..

答:
you would get all the ids in need of an insert by

```<code>SELECT id, SUM(attribute_id = 15)
FROM table
GROUP BY id
HAVING SUM(attribute_id = 15) = 0
</code>```

I am nog sure Mysql will allow this in 1 query like

```<code>INSERT INTO table (id, attribute_id, val)
SELECT id, 15 AS atr, 'NO' AS val
FROM table
GROUP BY id, atr, val
HAVING SUM(attribute_id = 15) = 0
</code>```

but try it

Else solve it using php by getting the ids from the first query and inserting afterwards. (Mysql is not always very allowing to read and write in the same table in one query)

Body:
I have to add one row for records where it is not present.. i cant empty/change database, beacause its on live..

for example:

id  |  attribute_id | val

28  |  11           | a

28  |  12           | b

28  |  13           | c

28  |  14           | d

suppose this is one record in table of same id, this records are already present in table.. i have to add one row for old records where it is not present..

It should be added like this..

id  |  attribute_id | val

28  |  11           | a

28  |  12           | b

28  |  13           | c

28  |  14           | d

28  |  15           | No

see the last row.. i have add attribute 15 for records(ids) where its not present

please suggest me mysql query to add this..

Body:
you would get all the ids in need of an insert by

SELECT id, SUM(attribute_id = 15)
FROM table
GROUP BY id
HAVING SUM(attribute_id = 15) = 0

I am nog sure Mysql will allow this in 1 query like

INSERT INTO table (id, attribute_id, val)
SELECT id, 15 AS atr, 'NO' AS val
FROM table
GROUP BY id, atr, val
HAVING SUM(attribute_id = 15) = 0

but try it

Else solve it using php by getting the ids from the first query and inserting afterwards. (Mysql is not always very allowing to read and write in the same table in one query)


问:
How can I write mathematics model in beamer LaTex
How to write math models in LaTex.
I tried this code:</p>

```<code>\begin{frame}
\frametitle{Random Walk}
E(Rj(j,t+1) | φ_t )=(Rj(j,t+1) )    // this model I copy from a papper
\end{frame}
</code>```

答:
You need to enclose mathematics type inside dollar signs $ ... $ for inline mathematics or for a block element \[ ... \]. Also φ should be typeset with \phi. And if you want the E to be bold you can use \mathbf{E}. Similarly if you want Rj to be typeset upright and next to each other instead of looking like variables multiplied, use \mathrm{Rj} or define your own symbol at the start of the document.

LaTeX is it's own language, and there's an entire Stack site dedicated to TeX and its variants: https://tex.stackexchange.com/

Since you're new it might be good to read up on a tutorial or two. There are a ton of resources online but I like the online LaTeX compiler ShareLaTeX and they've got a good set of tutorials covering the basics. I also think this is a great start to learning the ins and outs of LaTeX.

Body:
How to write math models in LaTex.
I tried this code:

\begin{frame}
\frametitle{Random Walk}
E(Rj(j,t+1) | φ_t )=(Rj(j,t+1) )    // this model I copy from a papper
\end{frame}


问:
Trigger .onclick() on hover over another element
I'm trying to trigger an .onclick() event when I hover over another div.

The element that needs to trigger the .onclick() event has the ID #exp_des_p_trig.

.

The element that needs to be triggered has the href value #exp_des_p in an a tag.

.

I can understand the basics/read JS but I can't write it (yet), I'm thinking something like this:

```<code><script>
jQuery('#exp_des_p_trig').hover();
    jQuery('#exp_des_p').onclick();
</script>
</code>```

Can anyone help me correct this so that it works?

UPDATE:

I emailed Visual Composer support about this and this is the response I got:

Instead of triggering a click event you can try attaching vc_active class to the tour vc_tta-tab and vc_tta-panel via js. The vc_active class is responsible for opening a tour content for display.

Thank you for the answers below, it seems that this is a Visual Composer related issue which I will address elsewhere.

答:
this is a solution:</p>

```<code>$(document).ready(function(){
    $('#divhover').hover(function (event){
    alert("divhover_hover");
    $("#aClick").trigger( "click" );
  });

  $('#aClick').on('click',function(event){
    alert("aClick_click");
  });

})
</code>```

Body:
I'm trying to trigger an .onclick() event when I hover over another div.

The element that needs to trigger the .onclick() event has the ID #exp_des_p_trig.

.

The element that needs to be triggered has the href value #exp_des_p in an a tag.

.

I can understand the basics/read JS but I can't write it (yet), I'm thinking something like this:

Can anyone help me correct this so that it works?

UPDATE:

I emailed Visual Composer support about this and this is the response I got:

Instead of triggering a click event you can try attaching vc_active class to the tour vc_tta-tab and vc_tta-panel via js. The vc_active class is responsible for opening a tour content for display.

Thank you for the answers below, it seems that this is a Visual Composer related issue which I will address elsewhere.

Body:
this is a solution:

$(document).ready(function(){
    $('#divhover').hover(function (event){
    alert("divhover_hover");
    $("#aClick").trigger( "click" );
  });

  $('#aClick').on('click',function(event){
    alert("aClick_click");
  });

})


问:
Table filtering with pipes using ngfor and web api data
I am trying to make a filter for my table so that when I search by a parameter it only shows the row containing the parameter. Here's a working example of what I'm trying to achieve - plunkr.

I used the code from that plunkr and this website as reference and tried implementing it in my solution. I get the table data from web api.

I'm trying to filter by "codeListVesselID".
Here is the code:

vesel.pipe.ts

import { Pipe, PipeTransform, Injectable } from '@angular/core';
import { CodeListVessel } from './vessels.component';

@Pipe({
    name: 'vesselfilter',
    pure: false
})
@Injectable()
export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], args: any[]): any {
    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(args[0].toLowerCase()) !== -1);
  }
}```
</div>
</div>
</p>

<p>The pipe is defined in app.module.ts under declarations.</p>

<p><strong>vessels.component.ts</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>import { Component, Input } from '@angular/core';
...
import { VesselIDFilter } from '../vessels/vessels.pipe';

@Component({
    selector: 'vessels',
    template: require('./vessels.component.html'),
    styleUrls: ['./vessel.component.css']
})

export class vesselsComponent {
    // to get the Vessel Details
    public vessel: CodeListVessel[] = [];
    ...

    constructor(public http: Http, private dialogService: DialogService, private confirmationService: ConfirmationService, private auth: Auth) {
        this.getData();
    }
    //to get all the Vessel data from Web API
    getData() {
        this.http.get('/api/CodeListVesselAPI/Vessel').subscribe(result => {
        this.vessel = result.json();
        });
    }
    ...
}

export interface CodeListVessel {
    codeListVesselID: string;
    mmsi: string;
    imo: number;
    ...
}</code>```

vessels.component.html

<input type="text" id="inputID" class="form-control" placeholder="Code" [(ngModel)]="codeListVesselID">

                    Code
                    MMSI
                    IMO
                    ...

                        {{CodeListVessel.codeListVesselID}}

                        {{CodeListVessel.mmsi}}

                        {{CodeListVessel.imo}}

                    ...

```

Here is the error I get for running the above code:

It points to the code in pipe but I don't know what the problem is.
If I remove the filter code the data shows properly in the table so the data gets through fine.

There may also be an issue in another part.

Any help would be appreciated.

答:
```<code>export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], args: any[]): any {
    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(args[0].toLowerCase()) !== -1);
  }
}
</code>```

In your pipe args is not going to be an array. You are actually receiving the id for the vessel that you want to filter on as the second argument. There are 2 things you can do.

Solution 1

You can change type the argument to what it actually is, which is a string:

```<code>export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], vesselId: string): any {
    if (!vesselId || vesselId === '') {
      return vessel;
    }

    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(vesselId.toLowerCase()) !== -1);
  }
}
</code>```

Solution 2

Or you can change the type to a proper rest argument:

```<code>export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], ...args: any[]): any {
    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(args[0].toLowerCase()) !== -1);
  }
}
</code>```

Make sure that if no filter is selected that you are actually implementing the desired behaviour. Do you want to show all items if no filter is selected or hide all items. This is up to you.

See plunker for working example: https://plnkr.co/edit/z8OwlH0JwfXe2qCLRP5B?p=preview

Body:
I am trying to make a filter for my table so that when I search by a parameter it only shows the row containing the parameter. Here's a working example of what I'm trying to achieve - plunkr.

I used the code from that plunkr and this website as reference and tried implementing it in my solution. I get the table data from web api.

I'm trying to filter by "codeListVesselID".
Here is the code:

vesel.pipe.ts

import { Pipe, PipeTransform, Injectable } from '@angular/core';
import { CodeListVessel } from './vessels.component';

@Pipe({
    name: 'vesselfilter',
    pure: false
})
@Injectable()
export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], args: any[]): any {
    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(args[0].toLowerCase()) !== -1);
  }
}

The pipe is defined in app.module.ts under declarations.

vessels.component.ts

import { Component, Input } from '@angular/core';
...
import { VesselIDFilter } from '../vessels/vessels.pipe';

@Component({
    selector: 'vessels',
    template: require('./vessels.component.html'),
    styleUrls: ['./vessel.component.css']
})

export class vesselsComponent {
    // to get the Vessel Details
    public vessel: CodeListVessel[] = [];
    ...

    constructor(public http: Http, private dialogService: DialogService, private confirmationService: ConfirmationService, private auth: Auth) {
        this.getData();
    }
    //to get all the Vessel data from Web API
    getData() {
        this.http.get('/api/CodeListVesselAPI/Vessel').subscribe(result => {
        this.vessel = result.json();
        });
    }
    ...
}

export interface CodeListVessel {
    codeListVesselID: string;
    mmsi: string;
    imo: number;
    ...
}

vessels.component.html

<input type="text" id="inputID" class="form-control" placeholder="Code" [(ngModel)]="codeListVesselID">

                    Code
                    MMSI
                    IMO
                    ...

                        {{CodeListVessel.codeListVesselID}}

                        {{CodeListVessel.mmsi}}

                        {{CodeListVessel.imo}}

                    ...

Here is the error I get for running the above code:

It points to the code in pipe but I don't know what the problem is.
If I remove the filter code the data shows properly in the table so the data gets through fine.

There may also be an issue in another part.

Any help would be appreciated.

Body:
export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], args: any[]): any {
    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(args[0].toLowerCase()) !== -1);
  }
}

In your pipe args is not going to be an array. You are actually receiving the id for the vessel that you want to filter on as the second argument. There are 2 things you can do.

Solution 1

You can change type the argument to what it actually is, which is a string:

export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], vesselId: string): any {
    if (!vesselId || vesselId === '') {
      return vessel;
    }

    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(vesselId.toLowerCase()) !== -1);
  }
}

Solution 2

Or you can change the type to a proper rest argument:

export class VesselIDFilter implements PipeTransform {
  transform(vessel: CodeListVessel[], ...args: any[]): any {
    return vessel.filter(CodeListVessel => CodeListVessel.codeListVesselID.toLowerCase().indexOf(args[0].toLowerCase()) !== -1);
  }
}

Make sure that if no filter is selected that you are actually implementing the desired behaviour. Do you want to show all items if no filter is selected or hide all items. This is up to you.

See plunker for working example: https://plnkr.co/edit/z8OwlH0JwfXe2qCLRP5B?p=preview