问:
OpenCV and TBB error x64
I have the following configuration:

OpenCV 3.2.0-dev

Windows 10.0.14393 AMD64

CMake:                       3.7.1

CMake generator:             MinGW Makefiles

GCC MinGW 6.3.0

Intel TBB 2017 Update 4

I'm trying to install OpenCV with TBB. I downloaded the Intel TBB 2017 Update 4 and set every path in the correct way.

I build (of course) the TBB library before to add it in the CMake, in this way:

```<code>mingw32-make compiler=gcc arch=ia64
</code>```

And I add the following path in the system variables:

```<code>C:\tbb-2017\include
C:\tbb-2017\build\windows_intel64_gcc_mingw6.3.0_release
</code>```

But I have this error when I compile with CMake:

```<code>C:\opencv3\release>mingw32-make -j8
[  1%] Built target zlib[  1%] [  1%] [  1%] Building CXX object modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj[  1%]

Building CXX object modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/opencv_ts_pch_dephelp.cxx.objBuilding CXX object modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/opencv_imgproc_pch_dephelp.cxx.obj
[  4%] Built target libjpeg

[  6%] Built target libjasper
Building CXX object modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/opencv_videoio_pch_dephelp.cxx.obj
[  6%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/opencv_imgcodecs_px.obj
[  6%] Built target opencv_perf_core_pch_dephelp
[  6%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/opencv_highgui_pch_dephelp.cxx.obj
[  7%] Building CXX object modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj
Scanning dependencies of target opencv_flann_pch_dephelp
In file included from C:/opencv3/opencv-master/modules/core/src/precomp.hpp:55:0,
                 from C:\opencv3\release\modules\core\opencv_core_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
cIn file included from C:/opencv3/opencv-master/modules/imgproc/src/precomp.hpp:50:0,
                 from C:\opencv3\release\modules\imgproc\opencv_imgproc_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
oIn file included from C:/opencv3/opencv-master/modules/ts/src/precomp.hpp:2:0,
                 from C:\opencv3\release\modules\ts\opencv_ts_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
cmIn file included from C:/opencv3/opencv-master/modules/videoio/src/precomp.hpp:48:0,
                 from C:\opencv3\release\modules\videoio\opencv_videoio_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
ocpcmoi[  7%] lmoBuilding CXX object modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.cxx.obj
ppmaiiptlIn file included from C:/opencv3/opencv-master/modules/imgcodecs/src/precomp.hpp:48:0,
                 from C:\opencv3\release\modules\imgcodecs\opencv_imgcodecs_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
liiacalototanimit opoitninoe l nrtat metetirirenmomrainimtn nieatandteta.eret
mddei..dn

.a
tedmodules\core\CMakeFiles\opencv_core_pch_dephelp.dir\build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj' failed
.mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj] Error 1
modules\imgproc\CMakeFiles\opencv_imgproc_pch_dephelp.dir\build.make:62: recipe for target 'modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/opencv_imgproc_pch_dephelp.cxx.obj' failed

modules\ts\CMakeFiles\opencv_ts_pch_dephelp.dir\build.make:62: recipe for target 'modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/opencv_ts_pch_dephelp.cxx.obj' failed
CMakeFiles\Makefile2:2216: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all' failed
modules\videoio\CMakeFiles\opencv_videoio_pch_dephelp.dir\build.make:62: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/opencv_videoio_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/opencv_imgproc_pch_dephelp.cxx.obj] Error 1
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/opencv_ts_pch_dephelp.cxx.obj] Error 1
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all] Error 2
mingw32-make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/opencv_videoio_pch_dephelp.cxx.obj] Error 1
mingw32-make[1]: *** Waiting for unfinished jobs....
CMakeFiles\Makefile2:8292: recipe for target 'modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/all' failed
modules\imgcodecs\CMakeFiles\opencv_imgcodecs_pch_dephelp.dir\build.make:62: recipe for target 'modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/opencv_imgcodecs_pch_dephelp.cxx.obj' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/all] Error 2
mingw32-make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/opencv_imgcodecs_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:2867: recipe for target 'modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/all] Error 2
CMakeFiles\Makefile2:7513: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/all] Error 2
CMakeFiles\Makefile2:6906: recipe for target 'modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/all] Error 2
In file included from C:/opencv3/opencv-master/modules/highgui/src/precomp.hpp:48:0,
                 from C:\opencv3\release\modules\highgui\opencv_highgui_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
compilation terminated.
modules\highgui\CMakeFiles\opencv_highgui_pch_dephelp.dir\build.make:62: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/opencv_highgui_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/opencv_highgui_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:8085: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/all] Error 2
In file included from C:/opencv3/opencv-master/modules/core/test/test_precomp.hpp:17:0,
                 from C:\opencv3\release\modules\core\opencv_test_core_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
compilation terminated.
modules\core\CMakeFiles\opencv_test_core_pch_dephelp.dir\build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:2360: recipe for target 'modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/all] Error 2
In file included from C:/opencv3/opencv-master/modules/flann/src/precomp.hpp:23:0,
                 from C:\opencv3\release\modules\flann\opencv_flann_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
compilation terminated.
modules\flann\CMakeFiles\opencv_flann_pch_dephelp.dir\build.make:62: recipe for target 'modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:2617: recipe for target 'modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

C:\opencv3\release>
</code>```

Can you help me?

Solution

I changed from CMake the ENABLE_PRECOMPILED_HEADERS flag from ON to OFF and everythings worked...

答: I changed from CMake the ENABLE_PRECOMPILED_HEADERS flag from ON to OFF and everythings worked...</p>

Title: OpenCV and TBB error x64

Body:
I have the following configuration:

OpenCV 3.2.0-dev

Windows 10.0.14393 AMD64

CMake:                       3.7.1

CMake generator:             MinGW Makefiles

GCC MinGW 6.3.0

Intel TBB 2017 Update 4

I'm trying to install OpenCV with TBB. I downloaded the Intel TBB 2017 Update 4 and set every path in the correct way.

I build (of course) the TBB library before to add it in the CMake, in this way:

mingw32-make compiler=gcc arch=ia64

And I add the following path in the system variables:

C:\tbb-2017\include
C:\tbb-2017\build\windows_intel64_gcc_mingw6.3.0_release

But I have this error when I compile with CMake:

C:\opencv3\release>mingw32-make -j8
[  1%] Built target zlib[  1%] [  1%] [  1%] Building CXX object modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj[  1%]

Building CXX object modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/opencv_ts_pch_dephelp.cxx.objBuilding CXX object modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/opencv_imgproc_pch_dephelp.cxx.obj
[  4%] Built target libjpeg

[  6%] Built target libjasper
Building CXX object modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/opencv_videoio_pch_dephelp.cxx.obj
[  6%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/opencv_imgcodecs_px.obj
[  6%] Built target opencv_perf_core_pch_dephelp
[  6%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/opencv_highgui_pch_dephelp.cxx.obj
[  7%] Building CXX object modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj
Scanning dependencies of target opencv_flann_pch_dephelp
In file included from C:/opencv3/opencv-master/modules/core/src/precomp.hpp:55:0,
                 from C:\opencv3\release\modules\core\opencv_core_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
cIn file included from C:/opencv3/opencv-master/modules/imgproc/src/precomp.hpp:50:0,
                 from C:\opencv3\release\modules\imgproc\opencv_imgproc_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
oIn file included from C:/opencv3/opencv-master/modules/ts/src/precomp.hpp:2:0,
                 from C:\opencv3\release\modules\ts\opencv_ts_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
cmIn file included from C:/opencv3/opencv-master/modules/videoio/src/precomp.hpp:48:0,
                 from C:\opencv3\release\modules\videoio\opencv_videoio_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
ocpcmoi[  7%] lmoBuilding CXX object modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.cxx.obj
ppmaiiptlIn file included from C:/opencv3/opencv-master/modules/imgcodecs/src/precomp.hpp:48:0,
                 from C:\opencv3\release\modules\imgcodecs\opencv_imgcodecs_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
liiacalototanimit opoitninoe l nrtat metetirirenmomrainimtn nieatandteta.eret
mddei..dn

.a
tedmodules\core\CMakeFiles\opencv_core_pch_dephelp.dir\build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj' failed
.mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.obj] Error 1
modules\imgproc\CMakeFiles\opencv_imgproc_pch_dephelp.dir\build.make:62: recipe for target 'modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/opencv_imgproc_pch_dephelp.cxx.obj' failed

modules\ts\CMakeFiles\opencv_ts_pch_dephelp.dir\build.make:62: recipe for target 'modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/opencv_ts_pch_dephelp.cxx.obj' failed
CMakeFiles\Makefile2:2216: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all' failed
modules\videoio\CMakeFiles\opencv_videoio_pch_dephelp.dir\build.make:62: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/opencv_videoio_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/opencv_imgproc_pch_dephelp.cxx.obj] Error 1
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/opencv_ts_pch_dephelp.cxx.obj] Error 1
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all] Error 2
mingw32-make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/opencv_videoio_pch_dephelp.cxx.obj] Error 1
mingw32-make[1]: *** Waiting for unfinished jobs....
CMakeFiles\Makefile2:8292: recipe for target 'modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/all' failed
modules\imgcodecs\CMakeFiles\opencv_imgcodecs_pch_dephelp.dir\build.make:62: recipe for target 'modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/opencv_imgcodecs_pch_dephelp.cxx.obj' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts_pch_dephelp.dir/all] Error 2
mingw32-make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/opencv_imgcodecs_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:2867: recipe for target 'modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/imgproc/CMakeFiles/opencv_imgproc_pch_dephelp.dir/all] Error 2
CMakeFiles\Makefile2:7513: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio_pch_dephelp.dir/all] Error 2
CMakeFiles\Makefile2:6906: recipe for target 'modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs_pch_dephelp.dir/all] Error 2
In file included from C:/opencv3/opencv-master/modules/highgui/src/precomp.hpp:48:0,
                 from C:\opencv3\release\modules\highgui\opencv_highgui_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
compilation terminated.
modules\highgui\CMakeFiles\opencv_highgui_pch_dephelp.dir\build.make:62: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/opencv_highgui_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/opencv_highgui_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:8085: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui_pch_dephelp.dir/all] Error 2
In file included from C:/opencv3/opencv-master/modules/core/test/test_precomp.hpp:17:0,
                 from C:\opencv3\release\modules\core\opencv_test_core_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
compilation terminated.
modules\core\CMakeFiles\opencv_test_core_pch_dephelp.dir\build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:2360: recipe for target 'modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/all] Error 2
In file included from C:/opencv3/opencv-master/modules/flann/src/precomp.hpp:23:0,
                 from C:\opencv3\release\modules\flann\opencv_flann_pch_dephelp.cxx:1:
C:/opencv3/opencv-master/modules/core/include/opencv2/core/private.hpp:63:23: fatal error: tbb/tbb.h: No such file or directory
 #  include "tbb/tbb.h"
                       ^
compilation terminated.
modules\flann\CMakeFiles\opencv_flann_pch_dephelp.dir\build.make:62: recipe for target 'modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.cxx.obj' failed
mingw32-make[2]: *** [modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/opencv_flann_pch_dephelp.cxx.obj] Error 1
CMakeFiles\Makefile2:2617: recipe for target 'modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/all' failed
mingw32-make[1]: *** [modules/flann/CMakeFiles/opencv_flann_pch_dephelp.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

C:\opencv3\release>

Can you help me?

Solution

I changed from CMake the ENABLE_PRECOMPILED_HEADERS flag from ON to OFF and everythings worked...


来源: stackexchange

问:
Regex for dd-mmm-yy date format in ColdFusion
I want to ensure that the user uploaded csv have date in the format dd-mmm-yy (10-Feb-14). I have did my research and I could see that none of the ColdFusion date functions help me to resolve this.

I can use IsValid function with a regular expression validation. I am not good in writing regex. Your help appreciated.

答:
If you require particular date format like ((YYYY-MM-DD) or (YYYY-MM-DD HH:mm:ss)) only

it should not allow 2017-1-2

it should not allow 9:9:9 time format too

f (arguments.preparedInput.printFileLastModifiedMin neq "" or arguments.preparedInput.printFileLastModifiedMax neq "") {
                local.validMinDateFlag = "YES";
                local.validMaxDateFlag = "YES";

```<code>            if (arguments.preparedInput.printFileLastModifiedMin neq "")
                local.validMinDateFlag = isValid ("regex", arguments.preparedInput.printFileLastModifiedMin, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01])$");

            if (arguments.preparedInput.printFileLastModifiedMax neq "")
                local.validMaxDateFlag = isValid ("regex",arguments.preparedInput.printFileLastModifiedMax, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01])$");

            if (local.validMaxDateFlag eq "NO" or local.validMinDateFlag eq "NO"){
                if (local.validMinDateFlag eq "NO")
                    local.validMinDateFlag = isValid ("regex",arguments.preparedInput.printFileLastModifiedMin, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01]) (00|[0][0-9]|1[0-9]|2[0-3]):([0][0-9]|[0-5][0-9]):([0][0-9]|[0-5][0-9])$");

                if (local.validMaxDateFlag eq "NO")
                    local.validMaxDateFlag = isValid ("regex",arguments.preparedInput.printFileLastModifiedMax, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01]) (00|[0][0-9]|1[0-9]|2[0-3]):([0][0-9]|[0-5][0-9]):([0][0-9]|[0-5][0-9])$");
            }
</code>```

ContentLicense: CC BY-SA 3.0

Body:
If you require particular date format like ((YYYY-MM-DD) or (YYYY-MM-DD HH:mm:ss)) only

it should not allow 2017-1-2

it should not allow 9:9:9 time format too

f (arguments.preparedInput.printFileLastModifiedMin neq "" or arguments.preparedInput.printFileLastModifiedMax neq "") {
                local.validMinDateFlag = "YES";
                local.validMaxDateFlag = "YES";

            if (arguments.preparedInput.printFileLastModifiedMin neq "")
                local.validMinDateFlag = isValid ("regex", arguments.preparedInput.printFileLastModifiedMin, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01])$");

            if (arguments.preparedInput.printFileLastModifiedMax neq "")
                local.validMaxDateFlag = isValid ("regex",arguments.preparedInput.printFileLastModifiedMax, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01])$");

            if (local.validMaxDateFlag eq "NO" or local.validMinDateFlag eq "NO"){
                if (local.validMinDateFlag eq "NO")
                    local.validMinDateFlag = isValid ("regex",arguments.preparedInput.printFileLastModifiedMin, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01]) (00|[0][0-9]|1[0-9]|2[0-3]):([0][0-9]|[0-5][0-9]):([0][0-9]|[0-5][0-9])$");

                if (local.validMaxDateFlag eq "NO")
                    local.validMaxDateFlag = isValid ("regex",arguments.preparedInput.printFileLastModifiedMax, "^\d\d\d\d-(0[1-9]|1[0-2])-([0][1-9]|[12][0-9]|3[01]) (00|[0][0-9]|1[0-9]|2[0-3]):([0][0-9]|[0-5][0-9]):([0][0-9]|[0-5][0-9])$");
            }


问:
Declare a variable with SELECT SQL statement to be used in the WHERE clause
I have a very long SQL statement which has the following skeleton (using SQL server 2005):

```<code>SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    (SELECT another FROM ... WHERE...) AS Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
WHERE a.columnname = (SELECT another FROM ... WHERE...) ....
</code>```

This Importantvariable is a very long query by itself. However, it is used in other parts of the same query, including the WHERE clause and the INNER JOIN clauses. My question is, how can I somehow save it's value so I don't have to write the whole query every time. In this example above I would like to type a.columnname = Importantvariable instead of the whole query. I tried using DECLARE and save the value in a declared variable but it's not allowing me to do so with the following error:

```<code>A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operation.
</code>```

Of course, that makes sense but my whole point is to perform data retrieval, I just don't want to copy and paste the very long query that defined the Importantvariable on several different places in the query.
Any ideas?

答:
It sounds like you are looking for a VIEW. A view is essentially a stored SQL statement that can be called like a table name.

```<code>SELECT * FROM view_name ... WHERE ...
</code>```

often a view contains a number of joins and columns with aliases, allowing you to create virtual objects without duplicating data across multiple SQL tables.

Look at your documentation for specifics, but here is a link to W3schools examples
https://www.w3schools.com/sql/sql_view.asp

Body:
I have a very long SQL statement which has the following skeleton (using SQL server 2005):

SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    (SELECT another FROM ... WHERE...) AS Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
WHERE a.columnname = (SELECT another FROM ... WHERE...) ....

This Importantvariable is a very long query by itself. However, it is used in other parts of the same query, including the WHERE clause and the INNER JOIN clauses. My question is, how can I somehow save it's value so I don't have to write the whole query every time. In this example above I would like to type a.columnname = Importantvariable instead of the whole query. I tried using DECLARE and save the value in a declared variable but it's not allowing me to do so with the following error:

A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operation.

Of course, that makes sense but my whole point is to perform data retrieval, I just don't want to copy and paste the very long query that defined the Importantvariable on several different places in the query.
Any ideas?

Body:
It sounds like you are looking for a VIEW. A view is essentially a stored SQL statement that can be called like a table name.

SELECT * FROM view_name ... WHERE ...

often a view contains a number of joins and columns with aliases, allowing you to create virtual objects without duplicating data across multiple SQL tables.

Look at your documentation for specifics, but here is a link to W3schools examples
https://www.w3schools.com/sql/sql_view.asp


问:
Creating Date Partitioned Tables programmatically
Is there a way to create a date partitioned table using Apache Beam BigQueryIO, in other words, is there a way to use partition decorator for a table which is not created yet?

I know that I can create a table at first and then I can use partition decorator within my code but since I dynamically determine the TableDestination from fields of rows, I cannot create these tables in advance.

My code is like this:

```<code>rows.apply("Write rows",
    BigQueryIO.writeTableRows()
      .to(new SerializableFunction<ValueInSingleWindow<TableRow>, TableDestination>() {
          @Override
          public TableDestination apply(ValueInSingleWindow<TableRow> value) {
            TableRow t = value.getValue();

            String tableName = ... // get from the fields of table row
            String partition = ... // get the date part that will be used for decorator

            TableDestination td = new TableDestination(
                      "project-id:dataset-id." + tableName + "$" + partition, "");
              return td;
          }
      }).withSchema(someSchema)
      .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
    .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
</code>```

With this, it tries to create a table of project-id:dataset-id.tableName$partition and it complains that $ cannot be used inside a table name.

答:
it seems that this currently is not possible.

There is a request for this in the official BEAM JIRA issue list though:BEAM-2390 and an official pull request , so it looks like this is going to be possible soon!

Body:
Is there a way to create a date partitioned table using Apache Beam BigQueryIO, in other words, is there a way to use partition decorator for a table which is not created yet?

I know that I can create a table at first and then I can use partition decorator within my code but since I dynamically determine the TableDestination from fields of rows, I cannot create these tables in advance.

My code is like this:

rows.apply("Write rows",
    BigQueryIO.writeTableRows()
      .to(new SerializableFunction<ValueInSingleWindow<TableRow>, TableDestination>() {
          @Override
          public TableDestination apply(ValueInSingleWindow<TableRow> value) {
            TableRow t = value.getValue();

            String tableName = ... // get from the fields of table row
            String partition = ... // get the date part that will be used for decorator

            TableDestination td = new TableDestination(
                      "project-id:dataset-id." + tableName + "$" + partition, "");
              return td;
          }
      }).withSchema(someSchema)
      .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
    .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));

With this, it tries to create a table of project-id:dataset-id.tableName$partition and it complains that $ cannot be used inside a table name.


答:
You can use APPLY to create something like a named variable row-wise. If the value is calculated once and is valid for the whole set (more like a constant), you might use a CTE (starting with WITH before the SELECT).

The following will use an APPLY to find the table's name for all columns. You can use The.ImportantVariable in the column list as well as in a WHERE-clause:

```<code>SELECT The.ImportantVariable
      ,c.*
FROM sys.columns AS c
OUTER APPLY(SELECT name FROM sys.objects AS o WHERE c.object_id=o.object_id) AS The(ImportantVariable)
WHERE The.ImportantVariable LIKE 'a%';
</code>```

UPDATE Compare CTE and APPLY

Check this! There are some constant values in 1 single row provided by the CTE which you can CROSS JOIN into your query and use as named constants

```<code>WITH SomeConstants AS
(
    SELECT 'I''m a constant value' AS Constant1 --might be a complex statement too!
           ,0 AS Constant2
)
SELECT The.ImportantVariable
      ,Constant1
      ,Constant2
      ,c.*
FROM SomeConstants
CROSS JOIN sys.columns AS c
OUTER APPLY(SELECT name FROM sys.objects AS o WHERE c.object_id=o.object_id) AS The(ImportantVariable)
WHERE The.ImportantVariable LIKE 'a%'
</code>```

Title: Declare a variable with SELECT SQL statement to be used in the WHERE clause

Body:
You can use APPLY to create something like a named variable row-wise. If the value is calculated once and is valid for the whole set (more like a constant), you might use a CTE (starting with WITH before the SELECT).

The following will use an APPLY to find the table's name for all columns. You can use The.ImportantVariable in the column list as well as in a WHERE-clause:

SELECT The.ImportantVariable
      ,c.*
FROM sys.columns AS c
OUTER APPLY(SELECT name FROM sys.objects AS o WHERE c.object_id=o.object_id) AS The(ImportantVariable)
WHERE The.ImportantVariable LIKE 'a%';

UPDATE Compare CTE and APPLY

Check this! There are some constant values in 1 single row provided by the CTE which you can CROSS JOIN into your query and use as named constants

WITH SomeConstants AS
(
    SELECT 'I''m a constant value' AS Constant1 --might be a complex statement too!
           ,0 AS Constant2
)
SELECT The.ImportantVariable
      ,Constant1
      ,Constant2
      ,c.*
FROM SomeConstants
CROSS JOIN sys.columns AS c
OUTER APPLY(SELECT name FROM sys.objects AS o WHERE c.object_id=o.object_id) AS The(ImportantVariable)
WHERE The.ImportantVariable LIKE 'a%'


问:
input text box is hidden behind the keyboard on android browsers
input text box is hidden behind the keyboard on Android browsers, This issue can be solved by set position fixed for inputs but this's not a professional solution and it's causing many of other problems.

Any idea?

答:
Just add this to your manifest</p>

```<code><activity
            android:windowSoftInputMode="stateHidden|adjustPan">
 </activity>
</code>```

Body:
Just add this to your manifest

<activity
            android:windowSoftInputMode="stateHidden|adjustPan">
 </activity>


问:
Trying to make the navbar width 100% to fit nav items on one line
For some reason my navbar is not becoming 100% width. I tried to make .main-header 100% width but still not sure what the problem. The reason to make the navbar 100% is for all the nav items fit on one line. Any ideas what I am doing wrong?

Here is what the navbar looks like on the machine
http://imgur.com/a/za9LH

HTML

**Css**

/* Navigation */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: purple;
  width: 100%;
}
.logo-name {
  margin-left: 1%;
  background-color: red;
}
.main-nav {
  display: flex;
  background-color: yellow;
}

.main-nav li {
  padding: 0.3em;
  align-items: flex-end;
  background-color: transparent;
  font-size: 17px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><header class="main-header">
<!--<h1 class="logo-name"><li>R.J Roofer</li></h1>-->
  <h1 class="logo-name">R.J Roofer</h1>

  <nav class="main-nav">
    <li class="nav-item-1">home</li>
    <li>services</li>
    <li>gallery</li>
    <li>about us</li>
    <li>contact</li>
<!--<li>FREE QUOTE</li>-->
  </nav>
</header></code>```

答:
The problem was, that the container wasn't full width. And the list items were also too small. Here is a pen: https://codepen.io/praedictus/pen/zzvpez</p>

```<code>/* Navigation */

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: purple;
  width: 100%;
}
.logo-name {
  margin-left: 1%;
  background-color: red;
}
.main-nav {
  display: flex;
  background-color: yellow;
  width: 100%;
}

.main-nav li {
  padding: 0.3em;
  align-items: flex-end;
  background-color: transparent;
  font-size: 17px;
  display: block;
  float: left;
  width: 20%;
  text-align: center;
}
</code>```

Body:
For some reason my navbar is not becoming 100% width. I tried to make .main-header 100% width but still not sure what the problem. The reason to make the navbar 100% is for all the nav items fit on one line. Any ideas what I am doing wrong?

Here is what the navbar looks like on the machine
http://imgur.com/a/za9LH

HTML

**Css**

/* Navigation */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: purple;
  width: 100%;
}
.logo-name {
  margin-left: 1%;
  background-color: red;
}
.main-nav {
  display: flex;
  background-color: yellow;
}

.main-nav li {
  padding: 0.3em;
  align-items: flex-end;
  background-color: transparent;
  font-size: 17px;
}

R.J Roofer

home

services

gallery

about us

contact

Body:
The problem was, that the container wasn't full width. And the list items were also too small. Here is a pen: https://codepen.io/praedictus/pen/zzvpez

/* Navigation */

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: purple;
  width: 100%;
}
.logo-name {
  margin-left: 1%;
  background-color: red;
}
.main-nav {
  display: flex;
  background-color: yellow;
  width: 100%;
}

.main-nav li {
  padding: 0.3em;
  align-items: flex-end;
  background-color: transparent;
  font-size: 17px;
  display: block;
  float: left;
  width: 20%;
  text-align: center;
}


问:
Find which element of the stream does not match the given predicate in allmatch
I want to find out which element is failing the predicate in case of allmatch.

```<code>List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
boolean isEven = numbers.stream().allMatch(n-> n % 2 == 0);
</code>```

Here isEven is false, as element 1 fails the predicate.

I can use forEach over the stream to find which element fails like:

```<code>numbers.stream().forEach(n -> {
            if (n % 2 != 0)
                System.out.println(n + "is Odd");
        });
</code>```

Is there a way to figure out which elements fails the predicate in the allmatch when it returns false?

答:
Please remember that allMatch is a short-circuiting operation, meaning that the stream API may return false without finding all the elements that fail the test.

So if you want to find all the failing elements, you might have to do more work than a simple allMatch (as shown by other answers).  However, if you only care to find one element that fails the test, use findAny as follows:

```<code>Optional<Integer> odd = numbers.stream()
    .filter(n -> n % 2 != 0)
    .findAny();

boolean isEven = !odd.isPresent();

odd.ifPresent(x -> System.out.println(x + " is odd"));
</code>```

Body:
I want to find out which element is failing the predicate in case of allmatch.

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
boolean isEven = numbers.stream().allMatch(n-> n % 2 == 0);

Here isEven is false, as element 1 fails the predicate.

I can use forEach over the stream to find which element fails like:

numbers.stream().forEach(n -> {
            if (n % 2 != 0)
                System.out.println(n + "is Odd");
        });

Is there a way to figure out which elements fails the predicate in the allmatch when it returns false?

Body:
Please remember that allMatch is a short-circuiting operation, meaning that the stream API may return false without finding all the elements that fail the test.

So if you want to find all the failing elements, you might have to do more work than a simple allMatch (as shown by other answers).  However, if you only care to find one element that fails the test, use findAny as follows:

Optional<Integer> odd = numbers.stream()
    .filter(n -> n % 2 != 0)
    .findAny();

boolean isEven = !odd.isPresent();

odd.ifPresent(x -> System.out.println(x + " is odd"));


问:
Symbol addresses during load-time linking vs run-time linking in Linux
I am trying to understand the difference in the mechanisms underlying load-time linking (using gcc -l) versus run-time linking (using dlopen(), dlsym()) of dynamic libraries in Linux, and how these mechanisms affect the state of the library and the addresses of its symbols.

The experiment

I have three simple files:

libhello.c:

```<code>int var;
int func() {
    return 7;
}
</code>```

libhello.h:

```<code>extern int var;
int func();
</code>```

main.c:

```<code>#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <dlfcn.h>
#include "libhello.h"

int main() {
    void* h = dlopen("libhello.so", RTLD_NOW);
    printf("Address  Load-time linking    Run-time linking\n");
    printf("-------  -----------------    ----------------\n");
    printf("&var     0x%016" PRIxPTR "   0x%016" PRIxPTR "\n", (uintptr_t)&var , (uintptr_t)dlsym(h, "var" ));
    printf("&func    0x%016" PRIxPTR "   0x%016" PRIxPTR "\n", (uintptr_t)&func, (uintptr_t)dlsym(h, "func"));
}
</code>```

I compile libhello.c with the command gcc -shared -o libhello.so -fPIC libhello.c

I compile main.c with the command gcc main.c -L. -lhello -ldl

The observation

Running the main.c executable prints something like this:

```<code>Address  Load-time linking    Run-time linking
-------  -----------------    ----------------
&var     0x0000000000601060   0x00007fdb4acb1034
&func    0x0000000000400700   0x00007fdb4aab0695
</code>```

The load-time linking addresses remain the same, but the run-time linking addresses change every run.

The questions

Why do the run-time addresses change every run? Do they change due to Address space layout randomization?

If this is the case, why don't addresses change for load-time linking? Isn't load-time linking vulnerable to the same attacks that address randomization aims to protect against?

In the above program, the same library is loaded twice - once at load-time and then at run-time using dlopen(). The second load does not copy the state of the first load. I.e. if the value of var is changed before dlopen(), this value isn't reflected in the version of var loaded via dlsym(). Is there any way to retain this state during the second load?

答:
What you see depends on many variables. Here on a Debian 64bit I got in my first try

```<code>Address  Load-time linking    Run-time linking
-------  -----------------    ----------------
&var     0x0000000000600d58   0x0000000000600d58
&func    0x00000000004006d0   0x00000000004006d0
</code>```

Which means, that dlopen used the already linked library, which your system seems not to do. To get advantage of ASLR, you need to compile main.c with position independend code: gcc -fPIC main.c ./libhello.so -ldl.

```<code>Address  Load-time linking    Run-time linking
-------  -----------------    ----------------
&var     0x00007f4e6cec6944   0x00007f4e6cec6944
&func    0x00007f4e6ccc6670   0x00007f4e6ccc6670
</code>```

Body:
I am trying to understand the difference in the mechanisms underlying load-time linking (using gcc -l) versus run-time linking (using dlopen(), dlsym()) of dynamic libraries in Linux, and how these mechanisms affect the state of the library and the addresses of its symbols.

The experiment

I have three simple files:

libhello.c:

int var;
int func() {
    return 7;
}

libhello.h:

extern int var;
int func();

main.c:

#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <dlfcn.h>
#include "libhello.h"

int main() {
    void* h = dlopen("libhello.so", RTLD_NOW);
    printf("Address  Load-time linking    Run-time linking\n");
    printf("-------  -----------------    ----------------\n");
    printf("&var     0x%016" PRIxPTR "   0x%016" PRIxPTR "\n", (uintptr_t)&var , (uintptr_t)dlsym(h, "var" ));
    printf("&func    0x%016" PRIxPTR "   0x%016" PRIxPTR "\n", (uintptr_t)&func, (uintptr_t)dlsym(h, "func"));
}

I compile libhello.c with the command gcc -shared -o libhello.so -fPIC libhello.c

I compile main.c with the command gcc main.c -L. -lhello -ldl

The observation

Running the main.c executable prints something like this:

Address  Load-time linking    Run-time linking
-------  -----------------    ----------------
&var     0x0000000000601060   0x00007fdb4acb1034
&func    0x0000000000400700   0x00007fdb4aab0695

The load-time linking addresses remain the same, but the run-time linking addresses change every run.

The questions

Why do the run-time addresses change every run? Do they change due to Address space layout randomization?

If this is the case, why don't addresses change for load-time linking? Isn't load-time linking vulnerable to the same attacks that address randomization aims to protect against?

In the above program, the same library is loaded twice - once at load-time and then at run-time using dlopen(). The second load does not copy the state of the first load. I.e. if the value of var is changed before dlopen(), this value isn't reflected in the version of var loaded via dlsym(). Is there any way to retain this state during the second load?

Body:
What you see depends on many variables. Here on a Debian 64bit I got in my first try

Address  Load-time linking    Run-time linking
-------  -----------------    ----------------
&var     0x0000000000600d58   0x0000000000600d58
&func    0x00000000004006d0   0x00000000004006d0

Which means, that dlopen used the already linked library, which your system seems not to do. To get advantage of ASLR, you need to compile main.c with position independend code: gcc -fPIC main.c ./libhello.so -ldl.

Address  Load-time linking    Run-time linking
-------  -----------------    ----------------
&var     0x00007f4e6cec6944   0x00007f4e6cec6944
&func    0x00007f4e6ccc6670   0x00007f4e6ccc6670


问:
How do I get the RenderBody() output in two separate div tags
I have two
 tags in my _Layout view design, where one is for mobile view and another is for desktop view. The design was done by somebody else and the appropriate view is loaded when viewed on mobile and desktop. I can't alter the design, but I need to get the RenderBody() in moth divisions, like

```<code><div id="main">
  <div id="mobileView">
    @RenderBody()
  </div>
  <div id="desktopView">
    @RenderBody()
  </div>
</div>
</code>```

But this is not allowed, we cannot call RenderBody() two times. Is there any workaround to achieve this?

Thanks for any ideas :)

EDIT:
Below is how the view changes-

```<code>#mobileView{display:none}
@media screen and (max-width:767px){
#desktopView{display:none}
#mobileView{display:block}
</code>```

答:
I don't think so it is the good approach to render multiple @RenderBody() in one Layout. In this case work around is that you should make 2 layouts _LayoutMobile and _LayoutDesktop . aAt the runtime should replace the layout.i.e

```<code>@{
Layout =mobileView? "~/Views/Shared/_LayoutMobile.cshtml":"~/Views/Shared/_LayoutDesktop.cshtml";
}
</code>```

Body:
I have two
 tags in my _Layout view design, where one is for mobile view and another is for desktop view. The design was done by somebody else and the appropriate view is loaded when viewed on mobile and desktop. I can't alter the design, but I need to get the RenderBody() in moth divisions, like

    @RenderBody()

    @RenderBody()

But this is not allowed, we cannot call RenderBody() two times. Is there any workaround to achieve this?

Thanks for any ideas :)

EDIT:
Below is how the view changes-

#mobileView{display:none}
@media screen and (max-width:767px){
#desktopView{display:none}
#mobileView{display:block}

Body:
I don't think so it is the good approach to render multiple @RenderBody() in one Layout. In this case work around is that you should make 2 layouts _LayoutMobile and _LayoutDesktop . aAt the runtime should replace the layout.i.e

@{
Layout =mobileView? "~/Views/Shared/_LayoutMobile.cshtml":"~/Views/Shared/_LayoutDesktop.cshtml";
}


问:
How to insert OV5640 camera driver as module in yocto
I am trying to use the OV5640 camera driver as a module in yocto. So I took the .c code and made a makefile (based on the example hello-mod)

```<code>obj-m += OV5640.o
SRC := $(shell pwd)
all:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules
modules_install:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
clean:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) clean
</code>```

I also made a recipe in yocto

```<code>DESCRIPTION = "..."
LICENSE = "GPL-2.0"
LIC_FILES_CHKSUM = "\
   file:// ${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6 \
"

inherit module

SRCREV = "${AUTOREV}"
BPV = "0.0.0"
PV = "${BPV}+git${SRCREV}"

SRC_URI = "git://git/my-repo;protocol=ssh;user=git;branch=master \
"

S = "${WORKDIR}/git"
</code>```

In the git repo I have the .c code of the camera and the Makefile.

But when I try to build, it fails on do_compile and says:

fatal error: v4l2-int-device.h: No such file or directory

When I search on the file in the 'tmp' folder of yocto I find one in:

```<code>tmp/work-shared/myboard/kernel-source/drivers/media/platform/mxc/capture/v4l2-int-device.h
</code>```

The question is, How can I modify the recipe to be able to build the module without changing the source code or the makefile?

Note:

I also tried to add snippet below to the recipe but this gave no succes.

```<code>CFLAGS_prepend = " -I${STAGING_KERNEL_DIR}/drivers/media/platform/mxc/capture "
</code>```

答:
You need to modify your Makefile and add:

```<code>ccflags-y += -I$(KERNEL_SRC)/drivers/media/platform/mxc/capture/
</code>```

You can also try to compile it out of the tree, you need to set the variable KERNEL_SRC, source your environment, and compile it.

ContentLicense: CC BY-SA 4.0

Body:
I am trying to use the OV5640 camera driver as a module in yocto. So I took the .c code and made a makefile (based on the example hello-mod)

obj-m += OV5640.o
SRC := $(shell pwd)
all:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules
modules_install:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
clean:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) clean

I also made a recipe in yocto

DESCRIPTION = "..."
LICENSE = "GPL-2.0"
LIC_FILES_CHKSUM = "\
   file:// ${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6 \
"

inherit module

SRCREV = "${AUTOREV}"
BPV = "0.0.0"
PV = "${BPV}+git${SRCREV}"

SRC_URI = "git://git/my-repo;protocol=ssh;user=git;branch=master \
"

S = "${WORKDIR}/git"

In the git repo I have the .c code of the camera and the Makefile.

But when I try to build, it fails on do_compile and says:

fatal error: v4l2-int-device.h: No such file or directory

When I search on the file in the 'tmp' folder of yocto I find one in:

tmp/work-shared/myboard/kernel-source/drivers/media/platform/mxc/capture/v4l2-int-device.h

The question is, How can I modify the recipe to be able to build the module without changing the source code or the makefile?

Note:

I also tried to add snippet below to the recipe but this gave no succes.

CFLAGS_prepend = " -I${STAGING_KERNEL_DIR}/drivers/media/platform/mxc/capture "

Body:
You need to modify your Makefile and add:

ccflags-y += -I$(KERNEL_SRC)/drivers/media/platform/mxc/capture/

You can also try to compile it out of the tree, you need to set the variable KERNEL_SRC, source your environment, and compile it.


问:
Date format conversion issue PHP
See the below code returns the output as "Jun".

```<code>$date_removed =strtotime('2017-06-07 06:06:44');
$datev = date('d-m-Y', $date_removed);
$nameOfMonth = date('M', strtotime($datev));
echo $nameOfMonth;
</code>```

But the below code returns "Dec" as output.

```<code>$date_removed =strtotime('0000-00-00 00:00:00');
$datev = date('d-m-Y', $date_removed);
$nameOfMonth = date('M', strtotime($datev));
echo $nameOfMonth;
</code>```

Here the month value is null. So the return value should be null. Please let me know the issue in my code?

答:
strtotime() will return false if the date is invalid so you can check that using the return type:

```<code><?php
$date_removed =strtotime('0000-00-00 00:00:00');
if($date_removed>0)
{
    $datev = date('d-m-Y', $date_removed);
    $nameOfMonth = date('M', strtotime($datev));
    echo $nameOfMonth;
}
else
    echo "invalid date"; //or whatever you want
</code>```

Title: Date format conversion issue PHP

Body:
See the below code returns the output as "Jun".

$date_removed =strtotime('2017-06-07 06:06:44');
$datev = date('d-m-Y', $date_removed);
$nameOfMonth = date('M', strtotime($datev));
echo $nameOfMonth;

But the below code returns "Dec" as output.

$date_removed =strtotime('0000-00-00 00:00:00');
$datev = date('d-m-Y', $date_removed);
$nameOfMonth = date('M', strtotime($datev));
echo $nameOfMonth;

Here the month value is null. So the return value should be null. Please let me know the issue in my code?

Body:
strtotime() will return false if the date is invalid so you can check that using the return type:

<?php
$date_removed =strtotime('0000-00-00 00:00:00');
if($date_removed>0)
{
    $datev = date('d-m-Y', $date_removed);
    $nameOfMonth = date('M', strtotime($datev));
    echo $nameOfMonth;
}
else
    echo "invalid date"; //or whatever you want


问:
How can url encoding be managed with ActiveResource?
Is there a way to manage URL encoding with ActiveResource? Specifically I am looking for a way to pass an email address as a parameter.

Currently my query fails as the @ symbol gets URL encoded to %40, causing the lookup on the remote app to fail.

For example, the following query on the ActiveResource model Person…

```<code>Person.all(:from => :remote_find_by_email, :params => {:email => "john@example.com")
</code>```

Produces the following URL

http://example.com/people/remote_find_by_email.xml?email=john%40example.com

Alternately, is there something the remote app should be doing to decode the parameter before performing the lookup?

UPDATE

Thanks to eks, I added the following method and before filter to the controller on the remote app:

```<code>before_filter :cgi_unescape_params, :only => [:remote_find_by_email]

private

  def cgi_unescape_params
    params.each { |k, v| params[k] = CGI.unescape(v) }
  end
</code>```

答: Try using CGI::unescape on the remote end, that should take care of any % encoded value.  Cheers!</p>

ContentLicense: CC BY-SA 2.5

Body:
Is there a way to manage URL encoding with ActiveResource? Specifically I am looking for a way to pass an email address as a parameter.

Currently my query fails as the @ symbol gets URL encoded to %40, causing the lookup on the remote app to fail.

For example, the following query on the ActiveResource model Person…

Person.all(:from => :remote_find_by_email, :params => {:email => "john@example.com")

Produces the following URL

http://example.com/people/remote_find_by_email.xml?email=john%40example.com

Alternately, is there something the remote app should be doing to decode the parameter before performing the lookup?

UPDATE

Thanks to eks, I added the following method and before filter to the controller on the remote app:

before_filter :cgi_unescape_params, :only => [:remote_find_by_email]

private

  def cgi_unescape_params
    params.each { |k, v| params[k] = CGI.unescape(v) }
  end


问:
How to bind data in checkbox list in Gridview with same datatable?
I want to give checkbox list in Gridview. How can I bind data to checkbox list from same data table?

答:
What i understood that i am showing let me know you are asking for the same or not

This is the design portion

```<code><body>
    <form id="form1" runat="server">
    <div>
   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="gridview"
                                           >
                                            <Columns>
                                                <asp:TemplateField HeaderText="Name">
                                            <ItemTemplate>
                                                <asp:Label ID="name" runat="server" Text='<%#Eval("Name")%>'>></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                                  <asp:TemplateField HeaderText="Roll No">
                                            <ItemTemplate>
                                                <asp:Label ID="rollno" runat="server" Text='<%#Eval("Roll_No")%>'>></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                                  <asp:TemplateField HeaderText="Gender">
                                            <ItemTemplate>
                                               <asp:CheckBox runat="server" Text='<%#Eval("Gender")%>' />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                                </Columns>
       </asp:GridView>
    </div>
    </form>
</body>
</code>```

Here I have made a temoporary data table you can make data table through database also

```<code>protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack) {
            check_box();
        }
    }

    public void check_box() {

        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        dt.Columns.Add("Roll_NO");
        dt.Columns.Add("Gender");
        dt.Rows.Add();
        dt.Rows[0][0]="Prateek Ghosh";
        dt.Rows[0][1] = 123;
        dt.Rows[0][2] = "Male";
        dt.Rows.Add();
        dt.Rows[1][0] = "Rahul";
        dt.Rows[1][1] = 1234;
        dt.Rows[1][2] = "Male";
        dt.Rows.Add();
        dt.Rows[2][0] = "Neha";
        dt.Rows[2][1] = 12345;
        dt.Rows[2][2] = "Female";

        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
</code>```

Body:
What i understood that i am showing let me know you are asking for the same or not

This is the design portion

<body>
    <form id="form1" runat="server">
    <div>
   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="gridview"
                                           >
                                            <Columns>
                                                <asp:TemplateField HeaderText="Name">
                                            <ItemTemplate>
                                                <asp:Label ID="name" runat="server" Text='<%#Eval("Name")%>'>></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                                  <asp:TemplateField HeaderText="Roll No">
                                            <ItemTemplate>
                                                <asp:Label ID="rollno" runat="server" Text='<%#Eval("Roll_No")%>'>></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                                  <asp:TemplateField HeaderText="Gender">
                                            <ItemTemplate>
                                               <asp:CheckBox runat="server" Text='<%#Eval("Gender")%>' />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                                </Columns>
       </asp:GridView>
    </div>
    </form>
</body>

Here I have made a temoporary data table you can make data table through database also

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack) {
            check_box();
        }
    }

    public void check_box() {

        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        dt.Columns.Add("Roll_NO");
        dt.Columns.Add("Gender");
        dt.Rows.Add();
        dt.Rows[0][0]="Prateek Ghosh";
        dt.Rows[0][1] = 123;
        dt.Rows[0][2] = "Male";
        dt.Rows.Add();
        dt.Rows[1][0] = "Rahul";
        dt.Rows[1][1] = 1234;
        dt.Rows[1][2] = "Male";
        dt.Rows.Add();
        dt.Rows[2][0] = "Neha";
        dt.Rows[2][1] = 12345;
        dt.Rows[2][2] = "Female";

        GridView1.DataSource = dt;
        GridView1.DataBind();
    }


问:
How to notify front-end from backend?
I am using multer for file uploading. On the server I have this:

```<code>stream.on('finish', () => {
  console.log('finished')
  next()
})
</code>```

What would be the best way (with what command) to notify the frontend that 'finished' has happened? I want to know this in order to have a loading bar.

答:
You can use sockets for this type of communication. socket.io is a node package for web sockets. In the server you have

socket.emit('done')

whereas in the client side you can attach to the emit to receive new data

```<code>socket.on('done', function (data) {
    // Do something with data
});
</code>```

Title: How to notify front-end from backend?

Body:
I am using multer for file uploading. On the server I have this:

stream.on('finish', () => {
  console.log('finished')
  next()
})

What would be the best way (with what command) to notify the frontend that 'finished' has happened? I want to know this in order to have a loading bar.

Body:
You can use sockets for this type of communication. socket.io is a node package for web sockets. In the server you have

socket.emit('done')

whereas in the client side you can attach to the emit to receive new data

socket.on('done', function (data) {
    // Do something with data
});


答:
Use an outer or cross apply. It makes your query better readable and probably faster aswell. </p>

```<code>SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
outer apply (SELECT another  AS Importantvariable FROM ... WHERE...)
WHERE a.columnname = Importantvariable ....
</code>```

Body:
I have a very long SQL statement which has the following skeleton (using SQL server 2005):

SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    (SELECT another FROM ... WHERE...) AS Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
WHERE a.columnname = (SELECT another FROM ... WHERE...) ....

This Importantvariable is a very long query by itself. However, it is used in other parts of the same query, including the WHERE clause and the INNER JOIN clauses. My question is, how can I somehow save it's value so I don't have to write the whole query every time. In this example above I would like to type a.columnname = Importantvariable instead of the whole query. I tried using DECLARE and save the value in a declared variable but it's not allowing me to do so with the following error:

A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operation.

Of course, that makes sense but my whole point is to perform data retrieval, I just don't want to copy and paste the very long query that defined the Importantvariable on several different places in the query.
Any ideas?

Body:
Use an outer or cross apply. It makes your query better readable and probably faster aswell.

SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
outer apply (SELECT another  AS Importantvariable FROM ... WHERE...)
WHERE a.columnname = Importantvariable ....


问:
Very complex linq
I'm having trouble rewriteing a complex sql query as linq.

```<code>-- gets the SpecificationAttributeOptionIDs that are in the FilteredSpecs list, but don't match
    SELECT * FROM #FilteredSpecs [fs]
                            WHERE [fs].SpecificationAttributeOptionID NOT IN
                            (
                                -- gets the SpecificationAttributeOptionIDs that match
                                SELECT psam.SpecificationAttributeOptionID
                                FROM dbo.Nop_Product_SpecificationAttribute_Mapping psam
                                WHERE psam.AllowFiltering = 1 AND psam.ProductID = 1
                            )
</code>```

basically what I have, is a list FilteredSpec which is C# is a List of int. I'm trying to get all products that have all the attributeoptions from the FilteredSpec list set.

What I've tried is this (which given my limited knowledge of linq obviously doesn't work):

```<code>var query = from p in Products
                        where (p.NpProductSpecificationAttributes.Select(a => filters.Contains(a.NpSpecificationAttributeOption.SpecificationAttributeOptionId)).Count() == 0)
                        select p;
</code>```

Can anybody guide me in the right direction please?

答:
First off, never use Count() unless you really need to know exactly how many elements there are.  Using Count() to test for an empty set may require walking through the entire dataset.  This is critical for performance when your dataset size is bigger than a handful of items.  Use ! .Any() instead of .Count() == 0, .Any() instead of .Count() > 0.

Next, your NOT IN test in the original SQL sounds like a set difference operation.  In LINQ, that is represented by .Except()   A.Except(B) returns all the elements of A that are not found in B.

I'm a little confused by your problem description.  In text you say you want to find all the products that have all the attributeoptions found in the FilterSpec list.  But in both of your code samples, you're using NOT IN or testing for Contains returning an empty result, which seems to be running in the opposite direction of your text description.

If you are trying to find all the products that have all the attributeoptions found in the FilterSpec list, then you are looking for set equivalence.

If the items in your attributeoptions and your filterspec list are always listed in a particular order, then you could use Linq's .SequenceEqual() function.  I'll assume your attributeoptions are not ordered, so .SequenceEqual() isn't the right solution.

To test two sets of values A and B for equivalence independent of order, you can test for A.Except(B) is empty and B.Except(A) is empty.  Use ! .Any() to test for empty.  The first one says that everything in A can be found in B, and the second one says everything in B can be found in A.  What else is there?  Nothing, so the two sets must contain exactly the same elements.

Try something like this (not tested):

```<code>var query = from p in Products
            where !p.NpProductSpecificationAttributes.Except(filters).Any() &&
                  !filters.Except(p.NpProductSpecificationAttributes).Any()
            select p;
</code>```

You can probably get better performance by using a HashSet, if only to reduce the number of times hashsets must be created internally by the expression above.  The code below assumes that there are no duplicate items in the filters list nor in the product attributes.  If your SpecificationAttributeOptionId is not a primitive type (string, int) you may need to specify an equality comparer as well.

```<code>    var filterset = new HashSet<filteritemtype>(filters);
    var query = from p in Products
                where filterset.SetEquals(new HashSet<itemtype>(p.NpProductSpecificationAttributes))
                select p;
</code>```

Title: Very complex linq

Body:
I'm having trouble rewriteing a complex sql query as linq.

-- gets the SpecificationAttributeOptionIDs that are in the FilteredSpecs list, but don't match
    SELECT * FROM #FilteredSpecs [fs]
                            WHERE [fs].SpecificationAttributeOptionID NOT IN
                            (
                                -- gets the SpecificationAttributeOptionIDs that match
                                SELECT psam.SpecificationAttributeOptionID
                                FROM dbo.Nop_Product_SpecificationAttribute_Mapping psam
                                WHERE psam.AllowFiltering = 1 AND psam.ProductID = 1
                            )

basically what I have, is a list FilteredSpec which is C# is a List of int. I'm trying to get all products that have all the attributeoptions from the FilteredSpec list set.

What I've tried is this (which given my limited knowledge of linq obviously doesn't work):

var query = from p in Products
                        where (p.NpProductSpecificationAttributes.Select(a => filters.Contains(a.NpSpecificationAttributeOption.SpecificationAttributeOptionId)).Count() == 0)
                        select p;

Can anybody guide me in the right direction please?

Body:
First off, never use Count() unless you really need to know exactly how many elements there are.  Using Count() to test for an empty set may require walking through the entire dataset.  This is critical for performance when your dataset size is bigger than a handful of items.  Use ! .Any() instead of .Count() == 0, .Any() instead of .Count() > 0.

Next, your NOT IN test in the original SQL sounds like a set difference operation.  In LINQ, that is represented by .Except()   A.Except(B) returns all the elements of A that are not found in B.

I'm a little confused by your problem description.  In text you say you want to find all the products that have all the attributeoptions found in the FilterSpec list.  But in both of your code samples, you're using NOT IN or testing for Contains returning an empty result, which seems to be running in the opposite direction of your text description.

If you are trying to find all the products that have all the attributeoptions found in the FilterSpec list, then you are looking for set equivalence.

If the items in your attributeoptions and your filterspec list are always listed in a particular order, then you could use Linq's .SequenceEqual() function.  I'll assume your attributeoptions are not ordered, so .SequenceEqual() isn't the right solution.

To test two sets of values A and B for equivalence independent of order, you can test for A.Except(B) is empty and B.Except(A) is empty.  Use ! .Any() to test for empty.  The first one says that everything in A can be found in B, and the second one says everything in B can be found in A.  What else is there?  Nothing, so the two sets must contain exactly the same elements.

Try something like this (not tested):

var query = from p in Products
            where !p.NpProductSpecificationAttributes.Except(filters).Any() &&
                  !filters.Except(p.NpProductSpecificationAttributes).Any()
            select p;

You can probably get better performance by using a HashSet, if only to reduce the number of times hashsets must be created internally by the expression above.  The code below assumes that there are no duplicate items in the filters list nor in the product attributes.  If your SpecificationAttributeOptionId is not a primitive type (string, int) you may need to specify an equality comparer as well.

    var filterset = new HashSet<filteritemtype>(filters);
    var query = from p in Products
                where filterset.SetEquals(new HashSet<itemtype>(p.NpProductSpecificationAttributes))
                select p;


问:
Quick ways to test OLE DB Connection String
For debugging purpose I'd like to know ways to test OLE DB connection string quickly.

I've found this free software, it works on my machine, tested successfully.

Is there a even quicker way to do so, maybe from command line on Windows? Because most of the time, it is the client rather than me that would do this task, so I prefer a "zero-installation" approach that would impact their system the least.

答:
There is one quick UI Method to Verify it

Create an empty file: empty.txt

rename the extension udl: empty.udl

Now just double-click that file, it will ask the server and user name password, you gonna know how to do it.

Refer: http://www.gotknowhow.com/articles/test-a-database-connection-string-using-notepad


问:
Get Animation states from an Animator in Unity3d
I've used Animator to create two animation states, I want to change the speed of these animations at run type. How can I get these animations at run time and change their speed? Do I have to attach Animation component or Animator is enough?

答:
```<code>//get animation:

animator = GetComponent<Animator>();
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);

//get animation speed, add animation speed

Debug.Log("StateInfo length:  "+stateInfo.length);

if(Input.GetKeyDown(KeyCode.A))
{
    animator.speed += 1f;
}
</code>```


问:
Modify bitrix self-hosted crm search results
I've created a custom CRM component in Bitrix and placed it in the local folder. The global search and CRM search, however, does not search field values in this custom component.

How / where would I modify the search module to include the custom component?

Any pointers would be useful.

Thanks,
Jesal

答:
Component usually hasn't content for search.Look at MVC. Component is a controller.  All content in a model. In bitrix case your model it's iblock module. For add iblock elements to search module you need go to iblock settings and set checkbox "
Index elements for the Search module" http://joxi.ru/D2P8vgKspx4RQ2

After that you need reindex all data on page /bitrix/admin/search_reindex.php?lang=en. http://joxi.ru/eAODvELfxbqDdr


问:
Revoke a task from celery
I want to explicitly revoke a task from celery. This is how I'm currently doing:-

```<code>from celery.task.control import revoke

revoke(task_id, terminate=True)
</code>```

where task_id is string(have also tried converting it into UUID uuid.UUID(task_id).hex).

After the above procedure, when I start celery again celery worker -A proj it still consumes the same message and starts processing it. Why?

When viewed via flower, the message is still there in the broker section. how do I delete the message so that it cant be consumed again?

答:
How does revoke works?

When calling the revoke method the task doesn't get deleted from the queue immediately, all it does is tell celery(not your broker!) to save the task_id in a in-memory set(look here if you like reading source code like me).

When the task gets to the top of the queue, Celery will check if is it in the revoked set, if it does, it won't execute it.

It works this way to prevent O(n) search for each revoke call, where checking if the task_id is in the in-memory set is just O(1)

Why after restarting celery, your revoked tasks executed?

Understanding how things works, you now know that the set is just a normal python set, that being saved in-memory - that means when you restart, you lose this set, but the task is(of course) persistence and when the tasks turn comes, it will be executed as normal.

What can you do?

You will need to have a persistence set, this is done by initial your worker like this:

celery worker -A proj --statedb=/var/run/celery/worker.state

This will save the set on the filesystem.

References:

Celery source code of the in-memory set

Revoke doc

Persistent revokes docs

Title: Revoke a task from celery

Body:
I want to explicitly revoke a task from celery. This is how I'm currently doing:-

from celery.task.control import revoke

revoke(task_id, terminate=True)

where task_id is string(have also tried converting it into UUID uuid.UUID(task_id).hex).

After the above procedure, when I start celery again celery worker -A proj it still consumes the same message and starts processing it. Why?

When viewed via flower, the message is still there in the broker section. how do I delete the message so that it cant be consumed again?


问:
Function with variable parameter type
I have these two functions which are basically the same:

```<code>private Order getOrder( List<Order> orders, String gcsId )
{
    Predicate<Order> predicate = c -> c.getGcsId().equals( gcsId );
    Order obj = orders.stream().filter( predicate ).findFirst().get();
    return obj;
}

private OrderLine getOrderLine( List<OrderLine> orderLines, String gcsId )
{
    Predicate<OrderLine> predicate = c -> c.getGcsId().equals( gcsId );
    OrderLine obj = orderLines.stream().filter( predicate ).findFirst().get();
    return obj;
}
</code>```

The only difference is the type of the first parameter. How can I create a single function with the first parameter having a variable type?

Edit: This is how I call those functions in another method of the same class:

```<code>Order order = getOrder( orders, orderId );
OrderLine orderLine = getOrderLine( order.getOrderLines(), orderLineId );
</code>```

答:
You should create an Interface. See below:

```<code>import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class SomeFunctionsRefactored {

    public static void main(String[] args) {
        Order simpleOrder = new SimpleOrder();
        Order lineOrder = new LineOrder();
        String gcsId;
        List<Order> simpleOrders = new ArrayList(Arrays.asList(simpleOrder));
        List<Order> lineOrders = new ArrayList(Arrays.asList(lineOrder));

        Order order = getOrder(simpleOrders, "Hi I'm a simple order");
        System.out.println(order.getGcsId());  // Hi I'm a simple order

        order = getOrder(lineOrders, "Hi I'm a line order");
        System.out.println(order.getGcsId());  // Hi I'm a line order

    }

    private static Order getOrder(List<Order> orders, String gcsId) {
        Predicate<Order> predicate = c -> c.getGcsId().equals(gcsId);
        return orders.stream().filter(predicate).findFirst().get();
    }
</code>```

The interface:

```<code>interface Order {
    public String getGcsId();
}

class SimpleOrder implements Order {
    String gcsId = "Hi I'm a simple order";

    public String getGcsId() {
        return gcsId;
    }

}

class LineOrder implements Order {
    String gcsId = "Hi I'm a line order";

    public String getGcsId() {
        return gcsId;
    }
}
</code>```

Title: Function with variable parameter type

Body:
I have these two functions which are basically the same:

private Order getOrder( List<Order> orders, String gcsId )
{
    Predicate<Order> predicate = c -> c.getGcsId().equals( gcsId );
    Order obj = orders.stream().filter( predicate ).findFirst().get();
    return obj;
}

private OrderLine getOrderLine( List<OrderLine> orderLines, String gcsId )
{
    Predicate<OrderLine> predicate = c -> c.getGcsId().equals( gcsId );
    OrderLine obj = orderLines.stream().filter( predicate ).findFirst().get();
    return obj;
}

The only difference is the type of the first parameter. How can I create a single function with the first parameter having a variable type?

Edit: This is how I call those functions in another method of the same class:

Order order = getOrder( orders, orderId );
OrderLine orderLine = getOrderLine( order.getOrderLines(), orderLineId );

Body:
You should create an Interface. See below:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class SomeFunctionsRefactored {

    public static void main(String[] args) {
        Order simpleOrder = new SimpleOrder();
        Order lineOrder = new LineOrder();
        String gcsId;
        List<Order> simpleOrders = new ArrayList(Arrays.asList(simpleOrder));
        List<Order> lineOrders = new ArrayList(Arrays.asList(lineOrder));

        Order order = getOrder(simpleOrders, "Hi I'm a simple order");
        System.out.println(order.getGcsId());  // Hi I'm a simple order

        order = getOrder(lineOrders, "Hi I'm a line order");
        System.out.println(order.getGcsId());  // Hi I'm a line order

    }

    private static Order getOrder(List<Order> orders, String gcsId) {
        Predicate<Order> predicate = c -> c.getGcsId().equals(gcsId);
        return orders.stream().filter(predicate).findFirst().get();
    }

The interface:

interface Order {
    public String getGcsId();
}

class SimpleOrder implements Order {
    String gcsId = "Hi I'm a simple order";

    public String getGcsId() {
        return gcsId;
    }

}

class LineOrder implements Order {
    String gcsId = "Hi I'm a line order";

    public String getGcsId() {
        return gcsId;
    }
}


问:
Boolean variable becomes command-line option
Is there a more succinct way to do this with bash?

```<code>if [[ ${BOOL} == true ]]; then
    OPTION="--option"
else
    OPTION=
fi

command ${OPTION}
</code>```

BOOL is a string value guaranteed to be either: true or false

If true there should be an option.
If false there should be no option.

答:
Shorter than the other answers:

```<code>OPTION=$($BOOL && echo --option)
</code>```

Is it better? I'm not sure.

As long as it works and you understand it, I don't see a reason to change it.

Body:
Is there a more succinct way to do this with bash?

if [[ ${BOOL} == true ]]; then
    OPTION="--option"
else
    OPTION=
fi

command ${OPTION}

BOOL is a string value guaranteed to be either: true or false

If true there should be an option.
If false there should be no option.

Body:
Shorter than the other answers:

OPTION=$($BOOL && echo --option)

Is it better? I'm not sure.

As long as it works and you understand it, I don't see a reason to change it.


问:
java reason: actual and formal argument lists differ in length
I need help creating a setter method for my code. I have created two setter methods for both of my string values, but I am A) not sure if they are implemented correct, and B) not sure how to call them so that they appear on the screen. Essentially I would like to be able to just call my lion and hippo classes and have them already have a name and a size, and not have to implement them inside my main function directly by inserting something like
 Hippo h = new Hippo("Tom", "42")

```<code>package game2;

public class Game2 {

    public static void main(String[] args) {
        //I am getting the error here, what I want to do is figure out how to
        //get this to work and then declare a name and size for the animal
        Hippo h = new Hippo();
        Lion l = new Lion();
    }

}
</code>```

```<code>package game2;

public abstract class Animal {
    private String name;
    private String Size;

    public String getName() {
        return name;
    }

    public String getSize() {
        return Size;
    }

    public void setName(String name) {
        name = "Tom";
    }

    public void setSize(String name) {
        name = "42";
    }

    public Animal(String theName, String theSize) {
        name = theName;
        Size = theSize;
    }
 }
</code>```

```<code>package game2;

public class Hippo extends Animal {

    public Hippo(String name, String Size) {
        super(name, Size);
    }
}
</code>```

```<code>package game2;

public class Lion extends Animal{

    public Lion(String name, String Size) {
        super(name, Size);
    }
}
</code>```

答:
your code is not compiling because you are not using the right constructor,
Both Hippo's and Lion's constructors expect two string arguments so you have to do something like:</p>

```<code>Hippo h = new Hippo("myHippo", "220");
Lion l = new Lion("Simba", "400");
</code>```

Body:
I need help creating a setter method for my code. I have created two setter methods for both of my string values, but I am A) not sure if they are implemented correct, and B) not sure how to call them so that they appear on the screen. Essentially I would like to be able to just call my lion and hippo classes and have them already have a name and a size, and not have to implement them inside my main function directly by inserting something like
 Hippo h = new Hippo("Tom", "42")

package game2;

public class Game2 {

    public static void main(String[] args) {
        //I am getting the error here, what I want to do is figure out how to
        //get this to work and then declare a name and size for the animal
        Hippo h = new Hippo();
        Lion l = new Lion();
    }

}

package game2;

public abstract class Animal {
    private String name;
    private String Size;

    public String getName() {
        return name;
    }

    public String getSize() {
        return Size;
    }

    public void setName(String name) {
        name = "Tom";
    }

    public void setSize(String name) {
        name = "42";
    }

    public Animal(String theName, String theSize) {
        name = theName;
        Size = theSize;
    }
 }

package game2;

public class Hippo extends Animal {

    public Hippo(String name, String Size) {
        super(name, Size);
    }
}

package game2;

public class Lion extends Animal{

    public Lion(String name, String Size) {
        super(name, Size);
    }
}

Body:
your code is not compiling because you are not using the right constructor,
Both Hippo's and Lion's constructors expect two string arguments so you have to do something like:

Hippo h = new Hippo("myHippo", "220");
Lion l = new Lion("Simba", "400");


问:
Exclude from brace expansion
I know that

```<code>echo {1..10}
</code>```

do

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

but i do not want 6 and 7. Is it possible to exclude it?

答: As a workaround, echo {1..5} {8..10} may suffice.

Title: Exclude from brace expansion

Body:
I know that

echo {1..10}

do

1 2 3 4 5 6 7 8 9 10

but i do not want 6 and 7. Is it possible to exclude it?


问:
Declare a variable with SELECT SQL statement to be used in the WHERE clause
I have a very long SQL statement which has the following skeleton (using SQL server 2005):

```<code>SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    (SELECT another FROM ... WHERE...) AS Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
WHERE a.columnname = (SELECT another FROM ... WHERE...) ....
</code>```

This Importantvariable is a very long query by itself. However, it is used in other parts of the same query, including the WHERE clause and the INNER JOIN clauses. My question is, how can I somehow save it's value so I don't have to write the whole query every time. In this example above I would like to type a.columnname = Importantvariable instead of the whole query. I tried using DECLARE and save the value in a declared variable but it's not allowing me to do so with the following error:

```<code>A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operation.
</code>```

Of course, that makes sense but my whole point is to perform data retrieval, I just don't want to copy and paste the very long query that defined the Importantvariable on several different places in the query.
Any ideas?

答:
I recommend using a CTE like so:</p>

```<code>;with cte as
(
SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    (SELECT another FROM ... WHERE...) AS Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
)
select *,
       <maybe more uses of Importantvariable>
  from cte
 WHERE columnname = Importantvariable;
</code>```

Body:
I recommend using a CTE like so:

;with cte as
(
SELECT
    a.something AS Something,
    b.otherthing AS Otherthing,
    (SELECT another FROM ... WHERE...) AS Importantvariable,
....
FROM...
INNER JOIN...
INNER JOIN...
)
select *,
       <maybe more uses of Importantvariable>
  from cte
 WHERE columnname = Importantvariable;


答:
new Hippo()/Lion() is calling a function you don't have (empty constructor)

You have function Hippo(String name, String Size)  which need 2 parameters

try new Hippo("Billy", "10")

Title: java reason: actual and formal argument lists differ in length


问:
i have a hash map HashMap<String, ArrayList<String>> and i want to set these array value in recycle list in android
I sent the value of hashmap in adapter constructor but these value is not set in onBindViewHolder() in Recycleadapter.

Here is the working construction of the HashMap. Its values are supposed to reflect in the RecyclerView#onBindViewHolder.

```<code>HashMap<String, ArrayList<String>> hashmap = new HashMap<String, ArrayList<String>>();
ArrayList<String> listOne = new ArrayList<String>();
                           listOne.add(presubsFeaturesName);
                            listOne.add(presubsFeaturesUSer);
                            listOne.add(presubsFeaturesClient);
                            listOne.add(presubsFeaturesPassword);

                hashmap.put("A", listOne);
                System.out.println("mBasicDataListdcsdcfrfervw "+mBasicDataList);

                for (HashMap.Entry<String, ArrayList<String>> entry : hashmap.entrySet())
                {
                    String key = entry.getKey();
                    ArrayList<String> values = entry.getValue();
                    System.out.println("Key = " + key);
                    System.out.println("Values = " + values + "n");
                }

        mAdapter = new ComparePlanRecycleAdapter(hashmap);
                mAdapter.notifyDataSetChanged();
                mRecycleview.setHasFixedSize(true);
                //     mAdapter.getItemCount();
                // mAdapter.swap(dataList1);
                FragmentActivity fragmentActivity = getActivity();
                RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(fragmentActivity);
                mRecycleview.setLayoutManager(mLayoutManager);
                mRecycleview.setItemAnimator(new DefaultItemAnimator());
                //  mRecycleview.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));
                mRecycleview.setAdapter(mAdapter);
</code>```

Here is the custom RecyclerView.Adapter class

```<code>class ComparePlanRecycleAdapter extends RecyclerView.Adapter<ComparePlanRecycleAdapter.MyViewHolder> {

  //  private ArrayList<ComparePlan_Record> basicDataList;
 //   private ArrayList<ComparePlan_Record> predataList;
    boolean dataChanged = true;
    HashMap<String, ArrayList<String>> hashmap;

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textSubscriptionPlanSettingFeaturesName;
        TextView textBasicsubscriptionPlanSettingValue1;
        TextView textPremiumsubscriptionPlanSettingValue1;

        public MyViewHolder(View view) {
            super(view);
            textSubscriptionPlanSettingFeaturesName = (TextView) view.findViewById(R.id.subsplanname);
            textBasicsubscriptionPlanSettingValue1 = (TextView) view.findViewById(R.id.basicsubsvalue1);
            textPremiumsubscriptionPlanSettingValue1 = (TextView) view.findViewById(R.id.premiumsubsvalue1);
        }
    }
    public ComparePlanRecycleAdapter(HashMap<String, ArrayList<String>> hashmap) {

        this.hashmap = hashmap;
    //    this.predataList = predataList;
        System.out.println("hashmaphashmaphashmap "+hashmap);

    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.compareplan_recycleview_listpopulate, parent, false);

        return new MyViewHolder(itemView);
    }
    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
     //   final ComparePlan_Record basicRecord = basicDataList.get(position);
     //   final ComparePlan_Record preRecord = basicDataList.get(position);

        System.out.println("hashmaphashma "+hashmap);

      /*  for (int i = 0; i < getItemCount(); i++) {
            holder.textSubscriptionPlanSettingFeaturesName.setText(basicRecord.getSubscriptionPlanSettingFeaturesName());
            holder.textBasicsubscriptionPlanSettingValue1.setText(basicRecord.getBasicsubscriptionPlanSettingValue1());
            holder.textPremiumsubscriptionPlanSettingValue1.setText(basicRecord.getPremiumsubscriptionPlanSettingValue1());
         //   holder.textPremiumsubscriptionPlanSettingValue1.setText("PS");

            System.out.println("basicRecord.getPremiumsubscriptionPlanSettingValue1()"+basicRecord.getPremiumsubscriptionPlanSettingValue1());
        }*/
        }
    @Override
    public int getItemCount() {
        return hashmap.size();
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }
}
</code>```

How do i set the value of HashMap in RecyclerView#onBindViewHolder?.

答:
Hashmap doesn't not preserve ordering. You should use LinkedHashMap to retrieve values in Adapter

```<code>LinkedHashMap<String, List<String>> hMap;
</code>```

In onBindViewHolder:

```<code>List<List<String>> l = new ArrayList<List<String>>(hMap.values());
List yourlist = l.get(position);
</code>```

Body:
I sent the value of hashmap in adapter constructor but these value is not set in onBindViewHolder() in Recycleadapter.

Here is the working construction of the HashMap. Its values are supposed to reflect in the RecyclerView#onBindViewHolder.

HashMap<String, ArrayList<String>> hashmap = new HashMap<String, ArrayList<String>>();
ArrayList<String> listOne = new ArrayList<String>();
                           listOne.add(presubsFeaturesName);
                            listOne.add(presubsFeaturesUSer);
                            listOne.add(presubsFeaturesClient);
                            listOne.add(presubsFeaturesPassword);

                hashmap.put("A", listOne);
                System.out.println("mBasicDataListdcsdcfrfervw "+mBasicDataList);

                for (HashMap.Entry<String, ArrayList<String>> entry : hashmap.entrySet())
                {
                    String key = entry.getKey();
                    ArrayList<String> values = entry.getValue();
                    System.out.println("Key = " + key);
                    System.out.println("Values = " + values + "n");
                }

        mAdapter = new ComparePlanRecycleAdapter(hashmap);
                mAdapter.notifyDataSetChanged();
                mRecycleview.setHasFixedSize(true);
                //     mAdapter.getItemCount();
                // mAdapter.swap(dataList1);
                FragmentActivity fragmentActivity = getActivity();
                RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(fragmentActivity);
                mRecycleview.setLayoutManager(mLayoutManager);
                mRecycleview.setItemAnimator(new DefaultItemAnimator());
                //  mRecycleview.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));
                mRecycleview.setAdapter(mAdapter);

Here is the custom RecyclerView.Adapter class

class ComparePlanRecycleAdapter extends RecyclerView.Adapter<ComparePlanRecycleAdapter.MyViewHolder> {

  //  private ArrayList<ComparePlan_Record> basicDataList;
 //   private ArrayList<ComparePlan_Record> predataList;
    boolean dataChanged = true;
    HashMap<String, ArrayList<String>> hashmap;

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textSubscriptionPlanSettingFeaturesName;
        TextView textBasicsubscriptionPlanSettingValue1;
        TextView textPremiumsubscriptionPlanSettingValue1;

        public MyViewHolder(View view) {
            super(view);
            textSubscriptionPlanSettingFeaturesName = (TextView) view.findViewById(R.id.subsplanname);
            textBasicsubscriptionPlanSettingValue1 = (TextView) view.findViewById(R.id.basicsubsvalue1);
            textPremiumsubscriptionPlanSettingValue1 = (TextView) view.findViewById(R.id.premiumsubsvalue1);
        }
    }
    public ComparePlanRecycleAdapter(HashMap<String, ArrayList<String>> hashmap) {

        this.hashmap = hashmap;
    //    this.predataList = predataList;
        System.out.println("hashmaphashmaphashmap "+hashmap);

    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.compareplan_recycleview_listpopulate, parent, false);

        return new MyViewHolder(itemView);
    }
    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
     //   final ComparePlan_Record basicRecord = basicDataList.get(position);
     //   final ComparePlan_Record preRecord = basicDataList.get(position);

        System.out.println("hashmaphashma "+hashmap);

      /*  for (int i = 0; i < getItemCount(); i++) {
            holder.textSubscriptionPlanSettingFeaturesName.setText(basicRecord.getSubscriptionPlanSettingFeaturesName());
            holder.textBasicsubscriptionPlanSettingValue1.setText(basicRecord.getBasicsubscriptionPlanSettingValue1());
            holder.textPremiumsubscriptionPlanSettingValue1.setText(basicRecord.getPremiumsubscriptionPlanSettingValue1());
         //   holder.textPremiumsubscriptionPlanSettingValue1.setText("PS");

            System.out.println("basicRecord.getPremiumsubscriptionPlanSettingValue1()"+basicRecord.getPremiumsubscriptionPlanSettingValue1());
        }*/
        }
    @Override
    public int getItemCount() {
        return hashmap.size();
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }
}

How do i set the value of HashMap in RecyclerView#onBindViewHolder?.

Body:
Hashmap doesn't not preserve ordering. You should use LinkedHashMap to retrieve values in Adapter

LinkedHashMap<String, List<String>> hMap;

In onBindViewHolder:

List<List<String>> l = new ArrayList<List<String>>(hMap.values());
List yourlist = l.get(position);


问:
Invalid operand to binary expression Error
I'm trying to write this swift line in Objective-C.

Swift

```<code>timeRemainingLabel.text = String(format: "%02d:%02d", ((lround(timeRemaining) / 60) % 60), lround(timeRemaining) % 60)
</code>```

Objective-C

```<code>timeRemainingLabel.text = [NSString stringWithFormat:@"%02d:%02d", ((roundf(timeRemaining) / 60) % 60), roundf(timeRemaining) % 60];
</code>```

But it gives this error:

Invalid operand to binary expression Error.('float' and 'float')

How to fix this?

答:
```<code>try dividing with decimal value. i.e. **/60.0f** instead of **/60**

timeRemainingLabel.text = [NSString stringWithFormat:@"%02d:%02d", ((roundf(timeRemaining) / 60) % 60), roundf(timeRemaining) % 60];
</code>```

Body:
I'm trying to write this swift line in Objective-C.

Swift

timeRemainingLabel.text = String(format: "%02d:%02d", ((lround(timeRemaining) / 60) % 60), lround(timeRemaining) % 60)

Objective-C

timeRemainingLabel.text = [NSString stringWithFormat:@"%02d:%02d", ((roundf(timeRemaining) / 60) % 60), roundf(timeRemaining) % 60];

But it gives this error:

Invalid operand to binary expression Error.('float' and 'float')

How to fix this?


问:
Difference between pimpl and defining class inside .cpp file
Im trying to understand difference between pimpl and defining inside .cpp file

```<code>// foo.h - header file
#include <memory>
class foo
{
public:
    foo();
    ~foo();
    foo(foo&&);
    foo& operator=(foo&&);
private:
    class impl;
    std::unique_ptr<impl> pimpl;
};
// foo.cpp - implementation file
class foo::impl
{
public:
    void do_internal_work()
    {
        internal_data = 5;
    }
private:
    int internal_data = 0;
};
foo::foo()
    : pimpl{ std::make_unique<impl>() }
{
    pimpl->do_internal_work();
}
foo::~foo() = default;
foo::foo(foo&&) = default;
foo& foo::operator=(foo&&) = default;
</code>```

and

```<code>// foo.h - header file
#include <memory>
class foo
{
public:
    foo();
    ~foo();
    foo(foo&&);
    foo& operator=(foo&&);

};
// foo.cpp - implementation file
class impl
{
public:
    void do_internal_work()
    {
        internal_data = 5;
    }
private:
    int internal_data = 0;
};
foo::foo()
{
    impl _impl;
    _impl.do_internal_work();
}
foo::~foo() = default;
foo::foo(foo&&) = default;
foo& foo::operator=(foo&&) = default;
</code>```

and I see no benefit of using pimpl, because implementation is already hidden from viever in cpp file, and even he don't know a name for an internal class with do real work.

答: If you add a field to foo, then in the second case it has to be defined in the header (as well as field's type), but in the first case (pimpl idiom) you can define field in impl instead, and its instance will live as long as foo's instance.

Body:
Im trying to understand difference between pimpl and defining inside .cpp file

// foo.h - header file
#include <memory>
class foo
{
public:
    foo();
    ~foo();
    foo(foo&&);
    foo& operator=(foo&&);
private:
    class impl;
    std::unique_ptr<impl> pimpl;
};
// foo.cpp - implementation file
class foo::impl
{
public:
    void do_internal_work()
    {
        internal_data = 5;
    }
private:
    int internal_data = 0;
};
foo::foo()
    : pimpl{ std::make_unique<impl>() }
{
    pimpl->do_internal_work();
}
foo::~foo() = default;
foo::foo(foo&&) = default;
foo& foo::operator=(foo&&) = default;

and

// foo.h - header file
#include <memory>
class foo
{
public:
    foo();
    ~foo();
    foo(foo&&);
    foo& operator=(foo&&);

};
// foo.cpp - implementation file
class impl
{
public:
    void do_internal_work()
    {
        internal_data = 5;
    }
private:
    int internal_data = 0;
};
foo::foo()
{
    impl _impl;
    _impl.do_internal_work();
}
foo::~foo() = default;
foo::foo(foo&&) = default;
foo& foo::operator=(foo&&) = default;

and I see no benefit of using pimpl, because implementation is already hidden from viever in cpp file, and even he don't know a name for an internal class with do real work.