问:
oracle update stored procedure with user defined exception
I am trying to create this stored procedure which should take customer no and email address as input. Then update the email address for that customer. if new email address is same as old then exception should be raised.

```<code>CREATE OR REPLACE PROCEDURE UpdateEmail
(CUSTOMERID IN CUSTOMER.CUSTOMERNO%TYPE,
 N_EMAIL IN CUSTOMER.EMAIL%TYPE)

IS
DECLARE
  e_same EXCEPTION;
  V_ROWCOUNT NUMBER;

BEGIN
SELECT COUNT(EMAIL)
INTO V_ROWCOUNT
FROM CUSTOMER@FIT5148B
WHERE CUSTOMER.EMAIL = N_EMAIL
AND CUSTOMER.CUSTOMERNO = CUSTOMERID;

IF V_ROWCOUNT > 0

THEN RAISE e_same;
ELSE
UPDATE CUSTOMER
SET EMAIL = N_EMAIL
WHERE CUSTOMER.CUSTOMERNO = CUSTOMERID;
END IF;

EXCEPTION
 WHEN e_same THEN dbms_output.put_line ('email address exist');
END;
/
</code>```

But it is throwing error. Not sure if I am doing it right. I am using the latest Oracle SQL Developer.

Error(6,1): PLS-00103: Encountered the symbol "DECLARE" when expecting
  one of the following:     begin function pragma procedure subtype type
       current
  cursor delete    exists prior external language The symbol "begin" was
  substituted for "DECLARE" to continue.

  Error(28,4): PLS-00103:
  Encountered the symbol "end-of-file" when expecting one of the
  following:     ( begin case declare end exception exit for goto if
  loop mod    null pragma raise return select update while with          << continue close current delete fetch lock    insert open
  rollback savepoint set sql execute commit forall    merge pipe purge

答:
Remove DECLARE .

You should not use Declare in a Procedure. If you are writing a PLSQL block then only you should use Declare. Not in an actual Procedure body.

Body:
I am trying to create this stored procedure which should take customer no and email address as input. Then update the email address for that customer. if new email address is same as old then exception should be raised.

CREATE OR REPLACE PROCEDURE UpdateEmail
(CUSTOMERID IN CUSTOMER.CUSTOMERNO%TYPE,
 N_EMAIL IN CUSTOMER.EMAIL%TYPE)

IS
DECLARE
  e_same EXCEPTION;
  V_ROWCOUNT NUMBER;

BEGIN
SELECT COUNT(EMAIL)
INTO V_ROWCOUNT
FROM CUSTOMER@FIT5148B
WHERE CUSTOMER.EMAIL = N_EMAIL
AND CUSTOMER.CUSTOMERNO = CUSTOMERID;

IF V_ROWCOUNT > 0

THEN RAISE e_same;
ELSE
UPDATE CUSTOMER
SET EMAIL = N_EMAIL
WHERE CUSTOMER.CUSTOMERNO = CUSTOMERID;
END IF;

EXCEPTION
 WHEN e_same THEN dbms_output.put_line ('email address exist');
END;
/

But it is throwing error. Not sure if I am doing it right. I am using the latest Oracle SQL Developer.

Error(6,1): PLS-00103: Encountered the symbol "DECLARE" when expecting
  one of the following:     begin function pragma procedure subtype type
       current
  cursor delete    exists prior external language The symbol "begin" was
  substituted for "DECLARE" to continue.

  Error(28,4): PLS-00103:
  Encountered the symbol "end-of-file" when expecting one of the
  following:     ( begin case declare end exception exit for goto if
  loop mod    null pragma raise return select update while with          << continue close current delete fetch lock    insert open
  rollback savepoint set sql execute commit forall    merge pipe purge


来源: stackexchange

问:
How to get a date and time in Hexidecimal in C
I need to get the current date and time using C. However, I need it to be in hexadecimal format. Is their a function that returns the timestamp in hex or do I have to get the date and time and convert it to HEX? If so, does anyone have an example for the conversion in C?</p>

答:
You can get a pointer to a tm structure with localtime(), and get the needed values from the fields. Then you can use sprintf() to build a time string:

```<code>#include <stdio.h>
#include <time.h>

int main(void)
{
    time_t raw_time = time(NULL);
    struct tm *curr = localtime(&raw_time);

    int year = curr->tm_year + 1900;
    int month = curr->tm_mon + 1;
    int day = curr->tm_mday;

    int hour = curr->tm_hour;
    int min = curr->tm_min;
    int sec = curr->tm_sec;

    char time_str[40];
    sprintf(time_str, "%#x/%#x/%#x %#x:%#x:%#x",
            year, month, day, hour, min, sec);

    puts("Hex timestamp:");
    puts(time_str);

    sprintf(time_str, "%d/%d/%d %d:%d:%d",
            year, month, day, hour, min, sec);

    putchar('\n');
    puts("Decimal timestamp:");
    puts(time_str);

    return 0;
}
</code>```

Sample output:

Hex timestamp:
0x7e1/0x3/0x1f 0x14:0x2d:0x28

Decimal timestamp:
2017/3/31 20:45:40
```

ContentLicense: CC BY-SA 3.0

Body:
You can get a pointer to a tm structure with localtime(), and get the needed values from the fields. Then you can use sprintf() to build a time string:

#include <stdio.h>
#include <time.h>

int main(void)
{
    time_t raw_time = time(NULL);
    struct tm *curr = localtime(&raw_time);

    int year = curr->tm_year + 1900;
    int month = curr->tm_mon + 1;
    int day = curr->tm_mday;

    int hour = curr->tm_hour;
    int min = curr->tm_min;
    int sec = curr->tm_sec;

    char time_str[40];
    sprintf(time_str, "%#x/%#x/%#x %#x:%#x:%#x",
            year, month, day, hour, min, sec);

    puts("Hex timestamp:");
    puts(time_str);

    sprintf(time_str, "%d/%d/%d %d:%d:%d",
            year, month, day, hour, min, sec);

    putchar('\n');
    puts("Decimal timestamp:");
    puts(time_str);

    return 0;
}

Sample output:

Hex timestamp:
0x7e1/0x3/0x1f 0x14:0x2d:0x28

Decimal timestamp:
2017/3/31 20:45:40


问:
Why is the Android test runner reporting "Empty test suite"?
I am banging my head against the wall here trying to figure out why IntelliJ/Android is reporting  "Empty test suite". I have a small project with two IntelliJ Modules ("Projects" in Eclipse). The Unit test module has its own AndroidManifest.xml, which I have pasted at the bottom. I am trying to run an ActivityUnitTestCase, since the tests will be dependent upon the Context-object.

The package name of the main module is nilzor.myapp. The pacakge name of the test module is nilzor.myapp.tests

Why is not the test runner detecting the testBlah()-method as a test?

```<code><?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="nilzor.myapp.tests"
          android:versionCode="1"
          android:versionName="1.0">
    <!-- We add an application tag here just so that we can indicate that
         this package needs to link against the android.test library,
         which is needed when building test cases. -->
    <application>
        <uses-library android:name="android.test.runner"/>
    </application>
    <!--
    This declares that this application uses the instrumentation test runner targeting
    the package of nilzor.myapp.  To run the tests use the command:
    "adb shell am instrument -w nilzor.myapp.tests/android.test.InstrumentationTestRunner"
    -->
    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="nilzor.myapp"
                     android:label="Tests for nilzor.myapp"/>
</manifest>
</code>```

And here is my test class:;

```<code>package nilzor.myapp.tests;

public class NilzorSomeTest<T extends Activity> extends ActivityUnitTestCase<T>{
    public NilzorSomeTest(Class<T> activityClass){
        super(activityClass);
    }

    @SmallTest
    public void testBlah(){
        assertEquals(1,1);
    }
}
</code>```

I have read the testing fundamentals, the activity testing document, and tried following this Hello world test blog, even though it is for Eclipse. I cannot get the test runner to find and run my test. What am I doing wrong?

Some of the questions I still feel unsure about are:

Do I need an Annotation above the Unit test method?

Do I need to prefix the method with "test", or is that just for JUnit tests?

Can I have tests in sub-packages of nilzor.myapp.tests?

But the main question of this post is why does not the test runner detect my test?

答: I just renamed the file and the problem fixed.</p>

Body:
I am banging my head against the wall here trying to figure out why IntelliJ/Android is reporting  "Empty test suite". I have a small project with two IntelliJ Modules ("Projects" in Eclipse). The Unit test module has its own AndroidManifest.xml, which I have pasted at the bottom. I am trying to run an ActivityUnitTestCase, since the tests will be dependent upon the Context-object.

The package name of the main module is nilzor.myapp. The pacakge name of the test module is nilzor.myapp.tests

Why is not the test runner detecting the testBlah()-method as a test?

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="nilzor.myapp.tests"
          android:versionCode="1"
          android:versionName="1.0">

    <application>
        <uses-library android:name="android.test.runner"/>
    </application>

    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="nilzor.myapp"
                     android:label="Tests for nilzor.myapp"/>
</manifest>

And here is my test class:;

package nilzor.myapp.tests;

public class NilzorSomeTest<T extends Activity> extends ActivityUnitTestCase<T>{
    public NilzorSomeTest(Class<T> activityClass){
        super(activityClass);
    }

    @SmallTest
    public void testBlah(){
        assertEquals(1,1);
    }
}

I have read the testing fundamentals, the activity testing document, and tried following this Hello world test blog, even though it is for Eclipse. I cannot get the test runner to find and run my test. What am I doing wrong?

Some of the questions I still feel unsure about are:

Do I need an Annotation above the Unit test method?

Do I need to prefix the method with "test", or is that just for JUnit tests?

Can I have tests in sub-packages of nilzor.myapp.tests?

But the main question of this post is why does not the test runner detect my test?


问:
ES6 push and bind to an array
Please pardon my newbie verbiage here while I attempt to explain my problem (also I did search and came up with nothing, I'd also like to use ES6, not jQuery)

I'm trying to have a text input that when entered it's pushed into an empty array.  When more input is entered in, I would like to have that bound to the array as well.

So I have it working, kinda.  I can get one thing in the array but I can't seem to anything else to go in there.  Here's what I have so far:

My html:

```<code><input type="text" class="theplayer pre" name="Player" id="bind" placeholder="Enter Names" onclick='javascript: this.value = ""' />
</code>```

My JS:

```<code>    let namesOfPlayers = [];
    const currentValue = document.getElementById("bind").value;
    namesOfPlayers.push(currentValue);
    //I don't know how to add in another text/value here
    console.log('namesOfPlayers', namesOfPlayers);
</code>```

I don't know if I'm supposed to be doing a for each here or if there's a way to bind another value into the array.

Thanks and much appreciated for letting me try to clumsily explain this.

答:
You can include <input type="button"> element as sibling of <input type="text"> element. At click on <input type="button"> .push() .value of <input type="text"> to array

<input type="text"
       class="theplayer pre"
       name="Player"
       id="bind"
       placeholder="Enter Names" />
<input type="button" value="click" />
```

Title: ES6 push and bind to an array

Body:
Please pardon my newbie verbiage here while I attempt to explain my problem (also I did search and came up with nothing, I'd also like to use ES6, not jQuery)

I'm trying to have a text input that when entered it's pushed into an empty array.  When more input is entered in, I would like to have that bound to the array as well.

So I have it working, kinda.  I can get one thing in the array but I can't seem to anything else to go in there.  Here's what I have so far:

My html:

<input type="text" class="theplayer pre" name="Player" id="bind" placeholder="Enter Names" onclick='javascript: this.value = ""' />

My JS:

    let namesOfPlayers = [];
    const currentValue = document.getElementById("bind").value;
    namesOfPlayers.push(currentValue);
    //I don't know how to add in another text/value here
    console.log('namesOfPlayers', namesOfPlayers);

I don't know if I'm supposed to be doing a for each here or if there's a way to bind another value into the array.

Thanks and much appreciated for letting me try to clumsily explain this.

Body:
You can include <input type="button"> element as sibling of <input type="text"> element. At click on <input type="button"> .push() .value of <input type="text"> to array

<input type="text"
       class="theplayer pre"
       name="Player"
       id="bind"
       placeholder="Enter Names" />
<input type="button" value="click" />
<script>
  let namesOfPlayers = [];
  let input = document.getElementById("bind");
  let button = input.nextElementSibling;
  button.addEventListener("click", function() {
    namesOfPlayers.push(input.value);
    console.log(namesOfPlayers);
  });
</script>


问:
Python analyzing csv file
I'm trying to find the three most populated city parts(BYDEL) in 1992

I have a csv file looking like this: http://data.kk.dk/dataset/9070067f-ab57-41cd-913e-bc37bfaf9acd/resource/9fbab4aa-1ee0-4d25-b2b4-b7b63537d2ec/download/befkbhalderkoencivst.csv>

The csv file can be explained as:

AAR: Which year the observation was made

BYDEL: Which part of the city, described by an integer contained in following dict; 1=Indre By, 2=Østerbro, 3=Nørrebro, 4=Vesterbro/Kgs. Enghave, 5=Valby, 6=Vanløse, 7=Brønshøj-Husum, 8=Bispebjerg, 9=Amager Øst, 10=Amager Vest, 99=Udenfor inddeling

ALDER: The age of the observed people

PERSONER: Number of observations with the given features of the row

I have a solution but it is very repetitive and i think that it could be done smarter but I don't have enough experience with python. Could anyone point me in the right direction?

My code/solution looks like this:

```<code>df = pd.read_csv('befkbh.csv',quotechar='"',skipinitialspace=True, delimiter=',', encoding='latin1').fillna(0)
data = df.as_matrix()
Q31 = collections.defaultdict(list)
Q32 = collections.defaultdict(list)
Q33 = collections.defaultdict(list)
Q34 = collections.defaultdict(list)
Q35 = collections.defaultdict(list)
Q36 = collections.defaultdict(list)
Q37 = collections.defaultdict(list)
Q38 = collections.defaultdict(list)
Q39 = collections.defaultdict(list)
Q310 = collections.defaultdict(list)
Q399 = collections.defaultdict(list)
for row in data:
    key = row[0]
    if key == "" or key == 0: continue
    if key == 1992:
        if row[2] == 1:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q31.setdefault(key,[]).append(val)
        if row[2] == 2:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q32.setdefault(key,[]).append(val)
        if row[2] == 3:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q33.setdefault(key,[]).append(val)
        if row[2] == 4:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q34.setdefault(key,[]).append(val)
        if row[2] == 5:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q35.setdefault(key,[]).append(val)
        if row[2] == 6:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q36.setdefault(key,[]).append(val)
        if row[2] == 7:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q37.setdefault(key,[]).append(val)
        if row[2] == 8:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q38.setdefault(key,[]).append(val)
        if row[2] == 9:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q39.setdefault(key,[]).append(val)
        if row[2] == 10:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q310.setdefault(key,[]).append(val)
        if row[2] == 99:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q399.setdefault(key,[]).append(val)

Q312 = {}
for k, v in Q31.items(): Q312[k] = sum(v)
for k, v in Q312.items(): print ("{}:{}".format(k,v))
Q322 = {}
for k, v in Q32.items(): Q322[k] = sum(v)
for k, v in Q322.items(): print ("{}:{}".format(k,v))
Q332 = {}
for k, v in Q33.items(): Q332[k] = sum(v)
for k, v in Q332.items(): print ("{}:{}".format(k,v))
Q342 = {}
for k, v in Q34.items(): Q342[k] = sum(v)
for k, v in Q342.items(): print ("{}:{}".format(k,v))
Q352 = {}
for k, v in Q35.items(): Q352[k] = sum(v)
for k, v in Q352.items(): print ("{}:{}".format(k,v))
Q362 = {}
for k, v in Q36.items(): Q362[k] = sum(v)
for k, v in Q362.items(): print ("{}:{}".format(k,v))
Q372 = {}
for k, v in Q37.items(): Q372[k] = sum(v)
for k, v in Q372.items(): print ("{}:{}".format(k,v))
Q382 = {}
for k, v in Q38.items(): Q382[k] = sum(v)
for k, v in Q382.items(): print ("{}:{}".format(k,v))
Q392 = {}
for k, v in Q39.items(): Q392[k] = sum(v)
for k, v in Q392.items(): print ("{}:{}".format(k,v))
Q3102 = {}
for k, v in Q310.items(): Q3102[k] = sum(v)
for k, v in Q3102.items(): print ("{}:{}".format(k,v))
Q3992 = {}
for k, v in Q399.items(): Q3992[k] = sum(v)
for k, v in Q3992.items(): print ("{}:{}".format(k,v))
</code>```

答:
A more pythonic solution would use a dictionary instead of many (most) of your named variables.  You are also using setdefault with defaultdict instances - either one is a good choice, but using both is unnecessary.

My alternative version (without using pandas, since @DSM covered that well):

```<code>df = pd.read_csv('befkbh.csv',quotechar='"',skipinitialspace=True, delimiter=',', encoding='latin1').fillna(0)
data = df.as_matrix()
areas = { k : collections.defaultdict(list) for k in range(1,11) }
areas[99] = collections.defaultdict(list)

for row in data:
    key = row[0]
    if key == 1992 and row[1] in areas:
       areas[row[1]][key].append(0 if(row[5]) ==""  else float(row[5]))

for area in sorted(areas):
    for k, v in areas[area].items():
        print ("{}:{}".format(k, sum(v)))
</code>```

I'm assuming that row[2] in the question should have been row[1], since BYDEL is the second column, not the third.

To get the top 3 areas by year, I'd organize things a little differently, with the outer dict being the year, not the area.

That version looks like this:

```<code>years = collections.defaultdict(lambda : collections.defaultdict(list))

for row in data:
    years[row[0]][row[1]].append(0 if(row[5]) ==""  else float(row[5]))

for year in sorted(years):
    for n, area in sorted((sum(v), k) for k, v in years[year].items())[:-4:-1]:
        print ("{} {:4} {:9}".format(year, area, n))
</code>```

Title: Python analyzing csv file

Body:
I'm trying to find the three most populated city parts(BYDEL) in 1992

I have a csv file looking like this: http://data.kk.dk/dataset/9070067f-ab57-41cd-913e-bc37bfaf9acd/resource/9fbab4aa-1ee0-4d25-b2b4-b7b63537d2ec/download/befkbhalderkoencivst.csv>

The csv file can be explained as:

AAR: Which year the observation was made

BYDEL: Which part of the city, described by an integer contained in following dict; 1=Indre By, 2=Østerbro, 3=Nørrebro, 4=Vesterbro/Kgs. Enghave, 5=Valby, 6=Vanløse, 7=Brønshøj-Husum, 8=Bispebjerg, 9=Amager Øst, 10=Amager Vest, 99=Udenfor inddeling

ALDER: The age of the observed people

PERSONER: Number of observations with the given features of the row

I have a solution but it is very repetitive and i think that it could be done smarter but I don't have enough experience with python. Could anyone point me in the right direction?

My code/solution looks like this:

df = pd.read_csv('befkbh.csv',quotechar='"',skipinitialspace=True, delimiter=',', encoding='latin1').fillna(0)
data = df.as_matrix()
Q31 = collections.defaultdict(list)
Q32 = collections.defaultdict(list)
Q33 = collections.defaultdict(list)
Q34 = collections.defaultdict(list)
Q35 = collections.defaultdict(list)
Q36 = collections.defaultdict(list)
Q37 = collections.defaultdict(list)
Q38 = collections.defaultdict(list)
Q39 = collections.defaultdict(list)
Q310 = collections.defaultdict(list)
Q399 = collections.defaultdict(list)
for row in data:
    key = row[0]
    if key == "" or key == 0: continue
    if key == 1992:
        if row[2] == 1:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q31.setdefault(key,[]).append(val)
        if row[2] == 2:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q32.setdefault(key,[]).append(val)
        if row[2] == 3:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q33.setdefault(key,[]).append(val)
        if row[2] == 4:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q34.setdefault(key,[]).append(val)
        if row[2] == 5:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q35.setdefault(key,[]).append(val)
        if row[2] == 6:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q36.setdefault(key,[]).append(val)
        if row[2] == 7:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q37.setdefault(key,[]).append(val)
        if row[2] == 8:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q38.setdefault(key,[]).append(val)
        if row[2] == 9:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q39.setdefault(key,[]).append(val)
        if row[2] == 10:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q310.setdefault(key,[]).append(val)
        if row[2] == 99:
            val = 0 if(row[5]) ==""  else float(row[5])
            Q399.setdefault(key,[]).append(val)

Q312 = {}
for k, v in Q31.items(): Q312[k] = sum(v)
for k, v in Q312.items(): print ("{}:{}".format(k,v))
Q322 = {}
for k, v in Q32.items(): Q322[k] = sum(v)
for k, v in Q322.items(): print ("{}:{}".format(k,v))
Q332 = {}
for k, v in Q33.items(): Q332[k] = sum(v)
for k, v in Q332.items(): print ("{}:{}".format(k,v))
Q342 = {}
for k, v in Q34.items(): Q342[k] = sum(v)
for k, v in Q342.items(): print ("{}:{}".format(k,v))
Q352 = {}
for k, v in Q35.items(): Q352[k] = sum(v)
for k, v in Q352.items(): print ("{}:{}".format(k,v))
Q362 = {}
for k, v in Q36.items(): Q362[k] = sum(v)
for k, v in Q362.items(): print ("{}:{}".format(k,v))
Q372 = {}
for k, v in Q37.items(): Q372[k] = sum(v)
for k, v in Q372.items(): print ("{}:{}".format(k,v))
Q382 = {}
for k, v in Q38.items(): Q382[k] = sum(v)
for k, v in Q382.items(): print ("{}:{}".format(k,v))
Q392 = {}
for k, v in Q39.items(): Q392[k] = sum(v)
for k, v in Q392.items(): print ("{}:{}".format(k,v))
Q3102 = {}
for k, v in Q310.items(): Q3102[k] = sum(v)
for k, v in Q3102.items(): print ("{}:{}".format(k,v))
Q3992 = {}
for k, v in Q399.items(): Q3992[k] = sum(v)
for k, v in Q3992.items(): print ("{}:{}".format(k,v))

Body:
A more pythonic solution would use a dictionary instead of many (most) of your named variables.  You are also using setdefault with defaultdict instances - either one is a good choice, but using both is unnecessary.

My alternative version (without using pandas, since @DSM covered that well):

df = pd.read_csv('befkbh.csv',quotechar='"',skipinitialspace=True, delimiter=',', encoding='latin1').fillna(0)
data = df.as_matrix()
areas = { k : collections.defaultdict(list) for k in range(1,11) }
areas[99] = collections.defaultdict(list)

for row in data:
    key = row[0]
    if key == 1992 and row[1] in areas:
       areas[row[1]][key].append(0 if(row[5]) ==""  else float(row[5]))

for area in sorted(areas):
    for k, v in areas[area].items():
        print ("{}:{}".format(k, sum(v)))

I'm assuming that row[2] in the question should have been row[1], since BYDEL is the second column, not the third.

To get the top 3 areas by year, I'd organize things a little differently, with the outer dict being the year, not the area.

That version looks like this:

years = collections.defaultdict(lambda : collections.defaultdict(list))

for row in data:
    years[row[0]][row[1]].append(0 if(row[5]) ==""  else float(row[5]))

for year in sorted(years):
    for n, area in sorted((sum(v), k) for k, v in years[year].items())[:-4:-1]:
        print ("{} {:4} {:9}".format(year, area, n))


问:
My project builds with MSBuild 4 but not with MSBuild 3.5 even though I'm targeting the same version of the .NET Framework (3.5)?
When I build my solution using MSBuild 4 it compiles successfully:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe MySolution.sln

Build succeeded.

```<code>0 Warning(s)
0 Error(s)
</code>```

But when I try to do the same using MSBuild 3.5 I get the following error, even though the source is the same and I am using the same libraries and the same version of the .NET Framework.

C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe MySolution.sln

error CS1501: No overload for method 'InitializeClientContextFromStringSid' takes '2' arguments

error CS1501: No overload for method 'GetRoles' takes '0' arguments

The error that I get is related to Authorization Manager (AzMan).

The method 'InitializeClientContextFromStringSid' in the first error belongs to the public interface IAzApplication, a member of Microsoft.Interop.Security.AzRoles.

The method 'GetRoles' in the second error belongs to the public interface IAzClientContext, also a member of Microsoft.Interop.Security.AzRoles.

I am using the methods in the following way:

var clientContext = _azApplication.InitializeClientContextFromStringSid(member, 0);

where the variable member is a string containing the Windows Active Directory SID from an user and _azApplication is of type IAzApplication.

clientContext.GetRoles()

where clientContext is of type IAzClientContext.

Why does my solution builds with MSBuild 4 but not with MSBuild 3.5 even though I'm targeting the same version of the .NET Framework (3.5)?

答:
It looks like InitializeClientContextFromStringSid has an optional parameter in the specification. Though MSBuild in .Net Framework 4.0 supports the use of optional parameters in C# by allowing you to leave them out of the function call, previous versions of the MSBuild do not support this approach. So you must to supply the parameter even if it's not being used when building with older version of the Framework.

```<code>HRESULT InitializeClientContextFromStringSid(
  [in]            BSTR SidString,
  [in]            LONG lOptions,
  [in, optional]  VARIANT varReserved,
  [out]           IAzClientContext **ppClientContext
);
</code>```

The same issue is happening with the GetRolesmethod.

From my understanding, the reason you can build using the 4.0 version of MSBuild and target 3.5 Framework is that the CLR already supported the use of Optional parameters, for example VB.NET has always supported them. However, when using MSBuild 3.5, it is going to use the older rules/specification that did not allow support for Optional parameters in C# and thus will give you build errors.

ContentLicense: CC BY-SA 2.5

Body:
When I build my solution using MSBuild 4 it compiles successfully:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe MySolution.sln

Build succeeded.

0 Warning(s)
0 Error(s)

But when I try to do the same using MSBuild 3.5 I get the following error, even though the source is the same and I am using the same libraries and the same version of the .NET Framework.

C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe MySolution.sln

error CS1501: No overload for method 'InitializeClientContextFromStringSid' takes '2' arguments

error CS1501: No overload for method 'GetRoles' takes '0' arguments

The error that I get is related to Authorization Manager (AzMan).

The method 'InitializeClientContextFromStringSid' in the first error belongs to the public interface IAzApplication, a member of Microsoft.Interop.Security.AzRoles.

The method 'GetRoles' in the second error belongs to the public interface IAzClientContext, also a member of Microsoft.Interop.Security.AzRoles.

I am using the methods in the following way:

var clientContext = _azApplication.InitializeClientContextFromStringSid(member, 0);

where the variable member is a string containing the Windows Active Directory SID from an user and _azApplication is of type IAzApplication.

clientContext.GetRoles()

where clientContext is of type IAzClientContext.

Why does my solution builds with MSBuild 4 but not with MSBuild 3.5 even though I'm targeting the same version of the .NET Framework (3.5)?

Body:
It looks like InitializeClientContextFromStringSid has an optional parameter in the specification. Though MSBuild in .Net Framework 4.0 supports the use of optional parameters in C# by allowing you to leave them out of the function call, previous versions of the MSBuild do not support this approach. So you must to supply the parameter even if it's not being used when building with older version of the Framework.

HRESULT InitializeClientContextFromStringSid(
  [in]            BSTR SidString,
  [in]            LONG lOptions,
  [in, optional]  VARIANT varReserved,
  [out]           IAzClientContext **ppClientContext
);

The same issue is happening with the GetRolesmethod.

From my understanding, the reason you can build using the 4.0 version of MSBuild and target 3.5 Framework is that the CLR already supported the use of Optional parameters, for example VB.NET has always supported them. However, when using MSBuild 3.5, it is going to use the older rules/specification that did not allow support for Optional parameters in C# and thus will give you build errors.


问:
How do I unhook an action? My current method does not seem to be working
I am working on a WordPress website, with WooCommerce functionality.
I am currently trying to remove the social sharing feature, which is displayed on the Product Pages.  I am trying to achieve this through the removal of the Action from its Hook, by placing the following code in the functions.php file:

```<code><?php
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
?>
</code>```

Said functions.php is placed within the Child Theme I have created.

Unfortunately, this is not removing the social sharing feature.  Does anyone know why?  To see if there was an issue with the Hooks, I added an Action to the same Hook, to which this worked.

Could it be possible that the Social Sharing feature has been placed in some parent folder which overrides/has higher priority over the functions.php file in the Child theme?  If this is the case, what would be my options in getting said feature removed.  I can only think of placing the affected file in the Child theme and then manually removing the relevant coding.  This is a last resort as it may cause problems, at a later date, when parent files are updated etc.

答:
woocommerce_template_single_sharing() calls the Woocommerce template located at woocommerce/templates/single-product/share.php where there's a do_action call for other plugins & themes to add social sharing. If you want to "block" plugins from using that, your best bet (if you're building a theme) would be to use the built-in Woocommerce template override feature and simply prevent this do_action from firing. This would not cause any problems unless Woocommerce did a massive, structural rework. But otherwise, updating Woocommerce and any other plugins or a parent theme wouldn't affect your child theme.

In your child theme, create a directory called woocommerce, add a sub-directory called single-product, and then copy the share.php file from the above location in the plugin to that location in your theme.

Comment out the do_action and voila! No more social sharing and anything that hooks into that do_action won't run.

As an alternative...if you know exactly what's hooking into that do_action, you would run a remove_action on that bad boy, but then you need to hunt these things down and manually update your call any time a plugin tries to hook into it.

Body:
I am working on a WordPress website, with WooCommerce functionality.
I am currently trying to remove the social sharing feature, which is displayed on the Product Pages.  I am trying to achieve this through the removal of the Action from its Hook, by placing the following code in the functions.php file:

<?php
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
?>

Said functions.php is placed within the Child Theme I have created.

Unfortunately, this is not removing the social sharing feature.  Does anyone know why?  To see if there was an issue with the Hooks, I added an Action to the same Hook, to which this worked.

Could it be possible that the Social Sharing feature has been placed in some parent folder which overrides/has higher priority over the functions.php file in the Child theme?  If this is the case, what would be my options in getting said feature removed.  I can only think of placing the affected file in the Child theme and then manually removing the relevant coding.  This is a last resort as it may cause problems, at a later date, when parent files are updated etc.


问:
Cannot convert argument 1 from 'const char [5]' to 'LPCTSTR'
I'm using this codeproject: http://www.codeproject.com/Articles/10138/Voice-Recording-Playing-back-using-simple-classes

```<code>void CFisterDlg::OnRecord()
{
    CString string;
    m_RecButton.GetWindowText(string);
    if(string == "Record")
    {
        StartRecordingToFile();
        m_RecButton.SetWindowText("Stop");
    }
    else
    {
        StopRecordingToFile();
        m_RecButton.SetWindowText("Record");
    }
}
</code>```

But I get this error in numerous places:

```<code>error C2664: 'void CWnd::SetWindowTextW(LPCTSTR)' : cannot convert argument 1 from 'const char [5]' to 'LPCTSTR'
</code>```

I think it has something to do with me using the latest version of visual studio (2013).

答:
Try using Mulit-byte character encoding in Project Settings instead of Unicode.
In case of VS2013, VS2015 you need to download and install the MBCS library for visual studio from this link https://www.microsoft.com/en-us/download/confirmation.aspx?id=40770</p>

Body:
I'm using this codeproject: http://www.codeproject.com/Articles/10138/Voice-Recording-Playing-back-using-simple-classes

void CFisterDlg::OnRecord()
{
    CString string;
    m_RecButton.GetWindowText(string);
    if(string == "Record")
    {
        StartRecordingToFile();
        m_RecButton.SetWindowText("Stop");
    }
    else
    {
        StopRecordingToFile();
        m_RecButton.SetWindowText("Record");
    }
}

But I get this error in numerous places:

error C2664: 'void CWnd::SetWindowTextW(LPCTSTR)' : cannot convert argument 1 from 'const char [5]' to 'LPCTSTR'

I think it has something to do with me using the latest version of visual studio (2013).


问:
How to map hyperledger fabric peers (2nd, 3rd , 4th) with ports for REST communication
I have hyperledger fabric 0.6 env setup on Windows 7 64bit OS using docker-Toolbox and I am using REST API client to trigger requests. Following is my four-peer-ca.yaml docker compose file:-

```<code>version: "2"
services: baseimage: image: hyperledger/fabric-baseimage:latest

membersrvc:
  image: hyperledger/fabric-membersrvc

  ports:
    - "7054:7054"

  command: membersrvc

  environment:

    - MEMBERSRVC_CA_LOGGING_SERVER=INFO
    - MEMBERSRVC_CA_LOGGING_CA=INFO
    - MEMBERSRVC_CA_LOGGING_ECA=INFO
    - MEMBERSRVC_CA_LOGGING_ECAP=INFO
    - MEMBERSRVC_CA_LOGGING_ECAA=INFO
    - MEMBERSRVC_CA_LOGGING_ACA=INFO
    - MEMBERSRVC_CA_LOGGING_ACAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCA=INFO
    - MEMBERSRVC_CA_LOGGING_TCAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCAA=INFO
    - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

vp0:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"

  environment:
    - CORE_PEER_ID=vp0
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4

  command: sh -c "sleep 10; peer node start"
  links: - membersrvc

vp1:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "8050:7050"
    - "8051:7051"
    - "8053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp1
    - CORE_SECURITY_ENROLLID=test_vp1
    - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp2:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "9050:7050"
    - "9051:7051"
    - "9053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp2
    - CORE_SECURITY_ENROLLID=test_vp2
    - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp3:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "10050:7050"
    - "10051:7051"
    - "10053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp3
    - CORE_SECURITY_ENROLLID=test_vp3
    - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"**
</code>```

//------------
using docker-compose up command, my server is up and all 4 peers are created successfully.
in another docker terminal I executed following command which is also working fine:

```<code>CORE_CHAINCODE_ID_NAME=mycc006 CORE_PEER_ADDRESS=192.168.99.100:7051 ./chaincode_example02
</code>```

Since I m using docker toolbox only 192.168.99.100 is a acceptable ip address for CORE_PEER_ADDRESS.

The REST API request are responsive to only - 192.168.99.100:7050/chaincode for all operations

You can see in the docker-compose file above that I have mapped vp1, vp2, vp3 with different ports and forwarded to vp0.

But when I try to use any other peer, for example vp1 using 192.168.99.100:8050/chaincode the request fails as there is no response from vp1,vp2,vp3 even though I have specifically mapped ports with these peers.
Docker ps command shows memersrvc and all 4 peer containers running but ports are assigned only to vp0.

How do I map other peers vp1,vp2,vp3 with the ports inorder to access them via REST API ? Any help or guidance will be appreciated.

Thanks.

答:
your docker-compose file looks good beside some small issues in the mapping what I guess is related to the rendering on stackoverflow.
Is the problem, that the REST endpoints are not working at all? Is for example http://localhost:10050/chain not accessible? If so, you might want to make sure that you are using the right images
hyperledger/fabric-peer:x86_64-0.6.1-preview since that the docker-compose file works with 1.0-alpha images as well but there the REST API is missing.
That slightly modified docker-compose file I attached bellow works out of the box. If that solves your problem you have to look into your docker images and see where the latest tag is pointing to.

```<code>version: "2"
services: # baseimage: image: hyperledger/fabric-baseimage:latest

  membersrvc:
    image: hyperledger/fabric-membersrvc

    ports:
      - "7054:7054"

    command: membersrvc

    environment:

      - MEMBERSRVC_CA_LOGGING_SERVER=INFO
      - MEMBERSRVC_CA_LOGGING_CA=INFO
      - MEMBERSRVC_CA_LOGGING_ECA=INFO
      - MEMBERSRVC_CA_LOGGING_ECAP=INFO
      - MEMBERSRVC_CA_LOGGING_ECAA=INFO
      - MEMBERSRVC_CA_LOGGING_ACA=INFO
      - MEMBERSRVC_CA_LOGGING_ACAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCA=INFO
      - MEMBERSRVC_CA_LOGGING_TCAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCAA=INFO
      - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

  vp0:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "7050:7050"
      - "7051:7051"
      - "7053:7053"

    environment:
      - CORE_PEER_ID=vp0
      - CORE_SECURITY_ENROLLID=test_vp0
      - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4

    command: sh -c "sleep 10; peer node start"
    links:
      - membersrvc

  vp1:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "8050:7050"
      - "8051:7051"
      - "8053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp1
      - CORE_SECURITY_ENROLLID=test_vp1
      - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links:
      - membersrvc
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp2:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9050:7050"
      - "9051:7051"
      - "9053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp2
      - CORE_SECURITY_ENROLLID=test_vp2
      - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links:
      - membersrvc
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp3:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "10050:7050"
      - "10051:7051"
      - "10053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp3
      - CORE_SECURITY_ENROLLID=test_vp3
      - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links:
      - membersrvc
      - vp0
    command: sh -c "sleep 10; peer node start"
</code>```

Body:
I have hyperledger fabric 0.6 env setup on Windows 7 64bit OS using docker-Toolbox and I am using REST API client to trigger requests. Following is my four-peer-ca.yaml docker compose file:-

version: "2"
services: baseimage: image: hyperledger/fabric-baseimage:latest

membersrvc:
  image: hyperledger/fabric-membersrvc

  ports:
    - "7054:7054"

  command: membersrvc

  environment:

    - MEMBERSRVC_CA_LOGGING_SERVER=INFO
    - MEMBERSRVC_CA_LOGGING_CA=INFO
    - MEMBERSRVC_CA_LOGGING_ECA=INFO
    - MEMBERSRVC_CA_LOGGING_ECAP=INFO
    - MEMBERSRVC_CA_LOGGING_ECAA=INFO
    - MEMBERSRVC_CA_LOGGING_ACA=INFO
    - MEMBERSRVC_CA_LOGGING_ACAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCA=INFO
    - MEMBERSRVC_CA_LOGGING_TCAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCAA=INFO
    - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

vp0:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"

  environment:
    - CORE_PEER_ID=vp0
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4

  command: sh -c "sleep 10; peer node start"
  links: - membersrvc

vp1:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "8050:7050"
    - "8051:7051"
    - "8053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp1
    - CORE_SECURITY_ENROLLID=test_vp1
    - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp2:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "9050:7050"
    - "9051:7051"
    - "9053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp2
    - CORE_SECURITY_ENROLLID=test_vp2
    - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp3:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "10050:7050"
    - "10051:7051"
    - "10053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp3
    - CORE_SECURITY_ENROLLID=test_vp3
    - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"**

//------------
using docker-compose up command, my server is up and all 4 peers are created successfully.
in another docker terminal I executed following command which is also working fine:

CORE_CHAINCODE_ID_NAME=mycc006 CORE_PEER_ADDRESS=192.168.99.100:7051 ./chaincode_example02

Since I m using docker toolbox only 192.168.99.100 is a acceptable ip address for CORE_PEER_ADDRESS.

The REST API request are responsive to only - 192.168.99.100:7050/chaincode for all operations

You can see in the docker-compose file above that I have mapped vp1, vp2, vp3 with different ports and forwarded to vp0.

But when I try to use any other peer, for example vp1 using 192.168.99.100:8050/chaincode the request fails as there is no response from vp1,vp2,vp3 even though I have specifically mapped ports with these peers.
Docker ps command shows memersrvc and all 4 peer containers running but ports are assigned only to vp0.

How do I map other peers vp1,vp2,vp3 with the ports inorder to access them via REST API ? Any help or guidance will be appreciated.

Thanks.

Body:
your docker-compose file looks good beside some small issues in the mapping what I guess is related to the rendering on stackoverflow.
Is the problem, that the REST endpoints are not working at all? Is for example http://localhost:10050/chain not accessible? If so, you might want to make sure that you are using the right images
hyperledger/fabric-peer:x86_64-0.6.1-preview since that the docker-compose file works with 1.0-alpha images as well but there the REST API is missing.
That slightly modified docker-compose file I attached bellow works out of the box. If that solves your problem you have to look into your docker images and see where the latest tag is pointing to.

version: "2"
services: # baseimage: image: hyperledger/fabric-baseimage:latest

  membersrvc:
    image: hyperledger/fabric-membersrvc

    ports:
      - "7054:7054"

    command: membersrvc

    environment:

      - MEMBERSRVC_CA_LOGGING_SERVER=INFO
      - MEMBERSRVC_CA_LOGGING_CA=INFO
      - MEMBERSRVC_CA_LOGGING_ECA=INFO
      - MEMBERSRVC_CA_LOGGING_ECAP=INFO
      - MEMBERSRVC_CA_LOGGING_ECAA=INFO
      - MEMBERSRVC_CA_LOGGING_ACA=INFO
      - MEMBERSRVC_CA_LOGGING_ACAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCA=INFO
      - MEMBERSRVC_CA_LOGGING_TCAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCAA=INFO
      - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

  vp0:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "7050:7050"
      - "7051:7051"
      - "7053:7053"

    environment:
      - CORE_PEER_ID=vp0
      - CORE_SECURITY_ENROLLID=test_vp0
      - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4

    command: sh -c "sleep 10; peer node start"
    links:
      - membersrvc

  vp1:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "8050:7050"
      - "8051:7051"
      - "8053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp1
      - CORE_SECURITY_ENROLLID=test_vp1
      - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links:
      - membersrvc
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp2:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9050:7050"
      - "9051:7051"
      - "9053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp2
      - CORE_SECURITY_ENROLLID=test_vp2
      - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links:
      - membersrvc
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp3:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "10050:7050"
      - "10051:7051"
      - "10053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp3
      - CORE_SECURITY_ENROLLID=test_vp3
      - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links:
      - membersrvc
      - vp0
    command: sh -c "sleep 10; peer node start"


问:
jQuery to get background image height and change parent based on ratio
I have a background image for each item; in this case the image size is 580x374.

This is being set inline on the li a item for each as a background image but I need to set the elements height so it shows correctly. The image height returned I need to half as it's two images in one that I need to move position on hover but I can do that.

What I am having a problem with is getting the elements width, getting the background size, working out the ratio of the background image size and setting the height of the container to display it.

I need it to be responsive as well, so it sets right on page load whichever viewport size it is and resize.

Here is where I have got to so far, but I'm new to JS.

HTML EXAMPLE:

```<code><ul>
<li class="collection-list-item grid-item first collection-hover">
 <a href="/collections/butterfly-sofa" data-image="//cdn.shopify.com/s/files/1/1839/7697/collections/category-panel-butterfly.jpg?v=1490985733" style="background-image: url("//cdn.shopify.com/s/files/1/1839/7697/collections/category-panel-butterfly.jpg?v=1490985733");">
  <div class="collection-list-hover-desc right">

    <p>Dein eigener Ruhepol in einer hektischen Welt. Der durch eine Struktur im Inneren formstabile Sitzsack vereint Komfort und Ästhetik.</p>
  </div>
  <div class="collection-list-hover-button left">
    <span class="button">Entdecken</span>
  </div>
</a>
</li>
<li class="collection-list-item grid-item first collection-hover">
 <a href="/collections/butterfly-sofa" data-image="//cdn.shopify.com/s/files/1/1839/7697/collections/category-panel-butterfly.jpg?v=1490985733" style="background-image: url("//cdn.shopify.com/s/files/1/1839/7697/collections/category-panel-butterfly.jpg?v=1490985733");">
  <div class="collection-list-hover-desc right">

    <p>Dein eigener Ruhepol in einer hektischen Welt. Der durch eine Struktur im Inneren formstabile Sitzsack vereint Komfort und Ästhetik.</p>
  </div>
  <div class="collection-list-hover-button left">
    <span class="button">Entdecken</span>
  </div>
</a>
</li>
<li class="collection-list-item grid-item first collection-hover">
 <a href="/collections/butterfly-sofa" data-image="//cdn.shopify.com/s/files/1/1839/7697/collections/category-panel-butterfly.jpg?v=1490985733" style="background-image: url("//cdn.shopify.com/s/files/1/1839/7697/collections/category-panel-butterfly.jpg?v=1490985733");">
  <div class="collection-list-hover-desc right">

    <p>Dein eigener Ruhepol in einer hektischen Welt. Der durch eine Struktur im Inneren formstabile Sitzsack vereint Komfort und Ästhetik.</p>
  </div>
  <div class="collection-list-hover-button left">
    <span class="button">Entdecken</span>
  </div>
</a>
</li>
</ul>
</code>```

JS:

```<code>$('.collection-hover a').each(function (index, value){
  var collection_bg_img = new Image;
  collection_bg_img.src = $(this).data('image');
  var bgImgWidth = collection_bg_img.width;
  var bgImgHeight = collection_bg_img.height;
  var divWidth = $(this).width();
  var realImgHeight = ( bgImgHeight / bgImgWidth) * divWidth;
  var halfImage = (realImgHeight / 2);
  $(this).height(halfImage);
  //console.log(halfImage);
});
</code>```

I guess could set a max width and height and change it width whatever width is set by viewport and adjust height based on ratio?

UPDATE

I tried something like this, not got it working yet though... but maybe a good approach as would be a max width:

```<code>$('.collection-hover a').each(function() {
var maxWidth = 580; // Max width for the image
var maxHeight = 374;    // Max height for the image
var ratio = 0;  // Used for aspect ratio
var width = $(this).width();    // Current image width
var height = $(this).height();  // Current image height

// Check if the current width is larger than the max
if(width > maxWidth){
  ratio = maxWidth / width;   // get ratio for scaling image
  $(this).css("width", maxWidth); // Set new width
  $(this).css("height", height * ratio);  // Scale height based on ratio
  height = height * ratio;    // Reset height to match scaled image
}

var width = $(this).width();    // Current image width
var height = $(this).height();  // Current image height

// Check if current height is larger than max
if(height > maxHeight){
  ratio = maxHeight / height; // get ratio for scaling image
  $(this).css("height", maxHeight);   // Set new height
  $(this).css("width", width * ratio);    // Scale width based on ratio
  width = width * ratio;    // Reset width to match scaled image
}

});
</code>```

答:
If I understand this question correctly, you're trying to:

Add a div to a webpage, the width of which is unknowable.

Add a background to that div and have the background stretch to the width of the div

Resize the div to 1/2 the height of the stretched background

This can actually be accomplished with a combination of img tags and pure CSS.

Here's a JsFiddle demonstating that: https://jsfiddle.net/x11n48yz/1/

```<code><div id='my-page'>
  <div class='image-holder'>
    <img src='http://cflrs.in/wp-content/uploads/2017/01/example.jpg'/>
  </div>
</div>
</code>```

```<code>#my-page {
  background-color: green;
  width: 200px;
  height: 800px;
}

.image-holder {
  position:relative;
  width: 100%;
  height: 0;
  padding-bottom: 50%;
  margin-bottom: -10%;
  overflow: hidden;
}
.image-holder img {
  width: 100%;
  height: 200%;
  position: absolute;
  left: 0;
}

.image-holder img:hover {
  bottom: 0;
}
</code>```

Body:
I have a background image for each item; in this case the image size is 580x374.

This is being set inline on the li a item for each as a background image but I need to set the elements height so it shows correctly. The image height returned I need to half as it's two images in one that I need to move position on hover but I can do that.

What I am having a problem with is getting the elements width, getting the background size, working out the ratio of the background image size and setting the height of the container to display it.

I need it to be responsive as well, so it sets right on page load whichever viewport size it is and resize.

Here is where I have got to so far, but I'm new to JS.

HTML EXAMPLE:

Dein eigener Ruhepol in einer hektischen Welt. Der durch eine Struktur im Inneren formstabile Sitzsack vereint Komfort und Ästhetik.

    Entdecken

Dein eigener Ruhepol in einer hektischen Welt. Der durch eine Struktur im Inneren formstabile Sitzsack vereint Komfort und Ästhetik.

    Entdecken

Dein eigener Ruhepol in einer hektischen Welt. Der durch eine Struktur im Inneren formstabile Sitzsack vereint Komfort und Ästhetik.

    Entdecken

JS:

$('.collection-hover a').each(function (index, value){
  var collection_bg_img = new Image;
  collection_bg_img.src = $(this).data('image');
  var bgImgWidth = collection_bg_img.width;
  var bgImgHeight = collection_bg_img.height;
  var divWidth = $(this).width();
  var realImgHeight = ( bgImgHeight / bgImgWidth) * divWidth;
  var halfImage = (realImgHeight / 2);
  $(this).height(halfImage);
  //console.log(halfImage);
});

I guess could set a max width and height and change it width whatever width is set by viewport and adjust height based on ratio?

UPDATE

I tried something like this, not got it working yet though... but maybe a good approach as would be a max width:

$('.collection-hover a').each(function() {
var maxWidth = 580; // Max width for the image
var maxHeight = 374;    // Max height for the image
var ratio = 0;  // Used for aspect ratio
var width = $(this).width();    // Current image width
var height = $(this).height();  // Current image height

// Check if the current width is larger than the max
if(width > maxWidth){
  ratio = maxWidth / width;   // get ratio for scaling image
  $(this).css("width", maxWidth); // Set new width
  $(this).css("height", height * ratio);  // Scale height based on ratio
  height = height * ratio;    // Reset height to match scaled image
}

var width = $(this).width();    // Current image width
var height = $(this).height();  // Current image height

// Check if current height is larger than max
if(height > maxHeight){
  ratio = maxHeight / height; // get ratio for scaling image
  $(this).css("height", maxHeight);   // Set new height
  $(this).css("width", width * ratio);    // Scale width based on ratio
  width = width * ratio;    // Reset width to match scaled image
}

});

Body:
If I understand this question correctly, you're trying to:

Add a div to a webpage, the width of which is unknowable.

Add a background to that div and have the background stretch to the width of the div

Resize the div to 1/2 the height of the stretched background

This can actually be accomplished with a combination of img tags and pure CSS.

Here's a JsFiddle demonstating that: https://jsfiddle.net/x11n48yz/1/

<div id='my-page'>
  <div class='image-holder'>
    <img src='http://cflrs.in/wp-content/uploads/2017/01/example.jpg'/>
  </div>
</div>

#my-page {
  background-color: green;
  width: 200px;
  height: 800px;
}

.image-holder {
  position:relative;
  width: 100%;
  height: 0;
  padding-bottom: 50%;
  margin-bottom: -10%;
  overflow: hidden;
}
.image-holder img {
  width: 100%;
  height: 200%;
  position: absolute;
  left: 0;
}

.image-holder img:hover {
  bottom: 0;
}


问:
Call TinyMCE in a WordPress plugin
Is there a way to add TinyMCE into my own WordPress plugin?

I have a textarea in my back end script and want to make this area into a TinyMCE WYSIWYG editable field. Is there a way to do that?

This code does not work for me:

```<code><?php
    wp_tiny_mce(false,array("editor_selector" => "test"));
?>
<textarea class="test" id="test" name="test"></textarea>
</code>```

It shows the javascript error

```<code>f is undefined
</code>```

Firebug screenshot:

This didn't work either:

```<code><textarea class="theEditor" id="videogalerie-add_description" name="videogalerie-add_description"></textarea>
</code>```

答:
The following example works for me.  Just make sure to use the id of the textarea you want to select in the $a["elements"] variable.

Assuming you have a textarea with the id of 'intro':

```<code>// attach the tiny mce editor to this textarea
if (function_exists('wp_tiny_mce')) {

  add_filter('teeny_mce_before_init', create_function('$a', '
    $a["theme"] = "advanced";
    $a["skin"] = "wp_theme";
    $a["height"] = "200";
    $a["width"] = "800";
    $a["onpageload"] = "";
    $a["mode"] = "exact";
    $a["elements"] = "intro";
    $a["editor_selector"] = "mceEditor";
    $a["plugins"] = "safari,inlinepopups,spellchecker";

    $a["forced_root_block"] = false;
    $a["force_br_newlines"] = true;
    $a["force_p_newlines"] = false;
    $a["convert_newlines_to_brs"] = true;

    return $a;'));

 wp_tiny_mce(true);
}
</code>```

?>

Title: Call TinyMCE in a WordPress plugin

Body:
Is there a way to add TinyMCE into my own WordPress plugin?

I have a textarea in my back end script and want to make this area into a TinyMCE WYSIWYG editable field. Is there a way to do that?

This code does not work for me:

<?php
    wp_tiny_mce(false,array("editor_selector" => "test"));
?>
<textarea class="test" id="test" name="test"></textarea>

It shows the javascript error

f is undefined

Firebug screenshot:

This didn't work either:

<textarea class="theEditor" id="videogalerie-add_description" name="videogalerie-add_description"></textarea>

Body:
The following example works for me.  Just make sure to use the id of the textarea you want to select in the $a["elements"] variable.

Assuming you have a textarea with the id of 'intro':

// attach the tiny mce editor to this textarea
if (function_exists('wp_tiny_mce')) {

  add_filter('teeny_mce_before_init', create_function('$a', '
    $a["theme"] = "advanced";
    $a["skin"] = "wp_theme";
    $a["height"] = "200";
    $a["width"] = "800";
    $a["onpageload"] = "";
    $a["mode"] = "exact";
    $a["elements"] = "intro";
    $a["editor_selector"] = "mceEditor";
    $a["plugins"] = "safari,inlinepopups,spellchecker";

    $a["forced_root_block"] = false;
    $a["force_br_newlines"] = true;
    $a["force_p_newlines"] = false;
    $a["convert_newlines_to_brs"] = true;

    return $a;'));

 wp_tiny_mce(true);
}

?>


问:
Skipping page number on the coversheet in Access Report, and new page number from the 2nd page by group
I was able to find an example code for Access VBA to insert "Page of pages" per group header. Each group is an individual invoice to our client.

Now, I want to add the cover sheet that shows the total invoice amount, and I can do that. But the cover sheet messes up the page number of the very first invoice following the cover sheet.

For example, The first invoice is only one page. So without the coversheet, the page number shows as "page 1 of 1".

But when I add the Report Header, and force the new page "After the selection", the coversheet shows page 1 of 2 and the first invoice shows page 2 of 2.

Is there a way to not have the page number at all on the coversheet, and the following page has the new page 1 numbering?

ctlGrpPages is the control that shows page numbers, and it is placed in the page footer.

Thank you very much in advance.

```<code>Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As
Integer)
Dim i As Integer

  If Me.Pages = 0 Then
    ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)
GrpNameCurrent = Me![Claim Number]
If GrpNameCurrent = GrpNamePrevious Then
    GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
    GrpPages = GrpArrayPage(Me.Page)
        For i = Me.Page - ((GrpPages) - 1) To Me.Page
            GrpArrayPages(i) = GrpPages
        Next i
Else
    GrpPage = 1
    GrpArrayPage(Me.Page) = GrpPage
    GrpArrayPages(Me.Page) = GrpPage
End If
 Else
   Me!ctlGrpPages.Value = "Page " & GrpArrayPage(Me.Page) & " of " &
GrpArrayPages(Me.Page)
  End If
  GrpNamePrevious = GrpNameCurrent
End Sub
</code>```

答: What is your setting for report property PageFooter? Have you tried 'Not with Rpt Hdr'?</p>

Body:
I was able to find an example code for Access VBA to insert "Page of pages" per group header. Each group is an individual invoice to our client.

Now, I want to add the cover sheet that shows the total invoice amount, and I can do that. But the cover sheet messes up the page number of the very first invoice following the cover sheet.

For example, The first invoice is only one page. So without the coversheet, the page number shows as "page 1 of 1".

But when I add the Report Header, and force the new page "After the selection", the coversheet shows page 1 of 2 and the first invoice shows page 2 of 2.

Is there a way to not have the page number at all on the coversheet, and the following page has the new page 1 numbering?

ctlGrpPages is the control that shows page numbers, and it is placed in the page footer.

Thank you very much in advance.

Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As
Integer)
Dim i As Integer

  If Me.Pages = 0 Then
    ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)
GrpNameCurrent = Me![Claim Number]
If GrpNameCurrent = GrpNamePrevious Then
    GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
    GrpPages = GrpArrayPage(Me.Page)
        For i = Me.Page - ((GrpPages) - 1) To Me.Page
            GrpArrayPages(i) = GrpPages
        Next i
Else
    GrpPage = 1
    GrpArrayPage(Me.Page) = GrpPage
    GrpArrayPages(Me.Page) = GrpPage
End If
 Else
   Me!ctlGrpPages.Value = "Page " & GrpArrayPage(Me.Page) & " of " &
GrpArrayPages(Me.Page)
  End If
  GrpNamePrevious = GrpNameCurrent
End Sub


问:
Java Class with multiple methods that can be executed in a thread
I am new to Java multithreaded programming. I have a use case where I have a runnable class called Diner and based on the state of different variables in the program, I want to execute different methods of the Diner Class in parallel.
One way to do that would be to have a single run() method containing multiple if conditions corresponding to different code blocks you want to execute as shown below.

```<code>    public class Diner implements Runnable  {
        Order order;
        int arrivalTime;

        public void run () {
            if(!isSeated){
                //do something to get a seat
            }
            if(!notEatenYet){
                //place order
            }
            if(!orderHasArrived){
                //start eating
            }
            if(finishedEating){
                //pay bill and leave
            }
        }
    }
</code>```

However, is there a more elegant way to do this? Like rather than having a single run() method that can be parallelized, have different methods in the class that could be parallelized (overloading run() ?).

I believe I can use Akka Actors to accomplish something like this, but I am looking for a native solution.

答:
In my opinion, for your case, simple inheritance can be a good option.

you can have several sub-classes inheriting Diner,

So there would be one Diner abstract class and several sub classes,

```<code>public abstract class Diner implements Runable{
    public Order order;
    public int arrivalTime;
}

public class NotSeatedDiner extends Diner {
    public void run () {
        // do something to find a seat
    }
}
</code>```

// some other subclasses

in your main function, you can have

```<code>List diners = new ArrayList<Diner>();

//maybe some factory producing different diners

diners.add(fac.getDiner("not seated"));

for(Diner diner : diners){
    diner.run();
}
</code>```

Body:
I am new to Java multithreaded programming. I have a use case where I have a runnable class called Diner and based on the state of different variables in the program, I want to execute different methods of the Diner Class in parallel.
One way to do that would be to have a single run() method containing multiple if conditions corresponding to different code blocks you want to execute as shown below.

    public class Diner implements Runnable  {
        Order order;
        int arrivalTime;

        public void run () {
            if(!isSeated){
                //do something to get a seat
            }
            if(!notEatenYet){
                //place order
            }
            if(!orderHasArrived){
                //start eating
            }
            if(finishedEating){
                //pay bill and leave
            }
        }
    }

However, is there a more elegant way to do this? Like rather than having a single run() method that can be parallelized, have different methods in the class that could be parallelized (overloading run() ?).

I believe I can use Akka Actors to accomplish something like this, but I am looking for a native solution.

Body:
In my opinion, for your case, simple inheritance can be a good option.

you can have several sub-classes inheriting Diner,

So there would be one Diner abstract class and several sub classes,

public abstract class Diner implements Runable{
    public Order order;
    public int arrivalTime;
}

public class NotSeatedDiner extends Diner {
    public void run () {
        // do something to find a seat
    }
}

// some other subclasses

in your main function, you can have

List diners = new ArrayList<Diner>();

//maybe some factory producing different diners

diners.add(fac.getDiner("not seated"));

for(Diner diner : diners){
    diner.run();
}


问:
Add a unique style class to each mySQL entry on page?
I have a php function to retrieve the three most recent entries to a table that holds news highlights. Here is my function:

```<code>function getHighlights(){
    return $this->query("
    SELECT *
    FROM `highlights`
    ORDER BY `inserted` DESC
    LIMIT 3
    ");

}
</code>```

These highlights are then placed on my homepage via a foreach loop. Here is my code:

```<code><?php foreach($highlights as $a){ ?>
     <div class="col-md-6 highlight">
                <div class="highlightItem">
                    <img class="highlight-backdrop" src="<?=$a->backdrop;?>">
                    <p class="highlight-title"><?=$a->title;?></p>
                </div>
     </div>
<?php } ?>
</code>```

I'd like for my homepage to ALWAYS be in this format:
News Highlight Format. However, the only reason it's in that format right now is because the images have predefined sizes that fit nicely together.

I want to be able to reference the most recent news highlight and set that image to always display as 300 x 210. I also want to reference the next two highlights and set them to always display as 300 x 100.

What's the best course of action for this?

答:
```<code><?php foreach($highlights as $index => $a){ ?>
     if($index == 0){
         <div class="col-md-6 highlight">
                <div class="highlightItem">
                    <img width="300" height="210" class="highlight-backdrop" src="<?=$a->backdrop;?>">
                    <p class="highlight-title"><?=$a->title;?></p>
                </div>
     </div>
     }else{
       <div class="col-md-6 highlight">
                <div class="highlightItem">
                    <img width="300" height="100" class="highlight-backdrop" src="<?=$a->backdrop;?>">
                    <p class="highlight-title"><?=$a->title;?></p>
                </div>
     </div>

     }

<?php } ?>
</code>```

try to use that code

Body:
I have a php function to retrieve the three most recent entries to a table that holds news highlights. Here is my function:

function getHighlights(){
    return $this->query("
    SELECT *
    FROM `highlights`
    ORDER BY `inserted` DESC
    LIMIT 3
    ");

}

These highlights are then placed on my homepage via a foreach loop. Here is my code:

<?php foreach($highlights as $a){ ?>

                    <img class="highlight-backdrop" src="<?=$a->backdrop;?>">

<?=$a->title;?>

<?php } ?>

I'd like for my homepage to ALWAYS be in this format:
News Highlight Format. However, the only reason it's in that format right now is because the images have predefined sizes that fit nicely together.

I want to be able to reference the most recent news highlight and set that image to always display as 300 x 210. I also want to reference the next two highlights and set them to always display as 300 x 100.

What's the best course of action for this?

Body:
<?php foreach($highlights as $index => $a){ ?>
     if($index == 0){
         <div class="col-md-6 highlight">
                <div class="highlightItem">
                    <img width="300" height="210" class="highlight-backdrop" src="<?=$a->backdrop;?>">
                    <p class="highlight-title"><?=$a->title;?></p>
                </div>
     </div>
     }else{
       <div class="col-md-6 highlight">
                <div class="highlightItem">
                    <img width="300" height="100" class="highlight-backdrop" src="<?=$a->backdrop;?>">
                    <p class="highlight-title"><?=$a->title;?></p>
                </div>
     </div>

     }

<?php } ?>

try to use that code


问:
Change color of items in appbar
I want to change the color of my app name, search icon and overflow menu in the appbar to white. I used textColorPrimary but its not working, it is all black.

Here is my code

colors.xml

```<code><resources>
    <color name="colorPrimary">#9C27B0</color>
    <color name="colorPrimaryDark">#CE93D8</color>
    <color name="textColorPrimary">#FFFFFF</color>
    <color name="windowBackground">#FFFFFF</color>
    <color name="navigationBarColor">#FFFFFF</color>
    <color name="colorAccent">#FF80AB</color>
</resource>
</code>```

styles.xml

```<code><style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="textColorPrimary">@color/textColorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
</code>```

AndroidManifest.xml

```<code>     <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme"
        android:label="@string/title_activity_welcome">
    </activity>
</code>```

menumain.xml

```<code>   <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_search"
        android:orderInCategory="100"
        android:title="@string/action_search"
        app:showAsAction="always" />

    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />

    </menu>
</code>```

This is what I want - A white text(app name), search icon(fixed,i used a white search icon so no problem) and white overflow menu

答:
Below theme will work

```<code> <style name="ToolbarThemeWhite" parent="@style/ThemeOverlay.AppCompat.ActionBar">
        <item name="colorControlNormal">@color/white</item>
        <item name="android:textColorPrimary">@color/white</item>
    </style>
</code>```

Use like

```<code>  <android.support.v7.widget.Toolbar
        ...
        app:theme="@style/ToolbarThemeWhite"
       ...
    />
</code>```

Title: Change color of items in appbar

Body:
I want to change the color of my app name, search icon and overflow menu in the appbar to white. I used textColorPrimary but its not working, it is all black.

Here is my code

colors.xml

<resources>
    <color name="colorPrimary">#9C27B0</color>
    <color name="colorPrimaryDark">#CE93D8</color>
    <color name="textColorPrimary">#FFFFFF</color>
    <color name="windowBackground">#FFFFFF</color>
    <color name="navigationBarColor">#FFFFFF</color>
    <color name="colorAccent">#FF80AB</color>
</resource>

styles.xml

AndroidManifest.xml

     <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme"
        android:label="@string/title_activity_welcome">
    </activity>

menumain.xml

   <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_search"
        android:orderInCategory="100"
        android:title="@string/action_search"
        app:showAsAction="always" />

    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />

    </menu>

This is what I want - A white text(app name), search icon(fixed,i used a white search icon so no problem) and white overflow menu

Body:
Below theme will work

 <style name="ToolbarThemeWhite" parent="@style/ThemeOverlay.AppCompat.ActionBar">
        <item name="colorControlNormal">@color/white</item>
        <item name="android:textColorPrimary">@color/white</item>
    </style>

Use like

  <android.support.v7.widget.Toolbar
        ...
        app:theme="@style/ToolbarThemeWhite"
       ...
    />


问:
How can an npm module provide its own Flow libdef out of the box?
I've written an npm module with Flow type annotations. Its .flowconfig file includes unsafe.enable_getters_and_setters=true because it uses getters and setters internally.

But the problem with that is anyone who depends on my module (and uses Flow themselves) is required to set the same option to avoid Flow complaining about my module when they type-check their project.

What I want to do (and what I'm hoping is possible) is to provide a libdef file out-of-the-box, and have this take precedence over my source code, so any dependent's Flow will only look at my libdef and will not look at my code and complain about the use of getters/setters.

Can someone explain how to do this? My guess would be that I'm supposed to create a .js.flow file corresponding with any .js file, and publish this with my module, and this would then take precedence and prevent Flow from looking in the original .js file. (And maybe it should be possible to even generate my .js.flow libdef file automatically..?) But I can't find any information on this.

The docs site is great, but it doesn't seem to explain how to do this. The single mention of the .js.flow file extension is a link to a JS alert('TODO') :)

答:
You can type your package and publish them here: https://github.com/flowtype/flow-typed. Using the flow-typed tool, you can generate a full stub for your package and then fill out the types.

Alternatively, if your package's main is say index.js and contains all your exports - you can create an index.js.flow and define types for all your exports there.


问:
PHP form validation failure
I am trying to do form field validation with php. I am checking if the submit button isset first and then if the form fields are empty, save it in a error variable, else if its not empty I have a function doing som form cleanup and setting the value to the textfield.Then submitted to another page.

But my error handling never happens and the form with empty fields are submitted to my action page url.

Whats wrong with code:

```<code> <html>
<head>
    <meta charset="UTF-8">
    <title></title>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
 <?php
 $fnameErr = "";
 $lnameErr = "";
 $Fname = "";
 $Lname = "";

if(isset($_POST["submit"])) {

if (empty($_POST["FirstName"])) {
$fnameErr = "First name is required";
} else {
$Fname = form_input($_POST["FirstName"]);
}

if (empty($_POST["LastName"])) {
$lnameErr = "Last name is required";
} else {
$Lname = form_input($_POST["LastName"]);
}

 }

function form_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
 ?>
 <h2>PHP Form Validation Example</h2>
  <p><span class="error">* required field.</span></p>
    <form action="intro.html.php" method="POST">
        Förnamn: <input type="text" name="FirstName">
        <span class="error">* <?php echo $fnameErr;?></span>
        <br>
        Efternamn: <input type="text" name="LastName">
        <span class="error">* <?php echo $lnameErr;?></span>
        <br>
        <input type="submit" name="submit" value="Skicka">
    </form>

    </body>
    </html>
</code>```

Thank you

答:
UPDATE

if file of action form is different with the form file you need to check the input on action.

here the index.php

```<code><html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .error {color: #FF0000;}
        </style>
    </head>
<body>
<?php
    /* get the return value when is not valid on into.html.php*/
    $fname = $_GET['fName']; $lname = $_GET['lName'];
    if($_GET['fName']=='false'){
        $fnameErr = "First name is required"; /*set value to show  notif*/
        $fname ="";
    }
    if($_GET['lName']=='false'){
        $lnameErr = "First name is required"; /*set value to show  notif*/
        $lname    ="";
    }
?>
<h2>PHP Form Validation Example</h2>
    <form action="intro.html.php" method="POST">
        Förnamn: <input type="text" name="FirstName" value="<?php echo $fname;?>">
        <span class="error">* <?php echo $fnameErr;?></span>
        <br>
        Efternamn: <input type="text" name="LastName" value="<?php echo $lname;?>">
        <span class="error">* <?php echo $lnameErr;?></span>
        <br>
        <input type="submit" name="submit" value="Skicka">
    </form>
    </body>
</html>
</code>```

and then set your intro.html.php like this

```<code><?php
function form_input($data) {
    if($data!=""){ /*add condition if data != "" then run so we don't need more else on section if $_POST is empty*/
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
    }
    return $data;
}

if(isset($_POST["submit"])) { /*check the submit*/

    $Fname = form_input($_POST["FirstName"]); /* get post data from input val to variable $Fname*/
    $Lname = form_input($_POST["LastName"]); /* get post data from input val to variable $Lname*/

    if(!empty($_POST["FirstName"]) and !empty($_POST["LastName"])!=""){ /*cek if FirstName and LasName is not empty*/
        /* do what you want to do here*/
        echo ' FName : '.$Fname.' | LName : '.$Lname;
    }
    else{
        /*we will redirect to index.php using javascript*/
        echo '
            <script>
            alert("all input must be field!");
            window.location.href="index.php?fName='.($_POST["FirstName"]==""?'false':$Fname).'&lName='.($_POST["LastName"]==""?'false':$Lname).'"; /* this ridect to index.php and set variable  $_GET fName and variable lName */
            </script>
        ';
    }

}
else{
    echo 'submit is undefined!'; /*echo submit empty, */
}

?>
</code>```

if you want to check input before submit, you can use HTML <input> required Attribute here the documentation

or you can use jquery to proses ajax submit or just check the input value you can see more in here

hope this help.

Title: PHP form validation failure

Body:
I am trying to do form field validation with php. I am checking if the submit button isset first and then if the form fields are empty, save it in a error variable, else if its not empty I have a function doing som form cleanup and setting the value to the textfield.Then submitted to another page.

But my error handling never happens and the form with empty fields are submitted to my action page url.

Whats wrong with code:

    <meta charset="UTF-8">
    <title></title>

 <?php
 $fnameErr = "";
 $lnameErr = "";
 $Fname = "";
 $Lname = "";

if(isset($_POST["submit"])) {

if (empty($_POST["FirstName"])) {
$fnameErr = "First name is required";
} else {
$Fname = form_input($_POST["FirstName"]);
}

if (empty($_POST["LastName"])) {
$lnameErr = "Last name is required";
} else {
$Lname = form_input($_POST["LastName"]);
}

 }

function form_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
 ?>

PHP Form Validation Example

* required field.

    <form action="intro.html.php" method="POST">
        Förnamn: <input type="text" name="FirstName">
        * <?php echo $fnameErr;?>

        Efternamn: <input type="text" name="LastName">
        * <?php echo $lnameErr;?>

        <input type="submit" name="submit" value="Skicka">
    </form>

Thank you

Body:
UPDATE

if file of action form is different with the form file you need to check the input on action.

here the index.php

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .error {color: #FF0000;}
        </style>
    </head>
<body>
<?php
    /* get the return value when is not valid on into.html.php*/
    $fname = $_GET['fName']; $lname = $_GET['lName'];
    if($_GET['fName']=='false'){
        $fnameErr = "First name is required"; /*set value to show  notif*/
        $fname ="";
    }
    if($_GET['lName']=='false'){
        $lnameErr = "First name is required"; /*set value to show  notif*/
        $lname    ="";
    }
?>
<h2>PHP Form Validation Example</h2>
    <form action="intro.html.php" method="POST">
        Förnamn: <input type="text" name="FirstName" value="<?php echo $fname;?>">
        <span class="error">* <?php echo $fnameErr;?></span>
        <br>
        Efternamn: <input type="text" name="LastName" value="<?php echo $lname;?>">
        <span class="error">* <?php echo $lnameErr;?></span>
        <br>
        <input type="submit" name="submit" value="Skicka">
    </form>
    </body>
</html>

and then set your intro.html.php like this

<?php
function form_input($data) {
    if($data!=""){ /*add condition if data != "" then run so we don't need more else on section if $_POST is empty*/
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
    }
    return $data;
}

if(isset($_POST["submit"])) { /*check the submit*/

    $Fname = form_input($_POST["FirstName"]); /* get post data from input val to variable $Fname*/
    $Lname = form_input($_POST["LastName"]); /* get post data from input val to variable $Lname*/

    if(!empty($_POST["FirstName"]) and !empty($_POST["LastName"])!=""){ /*cek if FirstName and LasName is not empty*/
        /* do what you want to do here*/
        echo ' FName : '.$Fname.' | LName : '.$Lname;
    }
    else{
        /*we will redirect to index.php using javascript*/
        echo '
            <script>
            alert("all input must be field!");
            window.location.href="index.php?fName='.($_POST["FirstName"]==""?'false':$Fname).'&lName='.($_POST["LastName"]==""?'false':$Lname).'"; /* this ridect to index.php and set variable  $_GET fName and variable lName */
            </script>
        ';
    }

}
else{
    echo 'submit is undefined!'; /*echo submit empty, */
}

?>

if you want to check input before submit, you can use HTML <input> required Attribute here the documentation

or you can use jquery to proses ajax submit or just check the input value you can see more in here

hope this help.


问:
How do you filter WHERE using a count?
Starting with this working query:

```<code>  MATCH (post:Post)<-[:AUTHOR]-(author:User)
  WHERE post.createdAt > { hotAfter } AND post.text =~ { keyword }
  MATCH (post)-[:HAS_COMMENT]->(comment:Comment)<-[:AUTHOR]-(commentAuthor:User)
  WITH post, author, count(DISTINCT commentAuthor) as participantsCount, count(comment) as commentsCount
  ORDER BY (participantsCount * commentsCount) DESC
  RETURN collect(post {.*, author, participantsCount, commentsCount})[0..{ LIMIT }] as posts
</code>```

I'd additionally like to filter the posts with number of comments that fit the criteria:

```<code>WHERE (count(DISTINCT commentAuthor) * count(comment)) <= { someNumber }
</code>```

But I am not sure where/how to apply this logic e.g. this is incorrect:

```<code>  MATCH (post:Post)<-[:AUTHOR]-(author:User)
  WHERE post.createdAt > { hotAfter } AND post.text =~ { keyword }
  MATCH (post)-[:HAS_COMMENT]->(comment:Comment)<-[:AUTHOR]-(commentAuthor:User)
  WHERE count(DISTINCT commentAuthor) * count(comment) <= 10
  WITH post, author, count(DISTINCT commentAuthor) as participantsCount, count(comment) as commentsCount
  ORDER BY (participantsCount * commentsCount) DESC
  RETURN collect(post {.*, author, participantsCount, commentsCount})[0..{ LIMIT }] as posts
</code>```

答:
Filtering on the collection at the end seems to work.</p>

```<code>  MATCH (post:Post)<-[:AUTHOR]-(author:User)
  WHERE post.createdAt > { hotAfter } AND post.text =~ { keyword }
  MATCH (post)-[:HAS_COMMENT]->(comment:Comment)<-[:AUTHOR]-(commentAuthor:User)
  WITH post, author, count(DISTINCT commentAuthor) as participantsCount, count(comment) as commentsCount
  ORDER BY (participantsCount * commentsCount) DESC
  RETURN filter (
    x in collect(post {.*, author, participantsCount, commentsCount})
    WHERE (x.participantsCount * x.commentsCount) <= { someNumber }
  )[0..{ LIMIT }] as posts
</code>```

Title: How do you filter WHERE using a count?

Body:
Starting with this working query:

  MATCH (post:Post)<-[:AUTHOR]-(author:User)
  WHERE post.createdAt > { hotAfter } AND post.text =~ { keyword }
  MATCH (post)-[:HAS_COMMENT]->(comment:Comment)<-[:AUTHOR]-(commentAuthor:User)
  WITH post, author, count(DISTINCT commentAuthor) as participantsCount, count(comment) as commentsCount
  ORDER BY (participantsCount * commentsCount) DESC
  RETURN collect(post {.*, author, participantsCount, commentsCount})[0..{ LIMIT }] as posts

I'd additionally like to filter the posts with number of comments that fit the criteria:

WHERE (count(DISTINCT commentAuthor) * count(comment)) <= { someNumber }

But I am not sure where/how to apply this logic e.g. this is incorrect:

  MATCH (post:Post)<-[:AUTHOR]-(author:User)
  WHERE post.createdAt > { hotAfter } AND post.text =~ { keyword }
  MATCH (post)-[:HAS_COMMENT]->(comment:Comment)<-[:AUTHOR]-(commentAuthor:User)
  WHERE count(DISTINCT commentAuthor) * count(comment) <= 10
  WITH post, author, count(DISTINCT commentAuthor) as participantsCount, count(comment) as commentsCount
  ORDER BY (participantsCount * commentsCount) DESC
  RETURN collect(post {.*, author, participantsCount, commentsCount})[0..{ LIMIT }] as posts

Body:
Filtering on the collection at the end seems to work.

  MATCH (post:Post)<-[:AUTHOR]-(author:User)
  WHERE post.createdAt > { hotAfter } AND post.text =~ { keyword }
  MATCH (post)-[:HAS_COMMENT]->(comment:Comment)<-[:AUTHOR]-(commentAuthor:User)
  WITH post, author, count(DISTINCT commentAuthor) as participantsCount, count(comment) as commentsCount
  ORDER BY (participantsCount * commentsCount) DESC
  RETURN filter (
    x in collect(post {.*, author, participantsCount, commentsCount})
    WHERE (x.participantsCount * x.commentsCount) <= { someNumber }
  )[0..{ LIMIT }] as posts