问:
Select multiple aggregation result from the same subquery
I find myself doing statistics like this more and more often - for every record in tbl1, use it as condition to scan tbl2 and do aggregation on tbl2, return the aggregated results. This is easy with sub-query.

But I need to do multiple aggregation in one pass in the same subquery instead of scanning multiple times.

For example, here is some sample data for analysis:

```<code>SELECT  to_timestamp((random()*999999)) evt_ts,
    evt_id
    INTO temp.test_so_44410354
FROM
    (
        SELECT *, (random()*2000)::int AS idx
            FROM generate_series( 1, 1000) AS evt_id
            ORDER BY idx
    ) AS t

evt_ts              |evt_id |
--------------------|-------|
1970-01-01 08:13:15 |109    |
1970-01-01 08:17:22 |762    |
1970-01-01 08:19:28 |630    |
1970-01-01 08:29:34 |429    |
1970-01-01 08:48:28 |70     |
</code>```

To see how events distribute over an given time frame,
current approach & query plan & desired output :

```<code>With wcal AS (
    SELECT ts, ts::date as dt
    FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
SELECT ts, dt
,(
    SELECT count(evt_ts)
    FROM temp.test_so_44410354 as el
    WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
) as ecnt
,(
    SELECT sum(evt_id) -- should be array_agg, sum is locate to the difference in the results.
    FROM temp.test_so_44410354 as el
    WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
) as eids
FROM wcal

QUERY PLAN                                                                                |
----------------------------------------------------------------------------------------------------|
CTE Scan on wcal  (cost=12.50..21314.08 rows=1000 width=28)                                         |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12)                  |
  SubPlan 2                                                                                |
    ->  Aggregate  (cost=10.63..10.64 rows=1 width=8)                                               |
          ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=8)            |
                Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))     |
                ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0)     |
                      Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval))) |
  SubPlan 3                                                                                |
    ->  Aggregate  (cost=10.63..10.64 rows=1 width=8)                                               |
    ...

ts                  |dt         |ecnt |eids  |
--------------------|-----------|-----|------|
1970-01-01 00:00:00 |1970-01-01 |0    |      |
1970-01-02 00:00:00 |1970-01-02 |68   |36156 |
1970-01-03 00:00:00 |1970-01-03 |85   |42103 |
1970-01-04 00:00:00 |1970-01-04 |94   |47092 |
1970-01-05 00:00:00 |1970-01-05 |74   |36276 |
....
</code>```

There are 2 subplans, it seems pg will have to scan table evt_log twice to do the same aggregation twice. I'd would like avoid this. since the aggregation conditions are exactly the same and it maybe be much faster if it can do many statistical aggregation in one pass. Logs can grow very big, the processing will take quite some time.

Feedback on proposed solution I
nested join is not working as expected:

```<code>With wcal AS (
SELECT ts, ts::date as dt
FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
, ag AS (
    SELECT
        count(evt_ts) AS ecnt
      , sum(evt_id) AS eids
    FROM temp.test_so_44410354 as el
    JOIN wcal ON ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
)
SELECT ts, dt, ag.ecnt, eids
FROM wcal
JOIN ag ON true

QUERY PLAN                                                                                |
----------------------------------------------------------------------------------------------------------------------|
Nested Loop  (cost=4239.57..4269.59 rows=1000 width=28)                                                               |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12)                                    |
  CTE ag                                                                                |
    ->  Aggregate  (cost=4227.06..4227.07 rows=1 width=16)                                                            |
          ->  Nested Loop  (cost=0.28..3671.50 rows=111111 width=12)                                                  |
                ->  CTE Scan on wcal wcal_1  (cost=0.00..20.00 rows=1000 width=8)                                     |
                ->  Index Scan using test_so_44410354_idx on test_so_44410354 el  (cost=0.28..2.54 rows=111 width=12) |
                      Index Cond: ((evt_ts < wcal_1.ts) AND (evt_ts > (wcal_1.ts - '1 day'::interval)))               |
  ->  CTE Scan on ag  (cost=0.00..0.02 rows=1 width=16)                                                               |
  ->  CTE Scan on wcal  (cost=0.00..20.00 rows=1000 width=12)                                                         |

ts                  |dt         |ecnt |eids   |
--------------------|-----------|-----|-------|
1970-01-01 00:00:00 |1970-01-01 |920  |464436 |
1970-01-04 00:00:00 |1970-01-04 |920  |464436 |
1970-01-05 00:00:00 |1970-01-05 |920  |464436 |
1970-01-06 00:00:00 |1970-01-06 |920  |464436 |
1970-01-07 00:00:00 |1970-01-07 |920  |464436 |
....
</code>```

Feedack on proposed solution II:
The writing are different but the query plan are basically the same with 2 sub plan.

```<code>DROP TYPE temp.my_agg ;
CREATE TYPE temp.my_agg AS ( ecnt int, eids int );
EXPLAIN
With wcal AS (
    SELECT ts, ts::date as dt
    FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
SELECT ts, dt
,(
    SELECT (count(evt_ts),sum(evt_id))::temp.my_agg
    FROM temp.test_so_44410354 as el
    WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
).*
FROM wcal

QUERY PLAN                                                                                |
--------------------------------------------------------------------------------------------------------------------------------------------|
CTE Scan on wcal  (cost=12.50..21349.08 rows=1000 width=20) (actual time=0.182..3.518 rows=12 loops=1)                                      |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12) (actual time=0.057..0.083 rows=12 loops=1)               |
  SubPlan 2                                                                                |
    ->  Aggregate  (cost=10.64..10.66 rows=1 width=32) (actual time=0.140..0.140 rows=1 loops=12)                                           |
          ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=12) (actual time=0.049..0.083 rows=77 loops=12)       |
                Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                             |
                Heap Blocks: exact=66                                                                                |
                ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0) (actual time=0.037..0.037 rows=77 loops=12) |
                      Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                         |
  SubPlan 3                                                                                |
    ...
Planning time: 0.548 ms                                                                                |
Execution time: 3.748 ms                                                                                |
</code>```

For proposed solution II, if the aggregation is returned as record, the query plan will look like below:
Which roughly doubled the speed c.f. previous query. (but record type element is not desired as final result.)

```<code>QUERY PLAN                                                                                |
--------------------------------------------------------------------------------------------------------------------------------------------|
CTE Scan on wcal  (cost=12.50..10690.79 rows=1000 width=44) (actual time=0.147..1.979 rows=12 loops=1)                                      |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12) (actual time=0.057..0.082 rows=12 loops=1)               |
  SubPlan 2                                                                                |
    ->  Aggregate  (cost=10.64..10.66 rows=1 width=32) (actual time=0.151..0.151 rows=1 loops=12)                                           |
          ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=12) (actual time=0.054..0.089 rows=77 loops=12)       |
                Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                             |
                Heap Blocks: exact=66                                                                                |
                ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0) (actual time=0.040..0.040 rows=77 loops=12) |
                      Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                         |
Planning time: 0.381 ms                                                                                |
Execution time: 2.147 ms                                                                                |
</code>```

The LATERAL join solution works just as expected. Thanks.

```<code>EXPLAIN ANALYZE
With wcal AS (
    SELECT ts, ts::date as dt
    FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
SELECT ts, dt, p.*
FROM wcal
     CROSS JOIN LATERAL (
        SELECT count(evt_ts), sum(evt_id)
        FROM temp.test_so_44410354 as el
        WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
    ) p

QUERY PLAN                                                                                |
------------------------------------------------------------------------------------------------------------------------------------------|
Nested Loop  (cost=23.15..10705.79 rows=1000 width=28) (actual time=0.130..1.611 rows=12 loops=1)                                         |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12) (actual time=0.054..0.075 rows=12 loops=1)             |
  ->  CTE Scan on wcal  (cost=0.00..20.00 rows=1000 width=12) (actual time=0.061..0.099 rows=12 loops=1)                                  |
  ->  Aggregate  (cost=10.64..10.65 rows=1 width=16) (actual time=0.123..0.123 rows=1 loops=12)                                           |
        ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=12) (actual time=0.044..0.074 rows=77 loops=12)       |
              Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                             |
              Heap Blocks: exact=66                                                                                |
              ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0) (actual time=0.033..0.033 rows=77 loops=12) |
                    Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                         |
Planning time: 0.399 ms                                                                                |
Execution time: 1.778 ms                                                                                |

ts                  |dt         |count |sum   |
--------------------|-----------|------|------|
1970-01-01 00:00:00 |1970-01-01 |0     |      |
1970-01-02 00:00:00 |1970-01-02 |68    |36156 |
1970-01-03 00:00:00 |1970-01-03 |85    |42103 |
1970-01-04 00:00:00 |1970-01-04 |94    |47092 |
1970-01-05 00:00:00 |1970-01-05 |74    |36276 |
1970-01-06 00:00:00 |1970-01-06 |96    |43797 |
</code>```

答:
It is tricky a bit but:</p>

```<code>create type t_my_aggs as (ecnt bigint, eids bigint[]);

With wcal AS (
    SELECT ts, ts::date as dt,
        extract( week from ts) as wk,
        extract( month from ts ) as mo,
        extract( quater from ts ) as qtr,
    FROM generate_series( t1, t2, tspan )
)
SELECT ts, dt, wk, mo, qtr
,(
    SELECT row(count(evt_ts), array_agg(evt_id))::t_my_aggs
    FROM ev_log as el
    WHERE ( el.ts < wcal.ts AND el.ts < wcal.ts - tspan )
).* from wcal;
</code>```

Body:
I find myself doing statistics like this more and more often - for every record in tbl1, use it as condition to scan tbl2 and do aggregation on tbl2, return the aggregated results. This is easy with sub-query.

But I need to do multiple aggregation in one pass in the same subquery instead of scanning multiple times.

For example, here is some sample data for analysis:

SELECT  to_timestamp((random()*999999)) evt_ts,
    evt_id
    INTO temp.test_so_44410354
FROM
    (
        SELECT *, (random()*2000)::int AS idx
            FROM generate_series( 1, 1000) AS evt_id
            ORDER BY idx
    ) AS t

evt_ts              |evt_id |
--------------------|-------|
1970-01-01 08:13:15 |109    |
1970-01-01 08:17:22 |762    |
1970-01-01 08:19:28 |630    |
1970-01-01 08:29:34 |429    |
1970-01-01 08:48:28 |70     |

To see how events distribute over an given time frame,
current approach & query plan & desired output :

With wcal AS (
    SELECT ts, ts::date as dt
    FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
SELECT ts, dt
,(
    SELECT count(evt_ts)
    FROM temp.test_so_44410354 as el
    WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
) as ecnt
,(
    SELECT sum(evt_id) -- should be array_agg, sum is locate to the difference in the results.
    FROM temp.test_so_44410354 as el
    WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
) as eids
FROM wcal

QUERY PLAN                                                                                |
----------------------------------------------------------------------------------------------------|
CTE Scan on wcal  (cost=12.50..21314.08 rows=1000 width=28)                                         |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12)                  |
  SubPlan 2                                                                                |
    ->  Aggregate  (cost=10.63..10.64 rows=1 width=8)                                               |
          ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=8)            |
                Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))     |
                ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0)     |
                      Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval))) |
  SubPlan 3                                                                                |
    ->  Aggregate  (cost=10.63..10.64 rows=1 width=8)                                               |
    ...

ts                  |dt         |ecnt |eids  |
--------------------|-----------|-----|------|
1970-01-01 00:00:00 |1970-01-01 |0    |      |
1970-01-02 00:00:00 |1970-01-02 |68   |36156 |
1970-01-03 00:00:00 |1970-01-03 |85   |42103 |
1970-01-04 00:00:00 |1970-01-04 |94   |47092 |
1970-01-05 00:00:00 |1970-01-05 |74   |36276 |
....

There are 2 subplans, it seems pg will have to scan table evt_log twice to do the same aggregation twice. I'd would like avoid this. since the aggregation conditions are exactly the same and it maybe be much faster if it can do many statistical aggregation in one pass. Logs can grow very big, the processing will take quite some time.

Feedback on proposed solution I
nested join is not working as expected:

With wcal AS (
SELECT ts, ts::date as dt
FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
, ag AS (
    SELECT
        count(evt_ts) AS ecnt
      , sum(evt_id) AS eids
    FROM temp.test_so_44410354 as el
    JOIN wcal ON ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
)
SELECT ts, dt, ag.ecnt, eids
FROM wcal
JOIN ag ON true

QUERY PLAN                                                                                |
----------------------------------------------------------------------------------------------------------------------|
Nested Loop  (cost=4239.57..4269.59 rows=1000 width=28)                                                               |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12)                                    |
  CTE ag                                                                                |
    ->  Aggregate  (cost=4227.06..4227.07 rows=1 width=16)                                                            |
          ->  Nested Loop  (cost=0.28..3671.50 rows=111111 width=12)                                                  |
                ->  CTE Scan on wcal wcal_1  (cost=0.00..20.00 rows=1000 width=8)                                     |
                ->  Index Scan using test_so_44410354_idx on test_so_44410354 el  (cost=0.28..2.54 rows=111 width=12) |
                      Index Cond: ((evt_ts < wcal_1.ts) AND (evt_ts > (wcal_1.ts - '1 day'::interval)))               |
  ->  CTE Scan on ag  (cost=0.00..0.02 rows=1 width=16)                                                               |
  ->  CTE Scan on wcal  (cost=0.00..20.00 rows=1000 width=12)                                                         |

ts                  |dt         |ecnt |eids   |
--------------------|-----------|-----|-------|
1970-01-01 00:00:00 |1970-01-01 |920  |464436 |
1970-01-04 00:00:00 |1970-01-04 |920  |464436 |
1970-01-05 00:00:00 |1970-01-05 |920  |464436 |
1970-01-06 00:00:00 |1970-01-06 |920  |464436 |
1970-01-07 00:00:00 |1970-01-07 |920  |464436 |
....

Feedack on proposed solution II:
The writing are different but the query plan are basically the same with 2 sub plan.

DROP TYPE temp.my_agg ;
CREATE TYPE temp.my_agg AS ( ecnt int, eids int );
EXPLAIN
With wcal AS (
    SELECT ts, ts::date as dt
    FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
SELECT ts, dt
,(
    SELECT (count(evt_ts),sum(evt_id))::temp.my_agg
    FROM temp.test_so_44410354 as el
    WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
).*
FROM wcal

QUERY PLAN                                                                                |
--------------------------------------------------------------------------------------------------------------------------------------------|
CTE Scan on wcal  (cost=12.50..21349.08 rows=1000 width=20) (actual time=0.182..3.518 rows=12 loops=1)                                      |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12) (actual time=0.057..0.083 rows=12 loops=1)               |
  SubPlan 2                                                                                |
    ->  Aggregate  (cost=10.64..10.66 rows=1 width=32) (actual time=0.140..0.140 rows=1 loops=12)                                           |
          ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=12) (actual time=0.049..0.083 rows=77 loops=12)       |
                Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                             |
                Heap Blocks: exact=66                                                                                |
                ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0) (actual time=0.037..0.037 rows=77 loops=12) |
                      Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                         |
  SubPlan 3                                                                                |
    ...
Planning time: 0.548 ms                                                                                |
Execution time: 3.748 ms                                                                                |

For proposed solution II, if the aggregation is returned as record, the query plan will look like below:
Which roughly doubled the speed c.f. previous query. (but record type element is not desired as final result.)

QUERY PLAN                                                                                |
--------------------------------------------------------------------------------------------------------------------------------------------|
CTE Scan on wcal  (cost=12.50..10690.79 rows=1000 width=44) (actual time=0.147..1.979 rows=12 loops=1)                                      |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12) (actual time=0.057..0.082 rows=12 loops=1)               |
  SubPlan 2                                                                                |
    ->  Aggregate  (cost=10.64..10.66 rows=1 width=32) (actual time=0.151..0.151 rows=1 loops=12)                                           |
          ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=12) (actual time=0.054..0.089 rows=77 loops=12)       |
                Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                             |
                Heap Blocks: exact=66                                                                                |
                ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0) (actual time=0.040..0.040 rows=77 loops=12) |
                      Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                         |
Planning time: 0.381 ms                                                                                |
Execution time: 2.147 ms                                                                                |

The LATERAL join solution works just as expected. Thanks.

EXPLAIN ANALYZE
With wcal AS (
    SELECT ts, ts::date as dt
    FROM generate_series( '1970-01-01 0:0:0', '1970-01-12 0:0:0', INTERVAL '1 day' ) AS ts
)
SELECT ts, dt, p.*
FROM wcal
     CROSS JOIN LATERAL (
        SELECT count(evt_ts), sum(evt_id)
        FROM temp.test_so_44410354 as el
        WHERE ( el.evt_ts < wcal.ts AND el.evt_ts > wcal.ts - INTERVAL '1 day'  )
    ) p

QUERY PLAN                                                                                |
------------------------------------------------------------------------------------------------------------------------------------------|
Nested Loop  (cost=23.15..10705.79 rows=1000 width=28) (actual time=0.130..1.611 rows=12 loops=1)                                         |
  CTE wcal                                                                                |
    ->  Function Scan on generate_series ts  (cost=0.00..12.50 rows=1000 width=12) (actual time=0.054..0.075 rows=12 loops=1)             |
  ->  CTE Scan on wcal  (cost=0.00..20.00 rows=1000 width=12) (actual time=0.061..0.099 rows=12 loops=1)                                  |
  ->  Aggregate  (cost=10.64..10.65 rows=1 width=16) (actual time=0.123..0.123 rows=1 loops=12)                                           |
        ->  Bitmap Heap Scan on test_so_44410354 el  (cost=4.33..10.62 rows=5 width=12) (actual time=0.044..0.074 rows=77 loops=12)       |
              Recheck Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                             |
              Heap Blocks: exact=66                                                                                |
              ->  Bitmap Index Scan on test_so_44410354_idx  (cost=0.00..4.33 rows=5 width=0) (actual time=0.033..0.033 rows=77 loops=12) |
                    Index Cond: ((evt_ts < wcal.ts) AND (evt_ts > (wcal.ts - '1 day'::interval)))                                         |
Planning time: 0.399 ms                                                                                |
Execution time: 1.778 ms                                                                                |

ts                  |dt         |count |sum   |
--------------------|-----------|------|------|
1970-01-01 00:00:00 |1970-01-01 |0     |      |
1970-01-02 00:00:00 |1970-01-02 |68    |36156 |
1970-01-03 00:00:00 |1970-01-03 |85    |42103 |
1970-01-04 00:00:00 |1970-01-04 |94    |47092 |
1970-01-05 00:00:00 |1970-01-05 |74    |36276 |
1970-01-06 00:00:00 |1970-01-06 |96    |43797 |

Body:
It is tricky a bit but:

create type t_my_aggs as (ecnt bigint, eids bigint[]);

With wcal AS (
    SELECT ts, ts::date as dt,
        extract( week from ts) as wk,
        extract( month from ts ) as mo,
        extract( quater from ts ) as qtr,
    FROM generate_series( t1, t2, tspan )
)
SELECT ts, dt, wk, mo, qtr
,(
    SELECT row(count(evt_ts), array_agg(evt_id))::t_my_aggs
    FROM ev_log as el
    WHERE ( el.ts < wcal.ts AND el.ts < wcal.ts - tspan )
).* from wcal;


来源: stackexchange

问:
Condense steps from htaccess
I Currently have the following htaccess code below which is to add a trailing slash and make sure it's https and www. (This is a wordpress site)

The issue is that if a URL is provided without a https, www or a slash.

E.g. - http://example.com/test

It requires 2 hops to get to it.

http://example.com/test - ORIGINAL (then 301's to below)

https://example.com/test (then 301's to below)

https://www.example.com/test/

How can I do this all in one step in the htaccess so it gets from http://example.com/test TO https://www.example.com/test/

```<code># BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# END HTTPS Redirection Plugin

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
</code>```

答:
This should do the trick for you:

```<code># 301 redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</code>```

Please, test via, for example, http://redirectcheck.com/

ContentLicense: CC BY-SA 3.0

Title: Condense steps from htaccess

Body:
I Currently have the following htaccess code below which is to add a trailing slash and make sure it's https and www. (This is a wordpress site)

The issue is that if a URL is provided without a https, www or a slash.

E.g. - http://example.com/test

It requires 2 hops to get to it.

http://example.com/test - ORIGINAL (then 301's to below)

https://example.com/test (then 301's to below)

https://www.example.com/test/

How can I do this all in one step in the htaccess so it gets from http://example.com/test TO https://www.example.com/test/

# BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# END HTTPS Redirection Plugin

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Body:
This should do the trick for you:

# 301 redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Please, test via, for example, http://redirectcheck.com/


问:
C# Decimal to byte[] and back in C
I have a system that stores a decimal value on a Mifare card

The C# decimal value is converted to a byte array of 16 bytes using this code

```<code>MemoryStream memStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memStream);
try
{
  try
  {
     writer.Write(m_Value);
     tmp = memStream.ToArray();
  }
  finally
  {
     memStream.Close();
  }
}
finally
{
  writer.Close();
}
</code>```

which gives a 16byte representation.

Now we have a customer which needs to read and convert these 16 bytes back to a decimal number, but in C

How is this done ?

Can anyone find a definition/spec of the C# byte representation, i cannot

答:
You don't need to use MemoryStream, BinaryWriter, etc, here; just decimal.GetBits(value) is fine. The contents are fully documented, here: https://msdn.microsoft.com/en-us/library/system.decimal.getbits(v=vs.110).aspx. There is a constructor that accepts the same format.

Note that this gives you an int[], not a byte[], but... getting between int and byte is trivial; probably the easiest is to use shift and mask.

The BinaryWriter version is not officially documented, but is probably just the integers from GetBits() written sequentially.

Title: C# Decimal to byte[] and back in C

Body:
I have a system that stores a decimal value on a Mifare card

The C# decimal value is converted to a byte array of 16 bytes using this code

MemoryStream memStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memStream);
try
{
  try
  {
     writer.Write(m_Value);
     tmp = memStream.ToArray();
  }
  finally
  {
     memStream.Close();
  }
}
finally
{
  writer.Close();
}

which gives a 16byte representation.

Now we have a customer which needs to read and convert these 16 bytes back to a decimal number, but in C

How is this done ?

Can anyone find a definition/spec of the C# byte representation, i cannot


问:
OLEDB date(time) issue asp.net c#
I have written a little excel helper which works fine. It uses this connection string:

```<code>"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<FILENAME>;Extended Properties=\"Excel 12.0;HDR=Yes;\";";
</code>```

Unfortunately when I deploy the code, cells, which contains a date string like this: 28/12/2008 are returned as: 12/25/2008 12:00:00 AM rather than 25/12/2008 00:00:00 after using ToString. I adjusted the time zone etc. of the machine (all machines are now UK time zones) but this hasn't changed anything. I am just curious what determines how OLEDB 'behaves'. The aim would be to get 25/12/2008 00:00:00 on both machines.

Thanks!

Christian

答:
I think that this might be something to do with the Culture being set to en-us.  You would need to format the DateTime accordingly.

Standard Date and Time format strings

ContentLicense: CC BY-SA 2.5

Title: OLEDB date(time) issue asp.net c#

Body:
I have written a little excel helper which works fine. It uses this connection string:

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<FILENAME>;Extended Properties=\"Excel 12.0;HDR=Yes;\";";

Unfortunately when I deploy the code, cells, which contains a date string like this: 28/12/2008 are returned as: 12/25/2008 12:00:00 AM rather than 25/12/2008 00:00:00 after using ToString. I adjusted the time zone etc. of the machine (all machines are now UK time zones) but this hasn't changed anything. I am just curious what determines how OLEDB 'behaves'. The aim would be to get 25/12/2008 00:00:00 on both machines.

Thanks!

Christian


问:
Getting errors installing Tensorflow GPU
I was earlier working with the CPU only version of tensorflow. I tried installing the GPU version now using this link.

But I think I messed up.

When I try to do import tensorflow it gives the following message:

```<code>ImportError: libcudart.so.7.5: cannot open shared object file: No such file or directory
</code>```

What should I do?

答:
It could be because a wrong version of cuda is installed : check /usr/local/ for the versions of cuda that are installed and if it matches with the version in the Tensorflow error. If it both versions don't match, you'll have to either install another version of cuda or Tensorflow.

Another reason could be because of missing environment variables (as explained here).
Try this :

```<code>export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda
</code>```

Body:
I was earlier working with the CPU only version of tensorflow. I tried installing the GPU version now using this link.

But I think I messed up.

When I try to do import tensorflow it gives the following message:

ImportError: libcudart.so.7.5: cannot open shared object file: No such file or directory

What should I do?

Body:
It could be because a wrong version of cuda is installed : check /usr/local/ for the versions of cuda that are installed and if it matches with the version in the Tensorflow error. If it both versions don't match, you'll have to either install another version of cuda or Tensorflow.

Another reason could be because of missing environment variables (as explained here).
Try this :

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda


问:
bootstrap rails drop down
I'm having difficulty trying to get a dropdown box in rails using the bootstrap framework.

```<code>  <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Categories<span class="caret"></span></a>
      <ul class="dropdown-menu">

<!--  trying to insert dynamic list for drop down -->

        <li role="separator" class="divider"></li>

     <li><%= link_to "All Categories", categories_path %></li>

      </ul>
    </li>
</code>```

I figured it would be similiar to the
 list
 from index

```<code> <% @categories.each do |category| %>

    <li><%= category.name %></li>
<%end >
</code>```

But the rails says .each is not defined...  my dropdown is in a _partial html file.  What am I doing wrong?

Thanks,
Joe

答:
When you call your partial, you should pass locals like that:

```<code><%= render 'my_partial', catgories: @categories %>
</code>```

And in your partial:

```<code><% categories.each do |category|%>
     <li><%= category.name %></li>
  <% end %>
</code>```

Title: bootstrap rails drop down

Body:
I'm having difficulty trying to get a dropdown box in rails using the bootstrap framework.

      Categories

<%= link_to "All Categories", categories_path %>

I figured it would be similiar to the
 list
 from index

 <% @categories.each do |category| %>

<%= category.name %>

<%end >

But the rails says .each is not defined...  my dropdown is in a _partial html file.  What am I doing wrong?

Thanks,
Joe

Body:
When you call your partial, you should pass locals like that:

<%= render 'my_partial', catgories: @categories %>

And in your partial:

<% categories.each do |category|%>
     <li><%= category.name %></li>
  <% end %>


问:
dicom header personal information conversion to a .txt file
I have a series of DICOM Images which I want to anonymize, I found few Matlab codes and some programs which do the job, but none of them export a .txt file of removed personal information. I was wondering if there is a function which can also save removed personal information of a DICOM images in .txt format for features uses. Also, I am trying to create a table which shows the corresponding new images ID to their real name.(subjects real name = personal-information-removed image ID)

Any thoughts?

Thanks for considering my request!

答:
One way to do this is to store the tags before and after anonymisation and use these to write your text file. In Matlab, dicominfo() will read the tags into a structure:

```<code>% Get tags before anonymization
tags_before = dicominfo(file_in);

% Anoymize
dicomanon(file_in, file_out); % Need to set tags values where required

% Get tags after anonymization
tags_after = dicominfo(file_out);

% Do something with the two structures
disp(['Patient ID:', tags_before.PatientID ' -> ' tags_after.PatientID]);
disp(['Date of Birth:', tags_before.PatientBirthDate ' -> ' tags_after.PatientBirthDate]);
disp(['Family Name:', tags_before.PatientName.FamilyName ' -> ' tags_after.PatientName.FamilyName]);
</code>```

You can then write out the before/after fields into a text file. You'd need to modify dicomanon() to choose your own values for the removed fields, since by default they are set to empty.

Body:
One way to do this is to store the tags before and after anonymisation and use these to write your text file. In Matlab, dicominfo() will read the tags into a structure:

% Get tags before anonymization
tags_before = dicominfo(file_in);

% Anoymize
dicomanon(file_in, file_out); % Need to set tags values where required

% Get tags after anonymization
tags_after = dicominfo(file_out);

% Do something with the two structures
disp(['Patient ID:', tags_before.PatientID ' -> ' tags_after.PatientID]);
disp(['Date of Birth:', tags_before.PatientBirthDate ' -> ' tags_after.PatientBirthDate]);
disp(['Family Name:', tags_before.PatientName.FamilyName ' -> ' tags_after.PatientName.FamilyName]);

You can then write out the before/after fields into a text file. You'd need to modify dicomanon() to choose your own values for the removed fields, since by default they are set to empty.


问:
How to simplify Logic Gate - mux simulation
When trying to make an multiplexor how do you go from this:

```<code> Not(in=a, out=nota);
    Not(in=b, out=notb);
    Not(in=sel, out=notsel);
    And(a=a, b=b, out=aAndb);
    And(a=a, b=notb, out=aAndNotb);
    And(a=nota, b=b, out=bAndNota);
    And(a=aAndb, b=sel, out=aAndBAndSel);
    And(a=aAndb, b=notsel, out=aAndBAndNotSel);
    And(a=aAndNotb, b=notsel, out=aAndNotBAndNotSel);
    And(a=bAndNota, b=sel, out=bAndNotaAndSel);
    Or(a=aAndBAndSel, b=aAndBAndNotSel, out=o1);
    Or(a=o1, b=aAndNotBAndNotSel, out=o2);
    Or(a=o2, b=bAndNotaAndSel, out=out);
</code>```

to this:

```<code>    Nand(a=sel, b=sel, out=notsel);
    Nand(a=a, b=notsel, out=asel);
    Nand(a=b, b=sel, out=bnotsel);
    Nand(a=asel, b=bnotsel, out=out);
</code>```

my answer are always very long and i'm not sure how you would go about finding a more elegant solution.

```<code>MUX Truth Table Answers
|   a   |   b   |  sel  |  out  |
|   0   |   0   |   0   |   0   |
|   0   |   0   |   1   |   0   |
|   0   |   1   |   0   |   0   |
|   0   |   1   |   1   |   1   |
|   1   |   0   |   0   |   1   |
|   1   |   0   |   1   |   0   |
|   1   |   1   |   0   |   1   |
|   1   |   1   |   1   |   1   |
</code>```

答: Write down the truth table of the expression you have, use Karnaugh map to minimize it, then use boolean algebra to get the second expression. (By adding double not and applying de morgan law)</p>

Body:
When trying to make an multiplexor how do you go from this:

 Not(in=a, out=nota);
    Not(in=b, out=notb);
    Not(in=sel, out=notsel);
    And(a=a, b=b, out=aAndb);
    And(a=a, b=notb, out=aAndNotb);
    And(a=nota, b=b, out=bAndNota);
    And(a=aAndb, b=sel, out=aAndBAndSel);
    And(a=aAndb, b=notsel, out=aAndBAndNotSel);
    And(a=aAndNotb, b=notsel, out=aAndNotBAndNotSel);
    And(a=bAndNota, b=sel, out=bAndNotaAndSel);
    Or(a=aAndBAndSel, b=aAndBAndNotSel, out=o1);
    Or(a=o1, b=aAndNotBAndNotSel, out=o2);
    Or(a=o2, b=bAndNotaAndSel, out=out);

to this:

    Nand(a=sel, b=sel, out=notsel);
    Nand(a=a, b=notsel, out=asel);
    Nand(a=b, b=sel, out=bnotsel);
    Nand(a=asel, b=bnotsel, out=out);

my answer are always very long and i'm not sure how you would go about finding a more elegant solution.

MUX Truth Table Answers
|   a   |   b   |  sel  |  out  |
|   0   |   0   |   0   |   0   |
|   0   |   0   |   1   |   0   |
|   0   |   1   |   0   |   0   |
|   0   |   1   |   1   |   1   |
|   1   |   0   |   0   |   1   |
|   1   |   0   |   1   |   0   |
|   1   |   1   |   0   |   1   |
|   1   |   1   |   1   |   1   |


问:
Why does a function parameter call a constructor with an argument?
I have this code(stolen from cplusplus.com):

```<code>// explicit:
#include <iostream>
using namespace std;

class A {};

class B {
public:
  explicit B (const A& x) {}
  B& operator= (const A& x) {return *this;}
  operator A() {return A();}
};

void fn (B x) {}

int main ()
{
  A foo;
  B bar (foo);
  bar = foo;
  foo = bar;

//  fn (foo);  // not allowed for explicit ctor.
  fn (bar);

  return 0;
}
</code>```

So apparently the statement fn (foo); would call the constructor defined in class B, and I do not really get why. Why would that call a constructor with an argument, I mean aren't things simply copied to the function parameters when not using a reference? If fn (foo); calls the constructor B (const A& x) {}, shouldn't fn (bar); generate an error since there is no constructor defined for an argument of type B, such as B (const B& x) {}?

答:
That is a result of an explicit creation of an object

```<code>fn(foo);
</code>```

is not implicitly possible since fn() doesn't takes any A object as parameter

BUT your foo parameter can actually be used to create an instance of B which match perfectly the fn parameter, you can prevent that implicitly conversion of objects using the explicit keyword.

And that is what you are doing here:

```<code> explicit B (const A& x) {}
</code>```

Body:
I have this code(stolen from cplusplus.com):

// explicit:
#include <iostream>
using namespace std;

class A {};

class B {
public:
  explicit B (const A& x) {}
  B& operator= (const A& x) {return *this;}
  operator A() {return A();}
};

void fn (B x) {}

int main ()
{
  A foo;
  B bar (foo);
  bar = foo;
  foo = bar;

//  fn (foo);  // not allowed for explicit ctor.
  fn (bar);

  return 0;
}

So apparently the statement fn (foo); would call the constructor defined in class B, and I do not really get why. Why would that call a constructor with an argument, I mean aren't things simply copied to the function parameters when not using a reference? If fn (foo); calls the constructor B (const A& x) {}, shouldn't fn (bar); generate an error since there is no constructor defined for an argument of type B, such as B (const B& x) {}?

Body:
That is a result of an explicit creation of an object

fn(foo);

is not implicitly possible since fn() doesn't takes any A object as parameter

BUT your foo parameter can actually be used to create an instance of B which match perfectly the fn parameter, you can prevent that implicitly conversion of objects using the explicit keyword.

And that is what you are doing here:

 explicit B (const A& x) {}


问:
Circular Floating Menu Builder error
( Im New in Android )
Im trying to add the Circular Floating Menu but for a reason i ignore the word Builder is in red.

i have this error:
Cannot resolve symbol 'Builder'
// this word  Builder in ( SubActionButton.Builder(this); ) is in red .

Thank you for your Help

```<code>// Create an icon
        ImageView icon = new ImageView(this);
        icon.setImageResource(R.mipmap.ic_launcher);

        FloatingActionButton actionButton = new FloatingActionButton.Builder(this)
                .setContentView(icon)
                .build();
        SubActionButton.Builder itemBuilder = new SubActionButton.Builder(this);
        // repeat many times:
        ImageView itemIcon1 = new ImageView(this);
        itemIcon1.setImageResource(R.mipmap.ic_launcher);

        ImageView itemIcon2 = new ImageView(this);
        itemIcon2.setImageResource(R.mipmap.ic_launcher);

        ImageView itemIcon3 = new ImageView(this);
        itemIcon3.setImageResource(R.mipmap.ic_launcher);

        SubActionButton button1 = itemBuilder.setContentView(itemIcon1).build();
        SubActionButton button2 = itemBuilder.setContentView(itemIcon2).build();
        SubActionButton button3 = itemBuilder.setContentView(itemIcon3).build();

        //attach the sub buttons to the main button
        FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(this)
                .addSubActionView(button1)
                .addSubActionView(button2)
                .addSubActionView(button3)
                .attachTo(actionButton)
                .build();
</code>```

答: I think that the FloatingActionButton that you're using is the support library native Android which doesn't have .Builder(), so you should use the CircularFloatingMenu's FloatingActionButton instead.

Title: Circular Floating Menu Builder error

Body:
( Im New in Android )
Im trying to add the Circular Floating Menu but for a reason i ignore the word Builder is in red.

i have this error:
Cannot resolve symbol 'Builder'
// this word  Builder in ( SubActionButton.Builder(this); ) is in red .

Thank you for your Help

// Create an icon
        ImageView icon = new ImageView(this);
        icon.setImageResource(R.mipmap.ic_launcher);

        FloatingActionButton actionButton = new FloatingActionButton.Builder(this)
                .setContentView(icon)
                .build();
        SubActionButton.Builder itemBuilder = new SubActionButton.Builder(this);
        // repeat many times:
        ImageView itemIcon1 = new ImageView(this);
        itemIcon1.setImageResource(R.mipmap.ic_launcher);

        ImageView itemIcon2 = new ImageView(this);
        itemIcon2.setImageResource(R.mipmap.ic_launcher);

        ImageView itemIcon3 = new ImageView(this);
        itemIcon3.setImageResource(R.mipmap.ic_launcher);

        SubActionButton button1 = itemBuilder.setContentView(itemIcon1).build();
        SubActionButton button2 = itemBuilder.setContentView(itemIcon2).build();
        SubActionButton button3 = itemBuilder.setContentView(itemIcon3).build();

        //attach the sub buttons to the main button
        FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(this)
                .addSubActionView(button1)
                .addSubActionView(button2)
                .addSubActionView(button3)
                .attachTo(actionButton)
                .build();


问:
Gulp browserSync reload
So my question is, is there a way that when I run gulp watch through my terminal my browser doesn't load on a new page but instead reloads on the present page?

https://i.stack.imgur.com/u1qXi.png

答:
You can for an option use the gulp-livereload library:

npm install --save-dev gulp-livereload

gulp-livereload will not automatically listen for changes. You now have to manually call livereload.listen unless you set the option start:

livereload({ start: true })

Usage:

```<code>var gulp = require('gulp'),
less = require('gulp-less'),
livereload = require('gulp-livereload');

gulp.task('less', function() {
  gulp.src('less/*.less')
    .pipe(less())
    .pipe(gulp.dest('css'))
    .pipe(livereload());
});

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch('less/*.less', ['less']);
});
</code>```

Title: Gulp browserSync reload

Body:
You can for an option use the gulp-livereload library:

npm install --save-dev gulp-livereload

gulp-livereload will not automatically listen for changes. You now have to manually call livereload.listen unless you set the option start:

livereload({ start: true })

Usage:

var gulp = require('gulp'),
less = require('gulp-less'),
livereload = require('gulp-livereload');

gulp.task('less', function() {
  gulp.src('less/*.less')
    .pipe(less())
    .pipe(gulp.dest('css'))
    .pipe(livereload());
});

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch('less/*.less', ['less']);
});


问:
getting webpack to ignore electron main process packages
While it is not necessary for Electron, I wanted to webpack all the render process javascript (as apposed to the nodejs (called main process) javascript. And put render process javascript in a single bundle.

Why:

This might be a bit faster for startup

It will give me the ability to use the webpack server for hot loading

Well I pointed webpack at the root of render-side javascript, and it started making the bundle. But it also is seeing some electron remote javascript components and is trying to bundle those in also, and is failing.

How do I get Webpack to ignore lines that are pointing to the remote/main process code: (all my main process code will be in a folder called ./main). I tried to exclude the ./main/* folder, but perhaps I did not do that properly

Example lines

```<code>const { remote } = require('electron')
const { dialog } = remote.require('electron')
const { dialog } = require('electron').remote
const utils = remote.require('../main/utils')
const watson = remote.require('../main/watson')
</code>```

Webpack.config.js

```<code>const webpack = require('webpack')
const path = require('path')

const config = {
    context: path.resolve(__dirname, '..', 'src'),
    entry: './dash/dash.js',
    output: {
        path: path.resolve(__dirname, '..' , 'dist'),
        filename: 'bundle.js'
    },
    module: {
        rules: [{
            test: /\.js$/,
            include: path.resolve(__dirname, 'src'),
            exclude: /(main)/,
            use: [{
                loader: 'babel-loader',
                options: {
                    "sourceMaps": "inline",
                    presets: [
                        ['react', "node7", "stage-3",
                            { modules: false }]
                    ]
                }
            }]
        }]
    }
}
</code>```

module.exports = config

Output

```<code>Hash: 3aa4f4a528c7beea5c01
Version: webpack 2.6.0
Time: 4157ms
    Asset     Size  Chunks                    Chunk Names
bundle.js  2.98 MB       0  [emitted]  [big]  main
   [0] ./~/process/browser.js 5.42 kB {0} [built]
   [1] ./~/react/react.js 56 bytes {0} [built]
  [52] ./dist/dash/actions.js 18.6 kB {0} [built]
  [53] ./~/electron/index.js 338 bytes {0} [built]
  [54] ./~/redux/es/index.js 1.08 kB {0} [built]
 [310] ./dist/dash/initialState.json 357 bytes {0} [built]
 [311] ./dist/dash/reducers.js 8.22 kB {0} [built]
 [312] ./dist/jsx/Dashboard.js 7.08 kB {0} [built]
 [313] ./dist/main/utils.js 12.6 kB {0} [built]
 [314] ./~/redux-devtools-extension/index.js 635 bytes {0} [built]
 [315] ./~/redux-thunk/lib/index.js 529 bytes {0} [built]
 [316] ./~/shallow-equal/objects/index.js 394 bytes {0} [built]
 [317] ./dist/dash/dash.js 8.74 kB {0} [built]
 [321] ./dist/jsx/Utilities.js 5.55 kB {0} [built]
 [322] ./dist/main 160 bytes {0} [built]
    + 755 hidden modules

WARNING in ./dist/main/utils.js
34:25-44 Critical dependency: the request of a dependency is an expression

ERROR in ./dist/main/utils.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\dist\main'
 @ ./dist/main/utils.js 5:11-24
 @ ./dist/dash/dash.js

ERROR in ./dist/main/utils.js
Module not found: Error: Can't resolve 'child_process' in 'd:\wwwroot\librarian2017\dashboard\dist\main'
 @ ./dist/main/utils.js 9:22-46
 @ ./dist/dash/dash.js

ERROR in ./~/electron/index.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\node_modules\electron'
 @ ./~/electron/index.js 1:9-22
 @ ./dist/dash/dash.js

ERROR in ./~/get-folder-size/index.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\node_modules\get-folder-size'
 @ ./~/get-folder-size/index.js 3:9-22
 @ ./dist/main/utils.js
 @ ./dist/dash/dash.js

ERROR in ./~/rmdir/lib/rmdir.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\node_modules\rmdir\lib'
 @ ./~/rmdir/lib/rmdir.js 9:9-22
 @ ./~/rmdir/index.js
 @ ./dist/main/utils.js
 @ ./dist/dash/dash.js
</code>```

答:
I notice that your webpack config does not have target defined. Adding that may help resolve the issue. See https://webpack.js.org/configuration/target/

There are two different targets for electron, one for the main and one for the renderer.

In my app I have two separate webpack configs for the main and renderer.

Body:
While it is not necessary for Electron, I wanted to webpack all the render process javascript (as apposed to the nodejs (called main process) javascript. And put render process javascript in a single bundle.

Why:

This might be a bit faster for startup

It will give me the ability to use the webpack server for hot loading

Well I pointed webpack at the root of render-side javascript, and it started making the bundle. But it also is seeing some electron remote javascript components and is trying to bundle those in also, and is failing.

How do I get Webpack to ignore lines that are pointing to the remote/main process code: (all my main process code will be in a folder called ./main). I tried to exclude the ./main/* folder, but perhaps I did not do that properly

Example lines

const { remote } = require('electron')
const { dialog } = remote.require('electron')
const { dialog } = require('electron').remote
const utils = remote.require('../main/utils')
const watson = remote.require('../main/watson')

Webpack.config.js

const webpack = require('webpack')
const path = require('path')

const config = {
    context: path.resolve(__dirname, '..', 'src'),
    entry: './dash/dash.js',
    output: {
        path: path.resolve(__dirname, '..' , 'dist'),
        filename: 'bundle.js'
    },
    module: {
        rules: [{
            test: /\.js$/,
            include: path.resolve(__dirname, 'src'),
            exclude: /(main)/,
            use: [{
                loader: 'babel-loader',
                options: {
                    "sourceMaps": "inline",
                    presets: [
                        ['react', "node7", "stage-3",
                            { modules: false }]
                    ]
                }
            }]
        }]
    }
}

module.exports = config

Output

Hash: 3aa4f4a528c7beea5c01
Version: webpack 2.6.0
Time: 4157ms
    Asset     Size  Chunks                    Chunk Names
bundle.js  2.98 MB       0  [emitted]  [big]  main
   [0] ./~/process/browser.js 5.42 kB {0} [built]
   [1] ./~/react/react.js 56 bytes {0} [built]
  [52] ./dist/dash/actions.js 18.6 kB {0} [built]
  [53] ./~/electron/index.js 338 bytes {0} [built]
  [54] ./~/redux/es/index.js 1.08 kB {0} [built]
 [310] ./dist/dash/initialState.json 357 bytes {0} [built]
 [311] ./dist/dash/reducers.js 8.22 kB {0} [built]
 [312] ./dist/jsx/Dashboard.js 7.08 kB {0} [built]
 [313] ./dist/main/utils.js 12.6 kB {0} [built]
 [314] ./~/redux-devtools-extension/index.js 635 bytes {0} [built]
 [315] ./~/redux-thunk/lib/index.js 529 bytes {0} [built]
 [316] ./~/shallow-equal/objects/index.js 394 bytes {0} [built]
 [317] ./dist/dash/dash.js 8.74 kB {0} [built]
 [321] ./dist/jsx/Utilities.js 5.55 kB {0} [built]
 [322] ./dist/main 160 bytes {0} [built]
    + 755 hidden modules

WARNING in ./dist/main/utils.js
34:25-44 Critical dependency: the request of a dependency is an expression

ERROR in ./dist/main/utils.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\dist\main'
 @ ./dist/main/utils.js 5:11-24
 @ ./dist/dash/dash.js

ERROR in ./dist/main/utils.js
Module not found: Error: Can't resolve 'child_process' in 'd:\wwwroot\librarian2017\dashboard\dist\main'
 @ ./dist/main/utils.js 9:22-46
 @ ./dist/dash/dash.js

ERROR in ./~/electron/index.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\node_modules\electron'
 @ ./~/electron/index.js 1:9-22
 @ ./dist/dash/dash.js

ERROR in ./~/get-folder-size/index.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\node_modules\get-folder-size'
 @ ./~/get-folder-size/index.js 3:9-22
 @ ./dist/main/utils.js
 @ ./dist/dash/dash.js

ERROR in ./~/rmdir/lib/rmdir.js
Module not found: Error: Can't resolve 'fs' in 'd:\wwwroot\librarian2017\dashboard\node_modules\rmdir\lib'
 @ ./~/rmdir/lib/rmdir.js 9:9-22
 @ ./~/rmdir/index.js
 @ ./dist/main/utils.js
 @ ./dist/dash/dash.js


问:
Why all the pins on a chip are not GPIOs?
Documentation of GPIOs in Linux states:

A "General Purpose Input/Output" (GPIO) is a flexible software-controlled
  digital signal.  They are provided from many kinds of chip, and are familiar
  to Linux developers working with embedded and custom hardware.

If we are capable of control the behavior of a pin, then why all the pins on a chip are not GPIOs?

OR

How can we provide functionality through software for a pin on chip?

Please explain.

答:
All the pins in SOC are not GPIO. A specific group of pins mapped as GPIO. Other pins are configured for specific interfaces like DDR, SPI, I2C... etc, which includes clock, data and power supply pins. GPIO is generic pins can be used for any purpose based on user requirement. It can be used for handling IRQs, trigger Resets, Glow LEDs..etc. </p>

<p>for example, Consider a FPGA is connected to SOC via GPIOs. User need to program the FPGA via these GPIO pins. In SOC side user need to write a specific program with mentioned sequence to drive those GPIO to program the FPGA config file. </p>

Body:
All the pins in SOC are not GPIO. A specific group of pins mapped as GPIO. Other pins are configured for specific interfaces like DDR, SPI, I2C... etc, which includes clock, data and power supply pins. GPIO is generic pins can be used for any purpose based on user requirement. It can be used for handling IRQs, trigger Resets, Glow LEDs..etc.

for example, Consider a FPGA is connected to SOC via GPIOs. User need to program the FPGA via these GPIO pins. In SOC side user need to write a specific program with mentioned sequence to drive those GPIO to program the FPGA config file.


问:
Laravel phpunit testing mail sending
Im trying to test mail sending in laravel 5.1 application.
    I need run tests on prod server.
    I need MAIL_DRIVER=log at app environment for running test.
    And MAIL_DRIVER=smtp for production in my .env file.
    I edited phpunit.xml at application root folder and added line:

```<code><env name="MAIL_DRIVER" value="log"/>

<php>
     <env name="APP_ENV" value="testing"/>
     <env name="CACHE_DRIVER" value="array"/>
     <env name="SESSION_DRIVER" value="array"/>
     <env name="QUEUE_DRIVER" value="sync"/>
     <env name="MAIL_DRIVER" value="log"/>
</php>
</code>```

The problem is when I running test it still use MAIL_DRIVER=smtp

Any idea what is wrong?

答: Try to redefine mail transport type directly. Changing environment constants will do nothing (or share the code where MAIL_DRIVER is used).</p>

Title: Laravel phpunit testing mail sending

Body:
Im trying to test mail sending in laravel 5.1 application.
    I need run tests on prod server.
    I need MAIL_DRIVER=log at app environment for running test.
    And MAIL_DRIVER=smtp for production in my .env file.
    I edited phpunit.xml at application root folder and added line:

<env name="MAIL_DRIVER" value="log"/>

<php>
     <env name="APP_ENV" value="testing"/>
     <env name="CACHE_DRIVER" value="array"/>
     <env name="SESSION_DRIVER" value="array"/>
     <env name="QUEUE_DRIVER" value="sync"/>
     <env name="MAIL_DRIVER" value="log"/>
</php>

The problem is when I running test it still use MAIL_DRIVER=smtp

Any idea what is wrong?


问:
How do you count the elements of an array in java
Say i have the array

```<code>int theArray = new int[20];
</code>```

The length of the array is 20 but the count is 0. How can i get the count?

答:
Your code won't compile, it should be int [] theArray = new int[20];;

You can get the array length as theArray.length;

For primitive types, the array will be initialized with the default values (0 for int).

You can make it Integer [] theArray = new Integer[20]; and then count initialized members as this code does:

```<code>public int count(Object [] array) {
    int c = 0;
    for(Object el: array) { if(el != null) c++; }
        return c;
}
</code>```

Please note that this answer isn't about why you may need this and what is the best way to do what you want.

Body:
Say i have the array

int theArray = new int[20];

The length of the array is 20 but the count is 0. How can i get the count?

Body:
Your code won't compile, it should be int [] theArray = new int[20];;

You can get the array length as theArray.length;

For primitive types, the array will be initialized with the default values (0 for int).

You can make it Integer [] theArray = new Integer[20]; and then count initialized members as this code does:

public int count(Object [] array) {
    int c = 0;
    for(Object el: array) { if(el != null) c++; }
        return c;
}

Please note that this answer isn't about why you may need this and what is the best way to do what you want.


问:
SonarQube How to set analysis for C# Only in TFS and MSBuild
I am trying to get a TFS build work flow to analyse for only C# code.

According to the documentation https://docs.sonarqube.org/display/SONAR/Analysis+Parameters

I need to pass /d:sonar.language with the name of the language to prevent multi-language analysis.  The documentation then links to the plugins page for a selection of languages.

I have tried every permutation I can think of C#, csharp, sonar-csharp etc. but I constantly get an error such as this:

```<code>ERROR: Error during SonarQube Scanner execution
ERROR: You must install a plugin that supports the language 'sonar-csharp'
</code>```

I'm obviously missing a trick somewhere, can anyone point me in the right direction?

We are using:

SonarQube 6.4

SonarQube Scanner for MSbuild - Begin Analysis (new) v2.1.2

TFS 2015

答:
The error message is telling you that no analyzer for "sonar-csharp" is installed on your SonarQube server.

Try running an analysis without this (deprecated) parameter. If you really must restrict what's analyzed, you can use file exclusions to ignore the extra files

Body:
I am trying to get a TFS build work flow to analyse for only C# code.

According to the documentation https://docs.sonarqube.org/display/SONAR/Analysis+Parameters

I need to pass /d:sonar.language with the name of the language to prevent multi-language analysis.  The documentation then links to the plugins page for a selection of languages.

I have tried every permutation I can think of C#, csharp, sonar-csharp etc. but I constantly get an error such as this:

ERROR: Error during SonarQube Scanner execution
ERROR: You must install a plugin that supports the language 'sonar-csharp'

I'm obviously missing a trick somewhere, can anyone point me in the right direction?

We are using:

SonarQube 6.4

SonarQube Scanner for MSbuild - Begin Analysis (new) v2.1.2

TFS 2015


问:
How to configure groups in Jboss EAP for Kerberos implementation?
I have configured my application with Kerberos authentication for a specific user in jboss-eap and it's working fine. But wants to configure the same on the basis of the group i.e users in a specific group will able to authenticate.

Standalone.xml configuration for user:-

```<code> <security-domains>
            <security-domain name="SPNEGO" cache-type="default">
                <authentication>
                    <login-module code="SPNEGO" flag="required">
                        <module-option name="serverSecurityDomain" value="host"/>
                    </login-module>
                </authentication>
                <mapping>
                    <mapping-module code="SimpleRoles" type="role">
                        <module-option name="saurabhgupta@ECO.COM" value="User"/>
                    </mapping-module>
                </mapping>
            </security-domain>
</code>```

My environment consists of:

linux server with JBoss EAP 6.2
client station with Windows 7 64bit + Chrome
Windows Server 2008 Active Directory (act as KDC)

Application War Location:- https://github.com/kwart/spnego-demo

Does anyone went all through this and solved it somehow?

Thank you in advance, Siddharth

答:
You can pair the SPNEGO login-module with others so that you can assign users to roles. Below is an example of how to associate your users to LDAP roles via Standalone.xml:

```<code>  <security-domain name="SPNEGO">
                <authentication>
                    <login-module code="SPNEGOUsers" flag="requisite">
                        <module-option name="password-stacking" value="useFirstPass"/>
                        <module-option name="serverSecurityDomain" value="host"/>
                        <module-option name="removeRealmFromPrincipal" value="true"/>
                    </login-module>
                    <login-module code="AdvancedAdLdap" flag="required">
                        <module-option name="password-stacking" value="useFirstPass"/>
                        <module-option name="bindDN" value="test"/>
                        <module-option name="bindCredential" value="test"/>
                        <module-option name="allowEmptyPassword" value="true"/>
                        <module-option name="java.naming.provider.url" value="ldap://test.jboss.redhat.com:389"/>
                        <module-option name="baseCtxDN" value="CN=Users,DC=jboss,DC=redhat,DC=com"/>
                        <module-option name="baseFilter" value="(sAMAccountName={0})"/>
                        <module-option name="roleAttributeID" value="memberOf"/>
                        <module-option name="roleAttributeIsDN" value="true"/>
                        <module-option name="roleNameAttributeID" value="cn"/>
                        <module-option name="recurseRoles" value="true"/>
                    </login-module>
                </authentication>
            </security-domain>
</code>```

Body:
I have configured my application with Kerberos authentication for a specific user in jboss-eap and it's working fine. But wants to configure the same on the basis of the group i.e users in a specific group will able to authenticate.

Standalone.xml configuration for user:-

 <security-domains>
            <security-domain name="SPNEGO" cache-type="default">
                <authentication>
                    <login-module code="SPNEGO" flag="required">
                        <module-option name="serverSecurityDomain" value="host"/>
                    </login-module>
                </authentication>
                <mapping>
                    <mapping-module code="SimpleRoles" type="role">
                        <module-option name="saurabhgupta@ECO.COM" value="User"/>
                    </mapping-module>
                </mapping>
            </security-domain>

My environment consists of:

linux server with JBoss EAP 6.2
client station with Windows 7 64bit + Chrome
Windows Server 2008 Active Directory (act as KDC)

Application War Location:- https://github.com/kwart/spnego-demo

Does anyone went all through this and solved it somehow?

Thank you in advance, Siddharth

Body:
You can pair the SPNEGO login-module with others so that you can assign users to roles. Below is an example of how to associate your users to LDAP roles via Standalone.xml:

  <security-domain name="SPNEGO">
                <authentication>
                    <login-module code="SPNEGOUsers" flag="requisite">
                        <module-option name="password-stacking" value="useFirstPass"/>
                        <module-option name="serverSecurityDomain" value="host"/>
                        <module-option name="removeRealmFromPrincipal" value="true"/>
                    </login-module>
                    <login-module code="AdvancedAdLdap" flag="required">
                        <module-option name="password-stacking" value="useFirstPass"/>
                        <module-option name="bindDN" value="test"/>
                        <module-option name="bindCredential" value="test"/>
                        <module-option name="allowEmptyPassword" value="true"/>
                        <module-option name="java.naming.provider.url" value="ldap://test.jboss.redhat.com:389"/>
                        <module-option name="baseCtxDN" value="CN=Users,DC=jboss,DC=redhat,DC=com"/>
                        <module-option name="baseFilter" value="(sAMAccountName={0})"/>
                        <module-option name="roleAttributeID" value="memberOf"/>
                        <module-option name="roleAttributeIsDN" value="true"/>
                        <module-option name="roleNameAttributeID" value="cn"/>
                        <module-option name="recurseRoles" value="true"/>
                    </login-module>
                </authentication>
            </security-domain>


问:
What's the difference between the variable name of an array and the address of that array?
In C++, the following code will compile:

```<code>int a[5];
int (*b)[5] = &a;
</code>```

while this won't:

```<code>int a[5];
int (*b)[5] = a;
</code>```

When compiling the second one, g++ gives me an error, saying "cannot convert 'int*' to 'int (*)[5]' in initialization".

However, I thought that a and &a are just the same because

```<code>std::cout << a << std::endl;
</code>```

and

```<code>std::cout << &a << std::endl;
</code>```

produce the same result.

Apparently, there is a difference between a, which is the name of the array variable, and &a, which is the address of that array. But what exactly is the difference?

答:
Their values (addresses they are pointing to) are equal, but their types differ:

(in that context) a is (int [5] decayed to) int *.

&a is int (*)[5]

If you declare int x;, you could observe the same difference (in type but not in value) between, for example, &x and (char *)&x.

Body:
In C++, the following code will compile:

int a[5];
int (*b)[5] = &a;

while this won't:

int a[5];
int (*b)[5] = a;

When compiling the second one, g++ gives me an error, saying "cannot convert 'int*' to 'int (*)[5]' in initialization".

However, I thought that a and &a are just the same because

std::cout << a << std::endl;

and

std::cout << &a << std::endl;

produce the same result.

Apparently, there is a difference between a, which is the name of the array variable, and &a, which is the address of that array. But what exactly is the difference?


问:
support for svg in qooxdoo
I like to load a svg into my qooxdoo gui, link some event handlers to svg elements (pointerdown, pointermove) and manipulate the svg elements from outside (style.transform=rotate). So I need access to the svg elements from the qooxdoo level. But how to embed the svg into qooxdoo not only as an image?
Is there support for handling a svg in qooxdoo?
I found a way how to embed svg in html5. Here you can embed the svg dom-structure by the tag: object. This is what I am looking for in qooxdoo.
And I found a qooxdoo svg-contrib; But this is some years old (2011) and I am wondering if it is already integrated into qooxdoo or if it is still the best starting point?</p>

答: D3.js is a good module to manipulate svg objects in Javascript. However, I'm not sure whether you can integrate the module to qooxdoo framework.</p>

Title: support for svg in qooxdoo


问:
Center Input box and Font Awesome icons
Others have asked something similar but I seem to be struggling vertical aligning the font awesome icon with an input box.  It works okay when you don`t use the sizing to increase the font awesome icons, but as soon as you enter the fa-3x or something like that the margin-top gets added.

Does anybody have any ideas ?

Simple example would be:

```<code><div>
    <i class='icon icon-3x icon-camera'></i>
    <span id="inputfield">
      <input type="text" value="input here">
    </span>
</div>

div {
    border: 1px solid #ccc;
    height: 30px;
    margin: 60px;
    padding: 4px;
    vertical-align: middle;
}
i{
    float: left;
}
#inputfield{
    line-height: 30px;
    float: left;
}
</code>```

答:
you can remove class fa-3x and give font size to the  or rather the curresponding class

find the fiddle here

```<code><div>
    <i class='fa fa-camera'></i>
    <span id="inputfield">
      <input type="text" value="input here">
    </span>
</div>

div {
    border: 1px solid #ccc;
    height: 30px;
    margin: 60px;
    padding: 4px;
    vertical-align: middle;
}
i{
    float: left;
}
i.fa-camera{
  font-size:35px;
}
#inputfield{
    line-height: 30px;
    float: left;
}
</code>```

Title: Center Input box and Font Awesome icons

Body:
Others have asked something similar but I seem to be struggling vertical aligning the font awesome icon with an input box.  It works okay when you don`t use the sizing to increase the font awesome icons, but as soon as you enter the fa-3x or something like that the margin-top gets added.

Does anybody have any ideas ?

Simple example would be:

      <input type="text" value="input here">

div {
    border: 1px solid #ccc;
    height: 30px;
    margin: 60px;
    padding: 4px;
    vertical-align: middle;
}
i{
    float: left;
}
#inputfield{
    line-height: 30px;
    float: left;
}

Body:
you can remove class fa-3x and give font size to the <i> or rather the curresponding class

find the fiddle here

<div>
    <i class='fa fa-camera'></i>
    <span id="inputfield">
      <input type="text" value="input here">
    </span>
</div>

div {
    border: 1px solid #ccc;
    height: 30px;
    margin: 60px;
    padding: 4px;
    vertical-align: middle;
}
i{
    float: left;
}
i.fa-camera{
  font-size:35px;
}
#inputfield{
    line-height: 30px;
    float: left;
}


问:
Cut a longer word/string in smaller chunks for fitting a field
I want to fill a field with a string of many words. When I have huge words I need a to split the word. If my word is longer than 10 letters I need a space at position 5 of this word.

How do I get the new "myString" with shorter words?

```<code>    static void Main(string[] args)
    {
        var myString = "This is my string with some loooooooooooooong words. Please devide meeeeeeeeeeeeeeeeeeeeeeeee";
        var myStringSplit = myString.Split();
        var query = myStringSplit.Where(x => x.Length > 10).ToList();
        foreach (var item in query)
        {
            item.Insert(5, " ");
        }
    }
</code>```

Edit: My expected result: myString = "This is my strin g with some loooo ooooo ooooo ng words. Pleas e devid e meeee eeeee eeeee eeeee eeeee e";

答:
Here is example how you can get your result:

```<code>public static void Main(string[] args)
{
    var myString = "This is my string with some loooooooooooooong words. Please devide meeeeeeeeeeeeeeeeeeeeeeeee";
    string[] myStringSplit = myString.Split();
    for (int i =0;i<myStringSplit.Length;i++)
    {
        if(myStringSplit[i].Length>5)
            myStringSplit[i] = Regex.Replace(myStringSplit[i], ".{5}(?=.)", "$0 ");
    }
    var resultString = myStringSplit.Aggregate((x,y)=> x+" "+y);
    Console.WriteLine(resultString);
}
</code>```

The output will be the following:

This is my strin g with some loooo ooooo ooooo ng words . Pleas e
  devid e meeee eeeee eeeee eeeee eeeee e

Body:
I want to fill a field with a string of many words. When I have huge words I need a to split the word. If my word is longer than 10 letters I need a space at position 5 of this word.

How do I get the new "myString" with shorter words?

    static void Main(string[] args)
    {
        var myString = "This is my string with some loooooooooooooong words. Please devide meeeeeeeeeeeeeeeeeeeeeeeee";
        var myStringSplit = myString.Split();
        var query = myStringSplit.Where(x => x.Length > 10).ToList();
        foreach (var item in query)
        {
            item.Insert(5, " ");
        }
    }

Edit: My expected result: myString = "This is my strin g with some loooo ooooo ooooo ng words. Pleas e devid e meeee eeeee eeeee eeeee eeeee e";

Body:
Here is example how you can get your result:

public static void Main(string[] args)
{
    var myString = "This is my string with some loooooooooooooong words. Please devide meeeeeeeeeeeeeeeeeeeeeeeee";
    string[] myStringSplit = myString.Split();
    for (int i =0;i<myStringSplit.Length;i++)
    {
        if(myStringSplit[i].Length>5)
            myStringSplit[i] = Regex.Replace(myStringSplit[i], ".{5}(?=.)", "$0 ");
    }
    var resultString = myStringSplit.Aggregate((x,y)=> x+" "+y);
    Console.WriteLine(resultString);
}

The output will be the following:

This is my strin g with some loooo ooooo ooooo ng words . Pleas e
  devid e meeee eeeee eeeee eeeee eeeee e


问:
Google play service library , not found in Eclipse directory folder
i am using eclipse to create apps,recently i had installed Google play service using sdk manager.but i didn't found any library in the installed location, i had searched for a solution in web and also re installing it! But, till yet i didn't get a solution to add Google play library into my project, kindly help me to come through .and also give any tips to add library in other ways</p>

答:
you can not get the library project from SDK location but you can get .aar file of google play service from YourSDKLocation -> extras -> google -> m2repository -> com -> google -> android -> gms -> play service and Follow this steps to create library project from .aar

you can also download the library project from here.


问:
Python Listing 2 Lists In Bullet Form
In my python code, I have 2 lists

```<code>myList = ["Example", "Example2", "Example3"]
mySecondList = ["0000", "1111", "2222"]
</code>```

I need to print these so they look like this:

```<code>- Example 0000
- Example2 1111
- Example3 2222
</code>```

Is there any way to achieve this?

答:
I would recommend using zip() or zip_longest() for your question.

But, without using any built-in modules/functions. You can create your own 'hacky' method by your own very similar to zip() function.

Here is an example:

```<code>def custom_zip(a, b, fill=None):
    length = max(len(a), len(b))
    for k in range(length):
        if k > len(a):
            yield fill, b[k]
        elif k > len(b):
            yield a[k], fill
        else:
            yield a[k], b[k]

a = ["Example", "Example2", "Example3"]
b = ["0000", "1111", "2222"]

for k, v in custom_zip(a,b):
    print("- {} {}".format(k, v))
</code>```

Output:

```<code>- Example 0000
- Example2 1111
- Example3 2222
</code>```

Also, you can take a look at the equivalent of zip() in the official documentation.

Title: Python Listing 2 Lists In Bullet Form

Body:
In my python code, I have 2 lists

myList = ["Example", "Example2", "Example3"]
mySecondList = ["0000", "1111", "2222"]

I need to print these so they look like this:

- Example 0000
- Example2 1111
- Example3 2222

Is there any way to achieve this?

Body:
I would recommend using zip() or zip_longest() for your question.

But, without using any built-in modules/functions. You can create your own 'hacky' method by your own very similar to zip() function.

Here is an example:

def custom_zip(a, b, fill=None):
    length = max(len(a), len(b))
    for k in range(length):
        if k > len(a):
            yield fill, b[k]
        elif k > len(b):
            yield a[k], fill
        else:
            yield a[k], b[k]

a = ["Example", "Example2", "Example3"]
b = ["0000", "1111", "2222"]

for k, v in custom_zip(a,b):
    print("- {} {}".format(k, v))

Output:

- Example 0000
- Example2 1111
- Example3 2222

Also, you can take a look at the equivalent of zip() in the official documentation.


问:
JQuery can't get input value from dynamically created field
Receiving  value from static field when keyup based on input field class(.inputclass) method, but once add field dynamically its not get the value.

Below the sample code, Please help.

$(function(){
 $(document).ready(function(){
  $(".inputclass").keyup(function() {
     alert($(this).val());
  });
 });
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="http://code.jquery.com/jquery-1.12.4.js"></script>
<form>
<table width="250" border="0" cellspacing="0" cellpadding="0" id="dataTable">
  <tr>
    <td>Field 1</td>
    <td><input type="text" class="inputclass" /></td>
  </tr>
  <script>
 var counter =1;
 $(function(){
  $('#addNew').click(function(){
   counter += 1;
   $('#dataTable').append('<tr><td>Field ' + counter + '</td><td><input type="text" class="inputclass"/></td></tr>');
  });
 });
</script>
</table><br/>
<input type="button" id="addNew" value=" ± Add New Field"/>
</form></code>```

答:
This is because when you assigned the event handler, it only assigned to the existing elements at the time.

Delegate to the document:

```<code>$(document).on('keyup', '.inputclass', function(){
   alert($(this).val())
});
</code>```

When you delegate to a parent or the document, you are using the event that bubbles up and so it doesn't matter if there are dynamic elements.

Body:
Receiving  value from static field when keyup based on input field class(.inputclass) method, but once add field dynamically its not get the value.

Below the sample code, Please help.

$(function(){
 $(document).ready(function(){
  $(".inputclass").keyup(function() {
     alert($(this).val());
  });
 });
});

<form>

    Field 1
    <input type="text" class="inputclass" />

<input type="button" id="addNew" value=" ± Add New Field"/>
</form>

Body:
This is because when you assigned the event handler, it only assigned to the existing elements at the time.

Delegate to the document:

$(document).on('keyup', '.inputclass', function(){
   alert($(this).val())
});

When you delegate to a parent or the document, you are using the event that bubbles up and so it doesn't matter if there are dynamic elements.


问:
jsx complied error map within map
```<code>{!this.state.isLoading && applicants.findIndex(obj => obj.is_new) === 1 &&
    <div>is new</div>
    {applicants.map((obj,index) => {
        if(obj.is_new){
            return this.renderApplicantsList(obj, index)
        }
    })}
}
</code>```

what's wrong with my code above? unexpected token but I can't spot any wrong in it.

答:
A JSX element may only contain a single root. The way you are checking for isLoading and is_new is also a bit awkward, I would go for something such as:</p>

```<code><div>
  {
    !this.state.isLoading && applicants.findIndex(obj => obj.is_new) === 1 ? (
      <div>
        <div>is new</div>
        {
          applicants.map((obj,index) => {
            if(obj.is_new){
              return this.renderApplicantsList(obj, index)
            }
          })
        }
      </div>
    ) : null
  }
</div>
</code>```

Title: jsx complied error map within map

Body:
{!this.state.isLoading && applicants.findIndex(obj => obj.is_new) === 1 &&

is new

    {applicants.map((obj,index) => {
        if(obj.is_new){
            return this.renderApplicantsList(obj, index)
        }
    })}
}

what's wrong with my code above? unexpected token but I can't spot any wrong in it.

Body:
A JSX element may only contain a single root. The way you are checking for isLoading and is_new is also a bit awkward, I would go for something such as:

<div>
  {
    !this.state.isLoading && applicants.findIndex(obj => obj.is_new) === 1 ? (
      <div>
        <div>is new</div>
        {
          applicants.map((obj,index) => {
            if(obj.is_new){
              return this.renderApplicantsList(obj, index)
            }
          })
        }
      </div>
    ) : null
  }
</div>


问:
Regex to remove non letters
I'm trying to remove non-letters from a string. Would this do it:</p>

```<code>c = o.replace(o.gsub!(/\W+/, ''))
</code>```

答:
Keep in mind that ruby considers the underscore _ to be a word character. So if you want to keep underscores as well, this should do it

```<code>string.gsub!(/\W+/, '')
</code>```

Otherwise, you need to do this:

```<code>string.gsub!(/[^a-zA-Z]/, '')
</code>```

Title: Regex to remove non letters

Body:
I'm trying to remove non-letters from a string. Would this do it:

c = o.replace(o.gsub!(/\W+/, ''))

Body:
Keep in mind that ruby considers the underscore _ to be a word character. So if you want to keep underscores as well, this should do it

string.gsub!(/\W+/, '')

Otherwise, you need to do this:

string.gsub!(/[^a-zA-Z]/, '')