问:
SYS_CONNECT_BY_PATH with CLOB
I have an ORA-01489: result of string concatenation is too long error executing this query on a Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production, PL/SQL Release 11.2.0.4.0 - Production, CORE 11.2.0.4.0 Production, TNS for Linux: Version 11.2.0.4.0 - Production, NLSRTL Version 11.2.0.4.0 - Production:

```<code>SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(SYS_CONNECT_BY_PATH(rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        CONCAT(CONCAT(unit.unit_name, ' - '), role3_.role_name) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;
</code>```

The problem with this query is with the use of CONCAT operator (||). Concat operator returns char1 concatenated with char2. The string returned is in the  same character set as char1. So here concat operator is trying to return varchar2,  which has limit of 4000 characters and getting exceeded. This problem may also come when we try to CONCAT a VARCHAR2 with CLOB. So here I want simply convert its first string to CLOB and avoid this error. After converting first string to CLOB, CONCAT operator will return string of CLOB type

So I add the TO_CLOB to convert the types but then I have the next error:

ORA-00932: inconsistent datatypes: expected - got CLOB

```<code>  SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(SYS_CONNECT_BY_PATH(rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        TO_CLOB(CONCAT(CONCAT(unit.unit_name, ' - '), role3_.role_name)) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;
</code>```

I also tried to use the package Hierarchy defined Here but then I got a ORA-00932: inconsistent datatypes: expected - got CLOB
https://community.oracle.com/thread/965324?start=0&tstart=0

```<code>SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(hierarchy.branch(level,rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        TO_CLOB(CONCAT(CONCAT(unit.unit_name, ' - '), role3_.role_name)) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;
</code>```

Then I tried as well with sys.stragg , but i got a ORA-00978: nested group function without GROUP BY

```<code>SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(SYS_CONNECT_BY_PATH(rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        sys.stragg(sys.stragg(unit.unit_name || ' - ' || role3_.role_name)) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;
</code>```

答:
You can build hierarchy CLOB path with subquery factoring syntax This may run really slow. Consider having two path columns - one for varchar2 result and one for CLOB. Build varchar2 till size allows, and keep NULL in CLOB path, and switch to CLOB when out of varchar2 capacity. This is a different question though.

```<code>with
base as (
select
    level as id,
    case when level > 1 then level - 1 end as parent_id,
    dbms_random.string('X', 2000) as val
from dual
connect by level <= 50
),
hier(id, parent_id, val, path) as (
    select
        b.id,
        b.parent_id,
        b.val,
        to_clob(concat('/', b.val)) as path
    from base b
    where b.parent_id is null
    union all
    select
        b.id,
        b.parent_id,
        b.val,
        concat(h.path, to_clob(' / '||b.val) )
    from base b
        join hier h on h.id = b.parent_id

)
select rownum, length(h.path)
from hier h;

ROWNUM  LENGTH(H.PATH)
1   2001
2   4004
3   6007
4   8010
5   10013
6   12016
7   14019
8   16022
9   18025
10  20028
11  22031
12  24034
13  26037
14  28040
15  30043
16  32046
17  34049
18  36052
19  38055
20  40058
21  42061
22  44064
23  46067
24  48070
25  50073
26  52076
27  54079
28  56082
29  58085
30  60088
31  62091
32  64094
33  66097
34  68100
35  70103
36  72106
37  74109
38  76112
39  78115
40  80118
41  82121
42  84124
43  86127
44  88130
45  90133
46  92136
47  94139
48  96142
49  98145
50  100148
</code>```

Title: SYS_CONNECT_BY_PATH with CLOB

Body:
I have an ORA-01489: result of string concatenation is too long error executing this query on a Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production, PL/SQL Release 11.2.0.4.0 - Production, CORE 11.2.0.4.0 Production, TNS for Linux: Version 11.2.0.4.0 - Production, NLSRTL Version 11.2.0.4.0 - Production:

SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(SYS_CONNECT_BY_PATH(rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        CONCAT(CONCAT(unit.unit_name, ' - '), role3_.role_name) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;

The problem with this query is with the use of CONCAT operator (||). Concat operator returns char1 concatenated with char2. The string returned is in the  same character set as char1. So here concat operator is trying to return varchar2,  which has limit of 4000 characters and getting exceeded. This problem may also come when we try to CONCAT a VARCHAR2 with CLOB. So here I want simply convert its first string to CLOB and avoid this error. After converting first string to CLOB, CONCAT operator will return string of CLOB type

So I add the TO_CLOB to convert the types but then I have the next error:

ORA-00932: inconsistent datatypes: expected - got CLOB

  SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(SYS_CONNECT_BY_PATH(rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        TO_CLOB(CONCAT(CONCAT(unit.unit_name, ' - '), role3_.role_name)) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;

I also tried to use the package Hierarchy defined Here but then I got a ORA-00932: inconsistent datatypes: expected - got CLOB
https://community.oracle.com/thread/965324?start=0&tstart=0

SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(hierarchy.branch(level,rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        TO_CLOB(CONCAT(CONCAT(unit.unit_name, ' - '), role3_.role_name)) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;

Then I tried as well with sys.stragg , but i got a ORA-00978: nested group function without GROUP BY

SELECT "USER_PRIMARY_UNIT","LOGIN","FIRST_NAME","LAST_NAME","UNIT_ROLE"
FROM (
SELECT user_primary_unit,login, first_name,  last_name,
       LTRIM(MAX(SYS_CONNECT_BY_PATH(rights,' / '))
       KEEP (DENSE_RANK LAST ORDER BY curr),' / ') AS UNIT_ROLE
      FROM
        (SELECT  login,
              first_name,
              last_name,
              user_primary_unit,
              rights,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) AS curr,
              ROW_NUMBER() OVER (PARTITION BY login ORDER BY rights) -1 AS prev
        FROM  (select   member0_.login,  member0_.first_name first_name, unit2.unit_name user_primary_unit,  member0_.last_name last_name,
                        sys.stragg(sys.stragg(unit.unit_name || ' - ' || role3_.role_name)) rights
 from
  IOT_DEVICES.t_member member0_
 inner join  IOT_DEVICES.t_user member0_1_    on member0_.member_id=member0_1_.user_id
 inner join  IOT_DEVICES.t_playable_role playedrole1_    on member0_.member_id=playedrole1_.user_id
 inner join  IOT_DEVICES.t_unit_role unitrole2_    on playedrole1_.unit_role_id=unitrole2_.unit_role_id
 inner join  IOT_DEVICES.t_role role3_    on unitrole2_.role_id=role3_.role_id
 inner join  IOT_DEVICES.t_unit unit    on unitrole2_.unit_id=unit.unit_id
 inner join  IOT_DEVICES.t_unit unit2    on unit2.unit_id=member0_1_.primary_unit_id
 where    current_date between playedrole1_.start_date and playedrole1_.end_date
 order by unit.unit_name
  ))
GROUP BY login, first_name,  last_name, user_primary_unit
CONNECT BY prev = PRIOR curr AND login = PRIOR login
START WITH curr = 1
)
ORDER BY user_PRIMARY_UNIT, FIRST_NAME, LAST_NAME;

Body:
You can build hierarchy CLOB path with subquery factoring syntax This may run really slow. Consider having two path columns - one for varchar2 result and one for CLOB. Build varchar2 till size allows, and keep NULL in CLOB path, and switch to CLOB when out of varchar2 capacity. This is a different question though.

with
base as (
select
    level as id,
    case when level > 1 then level - 1 end as parent_id,
    dbms_random.string('X', 2000) as val
from dual
connect by level <= 50
),
hier(id, parent_id, val, path) as (
    select
        b.id,
        b.parent_id,
        b.val,
        to_clob(concat('/', b.val)) as path
    from base b
    where b.parent_id is null
    union all
    select
        b.id,
        b.parent_id,
        b.val,
        concat(h.path, to_clob(' / '||b.val) )
    from base b
        join hier h on h.id = b.parent_id

)
select rownum, length(h.path)
from hier h;

ROWNUM  LENGTH(H.PATH)
1   2001
2   4004
3   6007
4   8010
5   10013
6   12016
7   14019
8   16022
9   18025
10  20028
11  22031
12  24034
13  26037
14  28040
15  30043
16  32046
17  34049
18  36052
19  38055
20  40058
21  42061
22  44064
23  46067
24  48070
25  50073
26  52076
27  54079
28  56082
29  58085
30  60088
31  62091
32  64094
33  66097
34  68100
35  70103
36  72106
37  74109
38  76112
39  78115
40  80118
41  82121
42  84124
43  86127
44  88130
45  90133
46  92136
47  94139
48  96142
49  98145
50  100148


来源: stackexchange

问:
Encountering Unreachable statement in switch case while implementing Firebase Auth
"Statement not reachable under the switch case for signing out using the button in menu item. "

```<code> @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
        switch (item.getItemId()) {
            case R.id.sign_out_menu:

                AuthUI.getInstance().signOut(this); //NOT REACHABLE
                return true;

                default:
                    return super.onOptionsItemSelected(item);
                    }
    }
</code>```

答:
write this line at the end of method
"return super.onOptionsItemSelected(item);"</p>

ContentLicense: CC BY-SA 4.0

Body:
"Statement not reachable under the switch case for signing out using the button in menu item. "

 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
        switch (item.getItemId()) {
            case R.id.sign_out_menu:

                AuthUI.getInstance().signOut(this); //NOT REACHABLE
                return true;

                default:
                    return super.onOptionsItemSelected(item);
                    }
    }

ContentLicense: CC BY-SA 3.0


问:
How to remove a specific route from a mounted engine in rails 4
In my routes.rb file I have mounted engine routes.

```<code>mount SomeEngine::Engine => '/', as: 'some_engine'
</code>```

It adds this route:

```<code>match '*path' => 'redirects#show',
  constraints: SomeEngine::RedirectConstraint.new,
  via: 'get'
</code>```

What this route does is that it catches all unknown URLs and passes them to SomeEngine::RedirectConstraint

I don't need that kind of functionality. Is it possible to remove that route from main app? I don't have an access to engine. Actually I need to add some routes after that engine and now they can't be reached because of match '*path' route.

答: In Rails routes: The priority is based upon order of creation: first created -> highest priority. This may help you.

Body:
In my routes.rb file I have mounted engine routes.

mount SomeEngine::Engine => '/', as: 'some_engine'

It adds this route:

match '*path' => 'redirects#show',
  constraints: SomeEngine::RedirectConstraint.new,
  via: 'get'

What this route does is that it catches all unknown URLs and passes them to SomeEngine::RedirectConstraint

I don't need that kind of functionality. Is it possible to remove that route from main app? I don't have an access to engine. Actually I need to add some routes after that engine and now they can't be reached because of match '*path' route.


问:
PHP Laravel - jQuery not working - ReferenceError: $ is not defined
I created a fresh Laravel project and added jquery file at:

```<code>rootproject/public/js/jquery-3.2.0.min.js
</code>```

Now in welcome.blade.php, in html header tag I am referencing it as:

```<code><link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">
</code>```

And put an alert() message in document load function.

```<code>$( document ).ready(function() {
  alert("my message");
});
</code>```

But its not working. In console log it is showing error message:

```<code>ReferenceError: $ is not defined
</code>```

Can anybody suggest how to fix it?

答:
Replace

```<code><link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">
</code>```

with:

```<code><script src="{{ asset('js/jquery-3.2.0.min.js') }}"></script>
</code>```

Body:
I created a fresh Laravel project and added jquery file at:

rootproject/public/js/jquery-3.2.0.min.js

Now in welcome.blade.php, in html header tag I am referencing it as:

<link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">

And put an alert() message in document load function.

$( document ).ready(function() {
  alert("my message");
});

But its not working. In console log it is showing error message:

ReferenceError: $ is not defined

Can anybody suggest how to fix it?

Body:
Replace

<link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">

with:

<script src="{{ asset('js/jquery-3.2.0.min.js') }}"></script>


答:
You are including JS file in CSS way:

```<code><link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">
</code>```

that's the issue. Replace it with:

```<code><script src="{{ asset('js/jquery-3.2.0.min.js') }}"></script>
</code>```

every thing will be fine.

Title: PHP Laravel - jQuery not working - ReferenceError: $ is not defined

Body:
You are including JS file in CSS way:

<link href="{{ asset('/js/jquery-3.2.0.min.js') }}" rel="stylesheet">

that's the issue. Replace it with:

<script src="{{ asset('js/jquery-3.2.0.min.js') }}"></script>

every thing will be fine.


问:
regex pattern to match current directory in dir output
I try to extract the creation date of a specific directory from the output produced by the dir command in Windows.

Example:

dir c:\folder\Myfolder\ /T:C /A:D

Output:

```<code>22-11-2013  15:09    <DIR>          .
22-11-2013  15:09    <DIR>          ..
21-03-2015  14:32    <DIR>          Folder1
12-09-2014  11:03    <DIR>          Folder2
18-10-2016  13:29    <DIR>          Folder3
</code>```

I tried to pipe the output to findstr in order to use a regular expression. But dir c:\folder\Myfolder\ /T:C /A:D | findstr \r "\." shows both the . and .. lines.

What I need is the date and time of Myfolder (i.e. line with the single .) in order to create a timestamp for this folder.

答:
For the last write time, there is not need for the pipe to findstr. The same information can be retrieved as

```<code>for /d %%a in ("c:\folder\Myfolder") do echo %%~ta
</code>```

Use the ~t modifier of the for replaceable parameter to retrieve the timestamp of the folder.

But this method can not be used to retrieve the folder creation time (as Magoo comments). To retrieve it you will need to maintain your original approach

```<code>dir /tc /ad "c:\folder\Myfolder\.?" | findstr /e /c:" \."
</code>```

(the .? is just to shorten the list to be filtered by findstr and the enumeration time in dir)

Or you can use wmic (in this case, it is necessary to change the folder naming format, doubling backslashes)

```<code>wmic fsdir where name="c:\\folder\\Myfolder" get CreationDate /value
</code>```

In this case, you will get something like

```<code>CreationDate=20160927171354.871547+120
</code>```

Body:
I try to extract the creation date of a specific directory from the output produced by the dir command in Windows.

Example:

dir c:\folder\Myfolder\ /T:C /A:D

Output:

22-11-2013  15:09    <DIR>          .
22-11-2013  15:09    <DIR>          ..
21-03-2015  14:32    <DIR>          Folder1
12-09-2014  11:03    <DIR>          Folder2
18-10-2016  13:29    <DIR>          Folder3

I tried to pipe the output to findstr in order to use a regular expression. But dir c:\folder\Myfolder\ /T:C /A:D | findstr \r "\." shows both the . and .. lines.

What I need is the date and time of Myfolder (i.e. line with the single .) in order to create a timestamp for this folder.

Body:
For the last write time, there is not need for the pipe to findstr. The same information can be retrieved as

for /d %%a in ("c:\folder\Myfolder") do echo %%~ta

Use the ~t modifier of the for replaceable parameter to retrieve the timestamp of the folder.

But this method can not be used to retrieve the folder creation time (as Magoo comments). To retrieve it you will need to maintain your original approach

dir /tc /ad "c:\folder\Myfolder\.?" | findstr /e /c:" \."

(the .? is just to shorten the list to be filtered by findstr and the enumeration time in dir)

Or you can use wmic (in this case, it is necessary to change the folder naming format, doubling backslashes)

wmic fsdir where name="c:\\folder\\Myfolder" get CreationDate /value

In this case, you will get something like

CreationDate=20160927171354.871547+120


问:
Can sprintf / formatted strings be passed directly to a function?
Is something like this allowed in C++? If so, how do I do it?

```<code>myFunction("User input: %s", a);
</code>```

Or is the only way to format it first and then pass it?

答:
It's legal to do what you're doing, except:

sprintf's behavior is to apply formatting to a string. Outside of that function (and the printf family in general), your arguments here don't really 'mean' anything, because your function signature could look like this:

```<code>void myFunction(const char* str1, const char* str2);
</code>```

But what it does is up to you.

If you want a string modified before passing it into some function, you will either have to modify it outside myFunction (via sprintf or whatever) or pass all your arguments in and call sprintf inside the function.

ContentLicense: CC BY-SA 2.5

Body:
Is something like this allowed in C++? If so, how do I do it?

myFunction("User input: %s", a);

Or is the only way to format it first and then pass it?

Body:
It's legal to do what you're doing, except:

sprintf's behavior is to apply formatting to a string. Outside of that function (and the printf family in general), your arguments here don't really 'mean' anything, because your function signature could look like this:

void myFunction(const char* str1, const char* str2);

But what it does is up to you.

If you want a string modified before passing it into some function, you will either have to modify it outside myFunction (via sprintf or whatever) or pass all your arguments in and call sprintf inside the function.


问:
Windows CLI doesn't show correct variables with spaces
There is this command line tool for MediaInfo that we use to print video file information. E.g. I want to get video file duration value:

```<code>mediainfo --Inform=General;%Duration/String2% video.mkv
46 min 57 s
</code>```

As you can see it prints 46 min 57 s which is correct.

Now lets say I want to put that value into a variable. So we run this:

```<code>for /f "usebackq" %a in (`"mediainfo --Inform=General;%%Duration/String2%% video.mkv"`) do set duration=%a
set duration=%46
</code>```

As you can see it gives set duration=%46 on a new line? And if I type next %duration% I get:

```<code>'%46' is not recognized as an internal or external command,
operable program or batch file.
</code>```

What is going on? How do I get my %duration% variable show 46 min 57 s?

答:
```<code>for /f "usebackqDELIMS=" %%a
</code>```

The default delimiters include space. This syntax disables delimiters so the entire line is assigned.

The metavariable a needs to have 2 % if you are running a batch file containintg this line. If you are running from the prompt, you need %a. This applies to the assignment instruction as well.

No idea what you are attempting to do with the %46 malarkey. Please explain.

Body:
There is this command line tool for MediaInfo that we use to print video file information. E.g. I want to get video file duration value:

mediainfo --Inform=General;%Duration/String2% video.mkv
46 min 57 s

As you can see it prints 46 min 57 s which is correct.

Now lets say I want to put that value into a variable. So we run this:

for /f "usebackq" %a in (`"mediainfo --Inform=General;%%Duration/String2%% video.mkv"`) do set duration=%a
set duration=%46

As you can see it gives set duration=%46 on a new line? And if I type next %duration% I get:

'%46' is not recognized as an internal or external command,
operable program or batch file.

What is going on? How do I get my %duration% variable show 46 min 57 s?

Body:
for /f "usebackqDELIMS=" %%a

The default delimiters include space. This syntax disables delimiters so the entire line is assigned.

The metavariable a needs to have 2 % if you are running a batch file containintg this line. If you are running from the prompt, you need %a. This applies to the assignment instruction as well.

No idea what you are attempting to do with the %46 malarkey. Please explain.


问:
How can I edit my php file with style.css?
I have made a website thats allows my visitors to upload pictures and view them on a other link. Here is mijn website http://sixpi.nl/dev And here is my code.
My question is how can I make the media.php page look nice. And how can I edit it with CSS? I want the media.php look like this (http://pexels.com) thank you.

This is my HTML file called index.html

```<code><!DOCTYPE html>
<html>
<head>
<body>

<a href="media.php">Kijk alle media!</a>
<script src="javascript.js"></script>
<img id="preview" alt="your image" width="100" height="100" />
<form action="upload.php" method="post" id="myForm" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="fileToUpload" id="fileToUpload"  onchange="document.getElementById('preview').src = window.URL.createObjectURL(this.files[0])">
    <button name="submit" class="btn btn-primary" type="submit" value="submit">Upload File</button>

 </form>
 </body>
 </head>
 </html>
</code>```

This is my upload script called upload.php

```<code><!DOCTYPE html>
<html>
<head>
<body>

<a href="media.php">Kijk alle media!</a>

<img id="preview" alt="your image" width="100" height="100" />

<form action="upload.php" method="post" id="myForm" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="fileToUpload" id="fileToUpload"  onchange="document.getElementById('preview').src = window.URL.createObjectURL(this.files[0])">
    <button name="submit" class="btn btn-primary" type="submit" value="submit">Upload File</button>
 </form>

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

This is my media link alle the uploaded images are visible called media.php

```<code><?php
     $files = glob("upload/*.*");
     for ($i=1; $i<count($files); $i++)
      {
        $image = $files[$i];
        $supported_file = array(
                'gif',
                'jpg',
                'jpeg',
                'png'
         );

         $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
         if (in_array($ext, $supported_file)) {
             echo $image ."<br />";
             echo '<img src="'.$image .'" alt="Random image" width="600" height="480" />'."<br /><br />";
            } else {
                continue;
            }
          }

       ?>
</code>```

答:
You can simply echo entire html code and you can use style for it. Here is and example :

```<code><?php
for($i=0;$i<10;$i++)
        {
            ?>
<div class="myClass"></div>
        <?php
        }
?>
</code>```

Here you can style the class called myClass in your css.

If you don't want to use looping then this would be useful to you.

```<code><div class="myClass"></div>
</code>```

Remember php can echo any html in double quotes. Hope this helps :)

Body:
I have made a website thats allows my visitors to upload pictures and view them on a other link. Here is mijn website http://sixpi.nl/dev And here is my code.
My question is how can I make the media.php page look nice. And how can I edit it with CSS? I want the media.php look like this (http://pexels.com) thank you.

This is my HTML file called index.html

<!DOCTYPE html>

Kijk alle media!

<form action="upload.php" method="post" id="myForm" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="fileToUpload" id="fileToUpload"  onchange="document.getElementById('preview').src = window.URL.createObjectURL(this.files[0])">
    <button name="submit" class="btn btn-primary" type="submit" value="submit">Upload File</button>

 </form>

This is my upload script called upload.php

<!DOCTYPE html>

Kijk alle media!

<form action="upload.php" method="post" id="myForm" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="fileToUpload" id="fileToUpload"  onchange="document.getElementById('preview').src = window.URL.createObjectURL(this.files[0])">
    <button name="submit" class="btn btn-primary" type="submit" value="submit">Upload File</button>
 </form>

This is my media link alle the uploaded images are visible called media.php

<?php
     $files = glob("upload/*.*");
     for ($i=1; $i<count($files); $i++)
      {
        $image = $files[$i];
        $supported_file = array(
                'gif',
                'jpg',
                'jpeg',
                'png'
         );

         $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
         if (in_array($ext, $supported_file)) {
             echo $image ."
";
             echo ''."

";
            } else {
                continue;
            }
          }

       ?>

Body:
You can simply echo entire html code and you can use style for it. Here is and example :

<?php
for($i=0;$i<10;$i++)
        {
            ?>
<div class="myClass"></div>
        <?php
        }
?>

Here you can style the class called myClass in your css.

If you don't want to use looping then this would be useful to you.

<div class="myClass"></div>

Remember php can echo any html in double quotes. Hope this helps :)


问:
Create files with PC8 character set
I'm going crazy, I have searched this and other forums since I got a file specification that tells the files my code produces should use PC8-characters (also known as CP437 or ISO-8859-1), it's a rather plain text file and contains international characters like Å (decimal 143), Ä (decimal 142) and Ö (decimal 148).

My code produces a string containing all characters that should be in the file and I can get a Unicode-version of it (I also succeeded to create a UTF8 version of the but it's useless in this case).

It would also be great if the file could be downloaded but I don't get any success with that either, the browser does not receive any file, I checked the antivirus and tried another browser without success.

For the moment I written a possibility to mail the file and that works fine.

In the case when I send the file by mail the code (without any encoding) looks like this:

```<code>MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(ReceiverMail, ReceiverName));
msg.From = new MailAddress(SenderMail, SenderName);
msg.Subject = Subject;
msg.Body = Body;
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(StringToSend);
sw.Flush();
ms.Position = 0;
Attachment at = new Attachment(ms, FileName);
msg.Attachments.Add(at);
using (SmtpClient smtp = new SmtpClient())
{
    smtp.Send(msg);
}
</code>```

In the case when I wan't to download the file in the browser my code looks like this:

```<code>Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(StringToSend);
sw.Flush();
ms.Position = 0;
Response.Write(ms);
Response.Flush();
Response.End();
</code>```

Please help!

答:
ISO-8859-1 is also known as Latin-1, you can get an encoder for this character set like this:

```<code>var encoding = Encoding.GetEncoding("ISO-8859-1");
</code>```

In your Response example you can use then this with Response.ContentEncoding:

```<code>Response.Clear();
Response.ClearHeaders();
Response.ClearContent();

Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);

Response.ContentType = "text/plain";
Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1");

Response.Write(stringToSend);

Response.Flush();
</code>```

Title: Create files with PC8 character set

Body:
I'm going crazy, I have searched this and other forums since I got a file specification that tells the files my code produces should use PC8-characters (also known as CP437 or ISO-8859-1), it's a rather plain text file and contains international characters like Å (decimal 143), Ä (decimal 142) and Ö (decimal 148).

My code produces a string containing all characters that should be in the file and I can get a Unicode-version of it (I also succeeded to create a UTF8 version of the but it's useless in this case).

It would also be great if the file could be downloaded but I don't get any success with that either, the browser does not receive any file, I checked the antivirus and tried another browser without success.

For the moment I written a possibility to mail the file and that works fine.

In the case when I send the file by mail the code (without any encoding) looks like this:

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(ReceiverMail, ReceiverName));
msg.From = new MailAddress(SenderMail, SenderName);
msg.Subject = Subject;
msg.Body = Body;
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(StringToSend);
sw.Flush();
ms.Position = 0;
Attachment at = new Attachment(ms, FileName);
msg.Attachments.Add(at);
using (SmtpClient smtp = new SmtpClient())
{
    smtp.Send(msg);
}

In the case when I wan't to download the file in the browser my code looks like this:

Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(StringToSend);
sw.Flush();
ms.Position = 0;
Response.Write(ms);
Response.Flush();
Response.End();

Please help!

Body:
ISO-8859-1 is also known as Latin-1, you can get an encoder for this character set like this:

var encoding = Encoding.GetEncoding("ISO-8859-1");

In your Response example you can use then this with Response.ContentEncoding:

Response.Clear();
Response.ClearHeaders();
Response.ClearContent();

Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);

Response.ContentType = "text/plain";
Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1");

Response.Write(stringToSend);

Response.Flush();


答:
In a batch file:

```<code>@echo off
for /f "tokens=*" %%a in ('mediainfo --Inform=General;%Duration/String2% video.mkv') do set duration=%%a
echo %duration%
pause
</code>```

In CMD

```<code>for /f "tokens=*" %a in ('mediainfo --Inform=General;%Duration/String2% video.mkv') do set duration=%a
echo %duration%
</code>```

Output:

46 min 57 s

Title: Windows CLI doesn't show correct variables with spaces

Body:
In a batch file:

@echo off
for /f "tokens=*" %%a in ('mediainfo --Inform=General;%Duration/String2% video.mkv') do set duration=%%a
echo %duration%
pause

In CMD

for /f "tokens=*" %a in ('mediainfo --Inform=General;%Duration/String2% video.mkv') do set duration=%a
echo %duration%

Output:

46 min 57 s


答:
```<code><script src="<?php echo URL::to('/'); ?>/public/js/jquery-3.2.0.min.js"></script>
</code>```

Add script in this way

Body:
<script src="<?php echo URL::to('/'); ?>/public/js/jquery-3.2.0.min.js"></script>

Add script in this way


答:
Remove the first line in the method onOptionsItemSelected

```<code>@Override
public boolean onOptionsItemSelected(MenuItem item) {
    return super.onOptionsItemSelected(item); // Remove this line

    switch(item.getItemId()){

    }
}
</code>```

Because you have a return statement in your code, everything under the 1st return statement which is not part of the switch is not reachable

Title: Encountering Unreachable statement in switch case while implementing Firebase Auth

Body:
"Statement not reachable under the switch case for signing out using the button in menu item. "

 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
        switch (item.getItemId()) {
            case R.id.sign_out_menu:

                AuthUI.getInstance().signOut(this); //NOT REACHABLE
                return true;

                default:
                    return super.onOptionsItemSelected(item);
                    }
    }

Body:
Remove the first line in the method onOptionsItemSelected

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    return super.onOptionsItemSelected(item); // Remove this line

    switch(item.getItemId()){

    }
}

Because you have a return statement in your code, everything under the 1st return statement which is not part of the switch is not reachable


问:
Pipe-lining / keyby of keyby of an RDD in pyspark(spark)
I have an rdd as rowsrdd given below, to which i have apply aggregation by using keyby() on keys (0,8) and reducebykey() on key (1):

```<code>rowsrdd=[[u'Chevrolet Chevelle Malibu', u'18.0', u'8', u'307.0', u'130.0', u'3504.', u'12.0', u'70', u'US'], [u'AMC Rebel SST', u'16.0', u'8', u'304.0', u'150.0', u'3433.', u'12.0', u'70', u'US']]
</code>```

Note: The above rdd is not complete, it is just a sample of complete rdd to get idea of code below.

```<code>def aggonvalfunc(y):
    return y[1]
resultedrdd=rowsrdd.keyBy(lambda w:(w[0],w[8])).mapValues(lambda aggkey:aggonvalfunc(aggkey))\
    .mapValues(float).reduceByKey(lambda x,y: x+y)
</code>```

which gave following resultedrdd:
which has attributes as car_name, country_name and a numerical_value

```<code>resultedrdd=[((u'Dodge Monaco Brougham', u'US'), 15.5), ((u'Chevrolet Monte Carlo S', u'US'), 15.0), ((u'Datsun 280-ZX', u'Japan'), 32.7), ((u'Datsun 510', u'Japan'), 27.2), ((u'Plymouth Duster', u'US'), 65.0), ((u'Chrysler Cordoba', u'US'), 15.5), ((u'Chevrolet Nova', u'US'), 55.0), ((u'Dodge D100', u'US'), 13.0), ((u'Pontiac Safari (sw)', u'US'), 13.0), ((u'Dodge Colt m/m', u'US'), 33.5), ((u'Volkswagen Pickup', u'Europe'), 44.0), ((u'AMC Rebel SST (sw)', u'US'), 0.0), ((u'Chevrolet Caprice Classic', u'US'), 47.5), ((u'Chrysler Lebaron Town @ Country (sw)', u'US'), 18.5), ((u'Chevrolet Impala', u'US'), 52.0), ((u'Pontiac Phoenix', u'US'), 60.5), ((u'Ford Gran Torino', u'US'), 44.5), ((u'Datsun 310', u'Japan'), 37.2), ((u'AMC Ambassador SST', u'US'), 17.0), ((u'Toyota Starlet', u'Japan'), 39.1), ((u'Audi Fox', u'Europe'), 29.0), ((u'Saab 99e', u'Europe'), 25.0), ((u'AMC Ambassador Brougham', u'US'), 13.0), ((u'Dodge Monaco (sw)', u'US'), 12.0), ((u'AMC Concord', u'US'), 43.7), ((u'Chevrolet Concours', u'US'), 17.5), ((u'Chevrolet Chevette', u'US'), 121.6), ((u'Chrysler Lebaron Salon', u'US'), 17.6), ((u'Ford Mustang GL', u'US'), 27.0), ((u'Buick Estate Wagon (sw)', u'US'), 30.9), ((u'Ford Torino 500', u'US'), 19.0), ((u'Volkswagen Rabbit l', u'Europe'), 36.0), ((u'Datsun B210 GX', u'Japan'), 39.4), ((u'Ford Maverick', u'US'), 99.0), ((u'Datsun F-10 Hatchback', u'Japan'), 33.5), ((u'Audi 100 LS', u'Europe'), 24.0), ((u'AMC Pacer d/l', u'US'), 17.5), ((u'Ford Fairmont', u'US'), 26.4), ((u'Chevrolet Malibu Classic (sw)', u'US'), 19.2), ((u'Toyota Corolla Mark II (sw)', u'Japan'), 23.0), ((u'Plymouth Volare Custom', u'US'), 19.0), ((u'Toyota Mark II', u'Japan'), 39.0), ((u'Plymouth Volare', u'US'), 20.5), ((u'Plymouth Sapporo', u'US'), 23.2), ((u'Ford Thunderbird', u'US'), 16.0), ((u'Chrysler Lebaron Medallion', u'US'), 26.0), ((u'Toyota Celica GT Liftback', u'Japan'), 21.1), ((u'Mercury Marquis', u'US'), 11.0), ((u'Mercury Monarch ghia', u'US'), 20.2), ((u'Datsun B210', u'Japan'), 31.0), ((u'Datsun B-210', u'Japan'), 32.0), ((u'Chevy S-10', u'US'), 31.0), ((u'Buick Century Special', u'US'), 20.6), ((u'Mercury Cougar Brougham', u'US'), 15.0), ((u'Oldsmobile Cutlass Supreme', u'US'), 17.0), ((u'Hi 1200D', u'US'), 9.0), ((u'Mercury Monarch', u'US'), 15.0), ((u'Buick Opel Isuzu Deluxe', u'US'), 30.0), ((u'Mercury Capri 2000', u'US'), 23.0), ((u'Dodge Dart Custom', u'US'), 15.0), ((u'Mercury Lynx l', u'US'), 36.0), ((u'AMC Matador', u'US'), 78.5), ((u'Volkswagen Rabbit Custom', u'Europe'), 60.9), ((u'Fiat Strada Custom', u'Europe'), 37.3), ((u'Renault 12tl', u'Europe'), 27.0), ((u'Honda Civic', u'Japan'), 95.0), ((u'Volvo 144ea', u'Europe'), 19.0), ((u'Dodge Coronet Brougham', u'US'), 16.0), ((u'Honda Accord LX', u'Japan'), 29.5), ((u'Dodge Magnum XE', u'US'), 17.5), ((u'AMC Gremlin', u'US'), 78.0), ((u'Dodge Coronet Custom (sw)', u'US'), 14.0), ((u'Saab 900s', u'Europe'), 0.0), ((u'Ford Fairmont Futura', u'US'), 24.0), ((u'Datsun PL510', u'Japan'), 54.0), ((u'Dodge Aspen SE', u'US'), 20.0), ((u'AMC Matador (sw)', u'US'), 29.0), ((u'Chrysler Newport Royal', u'US'), 13.0), ((u'Pontiac Astro', u'US'), 23.0), ((u'Plymouth Custom Suburb', u'US'), 13.0), ((u'Renault 12 (sw)', u'Europe'), 26.0), ((u'Pontiac Ventura SJ', u'US'), 18.5), ((u'Toyota Corolla Liftback', u'Japan'), 55.8), ((u'Oldsmobile Delta 88 Royale', u'US'), 12.0), ((u'Volkswagen Super Beetle', u'Europe'), 26.0), ((u'Citroen DS-21 Pallas', u'Europe'), 0.0), ((u'Buick Electra 225 Custom', u'US'), 12.0), ((u'Audi 4000', u'Europe'), 34.3), ((u'Datsun 310 GX', u'Japan'), 38.0), ((u'Toyota Cressida', u'Japan'), 25.4), ((u'Chevrolet Malibu', u'US'), 33.5), ((u'Volvo Diesel', u'Europe'), 30.7), ((u'Ford Mustang', u'US'), 18.0), ((u'BMW 320i', u'Europe'), 21.5), ((u'Subaru DL', u'Japan'), 63.8), ((u'Ford Pinto Runabout', u'US'), 21.0), ((u'Buick Skylark Limited', u'US'), 28.4), ((u'Dodge Aries Wagon (sw)', u'US'), 25.8), ((u'Oldsmobile Cutlass Salon Brougham', u'US'), 43.8), ((u'BMW 2002', u'Europe'), 26.0), ((u'Plymouth Fury iii', u'US'), 28.0), ((u'Cadillac Eldorado', u'US'), 23.0), ((u'Ford Gran Torino (sw)', u'US'), 27.0), ((u'Chevrolet Bel Air', u'US'), 15.0), ((u'Dodge Colt Hatchback Custom', u'US'), 35.7), ((u'Buick Skylark', u'US'), 47.1), ((u'Fiat 124B', u'Europe'), 30.0), ((u'Volvo 245', u'Europe'), 20.0), ((u'Mercury Grand Marquis', u'US'), 16.5), ((u'Mercury Capri v6', u'US'), 21.0), ((u'AMC Ambassador DPL', u'US'), 15.0), ((u'Buick Century Luxus (sw)', u'US'), 13.0), ((u'Plymouth Fury III', u'US'), 15.0), ((u'Renault 5 GTL', u'Europe'), 36.0), ((u'Mercury Marquis Brougham', u'US'), 12.0), ((u'Renault 18i', u'Europe'), 34.5), ((u'Ford Fiesta', u'US'), 36.1), ((u'Toyota Corolla Mark ii', u'Japan'), 24.0), ((u'Volkswagen Rabbit', u'Europe'), 158.8), ((u'Datsun 510 (sw)', u'Japan'), 28.0), ((u'Mercedes Benz 300d', u'Europe'), 25.4), ((u'Datsun 1200', u'Japan'), 35.0), ((u'Plymouth Arrow GS', u'US'), 25.5), ((u'Ford Mustang II 2+2', u'US'), 25.5), ((u'Oldsmobile Vista Cruiser', u'US'), 12.0), ((u'Mazda RX3', u'Japan'), 18.0), ((u'Volvo 264gl', u'Europe'), 17.0), ((u'Pontiac Grand Prix LJ', u'US'), 16.0), ((u'Dodge Omni', u'US'), 30.9), ((u'Pontiac Sunbird Coupe', u'US'), 24.5), ((u'AMC Rebel SST', u'US'), 16.0), ((u'Chevrolet Nova Custom', u'US'), 16.0), ((u'Mercedes-Benz 240d', u'Europe'), 30.0), ((u'Dodge Coronet Custom', u'US'), 15.0), ((u'Ford Escort 4W', u'US'), 34.4), ((u'Datsun 710', u'Japan'), 56.0), ((u'Ford Fairmont 4', u'US'), 22.3), ((u'Honda Civic CVCC', u'Japan'), 69.1), ((u'Dodge Charger 2.2', u'US'), 36.0), ((u'Dodge Colt (sw)', u'US'), 28.0), ((u'Plymouth Fury', u'US'), 18.0), ((u'Mazda GLC', u'Japan'), 46.6), ((u'Plymouth Valiant', u'US'), 40.0), ((u'Datsun 200SX', u'Japan'), 32.9), ((u'Plymouth Satellite Custom', u'US'), 16.0), ((u'Dodge Aspen', u'US'), 37.7), ((u'Volkswagen Super Beetle 117', u'Europe'), 0.0), ((u'Ford Grenada ghia', u'US'), 18.0), ((u'Ford Country', u'US'), 12.0), ((u'Volkswagen Dasher', u'Europe'), 81.5), ((u'Ford LTD', u'US'), 27.0), ((u'Plymouth Horizon TC3', u'US'), 34.5), ((u'Ford Mustang Boss 302', u'US'), 0.0), ((u'Saab 99le', u'Europe'), 24.0), ((u'AMC Concord DL 6', u'US'), 20.2), ((u'Dodge Challenger SE', u'US'), 15.0), ((u'Volkswagen Rabbit C (Diesel)', u'Europe'), 44.3), ((u'Pontiac Catalina Brougham', u'US'), 14.0), ((u'Pontiac Lemans V6', u'US'), 21.5), ((u'Peugeot 504 (sw)', u'Europe'), 21.0), ((u'Pontiac Catalina', u'US'), 44.0), ((u'Chevrolet Chevelle Malibu', u'US'), 35.0), ((u'Mercury Zephyr', u'US'), 20.8), ((u'Chevy C20', u'US'), 10.0), ((u'Dodge Colt Hardtop', u'US'), 25.0), ((u'Peugeot 505s Turbo Diesel', u'Europe'), 28.1), ((u'Mazda GLC Custom l', u'Japan'), 37.0), ((u'Chevrolet Vega (sw)', u'US'), 22.0), ((u'Buick Century', u'US'), 39.4), ((u'Plymouth Grand Fury', u'US'), 16.0), ((u'Oldsmobile Cutlass Ciera (diesel)', u'US'), 38.0), ((u'Ford Mustang Cobra', u'US'), 23.6), ((u'Ford Grenada gl', u'US'), 20.2), ((u'Toyota Camry', u'Japan'), 20.0), ((u'Honda Prelude', u'Japan'), 33.7), ((u'Ford Ranger', u'US'), 28.0), ((u'Mercury Zephyr 6', u'US'), 19.8), ((u'Chevrolete Chevelle Malibu', u'US'), 16.0), ((u'Dodge Colt', u'US'), 81.9), ((u"Plymouth 'Cuda 340", u'US'), 14.0), ((u'Datsun 210', u'Japan'), 72.6), ((u'Cadillac Seville', u'US'), 16.5), ((u'Pontiac J2000 SE Hatchback', u'US'), 31.0), ((u'Ford Fairmont (auto)', u'US'), 20.2), ((u'Plymouth Horizon', u'US'), 34.2), ((u'Chevrolet Vega 2300', u'US'), 28.0), ((u'Toyota Corolla Tercel', u'Japan'), 38.1), ((u'Volkswagen Model 111', u'Europe'), 27.0), ((u'Chevrolet Chevelle Concours (sw)', u'US'), 13.0), ((u'Audi 100LS', u'Europe'), 43.0), ((u'Datsun 200-SX', u'Japan'), 23.9), ((u'Datsun 810 Maxima', u'Japan'), 24.2), ((u'Plymouth Valiant Custom', u'US'), 19.0), ((u'Datsun 610', u'Japan'), 22.0), ((u'Mazda RX-4', u'Japan'), 21.5), ((u'Buick Century 350', u'US'), 13.0), ((u'Toyota Tercel', u'Japan'), 37.7), ((u'Dodge Rampage', u'US'), 32.0), ((u'Peugeot 304', u'Europe'), 30.0), ((u'Chevrolet Monza 2+2', u'US'), 20.0), ((u'Fiat x1.9', u'Europe'), 31.0), ((u'Chevrolet Cavalier 2-door', u'US'), 34.0), ((u'Ford Mustang II', u'US'), 13.0), ((u'Toyota Corolla', u'Japan'), 263.1), ((u'Ford Escort 2H', u'US'), 29.9), ((u'Audi 5000s (diesel)', u'Europe'), 36.4), ((u'Ford F108', u'US'), 13.0), ((u'Volkswagen Scirocco', u'Europe'), 31.5), ((u'Dodge Aries SE', u'US'), 29.0), ((u'Subaru', u'Japan'), 58.3), ((u'Dodge St. Regis', u'US'), 18.2), ((u'Peugeot 504', u'Europe'), 94.2), ((u'Chevrolet Chevelle Malibu Classic', u'US'), 33.5), ((u'Buick Skylark 320', u'US'), 15.0), ((u'Volkswagen Rabbit Custom Diesel', u'Europe'), 43.1), ((u'Mazda GLC Custom', u'Japan'), 31.0), ((u'Toyota Corolla Hardtop', u'Japan'), 24.0), ((u'Plymouth Satellite', u'US'), 18.0), ((u'AMC Concord d/l', u'US'), 18.1), ((u'Honda Accord CVCC', u'Japan'), 31.5), ((u'Pontiac Phoenix LJ', u'US'), 19.2), ((u'Oldsmobile Omega Brougham', u'US'), 26.8), ((u'Chevrolet Cavalier Wagon', u'US'), 27.0), ((u'Plymouth Satellite Custom (sw)', u'US'), 14.0), ((u'Honda Civic (auto)', u'Japan'), 32.0), ((u'Datsun 210 MPG', u'Japan'), 37.0), ((u'Mercedes-Benz 280s', u'Europe'), 16.5), ((u'Chevrolet Citation', u'US'), 80.3), ((u'Chrysler New Yorker Brougham', u'US'), 13.0), ((u'Nissan Stanza XE', u'Japan'), 36.0), ((u'Toyota Corolla 1200', u'Japan'), 63.0), ((u'Plymouth Satellite (sw)', u'US'), 0.0), ((u'Dodge Aspen 6', u'US'), 20.6), ((u'Chevrolet Cavalier', u'US'), 28.0), ((u'Saab 99gle', u'Europe'), 21.6), ((u'Plymouth Satellite Sebring', u'US'), 18.0), ((u'Buick Regal Sport Coupe (turbo)', u'US'), 17.7), ((u'Fiat 128', u'Europe'), 53.0), ((u'Plymouth Reliant', u'US'), 57.2), ((u'Ford Pinto', u'US'), 137.5), ((u'Plymouth Champ', u'US'), 39.0), ((u'Ford Futura', u'US'), 18.1), ((u'Plymouth Volare Premier v8', u'US'), 13.0), ((u'Ford Country Squire (sw)', u'US'), 28.5), ((u'Ford Torino', u'US'), 17.0), ((u'Plymouth Fury Gran Sedan', u'US'), 14.0), ((u'Fiat 131', u'Europe'), 28.0), ((u'AMC Hornet Sportabout (sw)', u'US'), 18.0), ((u'Pontiac Grand Prix', u'US'), 16.0), ((u'Oldsmobile Starfire SX', u'US'), 23.8), ((u'Audi 5000', u'Europe'), 20.3), ((u'Mazda RX2 Coupe', u'Japan'), 19.0), ((u'Datsun 510 Hatchback', u'Japan'), 37.0), ((u'Buick Century Limited', u'US'), 25.0), ((u'Oldsmobile Cutlass LS', u'US'), 26.6), ((u'Fiat 124 TC', u'Europe'), 26.0), ((u'Buick LeSabre Custom', u'US'), 13.0), ((u'Volkswagen Jetta', u'Europe'), 33.0), ((u'Fiat 124 Sport Coupe', u'Europe'), 26.0), ((u'Pontiac Firebird', u'US'), 19.0), ((u'Volkswagen Dasher (diesel)', u'Europe'), 43.4), ((u'Ford Pinto (sw)', u'US'), 22.0), ((u'Toyota Celica GT', u'Japan'), 32.0), ((u'Saab 99LE', u'Europe'), 25.0), ((u'Opel Manta', u'Europe'), 50.0), ((u'Chevrolet C10', u'US'), 13.0), ((u'Honda Accord', u'Japan'), 68.4), ((u'Ford Torino (sw)', u'US'), 0.0), ((u'Chevrolet Camaro', u'US'), 27.0), ((u'Buick Skyhawk', u'US'), 21.0), ((u'Honda Civic 1500 gl', u'Japan'), 44.6), ((u'Peugeot 604sl', u'Europe'), 16.2), ((u'Capri ii', u'US'), 25.0), ((u'Ford Grenada', u'US'), 18.5), ((u'Plymouth Cricket', u'US'), 26.0), ((u'Opel 1900', u'Europe'), 53.0), ((u'Chevrolet Monte Carlo Landau', u'US'), 34.7), ((u'AMC Hornet', u'US'), 77.5), ((u'Datsun 810', u'Japan'), 22.0), ((u'Mazda RX-7 GS', u'Japan'), 23.7), ((u'Mazda GLC 4', u'Japan'), 34.1), ((u'Chevrolet Monte Carlo', u'US'), 15.0), ((u'AMC Concord DL', u'US'), 23.0), ((u'Triumph TR7 Coupe', u'Europe'), 35.0), ((u'Ford Galaxie 500', u'US'), 43.0), ((u'Ford Grenada l', u'US'), 22.0), ((u'Ford F250', u'US'), 10.0), ((u'Oldsmobile Omega', u'US'), 11.0), ((u'Plymouth Horizon Miser', u'US'), 38.0), ((u'Ford LTD Landau', u'US'), 17.6), ((u'Ford Fairmont (man)', u'US'), 25.1), ((u'AMC Spirit DL', u'US'), 27.4), ((u'Chevrolet Woody', u'US'), 24.5), ((u'Mazda 626', u'Japan'), 62.900000000000006), ((u'Chevrolet Vega', u'US'), 66.0), ((u'Mazda GLC Deluxe', u'Japan'), 66.9), ((u'Honda Civic 1300', u'Japan'), 35.1), ((u'Volkswagen 411 (sw)', u'Europe'), 22.0), ((u'Volvo 244DL', u'Europe'), 22.0), ((u'AMC Pacer', u'US'), 19.0), ((u'Dodge D200', u'US'), 11.0), ((u'Volvo 145e (sw)', u'Europe'), 18.0), ((u'Dodge Diplomat', u'US'), 19.4), ((u'Plymouth Horizon 4', u'US'), 34.7), ((u'Renault Lecar Deluxe', u'Europe'), 40.9), ((u'Toyota Corolla 1600 (sw)', u'Japan'), 27.0), ((u'Volkswagen 1131 Deluxe Sedan', u'Europe'), 26.0), ((u'Volkswagen Type 3', u'Europe'), 23.0)]
</code>```

My question is, I want to again apply the aggregation(sum) on numerical_value of resultedrdd with respect to key as country_name, as i am facing problem while again doing keyby() on it. Any suggestion how could i achieve this? i would like to have suggestion.

Note: I am doing this i.e pipe-lining the rdd's for better and faster computation of aggregates with respect to different keys.

答:
You should map country_name as your sole key, and then you can just use reduceByKey():

```<code>new_rdd = resultedrdd.map(lambda (k,v): (k[1],v)).reduceByKey(lambda x,y: x+y)
new_rdd.collect()
#[(u'Europe', 1952.4),
# (u'Japan', 2405.6000000000004),
# (u'US', 5000.799999999999)]
</code>```

Body:
I have an rdd as rowsrdd given below, to which i have apply aggregation by using keyby() on keys (0,8) and reducebykey() on key (1):

rowsrdd=[[u'Chevrolet Chevelle Malibu', u'18.0', u'8', u'307.0', u'130.0', u'3504.', u'12.0', u'70', u'US'], [u'AMC Rebel SST', u'16.0', u'8', u'304.0', u'150.0', u'3433.', u'12.0', u'70', u'US']]

Note: The above rdd is not complete, it is just a sample of complete rdd to get idea of code below.

def aggonvalfunc(y):
    return y[1]
resultedrdd=rowsrdd.keyBy(lambda w:(w[0],w[8])).mapValues(lambda aggkey:aggonvalfunc(aggkey))\
    .mapValues(float).reduceByKey(lambda x,y: x+y)

which gave following resultedrdd:
which has attributes as car_name, country_name and a numerical_value

resultedrdd=[((u'Dodge Monaco Brougham', u'US'), 15.5), ((u'Chevrolet Monte Carlo S', u'US'), 15.0), ((u'Datsun 280-ZX', u'Japan'), 32.7), ((u'Datsun 510', u'Japan'), 27.2), ((u'Plymouth Duster', u'US'), 65.0), ((u'Chrysler Cordoba', u'US'), 15.5), ((u'Chevrolet Nova', u'US'), 55.0), ((u'Dodge D100', u'US'), 13.0), ((u'Pontiac Safari (sw)', u'US'), 13.0), ((u'Dodge Colt m/m', u'US'), 33.5), ((u'Volkswagen Pickup', u'Europe'), 44.0), ((u'AMC Rebel SST (sw)', u'US'), 0.0), ((u'Chevrolet Caprice Classic', u'US'), 47.5), ((u'Chrysler Lebaron Town @ Country (sw)', u'US'), 18.5), ((u'Chevrolet Impala', u'US'), 52.0), ((u'Pontiac Phoenix', u'US'), 60.5), ((u'Ford Gran Torino', u'US'), 44.5), ((u'Datsun 310', u'Japan'), 37.2), ((u'AMC Ambassador SST', u'US'), 17.0), ((u'Toyota Starlet', u'Japan'), 39.1), ((u'Audi Fox', u'Europe'), 29.0), ((u'Saab 99e', u'Europe'), 25.0), ((u'AMC Ambassador Brougham', u'US'), 13.0), ((u'Dodge Monaco (sw)', u'US'), 12.0), ((u'AMC Concord', u'US'), 43.7), ((u'Chevrolet Concours', u'US'), 17.5), ((u'Chevrolet Chevette', u'US'), 121.6), ((u'Chrysler Lebaron Salon', u'US'), 17.6), ((u'Ford Mustang GL', u'US'), 27.0), ((u'Buick Estate Wagon (sw)', u'US'), 30.9), ((u'Ford Torino 500', u'US'), 19.0), ((u'Volkswagen Rabbit l', u'Europe'), 36.0), ((u'Datsun B210 GX', u'Japan'), 39.4), ((u'Ford Maverick', u'US'), 99.0), ((u'Datsun F-10 Hatchback', u'Japan'), 33.5), ((u'Audi 100 LS', u'Europe'), 24.0), ((u'AMC Pacer d/l', u'US'), 17.5), ((u'Ford Fairmont', u'US'), 26.4), ((u'Chevrolet Malibu Classic (sw)', u'US'), 19.2), ((u'Toyota Corolla Mark II (sw)', u'Japan'), 23.0), ((u'Plymouth Volare Custom', u'US'), 19.0), ((u'Toyota Mark II', u'Japan'), 39.0), ((u'Plymouth Volare', u'US'), 20.5), ((u'Plymouth Sapporo', u'US'), 23.2), ((u'Ford Thunderbird', u'US'), 16.0), ((u'Chrysler Lebaron Medallion', u'US'), 26.0), ((u'Toyota Celica GT Liftback', u'Japan'), 21.1), ((u'Mercury Marquis', u'US'), 11.0), ((u'Mercury Monarch ghia', u'US'), 20.2), ((u'Datsun B210', u'Japan'), 31.0), ((u'Datsun B-210', u'Japan'), 32.0), ((u'Chevy S-10', u'US'), 31.0), ((u'Buick Century Special', u'US'), 20.6), ((u'Mercury Cougar Brougham', u'US'), 15.0), ((u'Oldsmobile Cutlass Supreme', u'US'), 17.0), ((u'Hi 1200D', u'US'), 9.0), ((u'Mercury Monarch', u'US'), 15.0), ((u'Buick Opel Isuzu Deluxe', u'US'), 30.0), ((u'Mercury Capri 2000', u'US'), 23.0), ((u'Dodge Dart Custom', u'US'), 15.0), ((u'Mercury Lynx l', u'US'), 36.0), ((u'AMC Matador', u'US'), 78.5), ((u'Volkswagen Rabbit Custom', u'Europe'), 60.9), ((u'Fiat Strada Custom', u'Europe'), 37.3), ((u'Renault 12tl', u'Europe'), 27.0), ((u'Honda Civic', u'Japan'), 95.0), ((u'Volvo 144ea', u'Europe'), 19.0), ((u'Dodge Coronet Brougham', u'US'), 16.0), ((u'Honda Accord LX', u'Japan'), 29.5), ((u'Dodge Magnum XE', u'US'), 17.5), ((u'AMC Gremlin', u'US'), 78.0), ((u'Dodge Coronet Custom (sw)', u'US'), 14.0), ((u'Saab 900s', u'Europe'), 0.0), ((u'Ford Fairmont Futura', u'US'), 24.0), ((u'Datsun PL510', u'Japan'), 54.0), ((u'Dodge Aspen SE', u'US'), 20.0), ((u'AMC Matador (sw)', u'US'), 29.0), ((u'Chrysler Newport Royal', u'US'), 13.0), ((u'Pontiac Astro', u'US'), 23.0), ((u'Plymouth Custom Suburb', u'US'), 13.0), ((u'Renault 12 (sw)', u'Europe'), 26.0), ((u'Pontiac Ventura SJ', u'US'), 18.5), ((u'Toyota Corolla Liftback', u'Japan'), 55.8), ((u'Oldsmobile Delta 88 Royale', u'US'), 12.0), ((u'Volkswagen Super Beetle', u'Europe'), 26.0), ((u'Citroen DS-21 Pallas', u'Europe'), 0.0), ((u'Buick Electra 225 Custom', u'US'), 12.0), ((u'Audi 4000', u'Europe'), 34.3), ((u'Datsun 310 GX', u'Japan'), 38.0), ((u'Toyota Cressida', u'Japan'), 25.4), ((u'Chevrolet Malibu', u'US'), 33.5), ((u'Volvo Diesel', u'Europe'), 30.7), ((u'Ford Mustang', u'US'), 18.0), ((u'BMW 320i', u'Europe'), 21.5), ((u'Subaru DL', u'Japan'), 63.8), ((u'Ford Pinto Runabout', u'US'), 21.0), ((u'Buick Skylark Limited', u'US'), 28.4), ((u'Dodge Aries Wagon (sw)', u'US'), 25.8), ((u'Oldsmobile Cutlass Salon Brougham', u'US'), 43.8), ((u'BMW 2002', u'Europe'), 26.0), ((u'Plymouth Fury iii', u'US'), 28.0), ((u'Cadillac Eldorado', u'US'), 23.0), ((u'Ford Gran Torino (sw)', u'US'), 27.0), ((u'Chevrolet Bel Air', u'US'), 15.0), ((u'Dodge Colt Hatchback Custom', u'US'), 35.7), ((u'Buick Skylark', u'US'), 47.1), ((u'Fiat 124B', u'Europe'), 30.0), ((u'Volvo 245', u'Europe'), 20.0), ((u'Mercury Grand Marquis', u'US'), 16.5), ((u'Mercury Capri v6', u'US'), 21.0), ((u'AMC Ambassador DPL', u'US'), 15.0), ((u'Buick Century Luxus (sw)', u'US'), 13.0), ((u'Plymouth Fury III', u'US'), 15.0), ((u'Renault 5 GTL', u'Europe'), 36.0), ((u'Mercury Marquis Brougham', u'US'), 12.0), ((u'Renault 18i', u'Europe'), 34.5), ((u'Ford Fiesta', u'US'), 36.1), ((u'Toyota Corolla Mark ii', u'Japan'), 24.0), ((u'Volkswagen Rabbit', u'Europe'), 158.8), ((u'Datsun 510 (sw)', u'Japan'), 28.0), ((u'Mercedes Benz 300d', u'Europe'), 25.4), ((u'Datsun 1200', u'Japan'), 35.0), ((u'Plymouth Arrow GS', u'US'), 25.5), ((u'Ford Mustang II 2+2', u'US'), 25.5), ((u'Oldsmobile Vista Cruiser', u'US'), 12.0), ((u'Mazda RX3', u'Japan'), 18.0), ((u'Volvo 264gl', u'Europe'), 17.0), ((u'Pontiac Grand Prix LJ', u'US'), 16.0), ((u'Dodge Omni', u'US'), 30.9), ((u'Pontiac Sunbird Coupe', u'US'), 24.5), ((u'AMC Rebel SST', u'US'), 16.0), ((u'Chevrolet Nova Custom', u'US'), 16.0), ((u'Mercedes-Benz 240d', u'Europe'), 30.0), ((u'Dodge Coronet Custom', u'US'), 15.0), ((u'Ford Escort 4W', u'US'), 34.4), ((u'Datsun 710', u'Japan'), 56.0), ((u'Ford Fairmont 4', u'US'), 22.3), ((u'Honda Civic CVCC', u'Japan'), 69.1), ((u'Dodge Charger 2.2', u'US'), 36.0), ((u'Dodge Colt (sw)', u'US'), 28.0), ((u'Plymouth Fury', u'US'), 18.0), ((u'Mazda GLC', u'Japan'), 46.6), ((u'Plymouth Valiant', u'US'), 40.0), ((u'Datsun 200SX', u'Japan'), 32.9), ((u'Plymouth Satellite Custom', u'US'), 16.0), ((u'Dodge Aspen', u'US'), 37.7), ((u'Volkswagen Super Beetle 117', u'Europe'), 0.0), ((u'Ford Grenada ghia', u'US'), 18.0), ((u'Ford Country', u'US'), 12.0), ((u'Volkswagen Dasher', u'Europe'), 81.5), ((u'Ford LTD', u'US'), 27.0), ((u'Plymouth Horizon TC3', u'US'), 34.5), ((u'Ford Mustang Boss 302', u'US'), 0.0), ((u'Saab 99le', u'Europe'), 24.0), ((u'AMC Concord DL 6', u'US'), 20.2), ((u'Dodge Challenger SE', u'US'), 15.0), ((u'Volkswagen Rabbit C (Diesel)', u'Europe'), 44.3), ((u'Pontiac Catalina Brougham', u'US'), 14.0), ((u'Pontiac Lemans V6', u'US'), 21.5), ((u'Peugeot 504 (sw)', u'Europe'), 21.0), ((u'Pontiac Catalina', u'US'), 44.0), ((u'Chevrolet Chevelle Malibu', u'US'), 35.0), ((u'Mercury Zephyr', u'US'), 20.8), ((u'Chevy C20', u'US'), 10.0), ((u'Dodge Colt Hardtop', u'US'), 25.0), ((u'Peugeot 505s Turbo Diesel', u'Europe'), 28.1), ((u'Mazda GLC Custom l', u'Japan'), 37.0), ((u'Chevrolet Vega (sw)', u'US'), 22.0), ((u'Buick Century', u'US'), 39.4), ((u'Plymouth Grand Fury', u'US'), 16.0), ((u'Oldsmobile Cutlass Ciera (diesel)', u'US'), 38.0), ((u'Ford Mustang Cobra', u'US'), 23.6), ((u'Ford Grenada gl', u'US'), 20.2), ((u'Toyota Camry', u'Japan'), 20.0), ((u'Honda Prelude', u'Japan'), 33.7), ((u'Ford Ranger', u'US'), 28.0), ((u'Mercury Zephyr 6', u'US'), 19.8), ((u'Chevrolete Chevelle Malibu', u'US'), 16.0), ((u'Dodge Colt', u'US'), 81.9), ((u"Plymouth 'Cuda 340", u'US'), 14.0), ((u'Datsun 210', u'Japan'), 72.6), ((u'Cadillac Seville', u'US'), 16.5), ((u'Pontiac J2000 SE Hatchback', u'US'), 31.0), ((u'Ford Fairmont (auto)', u'US'), 20.2), ((u'Plymouth Horizon', u'US'), 34.2), ((u'Chevrolet Vega 2300', u'US'), 28.0), ((u'Toyota Corolla Tercel', u'Japan'), 38.1), ((u'Volkswagen Model 111', u'Europe'), 27.0), ((u'Chevrolet Chevelle Concours (sw)', u'US'), 13.0), ((u'Audi 100LS', u'Europe'), 43.0), ((u'Datsun 200-SX', u'Japan'), 23.9), ((u'Datsun 810 Maxima', u'Japan'), 24.2), ((u'Plymouth Valiant Custom', u'US'), 19.0), ((u'Datsun 610', u'Japan'), 22.0), ((u'Mazda RX-4', u'Japan'), 21.5), ((u'Buick Century 350', u'US'), 13.0), ((u'Toyota Tercel', u'Japan'), 37.7), ((u'Dodge Rampage', u'US'), 32.0), ((u'Peugeot 304', u'Europe'), 30.0), ((u'Chevrolet Monza 2+2', u'US'), 20.0), ((u'Fiat x1.9', u'Europe'), 31.0), ((u'Chevrolet Cavalier 2-door', u'US'), 34.0), ((u'Ford Mustang II', u'US'), 13.0), ((u'Toyota Corolla', u'Japan'), 263.1), ((u'Ford Escort 2H', u'US'), 29.9), ((u'Audi 5000s (diesel)', u'Europe'), 36.4), ((u'Ford F108', u'US'), 13.0), ((u'Volkswagen Scirocco', u'Europe'), 31.5), ((u'Dodge Aries SE', u'US'), 29.0), ((u'Subaru', u'Japan'), 58.3), ((u'Dodge St. Regis', u'US'), 18.2), ((u'Peugeot 504', u'Europe'), 94.2), ((u'Chevrolet Chevelle Malibu Classic', u'US'), 33.5), ((u'Buick Skylark 320', u'US'), 15.0), ((u'Volkswagen Rabbit Custom Diesel', u'Europe'), 43.1), ((u'Mazda GLC Custom', u'Japan'), 31.0), ((u'Toyota Corolla Hardtop', u'Japan'), 24.0), ((u'Plymouth Satellite', u'US'), 18.0), ((u'AMC Concord d/l', u'US'), 18.1), ((u'Honda Accord CVCC', u'Japan'), 31.5), ((u'Pontiac Phoenix LJ', u'US'), 19.2), ((u'Oldsmobile Omega Brougham', u'US'), 26.8), ((u'Chevrolet Cavalier Wagon', u'US'), 27.0), ((u'Plymouth Satellite Custom (sw)', u'US'), 14.0), ((u'Honda Civic (auto)', u'Japan'), 32.0), ((u'Datsun 210 MPG', u'Japan'), 37.0), ((u'Mercedes-Benz 280s', u'Europe'), 16.5), ((u'Chevrolet Citation', u'US'), 80.3), ((u'Chrysler New Yorker Brougham', u'US'), 13.0), ((u'Nissan Stanza XE', u'Japan'), 36.0), ((u'Toyota Corolla 1200', u'Japan'), 63.0), ((u'Plymouth Satellite (sw)', u'US'), 0.0), ((u'Dodge Aspen 6', u'US'), 20.6), ((u'Chevrolet Cavalier', u'US'), 28.0), ((u'Saab 99gle', u'Europe'), 21.6), ((u'Plymouth Satellite Sebring', u'US'), 18.0), ((u'Buick Regal Sport Coupe (turbo)', u'US'), 17.7), ((u'Fiat 128', u'Europe'), 53.0), ((u'Plymouth Reliant', u'US'), 57.2), ((u'Ford Pinto', u'US'), 137.5), ((u'Plymouth Champ', u'US'), 39.0), ((u'Ford Futura', u'US'), 18.1), ((u'Plymouth Volare Premier v8', u'US'), 13.0), ((u'Ford Country Squire (sw)', u'US'), 28.5), ((u'Ford Torino', u'US'), 17.0), ((u'Plymouth Fury Gran Sedan', u'US'), 14.0), ((u'Fiat 131', u'Europe'), 28.0), ((u'AMC Hornet Sportabout (sw)', u'US'), 18.0), ((u'Pontiac Grand Prix', u'US'), 16.0), ((u'Oldsmobile Starfire SX', u'US'), 23.8), ((u'Audi 5000', u'Europe'), 20.3), ((u'Mazda RX2 Coupe', u'Japan'), 19.0), ((u'Datsun 510 Hatchback', u'Japan'), 37.0), ((u'Buick Century Limited', u'US'), 25.0), ((u'Oldsmobile Cutlass LS', u'US'), 26.6), ((u'Fiat 124 TC', u'Europe'), 26.0), ((u'Buick LeSabre Custom', u'US'), 13.0), ((u'Volkswagen Jetta', u'Europe'), 33.0), ((u'Fiat 124 Sport Coupe', u'Europe'), 26.0), ((u'Pontiac Firebird', u'US'), 19.0), ((u'Volkswagen Dasher (diesel)', u'Europe'), 43.4), ((u'Ford Pinto (sw)', u'US'), 22.0), ((u'Toyota Celica GT', u'Japan'), 32.0), ((u'Saab 99LE', u'Europe'), 25.0), ((u'Opel Manta', u'Europe'), 50.0), ((u'Chevrolet C10', u'US'), 13.0), ((u'Honda Accord', u'Japan'), 68.4), ((u'Ford Torino (sw)', u'US'), 0.0), ((u'Chevrolet Camaro', u'US'), 27.0), ((u'Buick Skyhawk', u'US'), 21.0), ((u'Honda Civic 1500 gl', u'Japan'), 44.6), ((u'Peugeot 604sl', u'Europe'), 16.2), ((u'Capri ii', u'US'), 25.0), ((u'Ford Grenada', u'US'), 18.5), ((u'Plymouth Cricket', u'US'), 26.0), ((u'Opel 1900', u'Europe'), 53.0), ((u'Chevrolet Monte Carlo Landau', u'US'), 34.7), ((u'AMC Hornet', u'US'), 77.5), ((u'Datsun 810', u'Japan'), 22.0), ((u'Mazda RX-7 GS', u'Japan'), 23.7), ((u'Mazda GLC 4', u'Japan'), 34.1), ((u'Chevrolet Monte Carlo', u'US'), 15.0), ((u'AMC Concord DL', u'US'), 23.0), ((u'Triumph TR7 Coupe', u'Europe'), 35.0), ((u'Ford Galaxie 500', u'US'), 43.0), ((u'Ford Grenada l', u'US'), 22.0), ((u'Ford F250', u'US'), 10.0), ((u'Oldsmobile Omega', u'US'), 11.0), ((u'Plymouth Horizon Miser', u'US'), 38.0), ((u'Ford LTD Landau', u'US'), 17.6), ((u'Ford Fairmont (man)', u'US'), 25.1), ((u'AMC Spirit DL', u'US'), 27.4), ((u'Chevrolet Woody', u'US'), 24.5), ((u'Mazda 626', u'Japan'), 62.900000000000006), ((u'Chevrolet Vega', u'US'), 66.0), ((u'Mazda GLC Deluxe', u'Japan'), 66.9), ((u'Honda Civic 1300', u'Japan'), 35.1), ((u'Volkswagen 411 (sw)', u'Europe'), 22.0), ((u'Volvo 244DL', u'Europe'), 22.0), ((u'AMC Pacer', u'US'), 19.0), ((u'Dodge D200', u'US'), 11.0), ((u'Volvo 145e (sw)', u'Europe'), 18.0), ((u'Dodge Diplomat', u'US'), 19.4), ((u'Plymouth Horizon 4', u'US'), 34.7), ((u'Renault Lecar Deluxe', u'Europe'), 40.9), ((u'Toyota Corolla 1600 (sw)', u'Japan'), 27.0), ((u'Volkswagen 1131 Deluxe Sedan', u'Europe'), 26.0), ((u'Volkswagen Type 3', u'Europe'), 23.0)]

My question is, I want to again apply the aggregation(sum) on numerical_value of resultedrdd with respect to key as country_name, as i am facing problem while again doing keyby() on it. Any suggestion how could i achieve this? i would like to have suggestion.

Note: I am doing this i.e pipe-lining the rdd's for better and faster computation of aggregates with respect to different keys.

Body:
You should map country_name as your sole key, and then you can just use reduceByKey():

new_rdd = resultedrdd.map(lambda (k,v): (k[1],v)).reduceByKey(lambda x,y: x+y)
new_rdd.collect()
#[(u'Europe', 1952.4),
# (u'Japan', 2405.6000000000004),
# (u'US', 5000.799999999999)]


问:
How to transform content inside a column
guys. Currently I am building React Weather app (http://powerful-headland-90755.herokuapp.com/#/weather)

and I wanna to make those columns in the bottom flipping to show content on the back side. I encountered a problem, that this animation requires child elements to be absolutely positioned, that's why columns themselves become very low height. I have semantic ui grid, and want to flip those squares on hover.

Any suggestions about how to not break grid while making them transform? Will be glad to receive any help or ideas!

答:
One technique is to make a div that takes up space, and render the actual card inside it which is absolutely positioned. You can then animate it without the grid item changing size.

```<code><div style={{width: '10em', height: '25em'}}>
  <div style={{
    position: 'absolute', top: 0, right: 0, left: 0, bottom: 0,
    transform: something,
  }}>
    content here
  </div>
</div>
</code>```

Inline styles used for example purposes.

Body:
One technique is to make a div that takes up space, and render the actual card inside it which is absolutely positioned. You can then animate it without the grid item changing size.

<div style={{width: '10em', height: '25em'}}>
  <div style={{
    position: 'absolute', top: 0, right: 0, left: 0, bottom: 0,
    transform: something,
  }}>
    content here
  </div>
</div>

Inline styles used for example purposes.


答:
Yes, this adds the NUL character to the end of the string. Actually, it is zero-padding the entire character array---read on for more details.

It should be obvious from reading that individual instruction that it is storing a 0 somewhere in memory, although you couldn't tell that it was actually putting it at the end of the string.

```<code>movw   $0x0,0x8(%rsp)
</code>```

You can see here that this instruction does a word move. Specifically, it moves the immediate value 0 ($0x0) to the memory location 0x8(%rsp), which is an 8-byte offset from the address in the rsp register.

If you expand the context in which you examine the code, things become even more clear. Consider the previous instruction:

```<code>movq   $0x64636261,(%rsp)
</code>```

This does a quad-word move of the immediate value 0x64636261 to the memory location stored in the rsp register. That immediate value, of course, is the string "abcd".

Now, a character is a single byte, and 0x64636261 is 4 bytes, just like the string "abcd". Why in the world is an 8-byte move being done here? Well, because the compiler is taking advantage of implicit zero-extension behavior. When it uses a quad-word move instruction with a double-word immediate, the double-word immediate is implicitly zero extended to a quad word. So what you are actually doing is moving 0x0000000064636261 to (%rsp).

The word move instruction is also zero-extended: the one-byte immediate value is implicitly zero-extended to a full word, and then the word 0x0000 is moved into memory at 0x8(%rsp).

All together, then we've moved 10 bytes into memory: 8 bytes from the quad-word move, and 2 bytes from the word move. This number 10 should look familiar---it is the size of the s array that you declared in your C code!

There is a basic rule of the C language that says:

"If there are … fewer characters in a string literal that is used to initialize an array of known size than there are elements in the array, the remainder of the [array] shall be initialized implicitly the same as objects that have static storage duration."

(C99 $6.7.8/21)

That effectively means that the rest of the array is filled with 0s.

The first 4 bytes of that array are filled with your string, "abcd", and then the next 6 bytes are filled with 0s. The assembly code just breaks the stores up the most optimal way possible: first, it does the largest possible store, and then it does the largest possible store that it can get away with without overrunning the maximum length of the array.

As for the rest of the code, let's walk through it line-by-line:

sub    $0x28,%rsp

rsp is the register that contains the stack pointer. This is subtracting 0x28 bytes from the stack pointer, effectively reserving 40 bytes of space on the stack for the function to use locally. It uses 10 bytes or so explicitly; the rest of the space is probably required by the calling convention or is allocated as an optimization to maintain alignment.

mov    %fs:0x28,%rax

This retrieves the value from %fs:0x28 and stores it in %rax. fs is a segment register, and 0x28 is an offset. Modern 32-bit and 64-bit operating systems don't use segmented addressing like the old 16-bit real mode required, but fs is commonly used for thread-local storage. So the code is reading the value at offset 0x28 from the beginning of the thread-local storage block, and placing it in the rax register.

mov    %rax,0x18(%rsp)

This stores the value from rax (the one we just loaded in there) into memory. Specifically, it loads it onto the stack at an offset of 0x18 from the stack pointer (rsp).

I'm guessing that these two lines of code implement some type of stack canary, but I can't be certain without more information about your operating system, compiler settings, etc. My compiler doesn't generate code like this when I compile your code.

xor    %eax,%eax

This one's simple, but a bit obscure. Bitwise XOR-ing a register with itself is an old trick for zeroing that register's contents. It's also by far the most optimal way of doing it, so that's the code that all compilers will generate.

Now, it might look a little bit strange that it's only zeroing the 32-bit eax register, instead of the whole 64-bit rax register, but it in fact, it is doing that. Virtually all instructions that operate on 32-bit registers in long mode implicitly zero the upper 32-bit half of the register. This is an important optimization at an architectural level, and since the compiler knows the processor is going to do it, it emits code that takes advantage of it. The 32-bit XOR instruction is smaller and thus faster than if it had emitted xor %rax,%rax, but the behavior is identical.

Why is the compiler emitting code to clear the rax/eax register? Because, in all x86 calling conventions that I'm aware of, that register is used for the function's return value. Your main function returns 0, so the compiler is arranging for that return value to be in the rax register.

Title: Null character assembly code

Body:
Does 0x00000000004005c7 <+28>:    movw   $0x0,0x8(%rsp) add the null character at the end of the string?

Could someone also explain the first 4 lines?

0x00000000004005ab <+0>:     sub    $0x28,%rsp
0x00000000004005af <+4>:     mov    %fs:0x28,%rax
0x00000000004005b8 <+13>:    mov    %rax,0x18(%rsp)
0x00000000004005bd <+18>:    xor    %eax,%eax
0x00000000004005bf <+20>:    movq   $0x64636261,(%rsp)
0x00000000004005c7 <+28>:    movw   $0x0,0x8(%rsp)
=> 0x00000000004005ce <+35>:    mov    %rsp,%rdi
0x00000000004005d1 <+38>:    callq  0x40059d <func>
0x00000000004005d6 <+43>:    mov    $0x0,%eax
0x00000000004005db <+48>:    mov    0x18(%rsp),%rdx
0x00000000004005e0 <+53>:    xor    %fs:0x28,%rdx
0x00000000004005e9 <+62>:    je     0x4005f0
0x00000000004005eb <+64>:    callq  0x400480         <__stack_chk_fail@plt>
0x00000000004005f0 <+69>:    add    $0x28,%rsp
0x00000000004005f4 <+73>:    retq

C code:

#include <stdio.h>

void func(char s[])
{
    printf("%s\n", s);
}

int main()
{
    char s[10] = "abcd";

    func(s);

    return 0;
}

Thanks.

OS:

Linux version 4.9.17-c9 (gcc version 4.9.2 (Debian 4.9.2-10) )

CPU:

vendor_id       : GenuineIntel

cpu family      : 6

model           : 63

model name      : Intel(R) Xeon(R) CPU @ 2.30GHz

Body:
Yes, this adds the NUL character to the end of the string. Actually, it is zero-padding the entire character array---read on for more details.

It should be obvious from reading that individual instruction that it is storing a 0 somewhere in memory, although you couldn't tell that it was actually putting it at the end of the string.

movw   $0x0,0x8(%rsp)

You can see here that this instruction does a word move. Specifically, it moves the immediate value 0 ($0x0) to the memory location 0x8(%rsp), which is an 8-byte offset from the address in the rsp register.

If you expand the context in which you examine the code, things become even more clear. Consider the previous instruction:

movq   $0x64636261,(%rsp)

This does a quad-word move of the immediate value 0x64636261 to the memory location stored in the rsp register. That immediate value, of course, is the string "abcd".

Now, a character is a single byte, and 0x64636261 is 4 bytes, just like the string "abcd". Why in the world is an 8-byte move being done here? Well, because the compiler is taking advantage of implicit zero-extension behavior. When it uses a quad-word move instruction with a double-word immediate, the double-word immediate is implicitly zero extended to a quad word. So what you are actually doing is moving 0x0000000064636261 to (%rsp).

The word move instruction is also zero-extended: the one-byte immediate value is implicitly zero-extended to a full word, and then the word 0x0000 is moved into memory at 0x8(%rsp).

All together, then we've moved 10 bytes into memory: 8 bytes from the quad-word move, and 2 bytes from the word move. This number 10 should look familiar---it is the size of the s array that you declared in your C code!

There is a basic rule of the C language that says:

"If there are … fewer characters in a string literal that is used to initialize an array of known size than there are elements in the array, the remainder of the [array] shall be initialized implicitly the same as objects that have static storage duration."

(C99 $6.7.8/21)

That effectively means that the rest of the array is filled with 0s.

The first 4 bytes of that array are filled with your string, "abcd", and then the next 6 bytes are filled with 0s. The assembly code just breaks the stores up the most optimal way possible: first, it does the largest possible store, and then it does the largest possible store that it can get away with without overrunning the maximum length of the array.

As for the rest of the code, let's walk through it line-by-line:

sub    $0x28,%rsp

rsp is the register that contains the stack pointer. This is subtracting 0x28 bytes from the stack pointer, effectively reserving 40 bytes of space on the stack for the function to use locally. It uses 10 bytes or so explicitly; the rest of the space is probably required by the calling convention or is allocated as an optimization to maintain alignment.

mov    %fs:0x28,%rax

This retrieves the value from %fs:0x28 and stores it in %rax. fs is a segment register, and 0x28 is an offset. Modern 32-bit and 64-bit operating systems don't use segmented addressing like the old 16-bit real mode required, but fs is commonly used for thread-local storage. So the code is reading the value at offset 0x28 from the beginning of the thread-local storage block, and placing it in the rax register.

mov    %rax,0x18(%rsp)

This stores the value from rax (the one we just loaded in there) into memory. Specifically, it loads it onto the stack at an offset of 0x18 from the stack pointer (rsp).

I'm guessing that these two lines of code implement some type of stack canary, but I can't be certain without more information about your operating system, compiler settings, etc. My compiler doesn't generate code like this when I compile your code.

xor    %eax,%eax

This one's simple, but a bit obscure. Bitwise XOR-ing a register with itself is an old trick for zeroing that register's contents. It's also by far the most optimal way of doing it, so that's the code that all compilers will generate.

Now, it might look a little bit strange that it's only zeroing the 32-bit eax register, instead of the whole 64-bit rax register, but it in fact, it is doing that. Virtually all instructions that operate on 32-bit registers in long mode implicitly zero the upper 32-bit half of the register. This is an important optimization at an architectural level, and since the compiler knows the processor is going to do it, it emits code that takes advantage of it. The 32-bit XOR instruction is smaller and thus faster than if it had emitted xor %rax,%rax, but the behavior is identical.

Why is the compiler emitting code to clear the rax/eax register? Because, in all x86 calling conventions that I'm aware of, that register is used for the function's return value. Your main function returns 0, so the compiler is arranging for that return value to be in the rax register.


问:
How to change Action Bar/Title Bar font?
Not sure if this is called the action bar or the title bar but I need to change the font to a font I have in my assets folder. How do I do this?

答:
You can access textview of your toolbar like this:

```<code>TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
</code>```

And then assign needed font:

```<code>mTitle.setTypeface(someTypeface);
</code>```

Body:
You can access textview of your toolbar like this:

TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);

And then assign needed font:

mTitle.setTypeface(someTypeface);


问:
Disabling contextmenu (the options seen on a right click) by adding event listener doesn't work

Disabling contextmenu via an event handler

I am trying to disable right click on an element. I found a solution which does it like so:

```<code><div oncontextmenu='return false'></div>
</code>```

But since it is not a good practice to have event handlers in html, I tried something like:

```<code><div id='test'></div>
</code>```

and on the js part of the code:

```<code>let test = document.getElementById('test')

test.addEventListener('contextmenu', (e) => {
  console.log('right click!')
  return false
})
</code>```

let test2 = document.getElementById('test2')

test2.addEventListener('contextmenu', (e) => {
  console.log('right click!')
  return false
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>div {
  height: 100px;
  width: 100px;
  border: 1px solid black;
}

#test1 {
  background-color: red;
}

#test2 {
  background-color: blue;
}</code>```

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

<p>Right click on <code>test1</code> would be successfully disabled, but not on <code>test2</code> and the console proves that the program control did reach the handler. </p>

<hr>

<p>I am not looking for a workaround as </p>

```

let test = document.getElementById('test')

test.addEventListener('contextmenu', (e) => {
  e.preventDefault()
  console.log('right click!')
})
```

works perfectly.

I want to know, why are the two elements in the above snippet behaving differently?

答:
This is weird behaviour. For some reason, a return false from an .addEventListener does not work (tested in latest stable chrome). You need to call the .preventDefault() method as shown below and return false to get what you want in modern and ancient browsers. A right click is logged to the console but no context menu shows up.

Note that I added some semicolons for style. Although in your example they were not technically needed, it is a good practice to include them.

let test2 = document.getElementById('test2')

test2.addEventListener('contextmenu', (e) => {
  console.log('right click!');
  e.preventDefault();//===added this===
  return false;
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>div {
  height: 100px;
  width: 100px;
  border: 1px solid black;
}

#test1 {
  background-color: red;
}

#test2 {
  background-color: blue;
}</code>```

```

Body:
Disabling contextmenu via an event handler

I am trying to disable right click on an element. I found a solution which does it like so:

But since it is not a good practice to have event handlers in html, I tried something like:

and on the js part of the code:

let test = document.getElementById('test')

test.addEventListener('contextmenu', (e) => {
  console.log('right click!')
  return false
})

let test2 = document.getElementById('test2')

test2.addEventListener('contextmenu', (e) => {
  console.log('right click!')
  return false
})

div {
  height: 100px;
  width: 100px;
  border: 1px solid black;
}

#test1 {
  background-color: red;
}

#test2 {
  background-color: blue;
}

Right click on test1 would be successfully disabled, but not on test2 and the console proves that the program control did reach the handler.

I am not looking for a workaround as

let test = document.getElementById('test')

test.addEventListener('contextmenu', (e) => {
  e.preventDefault()
  console.log('right click!')
})

works perfectly.

I want to know, why are the two elements in the above snippet behaving differently?

Body:
This is weird behaviour. For some reason, a return false from an .addEventListener does not work (tested in latest stable chrome). You need to call the .preventDefault() method as shown below and return false to get what you want in modern and ancient browsers. A right click is logged to the console but no context menu shows up.

Note that I added some semicolons for style. Although in your example they were not technically needed, it is a good practice to include them.

let test2 = document.getElementById('test2')

test2.addEventListener('contextmenu', (e) => {
  console.log('right click!');
  e.preventDefault();//===added this===
  return false;
});

div {
  height: 100px;
  width: 100px;
  border: 1px solid black;
}

#test1 {
  background-color: red;
}

#test2 {
  background-color: blue;
}

<div id='test1' oncontextmenu='return false'></div>
<div id='test2'></div>


问:
“unresolved dependency” for Spark 2.1.0 on SBT

version := "1.0"
 scalaVersion := "2.11.8"
 ivyScala :=
  ivyScala.value map { _.copy(overrideScalaVersion = true) }

  libraryDependencies += "org.apache.spark" %% "spark-core" % "2.1.0"

I try to get spark into my develop environment, when i try to assembly jar by sbt, but it failed and showed [error] in my sbt just like below:

```<code>[warn]  :::::::::::::::::::::::::::::::::::::::::::::: <br/>
[warn]  ::          UNRESOLVED DEPENDENCIES         :: <br/>
[warn]  :::::::::::::::::::::::::::::::::::::::::::::: <br/>
[warn]  :: org.apache.spark#spark-core_2.11;2.1.0: not found <br/>
[warn]  :::::::::::::::::::::::::::::::::::::::::::::: <br/>
[warn]
[warn]  Note: Unresolved dependencies path: <br/>
[warn]      org.apache.spark:spark-core_2.11:2.1.0  (D:\MyDocument\IDEA\Scala\model\build.sbt#L9-10) <br/>
[warn]        +- org.apache.spark:spark-catalyst_2.11:2.1.0 <br/>
[warn]        +- org.apache.spark:spark-sql_2.11:2.1.0 (D:\MyDocument\IDEA\Scala\model\build.sbt#L15-16) <br/>
[warn]        +- org.apache.spark:spark-hive_2.11:2.1.0 (D:\MyDocument\IDEA\Scala\model\build.sbt#L11-12) <br/>
[warn]        +- default:producttagmodel_2.11:1.0 <br/>
[trace] Stack trace suppressed: run 'last *:update' for the full output. <br/>
[error] (*:update) sbt.ResolveException: unresolved dependency: org.apache.spark#spark-core_2.11;2.1.0: not found
</code>```

my IntelliJ version is 2016.3.5, and sbt version is 0.13.13 and scala version is 2.11.8; i found that sbt have download the spark-core.jar successfully which i find it in my .ivy/cache directory, but it always show "unknown artifact. Not Resovled or Indexed". I have refresh my project index many times but it didn't work.  i create a new project by using the same build.sbt in case of the IntelliJ cache disturb, but it didn't work. I am totally confused of this problem.

    here is my build.sbt setting below:

答:
How about changing the dependency to :

```<code>libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.1.0"
</code>```

In addition for a spark app, this is normally added as "provided", it should not be included in the jar, as when you submit your job, the related spark libs are installed already in driver and executors.

Body:
version := "1.0"
 scalaVersion := "2.11.8"
 ivyScala :=
  ivyScala.value map { _.copy(overrideScalaVersion = true) }

  libraryDependencies += "org.apache.spark" %% "spark-core" % "2.1.0"

I try to get spark into my develop environment, when i try to assembly jar by sbt, but it failed and showed [error] in my sbt just like below:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

[warn]  ::          UNRESOLVED DEPENDENCIES         ::

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

[warn]  :: org.apache.spark#spark-core_2.11;2.1.0: not found

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

[warn]
[warn]  Note: Unresolved dependencies path:

[warn]      org.apache.spark:spark-core_2.11:2.1.0  (D:\MyDocument\IDEA\Scala\model\build.sbt#L9-10)

[warn]        +- org.apache.spark:spark-catalyst_2.11:2.1.0

[warn]        +- org.apache.spark:spark-sql_2.11:2.1.0 (D:\MyDocument\IDEA\Scala\model\build.sbt#L15-16)

[warn]        +- org.apache.spark:spark-hive_2.11:2.1.0 (D:\MyDocument\IDEA\Scala\model\build.sbt#L11-12)

[warn]        +- default:producttagmodel_2.11:1.0

[trace] Stack trace suppressed: run 'last *:update' for the full output.

[error] (*:update) sbt.ResolveException: unresolved dependency: org.apache.spark#spark-core_2.11;2.1.0: not found

my IntelliJ version is 2016.3.5, and sbt version is 0.13.13 and scala version is 2.11.8; i found that sbt have download the spark-core.jar successfully which i find it in my .ivy/cache directory, but it always show "unknown artifact. Not Resovled or Indexed". I have refresh my project index many times but it didn't work.  i create a new project by using the same build.sbt in case of the IntelliJ cache disturb, but it didn't work. I am totally confused of this problem.

    here is my build.sbt setting below:

Body:
How about changing the dependency to :

libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.1.0"

In addition for a spark app, this is normally added as "provided", it should not be included in the jar, as when you submit your job, the related spark libs are installed already in driver and executors.


问:
Best Practice to Update EAV table rows
I have the following table:

```<code>SubjectID AttributeID ValueID
1         1           2
1         1           3
1         2           1
2         1           3
2         2           1
1         3           1
</code>```

An attribute can have multiple values (multiple appearances in the above table for the same attribute).
There is no constraint of how many appearances for the same attribute (different value).

I wan't to Update the Subject with SubjectID=1, to change the ValueID to only 1 where the AttributeID is 1, so

Before:

```<code>Select * from Subject WHERE SubjectID=1 AND AttributeID=1
--returns:
SubjectID AttributeID ValueID
1         1           2
1         1           3
</code>```

After:

```<code>Select * from Subject WHERE SubjectID=1 AND AttributeID=1
--returns:
SubjectID AttributeID ValueID
1         1           1
</code>```

I am doing this with a stored procedure with optional parameters (all null and update only the attributes that were provided), now this is not an issue. My question is:

What is the best practice to update this rows? I see the following answers as viable:

Delete all the rows that contain the specified attribute, then insert the new ones;

If there is only one attribute of that type (for the specified subject) update that one (not a good solution if there are more than 1 for the same attribute)

Any other ideas?

答:
Using set rowcount is deprecated, use top (n) instead.

Important

  Using SET ROWCOUNT will not affect DELETE, INSERT, and UPDATE statements in a future release of SQL Server. Avoid using SET ROWCOUNT with DELETE, INSERT, and UPDATE statements in new development work, and plan to modify applications that currently use it. For a similar behavior, use the TOP syntax. For more information, see TOP (Transact-SQL).

```<code>update top (1) Subject
  set ValueID = 1
where SubjectID = 1
  and AttributeID = 1;

delete Subject
where SubjectID = 1
  and AttributeID = 1
  and ValueID <> 1;
</code>```

rextester demo: http://rextester.com/ATDKI87027

returns:

```<code>+-----------+-------------+---------+
| SubjectID | AttributeID | ValueID |
+-----------+-------------+---------+
|         1 |           1 |       1 |
|         1 |           2 |       1 |
|         2 |           1 |       3 |
|         2 |           2 |       1 |
|         1 |           3 |       1 |
+-----------+-------------+---------+
</code>```

Title: Best Practice to Update EAV table rows

Body:
I have the following table:

SubjectID AttributeID ValueID
1         1           2
1         1           3
1         2           1
2         1           3
2         2           1
1         3           1

An attribute can have multiple values (multiple appearances in the above table for the same attribute).
There is no constraint of how many appearances for the same attribute (different value).

I wan't to Update the Subject with SubjectID=1, to change the ValueID to only 1 where the AttributeID is 1, so

Before:

Select * from Subject WHERE SubjectID=1 AND AttributeID=1
--returns:
SubjectID AttributeID ValueID
1         1           2
1         1           3

After:

Select * from Subject WHERE SubjectID=1 AND AttributeID=1
--returns:
SubjectID AttributeID ValueID
1         1           1

I am doing this with a stored procedure with optional parameters (all null and update only the attributes that were provided), now this is not an issue. My question is:

What is the best practice to update this rows? I see the following answers as viable:

Delete all the rows that contain the specified attribute, then insert the new ones;

If there is only one attribute of that type (for the specified subject) update that one (not a good solution if there are more than 1 for the same attribute)

Any other ideas?

Body:
Using set rowcount is deprecated, use top (n) instead.

Important

  Using SET ROWCOUNT will not affect DELETE, INSERT, and UPDATE statements in a future release of SQL Server. Avoid using SET ROWCOUNT with DELETE, INSERT, and UPDATE statements in new development work, and plan to modify applications that currently use it. For a similar behavior, use the TOP syntax. For more information, see TOP (Transact-SQL).

update top (1) Subject
  set ValueID = 1
where SubjectID = 1
  and AttributeID = 1;

delete Subject
where SubjectID = 1
  and AttributeID = 1
  and ValueID <> 1;

rextester demo: http://rextester.com/ATDKI87027

returns:

+-----------+-------------+---------+
| SubjectID | AttributeID | ValueID |
+-----------+-------------+---------+
|         1 |           1 |       1 |
|         1 |           2 |       1 |
|         2 |           1 |       3 |
|         2 |           2 |       1 |
|         1 |           3 |       1 |
+-----------+-------------+---------+


问:
Return identity of last inserted row from stored procedure
I am trying to return identity of last inserted row from a stored procedure.

A simplified version of my code looks like this:

```<code>CREATE PROCEDURE [sp_name]
    @AuthorisationCode uniqueidentifier
AS
    INSERT INTO [tablename]
           ([AuthorisationCode]
           )
     VALUES
           (@AuthorisationCode
           )

 RETURN @@IDENTITY

GO
</code>```

I am calling this stored procedure via Execute Scalar in Enterprise library 4.1.

It returns null. Anybody see what I am doing wrong.

答:
I'd say you should be using SCOPE_IDENTITY() as @@identity will return the identity of the last thing inserted (which may not be your stored procedure if multiple queries are running simultaneously).

You also need to SELECT it, not RETURN it.

ExecuteScalar will return the first column value from the first row of a result set.

So...

```<code>SELECT SCOPE_IDENTITY();
</code>```

is probably more what you want.

Body:
I am trying to return identity of last inserted row from a stored procedure.

A simplified version of my code looks like this:

CREATE PROCEDURE [sp_name]
    @AuthorisationCode uniqueidentifier
AS
    INSERT INTO [tablename]
           ([AuthorisationCode]
           )
     VALUES
           (@AuthorisationCode
           )

 RETURN @@IDENTITY

GO

I am calling this stored procedure via Execute Scalar in Enterprise library 4.1.

It returns null. Anybody see what I am doing wrong.

Body:
I'd say you should be using SCOPE_IDENTITY() as @@identity will return the identity of the last thing inserted (which may not be your stored procedure if multiple queries are running simultaneously).

You also need to SELECT it, not RETURN it.

ExecuteScalar will return the first column value from the first row of a result set.

So...

SELECT SCOPE_IDENTITY();

is probably more what you want.