问:
Error "not mutually convertible in Unicode program" when adding line to table
I'm trying to add data from a internal table to a custom one.

```<code> DATA: BEGIN OF TMP_CTRYGRP_T OCCURS 1000,
  CTYGR TYPE /SAPSLL/CTYGR,
  TEXT1 TYPE /SAPSLL/TEXT60,
  END OF TMP_CTRYGRP_T.

SELECT ctygr, text1 FROM /SAPSLL/CTYGPT INTO TABLE @DATA(lt_countryGroupsTable)

LOOP AT lt_countryGroupsTable ASSIGNING FIELD-SYMBOL(<ls_countryGroups>).
  APPEND <ls_countryGroups> TO TMP_CTRYGRP_T.
ENDLOOP.
</code>```

Then I want to add the line in a custom Table Type ZZ_T_TAB

So I've tried to create a field-symbol of this table, creating an internal table from it, but none of the solutions I've tried was permitting me to add lines in that Custom table (even if the one in the program had the lines).

The problem I mainly encountered was:

are not mutually convertible in a Unicode program.

So my questions are:

Why does that error happen? Googling it didn't provide me an understandable answer

For the moment I'm using an internal table limited to 1000 rows. But I don't really know by advance the number of lines the search could provide. Is there any way to improve that?

How to add lines from any solution to my ZZ_T_TAB then? And afterwards how could I add other fields in the same table, for the rows already existing?

As some of you maybe understood, I'm quite a rookie in ABAP.
So if there's any useful link to understand all of that I would be happy if you can share it with me.

答:
Why don't you directly select into the table?

Don't use OCCURS as it is declared obsolete and already forbidden in classes.

Declare your own structure as type and mark your custom internal table as TYPE STANDARD TABLE OF struct_type. This way, there will be no upper bounds

```<code>TYPES:
BEGIN OF struct_type,
    CTYGR TYPE /SAPSLL/CTYGR,
    TEXT1 TYPE /SAPSLL/TEXT60,
END OF struct_type.

DATA tmp_ctrygrp_t TYPE STANDARD TABLE OF struct_type WITH EMPTY KEY.
</code>```

Body:
I'm trying to add data from a internal table to a custom one.

 DATA: BEGIN OF TMP_CTRYGRP_T OCCURS 1000,
  CTYGR TYPE /SAPSLL/CTYGR,
  TEXT1 TYPE /SAPSLL/TEXT60,
  END OF TMP_CTRYGRP_T.

SELECT ctygr, text1 FROM /SAPSLL/CTYGPT INTO TABLE @DATA(lt_countryGroupsTable)

LOOP AT lt_countryGroupsTable ASSIGNING FIELD-SYMBOL(<ls_countryGroups>).
  APPEND <ls_countryGroups> TO TMP_CTRYGRP_T.
ENDLOOP.

Then I want to add the line in a custom Table Type ZZ_T_TAB

So I've tried to create a field-symbol of this table, creating an internal table from it, but none of the solutions I've tried was permitting me to add lines in that Custom table (even if the one in the program had the lines).

The problem I mainly encountered was:

are not mutually convertible in a Unicode program.

So my questions are:

Why does that error happen? Googling it didn't provide me an understandable answer

For the moment I'm using an internal table limited to 1000 rows. But I don't really know by advance the number of lines the search could provide. Is there any way to improve that?

How to add lines from any solution to my ZZ_T_TAB then? And afterwards how could I add other fields in the same table, for the rows already existing?

As some of you maybe understood, I'm quite a rookie in ABAP.
So if there's any useful link to understand all of that I would be happy if you can share it with me.

Body:
Why don't you directly select into the table?

Don't use OCCURS as it is declared obsolete and already forbidden in classes.

Declare your own structure as type and mark your custom internal table as TYPE STANDARD TABLE OF struct_type. This way, there will be no upper bounds

TYPES:
BEGIN OF struct_type,
    CTYGR TYPE /SAPSLL/CTYGR,
    TEXT1 TYPE /SAPSLL/TEXT60,
END OF struct_type.

DATA tmp_ctrygrp_t TYPE STANDARD TABLE OF struct_type WITH EMPTY KEY.


来源: stackexchange

问:
If SQL Server ODBC driver times out, will it show as a long running query on the database side?
I have an application which uses a SQL Server ODBC driver to connect to a database. The driver is set to timeout after 5 seconds.

We have received timeouts on some insert statements, however the long running queries on the database are not picking up these timeouts.

If the driver is timing out the connection before the insert is complete, should the database be displaying these in the long running queries (in this case set to log any >2000 ms)? I notice that the ones that do appear say "Query Completed in x seconds", but there's nothing about incomplete queries.

Just wanted to rule this out before digging further into why they might be missing from the results.

Thanks

答: By doing some tests I found it doesn't record as a long running query unless the query is completed. All ODBC Driver timeouts returned no results in the long running queries.</p>

ContentLicense: CC BY-SA 3.0


问:
How to avoid to enter repeated number in input text form?
I'm trying past few days to solve input number form validation in javascript. The logic user doesn't allow to enter repeated same number like "00000000000", "11111111111". If they enter numbers on text field i have to show error message,

sample code,

```<code>var mobNumber = $('#phNo').val();

if(mobNumber.match("00000000") || mobNumber.match("1111111")) {
  alert('Please enter valid phone number');
}
</code>```

答:
You can simply write code like </p>

```<code>$(document).on('input', '#phNo', function() {
    var mobNumber = $(this).val();
    var res = mobNumber/(mobNumber/10);
    if(res == 111111111) {
      alert('Please enter valid phone number');
    }
});
</code>```

<p>this  is applicable for all numbers and you have to check the max and min length of the input .. </p>

Body:
I'm trying past few days to solve input number form validation in javascript. The logic user doesn't allow to enter repeated same number like "00000000000", "11111111111". If they enter numbers on text field i have to show error message,

sample code,

var mobNumber = $('#phNo').val();

if(mobNumber.match("00000000") || mobNumber.match("1111111")) {
  alert('Please enter valid phone number');
}

Body:
You can simply write code like

$(document).on('input', '#phNo', function() {
    var mobNumber = $(this).val();
    var res = mobNumber/(mobNumber/10);
    if(res == 111111111) {
      alert('Please enter valid phone number');
    }
});

this  is applicable for all numbers and you have to check the max and min length of the input ..


问:
setLightTouchEnabled(false); deprecated - alternative?
I have an app with a webview. I want to make the onclick highlight transparent.

setLightTouchEnabled(false); is deprecated now. Are there any alternatives?

I tried adding the -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
in the css, without any luck.

A link to an image that illustrates the issue:

Button onclick highlight

答:
Option 1:

```<code>Webview.requestFocus(View.FOCUS_DOWN|View.FOCUS_UP);

Webview.getSettings().setLightTouchEnabled(true);
</code>```

or Option 2:

```<code>mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
       switch (event.getAction()) {
           case MotionEvent.ACTION_DOWN:
           case MotionEvent.ACTION_UP:
               if (!v.hasFocus()) {
                   v.requestFocus();
               }
               break;
       }
       return false;
    }
});
</code>```

Body:
Option 1:

Webview.requestFocus(View.FOCUS_DOWN|View.FOCUS_UP);

Webview.getSettings().setLightTouchEnabled(true);

or Option 2:

mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
       switch (event.getAction()) {
           case MotionEvent.ACTION_DOWN:
           case MotionEvent.ACTION_UP:
               if (!v.hasFocus()) {
                   v.requestFocus();
               }
               break;
       }
       return false;
    }
});


问:
sqlsvr driver problems
I am trying to connect Azure database with PHP. I installed sqlsrv driver. It also appears in phpinfo as PDO drivers = mysql, sqlite, sqlsrv.

However, the below code is not working:

```<code>$serverName = "xduuewepx4.database.windows.net";

$connectionOptions = array("Database" => "master",

                           "UID" => "intelligaia",

                           "PWD" => "Maporamic7",

                           "MultipleActiveResultSets" => false);

$conn = sqlsrv_connect($serverName, $connectionOptions);

if($conn === false)

{

     die(print_r(sqlsrv_errors(), true));

}
</code>```

The reported error is:

Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www\test.php on line 20

Looking for your support.

答: The SQLSRV driver has two interfaces. If you want to use the PDO driver, you have to use regular PDO functions; the sqlsrv_connect() connect function belongs to the other API you are not planning to use.

Title: sqlsvr driver problems

Body:
I am trying to connect Azure database with PHP. I installed sqlsrv driver. It also appears in phpinfo as PDO drivers = mysql, sqlite, sqlsrv.

However, the below code is not working:

$serverName = "xduuewepx4.database.windows.net";

$connectionOptions = array("Database" => "master",

                           "UID" => "intelligaia",

                           "PWD" => "Maporamic7",

                           "MultipleActiveResultSets" => false);

$conn = sqlsrv_connect($serverName, $connectionOptions);

if($conn === false)

{

     die(print_r(sqlsrv_errors(), true));

}

The reported error is:

Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www\test.php on line 20

Looking for your support.

ContentLicense: CC BY-SA 2.5


问:
Sql query to combine multiple rows
I have a table as follows

|Cutomers|Orders|Items|
 |Cutomer1|Order1|Item1|
 |Cutomer1|Order1|Item2|
 |Cutomer1|Order1|Item3|
 |Cutomer1|Order2|Item1|
 |Cutomer1|Order2|Item3|
 |Cutomer1|Order2|Item4|
 |Cutomer2|Order1|Item6|
 |   .    |  .   |  .  |
 |   .    |  .   |  .  |
 |   .    |  .   |  .  |

I want to have the following table, seems like easy but i have no clue how to deal with it.

|Customers|Items|
 |Customer1|Item1|
 |Customer1|Item2|
 |Customer1|Item3|
 |Customer1|Item4|
 |Customer2|Item6|
 |   .     |   . |
 |   .     |   . |
 |   .     |   . |

Any suggestions are very much appreciated!

答:
I think this would suffice</p>

```<code>select  distinct Customers, Items
from    YourTable
</code>```

Title: Sql query to combine multiple rows

Body:
I think this would suffice

select  distinct Customers, Items
from    YourTable


问:
Two values can't be printed correctly (python3.5+numba+CUDA8.0)
There is an array, I'll do some calculation with it in GPU.

Before my calculation, I should get the subsets of this array.

When I print the subsets, find two values are not right.

The code is as follows:

```<code>import os,sys,time
import pandas as pd
import numpy as np

from numba import cuda, float32

os.environ['NUMBAPRO_NVVM']=r'D:\NVIDIA GPU Computing Toolkit\CUDA\v8.0\nvvm\bin\nvvm64_31_0.dll'
os.environ['NUMBAPRO_LIBDEVICE']=r'D:\NVIDIA GPU Computing Toolkit\CUDA\v8.0\nvvm\libdevice'

bpg = (3,1)
tpb = (2,2)

@cuda.jit
def calcu_TE(D,TE):
    gw = cuda.gridDim.x

    bx = cuda.blockIdx.x

    tx = cuda.threadIdx.x
    bw = cuda.blockDim.x
    ty = cuda.threadIdx.y
    bh = cuda.blockDim.y

    c_num = D.shape[0]
    #print(c_num)
    c_index = bx
    while c_index<c_num*c_num:
        c_x = int(c_index/c_num)
        c_y = c_index%c_num
        if c_x==c_y:
            TE[0] = 0.0
        else:
            X = D[c_x,:]
            Y = D[c_y,:]
            if bx==1 :
                print('c_index,bx,tx,ty,X: ',c_index,bx,tx,ty,'  ',X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7],X[8],X[9])
                print('c_index,bx,tx,ty,Y: ',c_index,bx,tx,ty,'  ',Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],Y[8],Y[9])
            #print('c_index,bx,tx,ty,Y: ',c_index,bx,tx,ty,Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],Y[8],Y[9])
            h = tx
            if h==0:
                Xi = X[1:]
                Xi1 = X[:-1]
                Yi = Y[1:]
                if bx==1 :
                    print('bx,tx,ty: ',bx,tx,ty,'\n Xi',Xi[0],Xi[1],Xi[2],Xi[3],Xi[4],Xi[5],Xi[6],Xi[7],Xi[8],
                          '\n Xi1',Xi1[0],Xi1[1],Xi1[2],Xi1[3],Xi1[4],Xi1[5],Xi1[6],Xi1[7],Xi1[8],
                          '\n Yi',Yi[0],Yi[1],Yi[2],Yi[3],Yi[4],Yi[5],Yi[6],Yi[7],Yi[8])
        c_index +=gw

D = np.array([[ 0.42487645,0.41607881,0.42027071,0.43751907,0.43512794,0.43656972,0.43940639,0.43864551,0.43447691,0.43120232],
              [2.989578,2.834707,2.942902,3.294948,2.868170,2.975180,3.066900,2.712719,2.835360,2.607334]], dtype=np.float32)
TE = np.empty([1,1])
print('D: ',D)

stream = cuda.stream()
with stream.auto_synchronize():
    dD = cuda.to_device(D, stream)
    dTE = cuda.to_device(TE, stream)
    calcu_TE[bpg, tpb, stream](dD,dTE)
</code>```

The output is:

```<code>D:  [[ 0.42487645  0.41607881  0.42027071  0.43751907  0.43512794  0.43656972
   0.43940639  0.43864551  0.43447691  0.43120232]
 [ 2.98957801  2.83470702  2.94290209  3.2949481   2.86817002  2.97517991
   3.06690001  2.71271896  2.83536005  2.6073339 ]]
c_index,bx,tx,ty,X:  1 1 0 0    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,X:  1 1 1 0    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,X:  1 1 0 1    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,X:  1 1 1 1    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,Y:  1 1 0 0    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334
c_index,bx,tx,ty,Y:  1 1 1 0    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334
c_index,bx,tx,ty,Y:  1 1 0 1    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334
c_index,bx,tx,ty,Y:  1 1 1 1    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334

bx,tx,ty:  1 0 0
 Xi 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
 Xi1 0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477
 Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 0.000000 18949972373983835000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
bx,tx,ty:  1 0 1
 Xi 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
 Xi1 0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477
 Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 0.000000 18949972373983835000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
</code>```

It's so strange.

Yi should be Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334.

But it was printed Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 0.000000 18949972373983835000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000.

There are two values wrong.

I do't know why it happened. Is there anything I ignored?

答:
This would appear to be a problem with the way the Numba compiler is producing code for the very long print statement in your kernel, and nothing to do with the correctness of your kernel. If you change the code like this (i.e. make the print statement shorter):

```<code>@cuda.jit
def calcu_TE(D,TE):
    gw = cuda.gridDim.x

    bx = cuda.blockIdx.x

    tx = cuda.threadIdx.x
    bw = cuda.blockDim.x
    ty = cuda.threadIdx.y
    bh = cuda.blockDim.y

    c_num = D.shape[0]
    c_index = bx
    while c_index<c_num*c_num:
        c_x = int(c_index/c_num)
        c_y = c_index%c_num
        if c_x==c_y:
            TE[0] = 0.0
        else:
            X = D[c_x,:]
            Y = D[c_y,:]
            if bx==1 :
                print('c_index,bx,tx,ty,X: ',c_index,bx,tx,ty,'  ',X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7],X[8],X[9])
                print('c_index,bx,tx,ty,Y: ',c_index,bx,tx,ty,'  ',Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],Y[8],Y[9])
            h = tx
            if h==0:
                Xi = X[1:]
                Xi1 = X[:-1]
                Yi = Y[1:]
                if bx==1 :
                    print('bx,tx,ty,Yi:',bx,tx,ty,'  ',Yi[0],Yi[1],Yi[2],Yi[3],Yi[4],Yi[5],Yi[6],Yi[7],Yi[8])
        c_index +=gw
</code>```

You should find that Yi is printed correctly. In general, relying on print statements to instrument kernels in CUDA is a rather poor idea, and often you will only confuse yourself by doing so, as in this case.

Body:
There is an array, I'll do some calculation with it in GPU.

Before my calculation, I should get the subsets of this array.

When I print the subsets, find two values are not right.

The code is as follows:

import os,sys,time
import pandas as pd
import numpy as np

from numba import cuda, float32

os.environ['NUMBAPRO_NVVM']=r'D:\NVIDIA GPU Computing Toolkit\CUDA\v8.0\nvvm\bin\nvvm64_31_0.dll'
os.environ['NUMBAPRO_LIBDEVICE']=r'D:\NVIDIA GPU Computing Toolkit\CUDA\v8.0\nvvm\libdevice'

bpg = (3,1)
tpb = (2,2)

@cuda.jit
def calcu_TE(D,TE):
    gw = cuda.gridDim.x

    bx = cuda.blockIdx.x

    tx = cuda.threadIdx.x
    bw = cuda.blockDim.x
    ty = cuda.threadIdx.y
    bh = cuda.blockDim.y

    c_num = D.shape[0]
    #print(c_num)
    c_index = bx
    while c_index<c_num*c_num:
        c_x = int(c_index/c_num)
        c_y = c_index%c_num
        if c_x==c_y:
            TE[0] = 0.0
        else:
            X = D[c_x,:]
            Y = D[c_y,:]
            if bx==1 :
                print('c_index,bx,tx,ty,X: ',c_index,bx,tx,ty,'  ',X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7],X[8],X[9])
                print('c_index,bx,tx,ty,Y: ',c_index,bx,tx,ty,'  ',Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],Y[8],Y[9])
            #print('c_index,bx,tx,ty,Y: ',c_index,bx,tx,ty,Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],Y[8],Y[9])
            h = tx
            if h==0:
                Xi = X[1:]
                Xi1 = X[:-1]
                Yi = Y[1:]
                if bx==1 :
                    print('bx,tx,ty: ',bx,tx,ty,'\n Xi',Xi[0],Xi[1],Xi[2],Xi[3],Xi[4],Xi[5],Xi[6],Xi[7],Xi[8],
                          '\n Xi1',Xi1[0],Xi1[1],Xi1[2],Xi1[3],Xi1[4],Xi1[5],Xi1[6],Xi1[7],Xi1[8],
                          '\n Yi',Yi[0],Yi[1],Yi[2],Yi[3],Yi[4],Yi[5],Yi[6],Yi[7],Yi[8])
        c_index +=gw

D = np.array([[ 0.42487645,0.41607881,0.42027071,0.43751907,0.43512794,0.43656972,0.43940639,0.43864551,0.43447691,0.43120232],
              [2.989578,2.834707,2.942902,3.294948,2.868170,2.975180,3.066900,2.712719,2.835360,2.607334]], dtype=np.float32)
TE = np.empty([1,1])
print('D: ',D)

stream = cuda.stream()
with stream.auto_synchronize():
    dD = cuda.to_device(D, stream)
    dTE = cuda.to_device(TE, stream)
    calcu_TE[bpg, tpb, stream](dD,dTE)

The output is:

D:  [[ 0.42487645  0.41607881  0.42027071  0.43751907  0.43512794  0.43656972
   0.43940639  0.43864551  0.43447691  0.43120232]
 [ 2.98957801  2.83470702  2.94290209  3.2949481   2.86817002  2.97517991
   3.06690001  2.71271896  2.83536005  2.6073339 ]]
c_index,bx,tx,ty,X:  1 1 0 0    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,X:  1 1 1 0    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,X:  1 1 0 1    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,X:  1 1 1 1    0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
c_index,bx,tx,ty,Y:  1 1 0 0    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334
c_index,bx,tx,ty,Y:  1 1 1 0    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334
c_index,bx,tx,ty,Y:  1 1 0 1    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334
c_index,bx,tx,ty,Y:  1 1 1 1    2.989578 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334

bx,tx,ty:  1 0 0
 Xi 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
 Xi1 0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477
 Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 0.000000 18949972373983835000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
bx,tx,ty:  1 0 1
 Xi 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477 0.431202
 Xi1 0.424876 0.416079 0.420271 0.437519 0.435128 0.436570 0.439406 0.438646 0.434477
 Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 0.000000 18949972373983835000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000

It's so strange.

Yi should be Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 2.835360 2.607334.

But it was printed Yi 2.834707 2.942902 3.294948 2.868170 2.975180 3.066900 2.712719 0.000000 18949972373983835000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000.

There are two values wrong.

I do't know why it happened. Is there anything I ignored?

Body:
This would appear to be a problem with the way the Numba compiler is producing code for the very long print statement in your kernel, and nothing to do with the correctness of your kernel. If you change the code like this (i.e. make the print statement shorter):

@cuda.jit
def calcu_TE(D,TE):
    gw = cuda.gridDim.x

    bx = cuda.blockIdx.x

    tx = cuda.threadIdx.x
    bw = cuda.blockDim.x
    ty = cuda.threadIdx.y
    bh = cuda.blockDim.y

    c_num = D.shape[0]
    c_index = bx
    while c_index<c_num*c_num:
        c_x = int(c_index/c_num)
        c_y = c_index%c_num
        if c_x==c_y:
            TE[0] = 0.0
        else:
            X = D[c_x,:]
            Y = D[c_y,:]
            if bx==1 :
                print('c_index,bx,tx,ty,X: ',c_index,bx,tx,ty,'  ',X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7],X[8],X[9])
                print('c_index,bx,tx,ty,Y: ',c_index,bx,tx,ty,'  ',Y[0],Y[1],Y[2],Y[3],Y[4],Y[5],Y[6],Y[7],Y[8],Y[9])
            h = tx
            if h==0:
                Xi = X[1:]
                Xi1 = X[:-1]
                Yi = Y[1:]
                if bx==1 :
                    print('bx,tx,ty,Yi:',bx,tx,ty,'  ',Yi[0],Yi[1],Yi[2],Yi[3],Yi[4],Yi[5],Yi[6],Yi[7],Yi[8])
        c_index +=gw

You should find that Yi is printed correctly. In general, relying on print statements to instrument kernels in CUDA is a rather poor idea, and often you will only confuse yourself by doing so, as in this case.


问:
Get start and End location and Date Sql server 2012
i want to convert this query to start GRP to End Grp and Start Date to End date.

```<code>select * from (
 select z.ZoneGroupId, zs.ObjectId,z.Name,case when zs.Inside=0 then 'Left' else 'Entered' end Crossing ,zs.TimeFirst
from  zs join
 z on zs.Zid=z.Zid
where zs.ObjectId=5696 and    z.ZoneGroupId in (1095,1096) and convert(date,zs.TimeFirst)>='2016/07/01'     ) s
where   (ZoneGroupId=1096 and s.Crossing='Entered') or (ZoneGroupId=1095 and s.Crossing='Left')
</code>```

2 table involve in query

table Z

```<code>  Zid(int)   Name(varchar)  ZoneGroupId (int)
   59         Oil            1095
   60         ENR            1096
   61         NRL            1096
</code>```

table Zs

```<code>  zsid(int)  zid(int)  ObjectId(int)   Timefirst(datetime)  Inside(boolan)

    1         60         1988           2016-07-01 00:39      1
    2         59         1988           2016-07-05 15:47      0
    3         61         1988           2016-07-06 22:54      1
    4         59         1988           2016-07-09 13:40      0
    5         60         1988           2016-07-10 07:58      1
    6         59         1988           2016-07-13 10:30      0
    7         59         1988           2016-09-10 10:21      0
    8         59         1990           2016-07-05 15:47      0
    9         61         1990           2016-07-06 22:54      1
</code>```

the result which i required from above query

```<code>  ZoneGroupId   ObjectId  Name   Crossing         TimeFirst
    1096        1988      ENR     Entered        2016-07-01 00:39
    1095        1988      Oil     Left           2016-07-05 15:47
    1096        1988      NRL     Entered        2016-07-06 22:54
    1095        1988      Oil     Left           2016-07-09 13:40
    1096        1988      ENR     Entered        2016-07-10 07:58
    1095        1988      Oil     Left           2016-07-13 10:30
    1095        1988      Oil     Left           2016-09-10 10:21
    1095        1990      Oil     Left           2016-07-05 15:47
    1096        1990      NRL     Entered        2016-07-06 22:54
</code>```

required result

```<code> ObjectId  StartName     StartDate            EndName     EndDate
 1988      Null           Null                 ENR      2016-07-01 00:39
 1988      Oil          2016-07-05 15:47       NRL      2016-7-06 22:54
 1988      Oil          2016-07-09 13:40       ENR      2016-07-10 07:58
 1988      Oil          2016-07-13 10:30       Null        Null
 1988      Oil          2016-09-10 10:21       Null        Null
 1988      Oil          2016-07-05 15:47       NRL      2016-7-06 22:54
</code>```

答:
First your sample data - please include this in your question in future.

```<code>declare @z table (Zid int, Name nvarchar(3), ZoneGroupId int);
insert into @z values
(59, 'Oil', 1095),
(60, 'ENR', 1096),
(61, 'NRL', 1096);

declare @zs table(zsid int, zid int, ObjectId  int, Timefirst datetime, Inside bit);
insert into @zs values
(   1, 60, 1988,   '2016-07-01 00:39', 1),
(    2, 59, 1988,   '2016-07-05 15:47', 0 ),
(    3, 61, 1988,   '2016-07-06 22:54', 1 ),
(    4, 59, 1988,   '2016-07-09 13:40', 0 ),
(    5, 60, 1988,   '2016-07-10 07:58', 1 ),
(    6, 59, 1988,   '2016-07-13 10:30', 0 ),
(    7, 59, 1988,   '2016-09-10 10:21', 0  ),
(    8, 59, 1990,   '2016-07-05 15:47', 0 ),
(    9, 61, 1990,   '2016-07-06 22:54', 1 );
</code>```

Then, I split the data into 2 tables, left and entered by using common-table-expressions. Add in a row number to put them in order by time.

Join the tables back together with a full outer join (to get all rows from both sides). The specify the following criteria on the join:

ObjectIds match

Entered.TimeFirst is the smallest one that is bigger than Left.TimeFirst

Left.TimeFirst is the largest one that is smaller than entered.TimeFirst

I also added an order by for clarity. Here is the query.

```<code>with entered as (
    select z.ZoneGroupId
         , zs.ObjectId
         , z.Name
         , 'Entered' Crossing
         , zs.TimeFirst
         , ROW_NUMBER() over (partition by ObjectID order by zs.TimeFirst) row_no
    from @zs zs
    inner join @z z on zs.Zid=z.Zid
    where zs.Inside <> 0 and (z.ZoneGroupId = 1096 and convert(date,zs.TimeFirst)>='2016/07/01')
), [left] as (
    select z.ZoneGroupId
         , zs.ObjectId
         , z.Name
         , 'Left' Crossing
         , zs.TimeFirst
         , ROW_NUMBER() over (partition by ObjectID order by zs.TimeFirst) row_no
    from @zs zs
    inner join @z z on zs.Zid=z.Zid
    where zs.Inside = 0 and (z.ZoneGroupId = 1095 and convert(date,zs.TimeFirst)>='2016/07/01')
)
select *
from [left]
full outer join entered
    on entered.row_no = (select MIN(row_no) from entered e
                          where e.TimeFirst > [left].TimeFirst
                          and e.ObjectId = [left].ObjectId)
    and [left].row_no = (select max(row_no) from [left] l
                          where l.TimeFirst < entered.TimeFirst
                          and l.ObjectId = entered.ObjectId)
    and [left].ObjectId = [entered].ObjectId
order by isnull([left].ObjectId,entered.ObjectId), ISNULL([left].TimeFirst,entered.TimeFirst)
</code>```

Body:
i want to convert this query to start GRP to End Grp and Start Date to End date.

select * from (
 select z.ZoneGroupId, zs.ObjectId,z.Name,case when zs.Inside=0 then 'Left' else 'Entered' end Crossing ,zs.TimeFirst
from  zs join
 z on zs.Zid=z.Zid
where zs.ObjectId=5696 and    z.ZoneGroupId in (1095,1096) and convert(date,zs.TimeFirst)>='2016/07/01'     ) s
where   (ZoneGroupId=1096 and s.Crossing='Entered') or (ZoneGroupId=1095 and s.Crossing='Left')

2 table involve in query

table Z

  Zid(int)   Name(varchar)  ZoneGroupId (int)
   59         Oil            1095
   60         ENR            1096
   61         NRL            1096

table Zs

  zsid(int)  zid(int)  ObjectId(int)   Timefirst(datetime)  Inside(boolan)

    1         60         1988           2016-07-01 00:39      1
    2         59         1988           2016-07-05 15:47      0
    3         61         1988           2016-07-06 22:54      1
    4         59         1988           2016-07-09 13:40      0
    5         60         1988           2016-07-10 07:58      1
    6         59         1988           2016-07-13 10:30      0
    7         59         1988           2016-09-10 10:21      0
    8         59         1990           2016-07-05 15:47      0
    9         61         1990           2016-07-06 22:54      1

the result which i required from above query

  ZoneGroupId   ObjectId  Name   Crossing         TimeFirst
    1096        1988      ENR     Entered        2016-07-01 00:39
    1095        1988      Oil     Left           2016-07-05 15:47
    1096        1988      NRL     Entered        2016-07-06 22:54
    1095        1988      Oil     Left           2016-07-09 13:40
    1096        1988      ENR     Entered        2016-07-10 07:58
    1095        1988      Oil     Left           2016-07-13 10:30
    1095        1988      Oil     Left           2016-09-10 10:21
    1095        1990      Oil     Left           2016-07-05 15:47
    1096        1990      NRL     Entered        2016-07-06 22:54

required result

 ObjectId  StartName     StartDate            EndName     EndDate
 1988      Null           Null                 ENR      2016-07-01 00:39
 1988      Oil          2016-07-05 15:47       NRL      2016-7-06 22:54
 1988      Oil          2016-07-09 13:40       ENR      2016-07-10 07:58
 1988      Oil          2016-07-13 10:30       Null        Null
 1988      Oil          2016-09-10 10:21       Null        Null
 1988      Oil          2016-07-05 15:47       NRL      2016-7-06 22:54

Body:
First your sample data - please include this in your question in future.

declare @z table (Zid int, Name nvarchar(3), ZoneGroupId int);
insert into @z values
(59, 'Oil', 1095),
(60, 'ENR', 1096),
(61, 'NRL', 1096);

declare @zs table(zsid int, zid int, ObjectId  int, Timefirst datetime, Inside bit);
insert into @zs values
(   1, 60, 1988,   '2016-07-01 00:39', 1),
(    2, 59, 1988,   '2016-07-05 15:47', 0 ),
(    3, 61, 1988,   '2016-07-06 22:54', 1 ),
(    4, 59, 1988,   '2016-07-09 13:40', 0 ),
(    5, 60, 1988,   '2016-07-10 07:58', 1 ),
(    6, 59, 1988,   '2016-07-13 10:30', 0 ),
(    7, 59, 1988,   '2016-09-10 10:21', 0  ),
(    8, 59, 1990,   '2016-07-05 15:47', 0 ),
(    9, 61, 1990,   '2016-07-06 22:54', 1 );

Then, I split the data into 2 tables, left and entered by using common-table-expressions. Add in a row number to put them in order by time.

Join the tables back together with a full outer join (to get all rows from both sides). The specify the following criteria on the join:

ObjectIds match

Entered.TimeFirst is the smallest one that is bigger than Left.TimeFirst

Left.TimeFirst is the largest one that is smaller than entered.TimeFirst

I also added an order by for clarity. Here is the query.

with entered as (
    select z.ZoneGroupId
         , zs.ObjectId
         , z.Name
         , 'Entered' Crossing
         , zs.TimeFirst
         , ROW_NUMBER() over (partition by ObjectID order by zs.TimeFirst) row_no
    from @zs zs
    inner join @z z on zs.Zid=z.Zid
    where zs.Inside <> 0 and (z.ZoneGroupId = 1096 and convert(date,zs.TimeFirst)>='2016/07/01')
), [left] as (
    select z.ZoneGroupId
         , zs.ObjectId
         , z.Name
         , 'Left' Crossing
         , zs.TimeFirst
         , ROW_NUMBER() over (partition by ObjectID order by zs.TimeFirst) row_no
    from @zs zs
    inner join @z z on zs.Zid=z.Zid
    where zs.Inside = 0 and (z.ZoneGroupId = 1095 and convert(date,zs.TimeFirst)>='2016/07/01')
)
select *
from [left]
full outer join entered
    on entered.row_no = (select MIN(row_no) from entered e
                          where e.TimeFirst > [left].TimeFirst
                          and e.ObjectId = [left].ObjectId)
    and [left].row_no = (select max(row_no) from [left] l
                          where l.TimeFirst < entered.TimeFirst
                          and l.ObjectId = entered.ObjectId)
    and [left].ObjectId = [entered].ObjectId
order by isnull([left].ObjectId,entered.ObjectId), ISNULL([left].TimeFirst,entered.TimeFirst)


问:
Wordpress The theme directory "a191f36de8a8e87d91a0a36d98a869cab74cc49f~default" does not exist
i am having a website dawrkawn.com but when i try to crustimize the theme from dashboard i am getting this error. im using a wordpess, kindly help

The theme directory "a191f36de8a8e87d91a0a36d98a869cab74cc49f~default" does not exist.

答: You can check the permision of folder with theme. For example set it to 777 (temporarily). Also reload the permalinks.</p>


问:
Correct place to read and write from stdin/stderr/stdout of external process which should be terminated within timeout
I have the java application which starts external process through process builder.

External application interracts with rest "world" through stdin,stdout,stderr. Also this process should not be executed longer than some timeout.

code looks like this:

```<code>ProcessBuilder pb = new ProcessBuilder(parameters);
Process process = pb.start();
OutputStream processOutputStream = process.getOutputStream();
IOUtils.write(inputJson, processOutputStream); // write data to external process
processOutputStream.close(); we don't need pass more arguments

InputStream errorStream = process.getErrorStream();

boolean responseWithinTimeout = process.waitFor(2000, TimeUnit.MILLISECONDS); //app should work not longer than 2 sec
if (process.isAlive()) {
    process.destroyForcibly();
}
String stringFromErrorStream = IOUtils.toString(errorStream, "UTF-8"); //read from external application error stream
</code>```

My questions:

Does 2000 niliseconds starts sincepb.start() or since  process.waitFor

Is it correct to read from  errorStream when application already killed or it should be placed before process.destroyForcibly()?

答:
Does 2000 milliseconds starts sincepb.start()

No.

or since process.waitFor()

Yes.

Is it correct to read from errorStream when application already killed

No.

or it should be placed before process.destroyForcibly()?

Yes. Best in a separate thread. You should also consume the process's stdout. Otherwise it can block.

Body:
I have the java application which starts external process through process builder.

External application interracts with rest "world" through stdin,stdout,stderr. Also this process should not be executed longer than some timeout.

code looks like this:

ProcessBuilder pb = new ProcessBuilder(parameters);
Process process = pb.start();
OutputStream processOutputStream = process.getOutputStream();
IOUtils.write(inputJson, processOutputStream); // write data to external process
processOutputStream.close(); we don't need pass more arguments

InputStream errorStream = process.getErrorStream();

boolean responseWithinTimeout = process.waitFor(2000, TimeUnit.MILLISECONDS); //app should work not longer than 2 sec
if (process.isAlive()) {
    process.destroyForcibly();
}
String stringFromErrorStream = IOUtils.toString(errorStream, "UTF-8"); //read from external application error stream

My questions:

Does 2000 niliseconds starts sincepb.start() or since  process.waitFor

Is it correct to read from  errorStream when application already killed or it should be placed before process.destroyForcibly()?


问:
Provide fallback symbol for dynamic linking
When dynamically linking a library is there a way to specify a fallback symbol in case one is missing at load time.

For example compiling a MEX file instead of mxCreateNumericArray I'd like to call mxCreateUninitNumericArray (with same signature). But the latter won't be present for older MATLAB versions. Same for mxArrayToString and mxArrayToUTF8String.

For MSVC I've been able to use /DELAYLOAD and hook into __pfnDliFailureHook2 on dliFailGetProc to provide a simple mapping. But what can I do on Unix based systems?

How to hook into libld in a similar way?

答:
I've not been able to hook into the dynamic linker, but providing weak symbols helped me out like this: </p>

```<code>extern "C"
char * __attribute__ ((weak)) mxArrayToUTF8String( mxArray const * array )
{
  return mxArrayToString( array ) ;
}
</code>```

Body:
I've not been able to hook into the dynamic linker, but providing weak symbols helped me out like this:

extern "C"
char * __attribute__ ((weak)) mxArrayToUTF8String( mxArray const * array )
{
  return mxArrayToString( array ) ;
}


答:
From Oracle 11gR2, the LISTAGG clause should do the trick:

```<code>SELECT customers,
       LISTAGG(items, ',') WITHIN GROUP (ORDER BY items)
FROM YOUR_TABLE
GROUP BY customers;
</code>```

try this, it might work

you can also wm_concat

```<code>SELECT customers, wm_concat(items) as item
FROM   table
GROUP BY customers;
</code>```

it might also work

for my sql,

```<code>select  distinct customers, items from tablename
</code>```

Title: Sql query to combine multiple rows

Body:
I have a table as follows

|Cutomers|Orders|Items|
 |Cutomer1|Order1|Item1|
 |Cutomer1|Order1|Item2|
 |Cutomer1|Order1|Item3|
 |Cutomer1|Order2|Item1|
 |Cutomer1|Order2|Item3|
 |Cutomer1|Order2|Item4|
 |Cutomer2|Order1|Item6|
 |   .    |  .   |  .  |
 |   .    |  .   |  .  |
 |   .    |  .   |  .  |

I want to have the following table, seems like easy but i have no clue how to deal with it.

|Customers|Items|
 |Customer1|Item1|
 |Customer1|Item2|
 |Customer1|Item3|
 |Customer1|Item4|
 |Customer2|Item6|
 |   .     |   . |
 |   .     |   . |
 |   .     |   . |

Any suggestions are very much appreciated!

Body:
From Oracle 11gR2, the LISTAGG clause should do the trick:

SELECT customers,
       LISTAGG(items, ',') WITHIN GROUP (ORDER BY items)
FROM YOUR_TABLE
GROUP BY customers;

try this, it might work

you can also wm_concat

SELECT customers, wm_concat(items) as item
FROM   table
GROUP BY customers;

it might also work

for my sql,

select  distinct customers, items from tablename


问:
Can a main method in Java return something?
I went through an interview recently and they ask me two questions in core Java.

Q 1.

Can we write a java class with:

```<code>public static int main(String[] args){
     System.out.println("Hello");
</code>```

I answered: No. The compiler won't compile it as it is expecting the return type of main to be int, though we can overload it.

Q 2: The next question I was unable to answer.

Write a program so that your Java main method could return something.

I.e. how can you make public static void main([] args) to return something?

Can any body help me to answer this?

答:
Yes, we can write main method with a return type other than void. This simply means that we can overload our main method. Some examples are

public static void main(String ... x){  }

public static int main(String []args){  }

public static void main(string array[]){ }

But, note here that the compiler will only know

```<code>public static void main(String []args){ }
</code>```

If above method is not present it will not compile.

Body:
I went through an interview recently and they ask me two questions in core Java.

Q 1.

Can we write a java class with:

public static int main(String[] args){
     System.out.println("Hello");

I answered: No. The compiler won't compile it as it is expecting the return type of main to be int, though we can overload it.

Q 2: The next question I was unable to answer.

Write a program so that your Java main method could return something.

I.e. how can you make public static void main([] args) to return something?

Can any body help me to answer this?

Body:
Yes, we can write main method with a return type other than void. This simply means that we can overload our main method. Some examples are

public static void main(String ... x){  }

public static int main(String []args){  }

public static void main(string array[]){ }

But, note here that the compiler will only know

public static void main(String []args){ }

If above method is not present it will not compile.


问:
Why is this div appearing above the  even though it's below it in the code?
See pics for quick viewing of issue: (http://prnt.sc/eqo56d) (http://prnt.sc/eqo6ab)

Website: http://match.onesquad.nl/

I've made sure all tags are closed in all templates using the footer as well as the footer itself:

```<code><div class="footer">
    <div class="personeel group">
        <div class="container group">
            <?php echo do_shortcode("[insert page='accountmanagers']");
            ?>
        </div>
    </div>
    <div class="nieuws group">
        <div class="container">
            <?php echo do_shortcode("[insert page='nieuws-front-page']"); ?>
        </div>
    </div>
    <footer class="group">
        <div class="container">
            <div class="row">
                <section class="col-lg-4 col-md-4 col-sm-12">
                    <div class="sectie first">
                        <h3>Over ons</h3>
                        <div class="row">
                            <section class="col-xs-12 col-sm-6">
                                <div class="kolom">
                                    <ul>
                                        <li>Over Match</li>
                                        <li>Accountmanagers</li>
                                        <li>Vormen van bemiddeling</li>
                                        <li>Kwaliteit</li>
                                    </ul>
                                </div>
                            </section>
                            <section class="col-xs-12 col-sm-6">
                                <div class="kolom">
                                    <ul>
                                        <li>Branches</li>
                                        <li>Certicering</li>
                                        <li>Match holding</li>
                                        <li>Contact</li>
                                    </ul>
                                </div>
                            </section>
                        </div>
                    </div>
                </section>
                <section class="col-lg-4 col-md-4 col-sm-12">
                    <div class="sectie second">
                        <h3>Bedrijven</h3>
                        <ul>
                            <li>Arbeidskrachten</li>
                            <li>Vacature plaatsen</li>
                            <li>Vormen van bemiddeling</li>
                        </ul>
                    </div>
                </section>
                <section class="col-lg-4 col-md-4 col-sm-12">
                    <div class="sectie third">
                        <h3>Baan zoeken</h3>
                        <div class="row">
                            <section class="col-xs-12 col-sm-6">
                                <div class="kolom">
                                    <ul>
                                        <li>Vacatures</li>
                                        <li>Inschrijven</li>
                                        <li>Werken bij Match</li>
                                        <li>Snel aan de slag</li>
                                    </ul>
                                </div>
                            </section>
                            <section class="col-xs-12 col-sm-6">
                                <div class="kolom">
                                    <ul>
                                        <li>Vormen van bemiddeling</li>
                                        <li>CV uploaden</li>
                                    </ul>
                                </div>
                            </section>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </footer>
    <div class="copyright">
        <p>Copyright 2017 - Match | Sitemap | Webdesign One Squad</p>
    </div>
</div>

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

Many thanks.

答:
It's because you have floated your footer right.  Add clear:right to your .copyright class and it will push the copyright below the footer

More information on clearing floats

Title: Why is this div appearing above the <footer> even though it's below it in the code?

Body:
See pics for quick viewing of issue: (http://prnt.sc/eqo56d) (http://prnt.sc/eqo6ab)

Website: http://match.onesquad.nl/

I've made sure all tags are closed in all templates using the footer as well as the footer itself:

            <?php echo do_shortcode("[insert page='accountmanagers']");
            ?>

            <?php echo do_shortcode("[insert page='nieuws-front-page']"); ?>

Over ons

Over Match

Accountmanagers

Vormen van bemiddeling

Kwaliteit

Branches

Certicering

Match holding

Contact

Bedrijven

Arbeidskrachten

Vacature plaatsen

Vormen van bemiddeling

Baan zoeken

Vacatures

Inschrijven

Werken bij Match

Snel aan de slag

Vormen van bemiddeling

CV uploaden

Copyright 2017 - Match | Sitemap | Webdesign One Squad

Many thanks.


问:
Same text but nonzero diff
I have two files, the contents of which are exactly same as it appears to my eyes, however, the diff of both shows all lines being different, the reason i suspect has something to do with character format/encoding but i am not sure.

The output of "file --mime" on both is same.

Can someone enlighten me on whats going on? and how could i possibly change one form to another, some command/tool.

答: Maybe line endings? Try dos2unix and unix2dos.

Title: Same text but nonzero diff


问:
Grunt not including javascript file
This is an angular app. I have a bower.json with a lot of libraries put like this:

```<code>"dependencies": {
    "angular": "^1.4.0",
    "bootstrap": "^3.2.0",
    ...
    "angular-socket-io": "^0.7.0",
    "socket.io-client": "^1.7.2"
</code>```

I run

```<code>bower install
</code>```

and I can see that in the "bower_components"-folder there are folders and files for both "angular-socket-io" and "socket.io-client".

When I then run this command:

```<code>grunt serve
</code>```

I can see that this one is included:

```<code><script src="bower_components/angular-socket-io/socket.js"></script>
</code>```

However, I cannot find any trace of "socket.io-client". Why? Am I supposed to include this manually? I wonder why then. All the other bower cmopoenents are beeing added autmatically of "grunt serve".

PS: This causes the error "io is not defined" when I try to instantiate a socket frmo a factory.

答:
I guess it was an issue with versions.
Im running angular 1.4.
Having this line:

"socket.io-client": "^0.7.10",

seems made the trick. Before I used latest version of socket.io-client (1.7). And I got incompatibility error.
But now the socket-client is being loaded.

Title: Grunt not including javascript file

Body:
This is an angular app. I have a bower.json with a lot of libraries put like this:

"dependencies": {
    "angular": "^1.4.0",
    "bootstrap": "^3.2.0",
    ...
    "angular-socket-io": "^0.7.0",
    "socket.io-client": "^1.7.2"

I run

bower install

and I can see that in the "bower_components"-folder there are folders and files for both "angular-socket-io" and "socket.io-client".

When I then run this command:

grunt serve

I can see that this one is included:

However, I cannot find any trace of "socket.io-client". Why? Am I supposed to include this manually? I wonder why then. All the other bower cmopoenents are beeing added autmatically of "grunt serve".

PS: This causes the error "io is not defined" when I try to instantiate a socket frmo a factory.


问:
tfidfvectorizer prints results based on all words
Though there are six different words. There are only 5 words printed in the result. How to get result based on all words  (6 columns vector)?

```<code>from sklearn.feature_extraction.text import TfidfVectorizer
sent=["This is a sample", "This is another example"]
tf = TfidfVectorizer(analyzer='word', ngram_range=(1,1), min_df = 0)
tfidf_matrix =  tf.fit_transform(sent)
print tfidf_matrix.toarray()
</code>```

[[ 0.          0.          0.50154891  0.70490949  0.50154891]  [
  0.57615236  0.57615236  0.40993715  0.          0.40993715]]

Also how to print the column details (features (words)) and row (document) ?

答:
You are using the default token_pattern, which only selects tokens of 2 or more char.

token_pattern :

“token”, only used if analyzer == 'word'. The default regexp selects
  tokens of 2 or more alphanumeric characters (punctuation is completely
  ignored and always treated as a token separator)

If you define a new token_pattern, you will get the 'a' character, e.g.:

```<code>from sklearn.feature_extraction.text import TfidfVectorizer
sent=["This is a sample", "This is another example"]
tf = TfidfVectorizer(token_pattern=u'(?u)\\b\\w+\\b')
tfidf_matrix =  tf.fit_transform(sent)
print tfidf_matrix.toarray()
tf.vocabulary_
</code>```

[[ 0.57615236  0.          0.          0.40993715  0.57615236  0.40993715]
 [ 0.          0.57615236  0.57615236  0.40993715  0.          0.40993715]]

```<code>tf.vocabulary_
</code>```

{u'a': 0, u'sample': 4, u'another': 1, u'this': 5, u'is': 3, u'example': 2}

Body:
Though there are six different words. There are only 5 words printed in the result. How to get result based on all words  (6 columns vector)?

from sklearn.feature_extraction.text import TfidfVectorizer
sent=["This is a sample", "This is another example"]
tf = TfidfVectorizer(analyzer='word', ngram_range=(1,1), min_df = 0)
tfidf_matrix =  tf.fit_transform(sent)
print tfidf_matrix.toarray()

[[ 0.          0.          0.50154891  0.70490949  0.50154891]  [
  0.57615236  0.57615236  0.40993715  0.          0.40993715]]

Also how to print the column details (features (words)) and row (document) ?

Body:
You are using the default token_pattern, which only selects tokens of 2 or more char.

token_pattern :

“token”, only used if analyzer == 'word'. The default regexp selects
  tokens of 2 or more alphanumeric characters (punctuation is completely
  ignored and always treated as a token separator)

If you define a new token_pattern, you will get the 'a' character, e.g.:

from sklearn.feature_extraction.text import TfidfVectorizer
sent=["This is a sample", "This is another example"]
tf = TfidfVectorizer(token_pattern=u'(?u)\\b\\w+\\b')
tfidf_matrix =  tf.fit_transform(sent)
print tfidf_matrix.toarray()
tf.vocabulary_

[[ 0.57615236  0.          0.          0.40993715  0.57615236  0.40993715]
 [ 0.          0.57615236  0.57615236  0.40993715  0.          0.40993715]]

tf.vocabulary_

{u'a': 0, u'sample': 4, u'another': 1, u'this': 5, u'is': 3, u'example': 2}


问:
Excel VBA: There must be a better way to use a loop to delete rows based on cell contents
A report produces a sheet that looks like this:

Format is inherited from source data, data is in cols A, D and G, with A merging ABC, D merging DEF and G on its own.

I want to keep only the lines highlighted in blue. I want the macro to check the contents of G:G and if Cell.Text = "" then entirerow.delete, else leave it alone.

Only problem is when it deletes row 2, then row 3 becomes row 2, meaning that it doesn't delete it, because it's already checked row 2. What was row 4 now becomes row 3, which is the next one to check, and it sees that text is there and doesn't delete, moves on to row four, deletes it, row 5 becomes row 4, remains unchecked, it moves on to row 6 (now row 5), sees that's blank, deletes it, but row 7 now becomes row 6 and isn't deleted... and so on.

The only way I've found around it is to use GOTO to restart the loop, then to use another GOTO to get out of the loop early. I appreciate that probably isn't the most elegant solution.

```<code>iRange = Application.Workbooks(2).Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1
Debug.Print (iRange)

RestartLoop:

For Each rCell In Application.Workbooks(2).Worksheets(2).Range("G2:G" & iRange)

    If Not rCell.Offset(0, -3).Value = "" Then

        If rCell.Text = "" Then
            Debug.Print (rCell.Address)
            rCell.EntireRow.Delete
            GoTo RestartLoop
        End If

    Else0

        GoTo LeaveLoop

    End If
Next rCell

LeaveLoop:
'Do the next thing
</code>```

(code is Option Explicit: Dim iRange As Integer Dim rCell as Range in declarations at top of code)

Here's the debug.print:

```<code>26
$G$2
$G$2
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$4
$G$4
$G$4
$G$4
$G$4
$G$6
$G$6
$G$7
</code>```

If anyone knows of a solution, and can also explain it for a layman, I'd appreciate it. The solution needs to be dynamic, because the original sheet produced is a different length each time, with a different number of blank and blue cells each time.

I have searched around a little but either I'm not understanding the answers fully, or they seem to give me the same problem.

答:
Have a look at the below, it works by building up a range from the cells which match your criteria then deleting all of them in one go. When testing this always do it on a copy of your original to make sure results are as expected before making it permanent

```<code>Dim DeleteRng As Range

Application.ScreenUpdating = False

IRange = Application.Workbooks(2).Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1

Debug.Print IRange

' This is dangerous, select workbook using ThisWorkbook, or setting the workbook to a variable
' Not just using the number, this could change when opening other workbooks as well
' Similar with above when setting IRange
For Each rcell In Application.Workbooks(2).Worksheets(2).Range("G2:G" & IRange)
    If Not rcell.Offset(0, -3).value = vbNullString And rcell.Text = vbNullString Then
        If DeleteRng Is Nothing Then
            Set DeleteRng = rcell
        Else
            Set DeleteRng = Union(DeleteRng, rcell)
        End If
    End If
Next rcell
Debug.Print DeleteRng.Address
DeleteRng.EntireRow.Delete

Application.ScreenUpdating = True
</code>```

Body:
A report produces a sheet that looks like this:

Format is inherited from source data, data is in cols A, D and G, with A merging ABC, D merging DEF and G on its own.

I want to keep only the lines highlighted in blue. I want the macro to check the contents of G:G and if Cell.Text = "" then entirerow.delete, else leave it alone.

Only problem is when it deletes row 2, then row 3 becomes row 2, meaning that it doesn't delete it, because it's already checked row 2. What was row 4 now becomes row 3, which is the next one to check, and it sees that text is there and doesn't delete, moves on to row four, deletes it, row 5 becomes row 4, remains unchecked, it moves on to row 6 (now row 5), sees that's blank, deletes it, but row 7 now becomes row 6 and isn't deleted... and so on.

The only way I've found around it is to use GOTO to restart the loop, then to use another GOTO to get out of the loop early. I appreciate that probably isn't the most elegant solution.

iRange = Application.Workbooks(2).Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1
Debug.Print (iRange)

RestartLoop:

For Each rCell In Application.Workbooks(2).Worksheets(2).Range("G2:G" & iRange)

    If Not rCell.Offset(0, -3).Value = "" Then

        If rCell.Text = "" Then
            Debug.Print (rCell.Address)
            rCell.EntireRow.Delete
            GoTo RestartLoop
        End If

    Else0

        GoTo LeaveLoop

    End If
Next rCell

LeaveLoop:
'Do the next thing

(code is Option Explicit: Dim iRange As Integer Dim rCell as Range in declarations at top of code)

Here's the debug.print:

26
$G$2
$G$2
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$3
$G$4
$G$4
$G$4
$G$4
$G$4
$G$6
$G$6
$G$7

If anyone knows of a solution, and can also explain it for a layman, I'd appreciate it. The solution needs to be dynamic, because the original sheet produced is a different length each time, with a different number of blank and blue cells each time.

I have searched around a little but either I'm not understanding the answers fully, or they seem to give me the same problem.

Body:
Have a look at the below, it works by building up a range from the cells which match your criteria then deleting all of them in one go. When testing this always do it on a copy of your original to make sure results are as expected before making it permanent

Dim DeleteRng As Range

Application.ScreenUpdating = False

IRange = Application.Workbooks(2).Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1

Debug.Print IRange

' This is dangerous, select workbook using ThisWorkbook, or setting the workbook to a variable
' Not just using the number, this could change when opening other workbooks as well
' Similar with above when setting IRange
For Each rcell In Application.Workbooks(2).Worksheets(2).Range("G2:G" & IRange)
    If Not rcell.Offset(0, -3).value = vbNullString And rcell.Text = vbNullString Then
        If DeleteRng Is Nothing Then
            Set DeleteRng = rcell
        Else
            Set DeleteRng = Union(DeleteRng, rcell)
        End If
    End If
Next rcell
Debug.Print DeleteRng.Address
DeleteRng.EntireRow.Delete

Application.ScreenUpdating = True


问:
Title text size of Toolbar
I am using Toolbar on which i set title text.but for different screen i have define different title text size using style.
but the problem is when i run this on phone which screen is mdpi the title text size is OK but for the screen of tablet mdpi the Title is looking too small
this is my style

```<code><style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
        <item name="android:textSize">15dp</item>
        <item name="android:textStyle">bold</item>
    </style>
</code>```

this is toolbar.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="50dp"

    app:titleTextAppearance="@style/Toolbar.TitleText"
    android:subtitleTextAppearance="@style/AppTheme.Toolbar.SubTitle"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</code>```

i have declared this style in all folder like style.xml(mdpi),style.xml(hdpi),style.xml(xhdpi) with diffrenttext size.
so please help me how to set text size of title so it look good on both phone and tablet

答:
in all dimens.xml

```<code><dimen name="myTextSize">xxxxxsp</dimen>
</code>```

in values/style.xml

```<code><style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">@dimen/myTextSize</item>
</style>
</code>```

Title: Title text size of Toolbar

Body:
I am using Toolbar on which i set title text.but for different screen i have define different title text size using style.
but the problem is when i run this on phone which screen is mdpi the title text size is OK but for the screen of tablet mdpi the Title is looking too small
this is my style

this is toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="50dp"

    app:titleTextAppearance="@style/Toolbar.TitleText"
    android:subtitleTextAppearance="@style/AppTheme.Toolbar.SubTitle"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

i have declared this style in all folder like style.xml(mdpi),style.xml(hdpi),style.xml(xhdpi) with diffrenttext size.
so please help me how to set text size of title so it look good on both phone and tablet

Body:
in all dimens.xml

<dimen name="myTextSize">xxxxxsp</dimen>

in values/style.xml

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">@dimen/myTextSize</item>
</style>


问:
Set properties to jsf managed-bean
Have following first .jsf:

```<code><ui:repeat var="prod" value="#{showProducts.decoys}">
     <h:form>
       {prod.price}
       {prod.weight}
       {prod.size} >
    <h:commandButton value="Buy" action="shoppingCart"/>
    </h:form>
</ui:repeat>
</code>```

Have following shoppingCart.jsf:

```<code><h:form>
 <h:dataTable value="#{prod}">
  <h:column>
   #{prod.name}<br/>
  </h:column>
  <h:column>
   #{prod.price}<br/>
  </h:column>
  <h:column>
   <h:inputText value="#{prod.count}" size="3"/>
  </h:column>
</h:dataTable>
<h:inputText value="#{order.phone}"/><br/>
<h:inputText value="#{order.mail}"><br/>
<h:inputText value="#{order.city}"/><br/>
<h:commandButton value="Order" action="#{showProducts.persistOrder}">
</h:form>
</code>```

Faces-config:

```<code>    <managed-bean>
        <managed-bean-name>showProducts</managed-bean-name>
            <managed-bean-class>main.ShowProducts</managed-bean-class>
            <managed-bean-scope>session</managed-bean-scope>
...
            <managed-property>
               <property-name>product</property-name>
               <value>#{product}</value>
            </managed-property>
        </managed-bean>

    <managed-bean>
        <managed-bean-name>product</managed-bean-name>
        <managed-bean-class>main.Product</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
...
</code>```

The problem:

managed bean name defined as product

iteration goes this way(shoppingCart.jsf):

h:dataTable value="#{prod}">

so it means that this iteration is not connected with bean named product anyhow

How to set properties prod.price,prod.weight,prod.count to real managed bean properties:

```<code>product.price,product.weight,product.size
</code>```

答:
There are two problems:

You aren't setting a specific prod in the session scoped bean. You should do this.

```<code><h:commandButton value="Buy" action="shoppingCart">
    <f:setPropertyActionListener target="#{showProducts.product}" value="#{prod}" />
</h:commandButton>
</code>```

By the way, the managed-property declaration only sets an new/empty bean as property during parent bean's ceration. This is not necessarily the same prod instance as you have in the ui:repeat. You can just remove the #{product} bean from your faces-config.xml.

The h:dataTable doesn't make any sense here. You need h:panelGrid here.

```<code><h:panelGrid columns="3">
    <h:outputText value="#{showProducts.product.name}" />
    <h:outputText value="#{showProducts.product.price}" />
    <h:outputText value="#{showProducts.product.count}" />
</h:panelGrid>
</code>```

Title: Set properties to jsf managed-bean

Body:
Have following first .jsf:

<ui:repeat var="prod" value="#{showProducts.decoys}">
     <h:form>
       {prod.price}
       {prod.weight}
       {prod.size} >
    <h:commandButton value="Buy" action="shoppingCart"/>
    </h:form>
</ui:repeat>

Have following shoppingCart.jsf:

<h:form>
 <h:dataTable value="#{prod}">
  <h:column>
   #{prod.name}

  </h:column>
  <h:column>
   #{prod.price}

  </h:column>
  <h:column>
   <h:inputText value="#{prod.count}" size="3"/>
  </h:column>
</h:dataTable>
<h:inputText value="#{order.phone}"/>

<h:inputText value="#{order.mail}">

<h:inputText value="#{order.city}"/>

<h:commandButton value="Order" action="#{showProducts.persistOrder}">
</h:form>

Faces-config:

    <managed-bean>
        <managed-bean-name>showProducts</managed-bean-name>
            <managed-bean-class>main.ShowProducts</managed-bean-class>
            <managed-bean-scope>session</managed-bean-scope>
...
            <managed-property>
               <property-name>product</property-name>
               <value>#{product}</value>
            </managed-property>
        </managed-bean>

    <managed-bean>
        <managed-bean-name>product</managed-bean-name>
        <managed-bean-class>main.Product</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
...

The problem:

managed bean name defined as product

iteration goes this way(shoppingCart.jsf):

h:dataTable value="#{prod}">

so it means that this iteration is not connected with bean named product anyhow

How to set properties prod.price,prod.weight,prod.count to real managed bean properties:

product.price,product.weight,product.size

Body:
There are two problems:

You aren't setting a specific prod in the session scoped bean. You should do this.

<h:commandButton value="Buy" action="shoppingCart">
    <f:setPropertyActionListener target="#{showProducts.product}" value="#{prod}" />
</h:commandButton>

By the way, the managed-property declaration only sets an new/empty bean as property during parent bean's ceration. This is not necessarily the same prod instance as you have in the ui:repeat. You can just remove the #{product} bean from your faces-config.xml.

The h:dataTable doesn't make any sense here. You need h:panelGrid here.

<h:panelGrid columns="3">
    <h:outputText value="#{showProducts.product.name}" />
    <h:outputText value="#{showProducts.product.price}" />
    <h:outputText value="#{showProducts.product.count}" />
</h:panelGrid>


问:
Angular CLI ERROR in Cannot read property 'loadChildren' of null
I'm converting a project to use angular cli and everything is working (once it's build) but i've got a weird behaviour during build.

with ng serve
I always get this error the first time I try: ERROR in Cannot read property 'loadChildren' of null

with ng build throws the same error

but if I use ng build --watch
and after the first build fails and I edit a file to trigger the build again it will succeed. I've got also the same behaviour with ng build -prod --watch

Any ideas how to get the build right the first time?

please note that I do not have any child routes/modules in my project and I don't have any other output to see what is causing this.

Update: tested with child routes and I still get the same behaviour

Update: downgraded @angular libs to 2.4.0 from 4.0.0 and I still get the exact same behaviour, but with a different error message;

ERROR in AppModule is not an NgModule

答:
I had multiple ts files for my routes and what I did was import all those routes in my app.routes and then concat them all together to call forRoot:

export const appRoutes = xRoutes.concat(zRoutes) etc

after putting all my routes in one single file/export const statement the error/weird build behaviour disappeared.


问:
Generate signed apk android studio
I am new to android development and just finished my first app. I want to generate a signed apk in android studio. I read the developer docs but couldn't understand the steps. When I click on Build>Generate Signed APK..., it shows me a dialog box asking the following:

```<code>Keystore path  //with two options create new and choose existing
Keystore password
Key alias
key password
</code>```

I don't get what is keystore even after googling it. When I choose create new it asks me to select a path and locate a .jks file which I don't have! Can anyone please explain and list the steps in order to generate a signed apk.

答:
Official Android Documentation on the matter at hand with a step-by-step guide included on how to generate signed APK keys in Android Studio and even on how to setup the automatic APK key generation in a Gradle build.

https://developer.android.com/studio/publish/app-signing.html

Look under the chapter: Sign your release build

Title: Generate signed apk android studio

Body:
I am new to android development and just finished my first app. I want to generate a signed apk in android studio. I read the developer docs but couldn't understand the steps. When I click on Build>Generate Signed APK..., it shows me a dialog box asking the following:

Keystore path  //with two options create new and choose existing
Keystore password
Key alias
key password

I don't get what is keystore even after googling it. When I choose create new it asks me to select a path and locate a .jks file which I don't have! Can anyone please explain and list the steps in order to generate a signed apk.


问:
Thymeleaf: add HTML to th:replace function
I would like to add some HTML in the th:replace function in Thymeleaf, like so:

```<code><div th:replace="elements/listview :: row (subtext='Test<br />Test')" ></div>
</code>```

My 'listview' template is like this:

```<code> <div class="listview-row" th:fragment="row">
            <span class="listview-subtext" th:if="${subtext != null}" th:utext="${subtext}">

            </span>
        </div>
</code>```

It doesn't compile. Of course I want it to compile as:

```<code> <div class="listview-row">
            <span class="listview-subtext">
                Test<br />Test
            </span>
        </div>
</code>```

.. with the HTML in place. Is there any way to do that? Thank you in advance for any help.

答:
Try this:

```
</div>
</div>
</p>

<p>and use it like this:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><div th:replace="elements/listview :: row ('Test<br />Test')" ></div></code>```

Body:
I would like to add some HTML in the th:replace function in Thymeleaf, like so:

My 'listview' template is like this:

It doesn't compile. Of course I want it to compile as:

                Test
Test

.. with the HTML in place. Is there any way to do that? Thank you in advance for any help.

Body:
Try this:

<div class="listview-row" th:fragment="row(subtext)">
            <span class="listview-subtext" th:if="${subtext != null}" th:utext="${subtext}">

            </span>
        </div>

and use it like this:

<div th:replace="elements/listview :: row ('Test<br />Test')" ></div>


问:
Python Access odbc and should skip the row
I am using MS Access to import the table information. Table is below:

```<code>Field1   Field2
U1a14    High Speed Link
U0001    Medium speed data
U0022    Low Speed Link
</code>```

My code value is like: code = U1a14
code = U0001
code = B11DB (This code is not present in table)

I am connecting to odbc and searching for code in table.

```<code>connection = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;SafeTransactions=0;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:\PYTHON27;DBQ=C:\PYTHON27\iso14229dtcs.mdb;')
cursor1 = connection.cursor()
cursor1.execute("SELECT Field2 FROM Table Where Field1 = '{}'".format(code))

for row in cursor1.fetchone():
  print row
</code>```

I am getting error:

```<code>error:
for row in cursor1.fetchone():
TypeError: 'NoneType' object is not iterable
</code>```

How Can I fix it, If the code is not present in my Table, it should skip and print only existing row

答:
Change the code to the following, check cursor1.fetchone() is not NULL.

```<code>    connection = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;SafeTransactions=0;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:\PYTHON27;DBQ=C:\PYTHON27\iso14229dtcs.mdb;')
    cursor1 = connection.cursor()
    cursor1.execute("SELECT Field2 FROM Table Where Field1 = '{}'".format(code))
    row = cursor1.fetchone()
    while row is not None:
        print row[0], row[1]
        row = cursor1.fetchone()
    cursor1.close()
    connection.close()
</code>```

Body:
I am using MS Access to import the table information. Table is below:

Field1   Field2
U1a14    High Speed Link
U0001    Medium speed data
U0022    Low Speed Link

My code value is like: code = U1a14
code = U0001
code = B11DB (This code is not present in table)

I am connecting to odbc and searching for code in table.

connection = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;SafeTransactions=0;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:\PYTHON27;DBQ=C:\PYTHON27\iso14229dtcs.mdb;')
cursor1 = connection.cursor()
cursor1.execute("SELECT Field2 FROM Table Where Field1 = '{}'".format(code))

for row in cursor1.fetchone():
  print row

I am getting error:

error:
for row in cursor1.fetchone():
TypeError: 'NoneType' object is not iterable

How Can I fix it, If the code is not present in my Table, it should skip and print only existing row

Body:
Change the code to the following, check cursor1.fetchone() is not NULL.

    connection = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;SafeTransactions=0;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:\PYTHON27;DBQ=C:\PYTHON27\iso14229dtcs.mdb;')
    cursor1 = connection.cursor()
    cursor1.execute("SELECT Field2 FROM Table Where Field1 = '{}'".format(code))
    row = cursor1.fetchone()
    while row is not None:
        print row[0], row[1]
        row = cursor1.fetchone()
    cursor1.close()
    connection.close()


问:
Common libraries in a large team
Assume you have five products, and all of them use one or more of the company's internal libraries, written by individual developers.

It sounds simple but in practice, I found it to be very difficult to maintain.

How do you deal with the following scenarios:

A developer unintentionally introduces a bug and breaks everything in production.

Every library has to mature, That means the API needs to evolve, so how do you deploy the updated version to production if every developer needs to update/test their code while they are extremely busy on other projects? Is this a resource and time issue?

Version control, deployment,and usage. Would you store this in one global location or force each project to use, say, svn:externals to "tie" a library?

I've found that it is extremely hard to come up with a good strategy. My own pet theory is this:

Each common library has to have a super-thorough set of tests or else it should never be common, even if it means someone else duplicates the effort. Duplicate untested code is better than common untested code (you break only one project).

Each common library has to have a dedicated maintainer (can be offset by a really good test suite in a smaller team).

Each project should check out the version of the library that is known to work with it. This means a developer does not have to get pulled away to update API usage, as the common code gets updated. Which it will be. Every non-trivial piece of code evolves over months and years.

Thank you for your thoughts on this!

答:
"Duplication is the root of all evil"

Sounds to me like you need:

An artifact repository like Ivy so you can have the libraries shared and versioned with a distinction between versions that are API stable and ones that are "maturing"

Tests for the libraries

Tests for the projects using them

A continuous integration system so that when an incompatibility or bug is introduced both the project and the original library developer are notified

OwnerDisplayName: Andrei

Title: Common libraries in a large team

LastEditorDisplayName: Roger Lipscombe

OwnerDisplayName: Jeffrey Fredrick


问:
Rails 3. Live searching
I am developing a "live search" in Rails 3 using the below guide. I am just a bit afraid that this "query by type" will be very heavy on the database server (I am using Heroku).
Is searching like this a big no-no or do you guys think it will be ok, even if I got 500 users? Any input is good! Thanks!</p>

答: You may want to use a full-text search engine like Sphinx. Look at this Railscast episode to learn more.</p>

Title: Rails 3. Live searching


问:
Is it possible to do a 'normalized' dense_rank() in hive?
I have a consumer table like so.

```<code>consumer | product | quantity
-------- | ------- | --------
a        | x       | 3
a        | y       | 4
a        | z       | 1
b        | x       | 3
b        | y       | 5
c        | x       | 4
</code>```

What I want is a 'normalized' rank assigned to each consumer so that I can split the table easily for testing and training. I used the dense_rank() in hive, so I got the below table.

```<code>rank | consumer | product | quantity
---- | -------- | ------- | --------
1    | a        | x       | 3
1    | a        | y       | 4
1    | a        | z       | 1
2    | b        | x       | 3
2    | b        | y       | 5
3    | c        | x       | 4
</code>```

This is well and good, but I want to scale this to use with any number of consumers, so I would ideally like the range of ranks between 0 and 1, like so.

```<code>rank | consumer | product | quantity
---- | -------- | ------- | --------
0.33 | a        | x       | 3
0.33 | a        | y       | 4
0.33 | a        | z       | 1
0.67 | b        | x       | 3
0.67 | b        | y       | 5
1    | c        | x       | 4
</code>```

This way, I'd always know what the range of ranks is, and can split the data in a standard way (rank <= 0.7 training, and rank > 0.7 testing)

Is there a way to achieve this in hive?

Or, is there a different and better approach to my original issue of splitting the data?

I tried to do a select * where rank < 0.7*max(rank), but hive says the MAX UDAF is not yet available in where clause.

Body:
I have a consumer table like so.

consumer | product | quantity
-------- | ------- | --------
a        | x       | 3
a        | y       | 4
a        | z       | 1
b        | x       | 3
b        | y       | 5
c        | x       | 4

What I want is a 'normalized' rank assigned to each consumer so that I can split the table easily for testing and training. I used the dense_rank() in hive, so I got the below table.

rank | consumer | product | quantity
---- | -------- | ------- | --------
1    | a        | x       | 3
1    | a        | y       | 4
1    | a        | z       | 1
2    | b        | x       | 3
2    | b        | y       | 5
3    | c        | x       | 4

This is well and good, but I want to scale this to use with any number of consumers, so I would ideally like the range of ranks between 0 and 1, like so.

rank | consumer | product | quantity
---- | -------- | ------- | --------
0.33 | a        | x       | 3
0.33 | a        | y       | 4
0.33 | a        | z       | 1
0.67 | b        | x       | 3
0.67 | b        | y       | 5
1    | c        | x       | 4

This way, I'd always know what the range of ranks is, and can split the data in a standard way (rank <= 0.7 training, and rank > 0.7 testing)

Is there a way to achieve this in hive?

Or, is there a different and better approach to my original issue of splitting the data?

I tried to do a select * where rank < 0.7*max(rank), but hive says the MAX UDAF is not yet available in where clause.

Body:
percent_rank

select  percent_rank() over (order by consumer) as pr
       ,*

from    mytable
;

+-----+----------+---------+----------+
| pr  | consumer | product | quantity |
+-----+----------+---------+----------+
| 0.0 | a        | z       |        1 |
| 0.0 | a        | y       |        4 |
| 0.0 | a        | x       |        3 |
| 0.6 | b        | y       |        5 |
| 0.6 | b        | x       |        3 |
| 1.0 | c        | x       |        4 |
+-----+----------+---------+----------+

For filtering you'll need a sub-query / CTE

select  *

from   (select  percent_rank() over (order by consumer) as pr
               ,*

        from    mytable
        ) t

where   pr <= ...
;


问:
how to make the following scala immutable
Suppose I have the following code:

BroadcastMessage gets a list of groups of students in the form of iterators that can only be traversed once

On call to sendMessage it will send message to all students in the groups.

```<code>class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {

  def sendMessage:Unit = {
      groups.foreach(group=>group.foreach(sendeMessage))
  }

  private def sendMessage(student:Student): Unit ={
    EmailClient.sendMessage(student.email,message)
  }

}

case class Student(id: String,email:String)
</code>```

Say that student can exist in several groups and we don't want to send him more than one email.

The mutable solution would be to add mutable set and to add the id of the student to the set and only send the message if the id exists in the set.

```<code>class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {
  // evil mutable set
  private var set:scala.collection.mutable.Set[String] = Set()

  def sendMessage:Unit = {
      groups.foreach(group=>group.foreach(sendeMessage))
  }

  private def sendMessage(student:Student): Unit ={
    if (set.add(student.id)) {
      EmailClient.sendMessage(student.email, message)
    }
  }

}
</code>```

How do I implement it in immutable way?

答:
Well, I think that you are making two different mutable things in your example, while you only really need one.

You either need a private val set : mutable.Set[Student] = mutable.Set.empty[Student] or a private var set : Set[Student] = Set.empty[Student]. That is, you either need to mutate the set itself or just the reference to it that your class holds. I would personally go for the latter, ending up with something like:

```<code>case class Student(id: String,email:String)

class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {
  private var set : Set[Student] = Set.empty // <- no mutable Set, just a mutable reference to several immutable Sets

  def sendMessage:Unit = {
    groups.foreach(group=>group.foreach(sendMessage))
  }

  private def sendMessage(student:Student): Unit = {
    if (!set(student)) {
      set = set + student
      EmailClient.sendMessage(student.email, message)
    }
  }
}
</code>```

Finally, you could even get rid of the sendMessage(student : Student) method all together:

```<code>case class Student(id: String,email:String)

class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {
  private var set : Set[Student] = Set.empty

  def sendMessage:Unit = {

    val students = (for{
      group <- groups
      student <- group
    } yield student).toSet

    val toBeNotified = (students -- set)
    toBeNotified.foreach(student => EmailClient.sendMessage(student.email, message))

    set = set ++ toBeNotified
  }
}
</code>```

I guess it depends on style then...

Body:
Suppose I have the following code:

BroadcastMessage gets a list of groups of students in the form of iterators that can only be traversed once

On call to sendMessage it will send message to all students in the groups.

class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {

  def sendMessage:Unit = {
      groups.foreach(group=>group.foreach(sendeMessage))
  }

  private def sendMessage(student:Student): Unit ={
    EmailClient.sendMessage(student.email,message)
  }

}

case class Student(id: String,email:String)

Say that student can exist in several groups and we don't want to send him more than one email.

The mutable solution would be to add mutable set and to add the id of the student to the set and only send the message if the id exists in the set.

class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {
  // evil mutable set
  private var set:scala.collection.mutable.Set[String] = Set()

  def sendMessage:Unit = {
      groups.foreach(group=>group.foreach(sendeMessage))
  }

  private def sendMessage(student:Student): Unit ={
    if (set.add(student.id)) {
      EmailClient.sendMessage(student.email, message)
    }
  }

}

How do I implement it in immutable way?

Body:
Well, I think that you are making two different mutable things in your example, while you only really need one.

You either need a private val set : mutable.Set[Student] = mutable.Set.empty[Student] or a private var set : Set[Student] = Set.empty[Student]. That is, you either need to mutate the set itself or just the reference to it that your class holds. I would personally go for the latter, ending up with something like:

case class Student(id: String,email:String)

class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {
  private var set : Set[Student] = Set.empty // <- no mutable Set, just a mutable reference to several immutable Sets

  def sendMessage:Unit = {
    groups.foreach(group=>group.foreach(sendMessage))
  }

  private def sendMessage(student:Student): Unit = {
    if (!set(student)) {
      set = set + student
      EmailClient.sendMessage(student.email, message)
    }
  }
}

Finally, you could even get rid of the sendMessage(student : Student) method all together:

case class Student(id: String,email:String)

class BroadcastMessage(message:String,groups:List[Iterator[Student]]) {
  private var set : Set[Student] = Set.empty

  def sendMessage:Unit = {

    val students = (for{
      group <- groups
      student <- group
    } yield student).toSet

    val toBeNotified = (students -- set)
    toBeNotified.foreach(student => EmailClient.sendMessage(student.email, message))

    set = set ++ toBeNotified
  }
}

I guess it depends on style then...


问:
CMake list to string: simple semicolon replacement
I am confused with a very simple example. I have a standard list, so basically its string representation uses semicolon as delimiters. I want to replace it by another one:

```<code>set(L1 "A" "B" "C")
message("L1: ${L1}")

string(REPLACE ";" "<->" L2 ${L1})
message("L2: ${L2}")
</code>```

this snippet prints:

```<code>L1: A;B;C
L2: ABC
</code>```

and I don't understand why. According to some other SO answers, my string replacement seems valid. What am I doing wrong ? Is there a way to store the value A<->B<->C in my 2nd variable ?

Note: I use CMake 3.7.2

答:
Just put ${L1} in quotes:

```<code>set(L1 "A" "B" "C")
message("L1: ${L1}")

string(REPLACE ";" "<->" L2 "${L1}")
message("L2: ${L2}")
</code>```

Otherwise the list will be expanded again to a space separated parameter list.

Reference

cmake: when to quote variables?

Body:
I am confused with a very simple example. I have a standard list, so basically its string representation uses semicolon as delimiters. I want to replace it by another one:

set(L1 "A" "B" "C")
message("L1: ${L1}")

string(REPLACE ";" "<->" L2 ${L1})
message("L2: ${L2}")

this snippet prints:

L1: A;B;C
L2: ABC

and I don't understand why. According to some other SO answers, my string replacement seems valid. What am I doing wrong ? Is there a way to store the value A<->B<->C in my 2nd variable ?

Note: I use CMake 3.7.2

Body:
Just put ${L1} in quotes:

set(L1 "A" "B" "C")
message("L1: ${L1}")

string(REPLACE ";" "<->" L2 "${L1}")
message("L2: ${L2}")

Otherwise the list will be expanded again to a space separated parameter list.

Reference

cmake: when to quote variables?


答: But ${L1} isn't a string, it's a list. If you want a string then you need to enclose it in double-quotes like "${L1}".

Title: CMake list to string: simple semicolon replacement


答:
It's probably line endings. Is one from a Unix machine and the other from a Windows machine, by any chance?

http://en.wikipedia.org/wiki/Newline#Common_problems

Title: Same text but nonzero diff

Body:
I have two files, the contents of which are exactly same as it appears to my eyes, however, the diff of both shows all lines being different, the reason i suspect has something to do with character format/encoding but i am not sure.

The output of "file --mime" on both is same.

Can someone enlighten me on whats going on? and how could i possibly change one form to another, some command/tool.