问:
MySQL get the SUM of a column ONLY from the latest date
I have a table like this:

```<code>---------------------------------------
| id | name     | points |   date     |
---------------------------------------
| 1  | ana      | 1      | 2014-12-10 |
| 2  | tom      | 3      | 2015-12-09 |
| 3  | jim      | 1      | 2013-12-02 |
| 4  | ana      | 9      | 2014-12-10 |
| 5  | tom      | 3      | 2015-12-09 |
| 6  | jim      | 1      | 2016-12-08 |
| 7  | jim      | 5      | 2016-12-08 |
| 8  | ana      | 2      | 2016-12-08 |
| 9  | ana      | 1      | 2016-12-08 |
| 10 | tom      | 2      | 2013-12-07 |
-------------------------------------
</code>```

In this table, I have a group of names. These names may have duplicate entries on the same date with different points. They also have duplicate entries with different dates. The dates are all different, there is no pattern to them.

My goal is to return the following:

```<code>name, SUM(points) WHERE MAX(date) for the name group
</code>```

So basically my current query is:

```<code>SELECT name, SUM(points) FROM table GROUP BY name;
</code>```

However, I need this to only count point entries in the name group from the latest date for that name group, as opposed to summing all the points from all dates.

How can I do this?

答:
To aggregate the latest date per name, you can join against a subquery producing the MAX(date), joining on both the name and the date from the outer table and the subquery. This allows you to SUM() for that group.

```<code>SELECT
  t.name,
  SUM(points) AS total_points,
  max_date
FROM
  `table` t
  JOIN (
    -- Subquery produces latest date per name
    SELECT
      name,
      MAX(date) AS max_date
    FROM `table`
    GROUP BY name
  ) name_dates
    -- Join table to subquery on both name and the aggregate date
    ON t.name = name_dates.name AND t.date = max_date
-- Group for the outer SUM()
GROUP BY t.name, max_date
</code>```

This produces the result:

```<code>+------+--------------+---------------------+
| name | total_points | max_date            |
+------+--------------+---------------------+
| ana  |            3 | 2016-12-08 00:00:00 |
| jim  |            6 | 2016-12-08 00:00:00 |
| tom  |            6 | 2015-12-09 00:00:00 |
+------+--------------+---------------------+
</code>```

Here it is in action. http://sqlfiddle.com/#!9/dece38/1
(sqlfiddle is malfunctioning right now, may need to paste the query back in to reexecute)

Body:
I have a table like this:

---------------------------------------
| id | name     | points |   date     |
---------------------------------------
| 1  | ana      | 1      | 2014-12-10 |
| 2  | tom      | 3      | 2015-12-09 |
| 3  | jim      | 1      | 2013-12-02 |
| 4  | ana      | 9      | 2014-12-10 |
| 5  | tom      | 3      | 2015-12-09 |
| 6  | jim      | 1      | 2016-12-08 |
| 7  | jim      | 5      | 2016-12-08 |
| 8  | ana      | 2      | 2016-12-08 |
| 9  | ana      | 1      | 2016-12-08 |
| 10 | tom      | 2      | 2013-12-07 |
-------------------------------------

In this table, I have a group of names. These names may have duplicate entries on the same date with different points. They also have duplicate entries with different dates. The dates are all different, there is no pattern to them.

My goal is to return the following:

name, SUM(points) WHERE MAX(date) for the name group

So basically my current query is:

SELECT name, SUM(points) FROM table GROUP BY name;

However, I need this to only count point entries in the name group from the latest date for that name group, as opposed to summing all the points from all dates.

How can I do this?

Body:
To aggregate the latest date per name, you can join against a subquery producing the MAX(date), joining on both the name and the date from the outer table and the subquery. This allows you to SUM() for that group.

SELECT
  t.name,
  SUM(points) AS total_points,
  max_date
FROM
  `table` t
  JOIN (
    -- Subquery produces latest date per name
    SELECT
      name,
      MAX(date) AS max_date
    FROM `table`
    GROUP BY name
  ) name_dates
    -- Join table to subquery on both name and the aggregate date
    ON t.name = name_dates.name AND t.date = max_date
-- Group for the outer SUM()
GROUP BY t.name, max_date

This produces the result:

+------+--------------+---------------------+
| name | total_points | max_date            |
+------+--------------+---------------------+
| ana  |            3 | 2016-12-08 00:00:00 |
| jim  |            6 | 2016-12-08 00:00:00 |
| tom  |            6 | 2015-12-09 00:00:00 |
+------+--------------+---------------------+

Here it is in action. http://sqlfiddle.com/#!9/dece38/1
(sqlfiddle is malfunctioning right now, may need to paste the query back in to reexecute)


来源: stackexchange

问:
Android Notification with FCM - Who started the FirebaseMessagingService?
According to the set up guide here, in a sample app, A) I created a class that extends firebase services class.  B) I put these classes in the AndroidManifest.xml

A) Java Class

```<code>public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        //a) What's the life cycle of the service? How can I ensure this method is getting called?
        //b) If the service is killed at some point, will system restart it on receiving new messages?
        Log.d(TAG, "From: " + remoteMessage.getFrom());
    }
}
</code>```

B) AndroidManifest.xml

```<code><service
    android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>
</code>```

Then, the app can receive notifications from FCM!

Here is my question:

Who started the FirebaseMessagingService notification service?
There must be some place calling startService(), isn't it?

My understanding is that, the downstream notification will deliver to my mobile device's google play service, regardless of the state of my app.
Then, to what extent can I ensure that my onMessageReceive() is called when the app or service is swipe closed/killed/force stop? Is the relevant behavior documented anywhere?

EDIT:

I am more concerned about the following case. Let's talk about the data message. (compared to the notification message.)
My client app received the FCM message and shows the default notification, because google play service is running and send it to the system tray. But my onMessageReceive() is not called, because MyFirebaseMessagingService is killed by system and not restarted. Is it possible?

答:
1. Who started the FirebaseMessagingService notification service? There must be some place calling startService(), isn't it?

The SDK does this automatically for you.

2. My understanding is that, the downstream notification will deliver to my mobile device's google play service, regardless of the state of my app. Then, to what extent can I ensure that my onMessageReceive() is called when the app or service is swipe closed/killed/force stop? Is the relevant behavior documented anywhere?

The official docs for Receiving Message for Android is here. It discusses the behavior of the message (depending on the type of message payload you use (i.e. notification or data)) for when your app is in foreground and background.

To be able to handle the message yourself (in onMessageReceived()), you'll have to send data-only message payloads.

For the topic with regards to swipe closed/killed/force stopped, this topic has been discussed for quite some time and there doesn't seem to be a definite answer. During one of my testings, I am able to still receive a message (tested with a data-only message payload) if I Swipe close my app. But when I force closed it from the Settings menu, I wasn't able to receive any messages. Do note that this is not always the behavior.

There are some devices that were designed that when you swipe close the app, it will be the same as force stopping them (see my answer here).

There are also devices where even if the app is still just simply swiped away, even though it's not force closed, the device itself is preventing it from receiving messages. Others say that this can't be the case because apps like WhatsApp were able to do it. The reason I've learned so far for that is because the device manufacturers have whitelisted most of the well-known apps for it to be possible.

So just to answer your question, no. This is not documented anywhere because (IMO) this is a topic that depends also on the device and that FCM has no total control over.

3. I am more concerned about the following case. Let's talk about the data message. (compared to the notification message.) My client app received the FCM message and shows the default notification, because google play service is running and send it to the system tray. But my onMessageReceive() is not called, because MyFirebaseMessagingService is killed by system and not restarted. Is it possible?

AFAIK, the FirebaseMessagingService is tied with the Google Play Service so so long as Google Play Service is active, so will the Firebase service. A portion from my answer here:

However, I've seen that it was previously mentioned before for FirebaseMessagingService (see this post, comment by @ArthurThompson):

These services will be started by Google Play services, which is always running on the device. You don't have to and should not start/stop these services yourself.

ContentLicense: CC BY-SA 3.0

Body:
According to the set up guide here, in a sample app, A) I created a class that extends firebase services class.  B) I put these classes in the AndroidManifest.xml

A) Java Class

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        //a) What's the life cycle of the service? How can I ensure this method is getting called?
        //b) If the service is killed at some point, will system restart it on receiving new messages?
        Log.d(TAG, "From: " + remoteMessage.getFrom());
    }
}

B) AndroidManifest.xml

<service
    android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

Then, the app can receive notifications from FCM!

Here is my question:

Who started the FirebaseMessagingService notification service?
There must be some place calling startService(), isn't it?

My understanding is that, the downstream notification will deliver to my mobile device's google play service, regardless of the state of my app.
Then, to what extent can I ensure that my onMessageReceive() is called when the app or service is swipe closed/killed/force stop? Is the relevant behavior documented anywhere?

EDIT:

I am more concerned about the following case. Let's talk about the data message. (compared to the notification message.)
My client app received the FCM message and shows the default notification, because google play service is running and send it to the system tray. But my onMessageReceive() is not called, because MyFirebaseMessagingService is killed by system and not restarted. Is it possible?


问:
Selenium: How do I get the locator of the element which currently holds the cursor?
I'm writing an auto testing framework using Selenium.  I am trying to test our application which interacts with a third party web application.  I don't have access to the source code of the web app.

I want to be able to use selenium to put some text in a text box, but no matter how hard I try, selenium IDE isn't able to record me putting text into this box.

Firebug seems to imply that this is because the box that I am trying to write to is with a separate html form imbedded with the page.  However, I am able to interact with the web app so that the cursor is in the text box.

Is there a way to either:

a) Input text at the current cursor position (i.e. without referencing a locator because I can't seem to be able to get the locator.)

or,

b) Get the locator of the element which currently holds the cursor?

Thanks in advance,
Rik

答: If it is an iframe you need to change the focus to iframe and try to do the actions.</p>

ContentLicense: CC BY-SA 2.5


问:
Exception from cURL when attempting to arc diff (Error code 56)
Im attempting to arc diff a local commit to a remote repository on bitbucket using Arcanist for Phabricator. This is the first time I have seen this error and I can not seem to find similar information on the internet. I have attempted arc diff-ing other branches and it works as expected.

[cURL/56] (https://phabricator.website.com.au/api/differential.creatediff)  The cURL library raised an error while making a request. You may be able to find more information about this error (error code: 56) on the cURL site: http://curl.haxx.se/libcurl/c/libcurl-errors.html#CURLERECVERROR

The information on the error in the link suggested states:

CURLE_RECV_ERROR (56)

Failure with receiving network data.

答:
You just need to increase your upload limits depending on your HTTP server.
This guide has some information about what to change.

https://secure.phabricator.com/book/phabricator/article/configuring_file_storage/#configuring-upload-limit


问:
org.scalacheck and org.scalatest not found after sbt->compile
```<code>[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest_2.12;2.2.4: not found
[error] unresolved dependency: org.scalacheck#scalacheck_2.12;1.12.1: not found
[error] unresolved dependency: org.scalactic#scalatest;3.0.1: not found
[error] unresolved dependency: org.scalacheck#scalacheck;1.13.4: not found
[error] unresolved dependency: org.scalatest#scalatest;3.0.1: not found
</code>```

in scala-2.12.1/lib/ following files exists:
scalacheck_2.12-1.13.4.jar scalactic_2.11-3.0.1.jar scalatest_2.11-3.0.1.jar

in build.sbt contains:

```<code>scalaVersion := "2.12.1"
libraryDependencies += "junit" % "junit" % "4.10" % "test"
libraryDependencies ++= assignmentsMap.value.values.flatMap(_.dependencies).toSeq
libraryDependencies += "org.scalacheck" % "scalacheck" % "1.13.4" % "test"
libraryDependencies += "org.scalactic" % "scalatest" % "3.0.1"
libraryDependencies += "org.scalatest" % "scalatest" % "3.0.1" % "test"
</code>```

but $ sbt and then compile error is thrown:
scala> developer@cn-vm-yourname:~/example/quickcheck$ sbt
[info] Loading global plugins from /home/developer/.sbt/0.13/plugins
[info] Loading project definition from /home/developer/example/quickcheck/project
[info] Set current project to progfun2-quickcheck (in build file:/home/developer/example/quickcheck/)

compile

```<code>[info] Updating {file:/home/developer/example/quickcheck/}root...
[info] Resolving org.scalatest#scalatest_2.12;2.2.4 ...
[warn]  module not found: org.scalatest#scalatest_2.12;2.2.4
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalatest/scalatest_2.12/2.2.4/scalatest_2.12-2.2.4.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalatest/scalatest_2.12/2.2.4/scalatest_2.12-2.2.4.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[info] Resolving org.scalacheck#scalacheck_2.12;1.12.1 ...
[warn]  module not found: org.scalacheck#scalacheck_2.12;1.12.1
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.12.1/scalacheck_2.12-1.12.1.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalacheck/scalacheck_2.12/1.12.1/scalacheck_2.12-1.12.1.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[info] Resolving org.scalactic#scalatest;3.0.1 ...
[warn]  module not found: org.scalactic#scalatest;3.0.1
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalactic/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalactic/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[info] Resolving org.scalacheck#scalacheck;1.13.4 ...
[warn]  module not found: org.scalacheck#scalacheck;1.13.4
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalacheck/scalacheck/1.13.4/scalacheck-1.13.4.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalacheck/scalacheck/1.13.4/scalacheck-1.13.4.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[info] Resolving org.scalatest#scalatest;3.0.1 ...
[warn]  module not found: org.scalatest#scalatest;3.0.1
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalatest/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalatest/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[info] Resolving jline#jline;2.14.1 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scalatest#scalatest_2.12;2.2.4: not found
[warn]  :: org.scalacheck#scalacheck_2.12;1.12.1: not found
[warn]  :: org.scalactic#scalatest;3.0.1: not found
[warn]  :: org.scalacheck#scalacheck;1.13.4: not found
[warn]  :: org.scalatest#scalatest;3.0.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn]  Note: Unresolved dependencies path:
[warn]      org.scalatest:scalatest_2.12:2.2.4 (/home/developer/example/quickcheck/project/StudentBuildLike.scala#L27)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalactic:scalatest:3.0.1 (/home/developer/example/quickcheck/build.sbt#L11-12)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalacheck:scalacheck:1.13.4 (/home/developer/example/quickcheck/build.sbt#L10-11)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalatest:scalatest:3.0.1 (/home/developer/example/quickcheck/build.sbt#L12-13)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalacheck:scalacheck_2.12:1.12.1 (/home/developer/example/quickcheck/build.sbt#L9-10)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest_2.12;2.2.4: not found
[error] unresolved dependency: org.scalacheck#scalacheck_2.12;1.12.1: not found
[error] unresolved dependency: org.scalactic#scalatest;3.0.1: not found
[error] unresolved dependency: org.scalacheck#scalacheck;1.13.4: not found
[error] unresolved dependency: org.scalatest#scalatest;3.0.1: not found
</code>```

答:
Try removing this line from your build.sbt:</p>

```<code>libraryDependencies += "org.scalactic" % "scalatest" % "3.0.1"
</code>```

Body:
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest_2.12;2.2.4: not found
[error] unresolved dependency: org.scalacheck#scalacheck_2.12;1.12.1: not found
[error] unresolved dependency: org.scalactic#scalatest;3.0.1: not found
[error] unresolved dependency: org.scalacheck#scalacheck;1.13.4: not found
[error] unresolved dependency: org.scalatest#scalatest;3.0.1: not found

in scala-2.12.1/lib/ following files exists:
scalacheck_2.12-1.13.4.jar scalactic_2.11-3.0.1.jar scalatest_2.11-3.0.1.jar

in build.sbt contains:

scalaVersion := "2.12.1"
libraryDependencies += "junit" % "junit" % "4.10" % "test"
libraryDependencies ++= assignmentsMap.value.values.flatMap(_.dependencies).toSeq
libraryDependencies += "org.scalacheck" % "scalacheck" % "1.13.4" % "test"
libraryDependencies += "org.scalactic" % "scalatest" % "3.0.1"
libraryDependencies += "org.scalatest" % "scalatest" % "3.0.1" % "test"

but $ sbt and then compile error is thrown:
scala> developer@cn-vm-yourname:~/example/quickcheck$ sbt
[info] Loading global plugins from /home/developer/.sbt/0.13/plugins
[info] Loading project definition from /home/developer/example/quickcheck/project
[info] Set current project to progfun2-quickcheck (in build file:/home/developer/example/quickcheck/)

compile

[info] Updating {file:/home/developer/example/quickcheck/}root...
[info] Resolving org.scalatest#scalatest_2.12;2.2.4 ...
[warn]  module not found: org.scalatest#scalatest_2.12;2.2.4
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalatest/scalatest_2.12/2.2.4/scalatest_2.12-2.2.4.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalatest/scalatest_2.12/2.2.4/scalatest_2.12-2.2.4.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalatest/scalatest_2.12/2.2.4/ivys/ivy.xml
[info] Resolving org.scalacheck#scalacheck_2.12;1.12.1 ...
[warn]  module not found: org.scalacheck#scalacheck_2.12;1.12.1
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.12.1/scalacheck_2.12-1.12.1.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalacheck/scalacheck_2.12/1.12.1/scalacheck_2.12-1.12.1.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalacheck/scalacheck_2.12/1.12.1/ivys/ivy.xml
[info] Resolving org.scalactic#scalatest;3.0.1 ...
[warn]  module not found: org.scalactic#scalatest;3.0.1
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalactic/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalactic/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalactic/scalatest/3.0.1/ivys/ivy.xml
[info] Resolving org.scalacheck#scalacheck;1.13.4 ...
[warn]  module not found: org.scalacheck#scalacheck;1.13.4
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalacheck/scalacheck/1.13.4/scalacheck-1.13.4.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalacheck/scalacheck/1.13.4/scalacheck-1.13.4.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalacheck/scalacheck/1.13.4/ivys/ivy.xml
[info] Resolving org.scalatest#scalatest;3.0.1 ...
[warn]  module not found: org.scalatest#scalatest;3.0.1
[warn] ==== local: tried
[warn]   /home/developer/.ivy2/local/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-launcher-local: tried
[warn]   /home/developer/.activator/repository/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   /home/developer/activator-dist-1.3.12/repository/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalatest/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/org/scalatest/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[info] Resolving jline#jline;2.14.1 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scalatest#scalatest_2.12;2.2.4: not found
[warn]  :: org.scalacheck#scalacheck_2.12;1.12.1: not found
[warn]  :: org.scalactic#scalatest;3.0.1: not found
[warn]  :: org.scalacheck#scalacheck;1.13.4: not found
[warn]  :: org.scalatest#scalatest;3.0.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn]  Note: Unresolved dependencies path:
[warn]      org.scalatest:scalatest_2.12:2.2.4 (/home/developer/example/quickcheck/project/StudentBuildLike.scala#L27)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalactic:scalatest:3.0.1 (/home/developer/example/quickcheck/build.sbt#L11-12)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalacheck:scalacheck:1.13.4 (/home/developer/example/quickcheck/build.sbt#L10-11)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalatest:scalatest:3.0.1 (/home/developer/example/quickcheck/build.sbt#L12-13)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[warn]      org.scalacheck:scalacheck_2.12:1.12.1 (/home/developer/example/quickcheck/build.sbt#L9-10)
[warn]        +- progfun2-quickcheck:progfun2-quickcheck_2.12:0.1-SNAPSHOT
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest_2.12;2.2.4: not found
[error] unresolved dependency: org.scalacheck#scalacheck_2.12;1.12.1: not found
[error] unresolved dependency: org.scalactic#scalatest;3.0.1: not found
[error] unresolved dependency: org.scalacheck#scalacheck;1.13.4: not found
[error] unresolved dependency: org.scalatest#scalatest;3.0.1: not found

Body:
Try removing this line from your build.sbt:

libraryDependencies += "org.scalactic" % "scalatest" % "3.0.1"


问:
mvvmcross ios lock portrait orientation for specific MvxViewController
I have solution in Xamarin mvvmcross which support for IOS portrait and landscape screen orientations. IOS 8.0
I would like to add new MvxViewController but lock it only on Portrait mode.
I searched in Internet examples for ios swift, xamarin forms but all of this are not applied for mvvmcross solution
Is there way how I can lock Portrait mode only for one screen with Xamarin mvvmcroos?

Thank you

答:
Actually for me is working this method :
in App AppDelegate : MvxApplicationDelegate class i created

```<code>public bool RestrictRotation = true;
</code>```

and added method :

```<code>[Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow)
{
    if (this.RestrictRotation)
        return UIInterfaceOrientationMask.All;
    else
        return UIInterfaceOrientationMask.Portrait;
}
</code>```

then for view where I want only Portrait mode, I use

```<code>public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
    app.RestrictRotation = false;
}
</code>```

and for support all screen rotations I am setting :

```<code>public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
    app.RestrictRotation = true;
}
</code>```

Hope it will help!
Thank you

Body:
Actually for me is working this method :
in App AppDelegate : MvxApplicationDelegate class i created

public bool RestrictRotation = true;

and added method :

[Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow)
{
    if (this.RestrictRotation)
        return UIInterfaceOrientationMask.All;
    else
        return UIInterfaceOrientationMask.Portrait;
}

then for view where I want only Portrait mode, I use

public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
    app.RestrictRotation = false;
}

and for support all screen rotations I am setting :

public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
    app.RestrictRotation = true;
}

Hope it will help!
Thank you


问:
Xamarin.UITests ApkFile or InstalledApp has not been configured in VS
I have started a new Xamarin Cross Platform App project in visual studio.

This is just the template you get in VS studio. I have testing building this app on an Android emulator and real Android device and works fine. Launches the Welcome to Xamarin Forms!

The main purpose is to use Xamarin Test Cloud with Xamarmin.UITests within the current solution.

So I have added a new project to the solution (UI Test App (cross platform)). That also has the template for testing the screen launches. I have added the references to the .IOS and .Android projects.

When I run the selected tests. I get the following error ApkFile or InstalledApp has not been configured

```<code>if (platform == Platform.Android)
{
     return ConfigureApp
     .Android
     .StartApp();
}
</code>```

This should package up the .Droid project launch on the device and run the tests. I have also made sure USE SHARED RUN TIME is not selected in the Android Options for the .Droid project.

If I reference the APK externally this works but that is not how I want this to work. This should work in the the previous content taking the current project and running the tests.

```<code> if (platform == Platform.Android)
{
    return ConfigureApp
    .Android
    .ApkFile(@"C:\Users\frasera\Documents\Visual Studio 2017\Projects\App6\App6\App6.Android\bin\Debug\App6.Android.apk")
                .StartApp();
}
</code>```

答:
Looks like that may be required in some circumstances. See: https://developer.xamarin.com/guides/testcloud/uitest/working-with/running-tests-in-ide/#Running_Android_6.0_Applications_from_the_IDE

When the IDE installs an Android 6.0 app for the first time, it does not grant all permissions required by the application. The workaround for this is to use UITest to install and start the application:

```<code>ConfigureApp.Android.Debug().ApkFile(apkpath).StartApp ()
</code>```

Do use ApkFile() and do not use PreferIdeSettings(). This will force UITest to install instead of the IDE.

Body:
I have started a new Xamarin Cross Platform App project in visual studio.

This is just the template you get in VS studio. I have testing building this app on an Android emulator and real Android device and works fine. Launches the Welcome to Xamarin Forms!

The main purpose is to use Xamarin Test Cloud with Xamarmin.UITests within the current solution.

So I have added a new project to the solution (UI Test App (cross platform)). That also has the template for testing the screen launches. I have added the references to the .IOS and .Android projects.

When I run the selected tests. I get the following error ApkFile or InstalledApp has not been configured

if (platform == Platform.Android)
{
     return ConfigureApp
     .Android
     .StartApp();
}

This should package up the .Droid project launch on the device and run the tests. I have also made sure USE SHARED RUN TIME is not selected in the Android Options for the .Droid project.

If I reference the APK externally this works but that is not how I want this to work. This should work in the the previous content taking the current project and running the tests.

 if (platform == Platform.Android)
{
    return ConfigureApp
    .Android
    .ApkFile(@"C:\Users\frasera\Documents\Visual Studio 2017\Projects\App6\App6\App6.Android\bin\Debug\App6.Android.apk")
                .StartApp();
}

Body:
Looks like that may be required in some circumstances. See: https://developer.xamarin.com/guides/testcloud/uitest/working-with/running-tests-in-ide/#Running_Android_6.0_Applications_from_the_IDE

When the IDE installs an Android 6.0 app for the first time, it does not grant all permissions required by the application. The workaround for this is to use UITest to install and start the application:

ConfigureApp.Android.Debug().ApkFile(apkpath).StartApp ()

Do use ApkFile() and do not use PreferIdeSettings(). This will force UITest to install instead of the IDE.


问:
Rxjs, How to link up callback method to Observable?
I need to link up a call-back method to the Observable chain.

```<code>private testMethod(): Rx.Observable<any> {
        const deferred = this.$q.defer();
        let promise = deferred.promise;

        this.$window.fileChooser.open((results: any) => {
            deferred.resolve(results);
        }, (error: any) => {
            this.Logger.log(error);
        });

        return this.rx.Observable.fromPromise(promise)
            .map((contentURI: string) => {
                // need to link call-back method
                this.$window.FilePath.resolveNativePath(contentURI, (absolutePath: any) => {
                    // need to pass absolutePath to next map method
                    return absolutePath;
                });
            })
            .map((fileEntry: any) => {
                let results = [];
                results.push({
                    fileEntry,
                    mimeType: 'image/jpeg'
                });
                return results;
            })
            .catch(this.ExceptionService.observableCatcher('error'));
}
</code>```

from the promise, I can get a contentURI, and I need to call the this.$window.FilePath.resolveNativePath method which is using the call-back . and it should return the absolute path to next map method.

How can I link up the call-back method between returning promise and parsing map method?

答:
You can use bindCallback to create an observable for the callback:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/bindCallback';

...
.map((contentURI: string) => {
  const bound = Observable.bindCallback((
    path: string,
    callback: (result: string) => void
  ) => this.$window.FilePath.resolveNativePath(path, callback));
  return bound(contentURI);
})
...
```

I've used an arrow function so that argument types are explicit and so that resolveNativePath is called on this.$window.FilePath.

I've not used Function.prototype.bind, as it returns any and really messes with TypeScript's inferring of the types for the bindCallback function.

The above answer uses RxJS 5. However, the additional information that you've added to your question shows that you are using version 4. In that version, the function is named fromCallback.

Body:
I need to link up a call-back method to the Observable chain.

private testMethod(): Rx.Observable<any> {
        const deferred = this.$q.defer();
        let promise = deferred.promise;

        this.$window.fileChooser.open((results: any) => {
            deferred.resolve(results);
        }, (error: any) => {
            this.Logger.log(error);
        });

        return this.rx.Observable.fromPromise(promise)
            .map((contentURI: string) => {
                // need to link call-back method
                this.$window.FilePath.resolveNativePath(contentURI, (absolutePath: any) => {
                    // need to pass absolutePath to next map method
                    return absolutePath;
                });
            })
            .map((fileEntry: any) => {
                let results = [];
                results.push({
                    fileEntry,
                    mimeType: 'image/jpeg'
                });
                return results;
            })
            .catch(this.ExceptionService.observableCatcher('error'));
}

from the promise, I can get a contentURI, and I need to call the this.$window.FilePath.resolveNativePath method which is using the call-back . and it should return the absolute path to next map method.

How can I link up the call-back method between returning promise and parsing map method?

Body:
You can use bindCallback to create an observable for the callback:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/bindCallback';

...
.map((contentURI: string) => {
  const bound = Observable.bindCallback((
    path: string,
    callback: (result: string) => void
  ) => this.$window.FilePath.resolveNativePath(path, callback));
  return bound(contentURI);
})
...

I've used an arrow function so that argument types are explicit and so that resolveNativePath is called on this.$window.FilePath.

I've not used Function.prototype.bind, as it returns any and really messes with TypeScript's inferring of the types for the bindCallback function.

The above answer uses RxJS 5. However, the additional information that you've added to your question shows that you are using version 4. In that version, the function is named fromCallback.


问:
Ajax Form doesn't remain on page
Been beating my mind at this but its now time for me to ask for help (ask i got work tomorrow and dont want to be on this all night)

My form is inside a modal and this is my script

```<code>$(function() {
    $("#applyForm").on('submit' , function(e) {
        $.ajax({
            type: 'POST',
            url: $("#applyForm").attr("action"),
            data: $('#applyForm').serialize(),
            success: function(data){
              alert('successfully submitted')},
            error: function(data){
              alert('something went wrong')
          }

     });
});
});
</code>```

It all works, It fires up the script and submits to the backend with a success message but as soon as you close the popup sucess message it redirects to the action "apply-now" page.

How can i prevent this without it breaking the submit, As i've tried return false and preventDefault.

Heres the form

```<code><form action="/apply-now/" enctype="multipart/form-data" id="applyForm" method="post" name="applyForm" class="form">
<input name="is_data_submitted" type="hidden" value="1">
<input name="listing_id" type="hidden" value="{$listing_id}">

MY FORM DATA

<button type="submit" id="submit" class="btn btn-warning">Apply now</button>
</code>```

Any help would really be appreciated !

Thanks

J

答:
I Hope this work.

```<code>1) <button type="submit" id="submit" class="btn btn-warning">
   Apply  now</button> with preventDefault method
2) button type="button" id="submit" class="btn btn-warning">Apply now</button>
   change the type="submit" to type="button"
</code>```

Example

```<code><form action="/apply-now/" enctype="multipart/form-data" id="applyForm" method="post" name="applyForm" class="form">
<input name="is_data_submitted" type="text" value="1">
<input name="listing_id" type="text" value="999">
 MY FORM DATA
 <button type="button" id="submit" class="btn btn-warning">Apply now</button>
 </form>

$(document).ready(function(){
$("#applyForm").on('click','#submit' , function() {
alert("Click check")
console.log($('#applyForm').serialize())
});
});
</code>```

Title: Ajax Form doesn't remain on page

Body:
Been beating my mind at this but its now time for me to ask for help (ask i got work tomorrow and dont want to be on this all night)

My form is inside a modal and this is my script

$(function() {
    $("#applyForm").on('submit' , function(e) {
        $.ajax({
            type: 'POST',
            url: $("#applyForm").attr("action"),
            data: $('#applyForm').serialize(),
            success: function(data){
              alert('successfully submitted')},
            error: function(data){
              alert('something went wrong')
          }

     });
});
});

It all works, It fires up the script and submits to the backend with a success message but as soon as you close the popup sucess message it redirects to the action "apply-now" page.

How can i prevent this without it breaking the submit, As i've tried return false and preventDefault.

Heres the form

<form action="/apply-now/" enctype="multipart/form-data" id="applyForm" method="post" name="applyForm" class="form">
<input name="is_data_submitted" type="hidden" value="1">
<input name="listing_id" type="hidden" value="{$listing_id}">

MY FORM DATA

<button type="submit" id="submit" class="btn btn-warning">Apply now</button>

Any help would really be appreciated !

Thanks

J

Body:
I Hope this work.

1) <button type="submit" id="submit" class="btn btn-warning">
   Apply  now</button> with preventDefault method
2) button type="button" id="submit" class="btn btn-warning">Apply now</button>
   change the type="submit" to type="button"

Example

<form action="/apply-now/" enctype="multipart/form-data" id="applyForm" method="post" name="applyForm" class="form">
<input name="is_data_submitted" type="text" value="1">
<input name="listing_id" type="text" value="999">
 MY FORM DATA
 <button type="button" id="submit" class="btn btn-warning">Apply now</button>
 </form>

$(document).ready(function(){
$("#applyForm").on('click','#submit' , function() {
alert("Click check")
console.log($('#applyForm').serialize())
});
});


问:
Android 7.1 app shortcuts
I am using the static shortcuts as follows (part of the shortcut.xml).

```<code><shortcut
    android:shortcutId="Noraml"
    android:enabled="true"
    android:icon="@drawable/ic_t_voice_list"
    android:shortcutShortLabel="@string/sp_audio_effect_PrDdefault"
    android:shortcutLongLabel="@string/sp_audio_effect_PrDdefault">
    <intent
        android:action="com.app.shortcuts.IVRService"
        android:targetPackage="com.app.shortcuts"
        android:targetClass="com.app.shortcuts.AppService">
    </intent>
    <!-- If your shortcut is associated with multiple intents, include them
         here. The last intent in the list determines what the user sees when
         they launch this shortcut. -->
    <categories android:name="android.shortcut.conversation" />
</shortcut>
</code>```

And in manifest file as follows.

```<code><service
    android:name=".AppService"
    android:enabled="true" >
    <intent-filter>
        <action android:name="com.app.shortcuts.IVRService" />
        <action android:name="com.app.shortcuts.IVRRemoteService" />
    </intent-filter>
</service>
</code>```

But when I try to launch the app through shortcut, I am getting the "app is not installed" toast.

Are shortcuts only for activities? Or can we apply for services in the background without launching the app?

答:
Shortcuts can only launch activities as per the documentation:

Shortcuts provide users with quick access to activities other than an app's main activity in the currently-active launcher.

They cannot launch services.

Title: Android 7.1 app shortcuts

Body:
I am using the static shortcuts as follows (part of the shortcut.xml).

<shortcut
    android:shortcutId="Noraml"
    android:enabled="true"
    android:icon="@drawable/ic_t_voice_list"
    android:shortcutShortLabel="@string/sp_audio_effect_PrDdefault"
    android:shortcutLongLabel="@string/sp_audio_effect_PrDdefault">
    <intent
        android:action="com.app.shortcuts.IVRService"
        android:targetPackage="com.app.shortcuts"
        android:targetClass="com.app.shortcuts.AppService">
    </intent>

    <categories android:name="android.shortcut.conversation" />
</shortcut>

And in manifest file as follows.

<service
    android:name=".AppService"
    android:enabled="true" >
    <intent-filter>
        <action android:name="com.app.shortcuts.IVRService" />
        <action android:name="com.app.shortcuts.IVRRemoteService" />
    </intent-filter>
</service>

But when I try to launch the app through shortcut, I am getting the "app is not installed" toast.

Are shortcuts only for activities? Or can we apply for services in the background without launching the app?


问:
What is the significance of trailing slashes in a namespace URI?
I have been studying SOAP and WSDL in preparation for implementing a web service.  One thing that I have encountered that puzzles me is that some of the URIs that I have seen use a trailing slash such as:

```<code>http://www.w3.org/some-namespace/
</code>```

while other examples that I have studied omit this trailing slash.  I really have several questions regarding this:

What is the significance of the trailing slash?

Is the URI, http://www.w3.org/some-namespace the same as http://www.w3.org/some-namespace/?

If they are not the same, how do I decide when one form is warranted versus another?

I have read the guidelines given by w3c regarding URI's and these appear to indicate that that URI should be considered equal only if the case-sensitive comparison of the URI strings are considered equal.  Is this interpretation correct?

答:
Yes, the w3c guidelines regarding URI's you have read are correct.

The two namespaces having not equal-strings-uri's are different namespaces. Even capitalization and white-space matters.

A namespace-uri does not mean that issuing a request for it should produce a web-response. Therefore, any reasoning whether it should or shouldn't end with "/" is not too meaningful.

In fact, a namespace-uri may even not satisfy the syntax rules for an URI and it will still serve its purpose for defining a namespace. It is perfectly useful to use a namespace such as, let's say:

"\/^%$#sdhfgds"

as long as it is unique (do note that in no way I am recommending such use :)  ). Existing XML processors (such as parsers, XPath or XSLT processors) do not raise any errors when they encounter such namespace.

OwnerDisplayName: Jon Trauntvein

Body:
I have been studying SOAP and WSDL in preparation for implementing a web service.  One thing that I have encountered that puzzles me is that some of the URIs that I have seen use a trailing slash such as:

http://www.w3.org/some-namespace/

while other examples that I have studied omit this trailing slash.  I really have several questions regarding this:

What is the significance of the trailing slash?

Is the URI, http://www.w3.org/some-namespace the same as http://www.w3.org/some-namespace/?

If they are not the same, how do I decide when one form is warranted versus another?

I have read the guidelines given by w3c regarding URI's and these appear to indicate that that URI should be considered equal only if the case-sensitive comparison of the URI strings are considered equal.  Is this interpretation correct?

OwnerDisplayName: Dimitre Novatchev

LastEditorDisplayName: Dimitre Novatchev


问:
How to build a light meter program?
Given a live captured image (say, on an iPhone), how to calculate the require exposure time value programmatically based on the apertures, ISOs? Thanks!</p>

答:
The amount of captured light is proportional to shutterspeed*ISO/aperture.

So if, for instance, your iPhone has choosen f2.8, 1/60s ISO 800, and your camera has the constraints of f4 and ISO 100, the needed shutter speed would be 1/60s*800/2.8*4/100 ≈ 1/5s.

Title: How to build a light meter program?


问:
(C) When calling function, store multiple values in array
So, when calling a function I wish to put two values in, then those two values to be saved in an array in the function argument.

i.e

```<code>function(1,2); (calling the function)

void function(int x[2]); (declaration of function)
</code>```

with x[0] and x[1] being the two arguments when calling the function (i.e the 1 and 2).

Any help would be appreciated.

答:
Maybe Variable-length argument is what you want :

```<code>void function(int i, ...) {
    int tmp;
    va_list num_list;

    va_start(num_list, i);

    for(int j = 0; j < i; j++)
        cout << va_arg(num_list, int) << endl;

    va_end(num_list);
}
</code>```

the first 'i' is tell the function how much argument you input.
using this like:

```<code>function(2,3,4); // pass 2 argument, 3 and 4
</code>```

Body:
So, when calling a function I wish to put two values in, then those two values to be saved in an array in the function argument.

i.e

function(1,2); (calling the function)

void function(int x[2]); (declaration of function)

with x[0] and x[1] being the two arguments when calling the function (i.e the 1 and 2).

Any help would be appreciated.

Body:
Maybe Variable-length argument is what you want :

void function(int i, ...) {
    int tmp;
    va_list num_list;

    va_start(num_list, i);

    for(int j = 0; j < i; j++)
        cout << va_arg(num_list, int) << endl;

    va_end(num_list);
}

the first 'i' is tell the function how much argument you input.
using this like:

function(2,3,4); // pass 2 argument, 3 and 4


问:
Reshape numpy array and stacking into 3D at regular intervals
I have some time ordered images stored as a numpy 2D array with the shape (60000, 784). I would like to ultimately reshape the data to (1200, 28, 28, 50). What I am trying to do is orient subsequent stacks the 50 28x28 images on top of one another where the top image is the earliest in time.

I think the following code is getting me started, but this returns a list of 1200 images of shape (50, 28, 28). I would like an numpy array that is of shape (1200, 28, 28, 50).

```<code>import numpy as np

X = np.ones((60000, 784))
X = X.reshape(X.shape[0], 28, 28)

X_new = []
prev = 0
for i in range(50, len(X)+50, 50):
    X_new.append(np.dstack( [X[prev:i]] ))
    prev += i

#print type(X_new)     # 'list'
#print len(X_new)      # 1200
#print X_new[0].shape  # (50, 28, 28)
</code>```

答:
You should be able to reshape the initial array and keep the images in order. For example:

```<code># Get an array of length 60000, where each element is 784 numbers ranging from 1 to 60000 (so we can keep track)
X = np.outer(np.arange(1,60001,1),np.ones(784))

Y = X.reshape(1200, 28, 28, 50)
</code>```

Checking:

```<code>Y[0] = [ 28x28 array of 1's, 28x28 array of 2's, ..., 28x28 array of 50's]
Y[1] = [ 28x28 array of 51's, 28x28 array of 52's, ..., 28x28 array of 100's]
Y[2] = [ 28x28 array of 101's, 28x28 array of 102's, ..., 28x28 array of 150's]
</code>```

So you can see the images are stacked in groups of 50 that are in the correct order.

Edit:

Thanks to comments, it should actually be:

```<code>Y = X.reshape(1200, 50, 28, 28)
</code>```

To check this works:

```<code>X = np.outer(np.arange(1,60001,1),np.ones(784))
# Now let's change the first "image"
X[0] = np.arange(0,784,1)
Y = X.reshape(1200, 50, 28, 28)
</code>```

We expect the first image in Y to be a 28x28 array where the first row is 0-27, the second row is 28-55 and so on. This is what we get so a transpose is not necessary.

```<code>Y[0][0] = [[1,2,...,27],
           [28,29,...,55],
           ...
           [756,757,...,783]]
</code>```

Note: this is assuming the images are flattened row by row, i.e.

```<code>1 2 3
4 5 6   =>  1 2 3 4 5 6 7 8 9
7 8 9
</code>```

Body:
I have some time ordered images stored as a numpy 2D array with the shape (60000, 784). I would like to ultimately reshape the data to (1200, 28, 28, 50). What I am trying to do is orient subsequent stacks the 50 28x28 images on top of one another where the top image is the earliest in time.

I think the following code is getting me started, but this returns a list of 1200 images of shape (50, 28, 28). I would like an numpy array that is of shape (1200, 28, 28, 50).

import numpy as np

X = np.ones((60000, 784))
X = X.reshape(X.shape[0], 28, 28)

X_new = []
prev = 0
for i in range(50, len(X)+50, 50):
    X_new.append(np.dstack( [X[prev:i]] ))
    prev += i

#print type(X_new)     # 'list'
#print len(X_new)      # 1200
#print X_new[0].shape  # (50, 28, 28)

Body:
You should be able to reshape the initial array and keep the images in order. For example:

# Get an array of length 60000, where each element is 784 numbers ranging from 1 to 60000 (so we can keep track)
X = np.outer(np.arange(1,60001,1),np.ones(784))

Y = X.reshape(1200, 28, 28, 50)

Checking:

Y[0] = [ 28x28 array of 1's, 28x28 array of 2's, ..., 28x28 array of 50's]
Y[1] = [ 28x28 array of 51's, 28x28 array of 52's, ..., 28x28 array of 100's]
Y[2] = [ 28x28 array of 101's, 28x28 array of 102's, ..., 28x28 array of 150's]

So you can see the images are stacked in groups of 50 that are in the correct order.

Edit:

Thanks to comments, it should actually be:

Y = X.reshape(1200, 50, 28, 28)

To check this works:

X = np.outer(np.arange(1,60001,1),np.ones(784))
# Now let's change the first "image"
X[0] = np.arange(0,784,1)
Y = X.reshape(1200, 50, 28, 28)

We expect the first image in Y to be a 28x28 array where the first row is 0-27, the second row is 28-55 and so on. This is what we get so a transpose is not necessary.

Y[0][0] = [[1,2,...,27],
           [28,29,...,55],
           ...
           [756,757,...,783]]

Note: this is assuming the images are flattened row by row, i.e.

1 2 3
4 5 6   =>  1 2 3 4 5 6 7 8 9
7 8 9


问:
How to deploy a maven project that contain ejb,war and ear in ibm bluemix
i create a maven project that include EAR,WAR and EJB  and i waont to deploy it to ibm bluemix . i tested pulling  project from  https://www.hub.jazz.com and that project doesn't contain any EJB project .

So any one have a way to how to deploy a maven project that contain EJB,EAR and WAR to ibm bluemix .

答:
If you are using Cloud Foundry CLI,deploying War & Ear are using the same command in Bluemix.

```<code>cf push <your-app-name> -p <path/to/your/ear/yourapp.ear>
</code>```

Body:
If you are using Cloud Foundry CLI,deploying War & Ear are using the same command in Bluemix.

cf push <your-app-name> -p <path/to/your/ear/yourapp.ear>


问:
Could not load file or assembly 'Data' or one of its dependencies. Access is denied
I am trying to run the my asp.net mvc project on IIS 7 , I am trying to impersonate the user. Where Data is the data project of my application, i have added the dll reference to the asp.net mvc project

I tried giving full control to very one to this folder

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET File.

Any clue on how to fix this error?

答: Try running aspnet_regiis exe in the framework folder. With the -ga option, that will grant the impersonation user all the relevant permissions.</p>


问:
SQL how can I get latest row if a specific condition is matched
I am new to SQL but what I am trying to do is a comment reply feature . For instance lets say you have a profile_id of 11 and you commented a post with a post_id of 339 . If several other people commented on that post then I want to show you the latest comment on that post since you commented on it. Look at the first image below that is the table as you can see user 11 posted in the middle . I would like to get the last comment on that post that states blah blah since user 11 comments on it.

This is the table

 If I am user 11 I want to only see the latest comment posted on the same thread/post that I commented on . Which means that I want to see the post that says "Blah Blah" below however I am only getting my comment . Any suggestions would be great. I am using Postgres 9.6

答:
Next query will resolve your question:</p>

```<code>select cr.id, cr.stream_id, cr.comments
from comment_replies cr
where
cr.id in ( select cr2.id
           from comment_replies cr2
           where
           cr2.last_reply_timestamp = (select  max(cr3.last_reply_timestamp)
                                       from comment_replies cr3
                                       where cr3.stream_id=cr2.stream_id
                                      )
           and cr2.stream_id=cr.stream_id
        )
and cr.stream_id in (select cr2.stream_id
                     from comment_replies cr2
                     where cr2.profile_id=11)
</code>```

Body:
Next query will resolve your question:

select cr.id, cr.stream_id, cr.comments
from comment_replies cr
where
cr.id in ( select cr2.id
           from comment_replies cr2
           where
           cr2.last_reply_timestamp = (select  max(cr3.last_reply_timestamp)
                                       from comment_replies cr3
                                       where cr3.stream_id=cr2.stream_id
                                      )
           and cr2.stream_id=cr.stream_id
        )
and cr.stream_id in (select cr2.stream_id
                     from comment_replies cr2
                     where cr2.profile_id=11)


问:
Using a method return in a string in ruby
I can't figure out how to put the return of a method into a string. I had thought it would look like this,

```<code>def cat
 puts "Purrrrr..."
end

puts "The cat says #{cat}."
</code>```

but this is not working. I also tried

```<code>puts "The cat says %s." % cat
</code>```

and

```<code>puts "The cat says #{return.cat}."
</code>```

also

```<code>puts "The cat says #{send.cat}."
</code>```

I kept trying stuff and looking things up.

答:
In ruby you don't have to return a value explicitly. Last line result in a method will be returned by default.

In this case, the return value of 'puts' method is nil. So the return value of method 'cat' is nil.

If you are looking for a return string, you can just put a string at the last line of the method 'cat' as @Arup suggested. That will work.

Body:
I can't figure out how to put the return of a method into a string. I had thought it would look like this,

def cat
 puts "Purrrrr..."
end

puts "The cat says #{cat}."

but this is not working. I also tried

puts "The cat says %s." % cat

and

puts "The cat says #{return.cat}."

also

puts "The cat says #{send.cat}."

I kept trying stuff and looking things up.


问:
c++ - passing value between classes
I have 2 classes, Qtree and Qnode:

```<code>//QuadTree.hpp:
#include <stdio.h>
#include <iostream>
#include <SFML/Graphics.hpp>

class QNode;

class QTree{
public:
    int depth;
    sf::Vector2f bound;

    QTree();

    void setRoot(QNode q);
};

class QNode{
public:
    bool isLeaf = false;
    int layer = 0;
    sf::Vector2f position;
    sf::Vector2f bound;
};
</code>```

and

```<code>//Quadtree.cpp:
#include "QuadTree.hpp"

QTree::QTree(){
    bound = sf::Vector2f(100,200);
}

void QTree::setRoot(QNode q){
    q.bound = bound;
}
</code>```

then in main.cpp:

```<code>#include <iostream>
#include <SFML/Graphics.hpp>
#include "QuadTree.hpp"

using namespace std;

int main(){
    QTree qt;
    QNode q;

    qt.setRoot(q);

    cout << q.bound.x <<endl;

}
</code>```

and the cout result is 0. I am expecting it to be 100.
I am c++ beginner and did read a lot related to this from google. However still not sure how to get this to work.

How can I resolve this?

答:
You need to change setRoot() so it gets the argument by reference.

```<code>void QTree::setRoot(QNode &q){
    q.bound = bound;
}
</code>```

Your code is passing by value, so setRoot() modifies a copy of q.

Title: c++ - passing value between classes

Body:
I have 2 classes, Qtree and Qnode:

//QuadTree.hpp:
#include <stdio.h>
#include <iostream>
#include <SFML/Graphics.hpp>

class QNode;

class QTree{
public:
    int depth;
    sf::Vector2f bound;

    QTree();

    void setRoot(QNode q);
};

class QNode{
public:
    bool isLeaf = false;
    int layer = 0;
    sf::Vector2f position;
    sf::Vector2f bound;
};

and

//Quadtree.cpp:
#include "QuadTree.hpp"

QTree::QTree(){
    bound = sf::Vector2f(100,200);
}

void QTree::setRoot(QNode q){
    q.bound = bound;
}

then in main.cpp:

#include <iostream>
#include <SFML/Graphics.hpp>
#include "QuadTree.hpp"

using namespace std;

int main(){
    QTree qt;
    QNode q;

    qt.setRoot(q);

    cout << q.bound.x <<endl;

}

and the cout result is 0. I am expecting it to be 100.
I am c++ beginner and did read a lot related to this from google. However still not sure how to get this to work.

How can I resolve this?

Body:
You need to change setRoot() so it gets the argument by reference.

void QTree::setRoot(QNode &q){
    q.bound = bound;
}

Your code is passing by value, so setRoot() modifies a copy of q.


问:
How to draw a circle with text in the middle?
I found this example on stackoverflow:

Draw Circle using css alone

Which is great.  But I'd like to know how to modify that example so that I can include text in the middle of the circle?

I also found this:  Vertically and horizontally centering text in circle in CSS (like iphone notification badge)

but for some reason, its not working for me.  When I create the following test code:

```<code><div class="badge">1</div>
</code>```

instead of a circle, I get a oval shape.
I'm trying to play around with the code to see how I can get it to work.

答:
.circle {
  width: 500px;
  height: 500px;
  border-radius: 50%;
  font-size: 50px;
  color: #fff;
  line-height: 500px;
  text-align: center;
  background: #000
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="circle">Hello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A Circle</div></code>```

ContentLicense: CC BY-SA 4.0

Body:
I found this example on stackoverflow:

Draw Circle using css alone

Which is great.  But I'd like to know how to modify that example so that I can include text in the middle of the circle?

I also found this:  Vertically and horizontally centering text in circle in CSS (like iphone notification badge)

but for some reason, its not working for me.  When I create the following test code:

1

instead of a circle, I get a oval shape.
I'm trying to play around with the code to see how I can get it to work.

Body:
.circle {
  width: 500px;
  height: 500px;
  border-radius: 50%;
  font-size: 50px;
  color: #fff;
  line-height: 500px;
  text-align: center;
  background: #000
}

<div class="circle">Hello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A CircleHello I am A Circle</div>


问:
Split string at every Nth occurrence of character
I need to split a string like the following after every fourth pipe -

Input -

userid456|userid457|userid458|userid459|userid460|userid461|userid462|userid463|userid464|userid465|userid466|userid467|userid468|userid469|userid470|userid471|userid472|userid473|userid474|userid475|userid476|userid477|userid478|userid479|userid480|userid481|userid482|userid483

Output -

```<code>userid456|userid457|userid458|userid459

userid460|userid461|userid462|userid463

userid464|userid465|userid466|userid467

userid468|userid469|userid470|userid471
</code>```

etc.

Was trying to figure out if there is an easy way using regexp and String.split()

答:
The closest I could come up with is this:

```<code>String[] parts = input.split("(?<=\\G(\\w{1,11}\\|){4}+)");
</code>```

This has two issues:

you must specify a max number of characters between the | chars

It will include the | at the end of each part

The output looks like:

```<code>userid456|userid457|userid458|userid459|
userid460|userid461|userid462|userid463|
userid464|userid465|userid466|userid467|
userid468|userid469|userid470|userid471|
userid472|userid473|userid474|userid475|
userid476|userid477|userid478|userid479|
userid480|userid481|userid482|userid483
</code>```

Body:
I need to split a string like the following after every fourth pipe -

Input -

userid456|userid457|userid458|userid459|userid460|userid461|userid462|userid463|userid464|userid465|userid466|userid467|userid468|userid469|userid470|userid471|userid472|userid473|userid474|userid475|userid476|userid477|userid478|userid479|userid480|userid481|userid482|userid483

Output -

userid456|userid457|userid458|userid459

userid460|userid461|userid462|userid463

userid464|userid465|userid466|userid467

userid468|userid469|userid470|userid471

etc.

Was trying to figure out if there is an easy way using regexp and String.split()

Body:
The closest I could come up with is this:

String[] parts = input.split("(?<=\\G(\\w{1,11}\\|){4}+)");

This has two issues:

you must specify a max number of characters between the | chars

It will include the | at the end of each part

The output looks like:

userid456|userid457|userid458|userid459|
userid460|userid461|userid462|userid463|
userid464|userid465|userid466|userid467|
userid468|userid469|userid470|userid471|
userid472|userid473|userid474|userid475|
userid476|userid477|userid478|userid479|
userid480|userid481|userid482|userid483


问:
DataGridView - "Cell Selection Style" - Edit Cell
I'm working on a WinForm client with a DataGridView control. I notice users have to click once to select the cell and again to edit it. What is the way to change this to a single click edit mode? I thought I had seen something like this before but can't remember the name.</p>

答:
Well I have noticed a problem with EditMode.EditOnEnter

It biases a lot of DataGriView's default behavior, which is irritating.
Among others, the edited cell stays in edited mode even when the EndEdit method is explicitly called (you are force to click on another control to make the datagridview cell lose its focus.)

The following piece of code works pretty fine as it makes you edit by single clicking on any cell and ending the edit by hitting enter or clicking outside the DGView (just as you would do in the default behavior)

Here you go :

```<code>    private void myDatagridView_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            hitTestInfo = myDatagridView.HitTest(e.X, e.Y);
            if (hitTestInfo.Type == DataGridViewHitTestType.Cell)
                myDatagridView.BeginEdit(true);
            else
                myDatagridView.EndEdit();
        }
    }
</code>```

Body:
Well I have noticed a problem with EditMode.EditOnEnter

It biases a lot of DataGriView's default behavior, which is irritating.
Among others, the edited cell stays in edited mode even when the EndEdit method is explicitly called (you are force to click on another control to make the datagridview cell lose its focus.)

The following piece of code works pretty fine as it makes you edit by single clicking on any cell and ending the edit by hitting enter or clicking outside the DGView (just as you would do in the default behavior)

Here you go :

    private void myDatagridView_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            hitTestInfo = myDatagridView.HitTest(e.X, e.Y);
            if (hitTestInfo.Type == DataGridViewHitTestType.Cell)
                myDatagridView.BeginEdit(true);
            else
                myDatagridView.EndEdit();
        }
    }


问:
JSF java.lang.IllegalArgumentException: can't parse argument number
can someone help me figure out the problem i'm new on JSF. whenever i load my page and submit my form i get this error :
here is my code :

```<code>@ManagedBean
@ApplicationScoped
public class CommandeController extends JSFActions {

    final  static Logger LOGGER = LoggerFactory.getLogger( CommandeController.class );

    @ManagedProperty( value = "#{commandeBean}")
    private CommandeBean commandeBean;
    @ManagedProperty( value = "#{clientBean}")
    private ClientBean clientBean;
    @ManagedProperty( value = "#{etablissementBean}")
    private EtablissementBean etablissementBean;
    @ManagedProperty( value = "#{commandeFacade}")
    private ICommandeFacade commandeFacade;
</code>```

and my xhtml file look like

```<code><h:outputText value="#{lbl.postRef}"  />

<p:selectOneMenu value="#{commandeBean.idPoste}">
<f:selectItem itemLabel="Choisissez le poste" itemValue="-1"/>
    <f:selectItems value="#{jFActions.postes.entrySet()}" var="post"
        itemValue="#{post.key}" itemLabel="#{post.value}"/>
</p:selectOneMenu>

<h:outputText value="#{lbl.langUse}"  />

<p:selectOneMenu value="#{commandeBean.langUtilise}">
   <f:selectItem itemLabel="Choisissez la langue" itemValue="-1"/>
   <f:selectItem  itemValue="ar" itemLabel="Arabe"/>
   <f:selectItem  itemValue="en" itemLabel="Enlish"/>
   <f:selectItem  itemValue="fr" itemLabel="Frensh"/>
</p:selectOneMenu>

<h:outputText value="#{lbl.nbJ}"  />

<p:inputText id="txtNbrJour" value="#{commandeBean.nbJour}" converterMessage="#{msg.nbrInvalid}" >
    <f:convertNumber type="number" integerOnly="true" />
</p:inputText>

<h:outputText value="#{lbl.nbjMax}" />
<p:inputText id="txtNJAut" value="#{etablissementBean.nbJourAutorise}"  readonly="true" />
</code>```

```<code>ATTENTION: Erreur inattendue lors du traitement du bean géré «commandeController»
com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement du bean géré «commandeController»
    at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:398)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:262)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:94)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:259)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement de la propriété gérée «commandeBean»
    at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:117)
    at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:353)
    ... 35 more
Caused by: java.lang.IllegalArgumentException: can't parse argument number commandeBean
    at java.text.MessageFormat.makeFormat(MessageFormat.java:1339)
    at java.text.MessageFormat.applyPattern(MessageFormat.java:458)
    at java.text.MessageFormat.<init>(MessageFormat.java:350)
    at java.text.MessageFormat.format(MessageFormat.java:811)
    at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:398)
    at com.sun.faces.mgbean.BeanBuilder$Expression.validateLifespan(BeanBuilder.java:574)
    at com.sun.faces.mgbean.BeanBuilder$Expression.<init>(BeanBuilder.java:523)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:363)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
    ... 36 more
18 févr. 2014 10:48:37 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/sgrp-web] threw exception [Erreur inattendue lors du traitement du bean géré «commandeController»] with root cause
java.lang.IllegalArgumentException: can't parse argument number commandeBean
    at java.text.MessageFormat.makeFormat(MessageFormat.java:1339)
    at java.text.MessageFormat.applyPattern(MessageFormat.java:458)
    at java.text.MessageFormat.<init>(MessageFormat.java:350)
    at java.text.MessageFormat.format(MessageFormat.java:811)
    at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:398)
    at com.sun.faces.mgbean.BeanBuilder$Expression.validateLifespan(BeanBuilder.java:574)
    at com.sun.faces.mgbean.BeanBuilder$Expression.<init>(BeanBuilder.java:523)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:363)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
    at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:353)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:262)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:94)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:259)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at
</code>```

any help ??

答:
In my case it was happening because I was logging the JSON {"":{}} output and that why system generating this exception. JSON was treating like a string in LogDebug method.

Use vlogDebug("my log {0}",jsonObject). It will work as it is now in argument {0}.

Body:
can someone help me figure out the problem i'm new on JSF. whenever i load my page and submit my form i get this error :
here is my code :

@ManagedBean
@ApplicationScoped
public class CommandeController extends JSFActions {

    final  static Logger LOGGER = LoggerFactory.getLogger( CommandeController.class );

    @ManagedProperty( value = "#{commandeBean}")
    private CommandeBean commandeBean;
    @ManagedProperty( value = "#{clientBean}")
    private ClientBean clientBean;
    @ManagedProperty( value = "#{etablissementBean}")
    private EtablissementBean etablissementBean;
    @ManagedProperty( value = "#{commandeFacade}")
    private ICommandeFacade commandeFacade;

and my xhtml file look like

<h:outputText value="#{lbl.postRef}"  />

<f:selectItem itemLabel="Choisissez le poste" itemValue="-1"/>
    <f:selectItems value="#{jFActions.postes.entrySet()}" var="post"
        itemValue="#{post.key}" itemLabel="#{post.value}"/>

<h:outputText value="#{lbl.langUse}"  />

   <f:selectItem itemLabel="Choisissez la langue" itemValue="-1"/>
   <f:selectItem  itemValue="ar" itemLabel="Arabe"/>
   <f:selectItem  itemValue="en" itemLabel="Enlish"/>
   <f:selectItem  itemValue="fr" itemLabel="Frensh"/>

<h:outputText value="#{lbl.nbJ}"  />

    <f:convertNumber type="number" integerOnly="true" />

<h:outputText value="#{lbl.nbjMax}" />

ATTENTION: Erreur inattendue lors du traitement du bean géré «commandeController»
com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement du bean géré «commandeController»
    at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:398)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:262)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:94)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:259)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement de la propriété gérée «commandeBean»
    at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:117)
    at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:353)
    ... 35 more
Caused by: java.lang.IllegalArgumentException: can't parse argument number commandeBean
    at java.text.MessageFormat.makeFormat(MessageFormat.java:1339)
    at java.text.MessageFormat.applyPattern(MessageFormat.java:458)
    at java.text.MessageFormat.<init>(MessageFormat.java:350)
    at java.text.MessageFormat.format(MessageFormat.java:811)
    at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:398)
    at com.sun.faces.mgbean.BeanBuilder$Expression.validateLifespan(BeanBuilder.java:574)
    at com.sun.faces.mgbean.BeanBuilder$Expression.<init>(BeanBuilder.java:523)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:363)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
    ... 36 more
18 févr. 2014 10:48:37 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/sgrp-web] threw exception [Erreur inattendue lors du traitement du bean géré «commandeController»] with root cause
java.lang.IllegalArgumentException: can't parse argument number commandeBean
    at java.text.MessageFormat.makeFormat(MessageFormat.java:1339)
    at java.text.MessageFormat.applyPattern(MessageFormat.java:458)
    at java.text.MessageFormat.<init>(MessageFormat.java:350)
    at java.text.MessageFormat.format(MessageFormat.java:811)
    at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:398)
    at com.sun.faces.mgbean.BeanBuilder$Expression.validateLifespan(BeanBuilder.java:574)
    at com.sun.faces.mgbean.BeanBuilder$Expression.<init>(BeanBuilder.java:523)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:363)
    at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
    at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:353)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:262)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:94)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:259)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at

any help ??


问:
C#: Method Invocation Details
I have a website developed using C#. I want to see the caller of a method i.e, which method/event handler calls my method.

Suppose there is a button click. I would like to see it as follows

```<code>btnClick  BusinessLayerClass.SaveDocs(int docID, string docType) DataAccessLayerClass.Update()

btnClick  BusinessLayerClass.SaveDocs(int docID, string docType) DataAccessLayerClass.Increase()
</code>```

Is it possible to see such a stack information? Please advise..

Note: All projects are added as dlls. There is no services like WCF.

答:
System.Environment.StackTrace  can be used </p>

```<code>private void button1_Click(object sender, EventArgs e)
    {
                StackTrace st = new StackTrace(true);
        StackFrame[] fram = st.GetFrames();

        foreach (StackFrame sf in fram)
        {
            sf.GetFileColumnNumber();
            sf.GetFileLineNumber();
            sf.GetFileName();
            sf.GetILOffset();
            sf.GetMethod();

        }
    }
</code>```

Title: C#: Method Invocation Details

Body:
I have a website developed using C#. I want to see the caller of a method i.e, which method/event handler calls my method.

Suppose there is a button click. I would like to see it as follows

btnClick  BusinessLayerClass.SaveDocs(int docID, string docType) DataAccessLayerClass.Update()

btnClick  BusinessLayerClass.SaveDocs(int docID, string docType) DataAccessLayerClass.Increase()

Is it possible to see such a stack information? Please advise..

Note: All projects are added as dlls. There is no services like WCF.

Body:
System.Environment.StackTrace  can be used

private void button1_Click(object sender, EventArgs e)
    {
                StackTrace st = new StackTrace(true);
        StackFrame[] fram = st.GetFrames();

        foreach (StackFrame sf in fram)
        {
            sf.GetFileColumnNumber();
            sf.GetFileLineNumber();
            sf.GetFileName();
            sf.GetILOffset();
            sf.GetMethod();

        }
    }


问:
How can I perfectly center my image?
So I have an image on my website and I want to perfectly center it. I have tried many things but none have worked.

body{
background-color: black;
}

img {
  position: absolute;
  margin-top: 10%;
  text-align: center;
  height: 40%;
  z-index: -5
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><img src="images/astronaut.png"></code>```

答:
Like this?

body{
background-color: black;
}

img {
  position: absolute;
  margin-top: 10%;
  text-align: center;
  height: 40%;
  z-index: -5;
  left: 50%;
  top:50%;
  transform: translate(-50%, -50%);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><img src="images/astronaut.png"></code>```

The centering codes are the left, top, and especially the transform

Title: How can I perfectly center my image?

Body:
Like this?

body{
background-color: black;
}

img {
  position: absolute;
  margin-top: 10%;
  text-align: center;
  height: 40%;
  z-index: -5;
  left: 50%;
  top:50%;
  transform: translate(-50%, -50%);
}

<img src="images/astronaut.png">

The centering codes are the left, top, and especially the transform


问:
What is the best way to top k pool elements instead of only the max one in Tensorflow?
Now the max pooling function in tensorflow is

```
tf.nn.max_pool(value, ksize, strides, padding, name=None)
Returns:
A Tensor with type tf.float32. The max pooled output tensor.
```

I would like to have an extend version of max_pool, like

```
tf.nn.top_k_pool(value, ksize, strides, padding, k=1, name=None)

Performs the top k pooling on the input.

Args:

value: A 4-D Tensor with shape [batch, height, width, channels] and type tf.float32.
ksize: A list of ints that has length >= 4. The size of the window for each dimension of the input tensor.
strides: A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.
padding: A string, either 'VALID' or 'SAME'. The padding algorithm.
k: 0-D int32 Tensor. Number of top elements to look in each pool.
name: Optional name for the operation.
Returns:

A Tensor with type tf.float32. The max pooled output tensor. There will be an additional dimension saving the top k values.
```

I know that I can expend the tensorflow operation following https://www.tensorflow.org/versions/r0.7/how_tos/adding_an_op/index.html

I would like to know if there is an easier way to achieve that.

答: usd tf.reshape(), tf.matrix_transpose(), tf.nn.top_k(sorted=False), and the 'data_format' argument in tf.nn.conv2d(), see http://www.infocool.net/kb/OtherCloud/201703/318346.html for details</p>

Body:
Now the max pooling function in tensorflow is

tf.nn.max_pool(value, ksize, strides, padding, name=None)
Returns:
A Tensor with type tf.float32. The max pooled output tensor.

I would like to have an extend version of max_pool, like

tf.nn.top_k_pool(value, ksize, strides, padding, k=1, name=None)

Performs the top k pooling on the input.

Args:

value: A 4-D Tensor with shape [batch, height, width, channels] and type tf.float32.
ksize: A list of ints that has length >= 4. The size of the window for each dimension of the input tensor.
strides: A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.
padding: A string, either 'VALID' or 'SAME'. The padding algorithm.
k: 0-D int32 Tensor. Number of top elements to look in each pool.
name: Optional name for the operation.
Returns:

A Tensor with type tf.float32. The max pooled output tensor. There will be an additional dimension saving the top k values.

I know that I can expend the tensorflow operation following https://www.tensorflow.org/versions/r0.7/how_tos/adding_an_op/index.html

I would like to know if there is an easier way to achieve that.


问:
How does CUDA assign device IDs to GPUs?
When a computer has multiple CUDA-capable GPUs, each GPU is assigned a device ID. By default, CUDA kernels execute on device ID 0. You can use cudaSetDevice(int device) to select a different device.

Let's say I have two GPUs in my machine: a GTX 480 and a GTX 670. How does CUDA decide which GPU is device ID 0 and which GPU is device ID 1?

Ideas for how CUDA might assign device IDs (just brainstorming):

descending order of compute capability

PCI slot number

date/time when the device was added to system (device that was just added to computer is higher ID number)

Motivation: I'm working on some HPC algorithms, and I'm benchmarking and autotuning them for several GPUs. My processor has enough PCIe lanes to drive cudaMemcpys to 3 GPUs at full bandwidth. So, instead of constantly swapping GPUs in and out of my machine, I'm planning to just keep 3 GPUs in my computer. I'd like to be able to predict what will happen when I add or replace some GPUs in the computer.

答:
Set the environment variable CUDA_DEVICE_ORDER as:

```<code>export CUDA_DEVICE_ORDER=PCI_BUS_ID
</code>```

Then the GPU IDs will be ordered by pci bus IDs.

Body:
Set the environment variable CUDA_DEVICE_ORDER as:

export CUDA_DEVICE_ORDER=PCI_BUS_ID

Then the GPU IDs will be ordered by pci bus IDs.


问:
How to create nestable object
At the begining I would like to say hello, so ... Hello. I need to create a nested object structure.
I've got an object (xaml page) like this

```<code><navigation:Page x:Class="ItemTemplateExample.ContentItem"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       mc:Ignorable="d"
       xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
       d:DesignWidth="200" d:DesignHeight="20"
       Title="ContentItem Page">
<Grid x:Name="LayoutRoot">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Button x:Name="button1" />
    <ContentControl  Grid.Column="1" x:Name="content1" />
</Grid>
</code>```

Now I would like to use it in nested structure. For Example

```<code><local:ContentItem ButtonText="level 1">
     <local:ContentItem ButtonText="level 2" />
     <local:ContentItem ButtonText="level 2" />
     <local:ContentItem ButtonText="level 2">
          <local:ContentItem ButtonText="level 3" />
     </local:ContentItem>
</local:ContentItem>
</code>```

Where ButtonText will be known value (set when adding nested object) and Content of each object will be object of the same type. I have no idea how to start. Please give me some hint, exmaples. Thank You.

答: Possibly related:Example of Nested Collections</p>

Title: How to create nestable object

Body:
At the begining I would like to say hello, so ... Hello. I need to create a nested object structure.
I've got an object (xaml page) like this

<navigation:Page x:Class="ItemTemplateExample.ContentItem"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       mc:Ignorable="d"
       xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
       d:DesignWidth="200" d:DesignHeight="20"
       Title="ContentItem Page">
<Grid x:Name="LayoutRoot">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Button x:Name="button1" />
    <ContentControl  Grid.Column="1" x:Name="content1" />
</Grid>

Now I would like to use it in nested structure. For Example

<local:ContentItem ButtonText="level 1">
     <local:ContentItem ButtonText="level 2" />
     <local:ContentItem ButtonText="level 2" />
     <local:ContentItem ButtonText="level 2">
          <local:ContentItem ButtonText="level 3" />
     </local:ContentItem>
</local:ContentItem>

Where ButtonText will be known value (set when adding nested object) and Content of each object will be object of the same type. I have no idea how to start. Please give me some hint, exmaples. Thank You.