问:
Debugging 'CALayer position contains NaN: [nan nan]'
Right after updating Xcode to 8.3, I started receiving this error at launch: Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'

The main view for my app has a couple of container views, one of which holds a mapView. It appears the error has to do with the map, but I can't quite make out from the message what that might be. Any thoughts would be greatly appreciated!

```<code>*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001029b1b0b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x0000000102416141 objc_exception_throw + 48
2   CoreFoundation                      0x0000000102a1a625 +[NSException raise:format:] + 197
3   QuartzCore                          0x00000001039d90be _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
4   QuartzCore                          0x00000001039d9231 -[CALayer setPosition:] + 43
5   MapKit                              0x000000010354a97b -[MKMapView _updateScrollContainerView:] + 1214
6   MapKit                              0x000000010354bbeb -[MKMapView _sizeDidChangeWithCenterCoordinate:] + 55
7   MapKit                              0x000000010354606e -[MKMapView setBounds:] + 271
8   UIKit                               0x0000000103c14b23 -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 598
9   UIKit                               0x0000000103c14e0e -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 125
10  CoreFoundation                      0x0000000102942652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
11  CoreFoundation                      0x000000010294256f -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 335
12  UIKit                               0x0000000103c1387c -[UIView(Geometry) resizeSubviewsWithOldSize:] + 183
13  UIKit                               0x000000010452f1f9 -[UIView(AdditionalLayoutSupport) _is_layout] + 168
14  UIKit                               0x0000000103c1fd56 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 994
15  UIKit                               0x0000000103c3120b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
16  QuartzCore                          0x00000001039e2904 -[CALayer layoutSublayers] + 146
17  QuartzCore                          0x00000001039d6526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
18  QuartzCore                          0x00000001039d63a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
19  QuartzCore                          0x0000000103965e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
20  QuartzCore                          0x0000000103992130 _ZN2CA11Transaction6commitEv + 468
21  QuartzCore                          0x0000000103992b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
22  CoreFoundation                      0x0000000102957717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
23  CoreFoundation                      0x0000000102957687 __CFRunLoopDoObservers + 391
24  CoreFoundation                      0x000000010293c038 CFRunLoopRunSpecific + 440
25  UIKit                               0x0000000103b6802f -[UIApplication _run] + 468
26  UIKit                               0x0000000103b6e0d4 UIApplicationMain + 159
27  Pulley                              0x0000000101bd95b7 main + 55
28  libdyld.dylib                       0x0000000109eaa65d start + 1
29  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
</code>```

答: I figured it out. The problem stemmed from a 3rd party extension I was using for MapKit. After removing my mapView from storyboard and creating a new one programmatically, a new error pointed me to methods in the extension. </p>

Body:
Right after updating Xcode to 8.3, I started receiving this error at launch: Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'

The main view for my app has a couple of container views, one of which holds a mapView. It appears the error has to do with the map, but I can't quite make out from the message what that might be. Any thoughts would be greatly appreciated!

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001029b1b0b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x0000000102416141 objc_exception_throw + 48
2   CoreFoundation                      0x0000000102a1a625 +[NSException raise:format:] + 197
3   QuartzCore                          0x00000001039d90be _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
4   QuartzCore                          0x00000001039d9231 -[CALayer setPosition:] + 43
5   MapKit                              0x000000010354a97b -[MKMapView _updateScrollContainerView:] + 1214
6   MapKit                              0x000000010354bbeb -[MKMapView _sizeDidChangeWithCenterCoordinate:] + 55
7   MapKit                              0x000000010354606e -[MKMapView setBounds:] + 271
8   UIKit                               0x0000000103c14b23 -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 598
9   UIKit                               0x0000000103c14e0e -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 125
10  CoreFoundation                      0x0000000102942652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
11  CoreFoundation                      0x000000010294256f -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 335
12  UIKit                               0x0000000103c1387c -[UIView(Geometry) resizeSubviewsWithOldSize:] + 183
13  UIKit                               0x000000010452f1f9 -[UIView(AdditionalLayoutSupport) _is_layout] + 168
14  UIKit                               0x0000000103c1fd56 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 994
15  UIKit                               0x0000000103c3120b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
16  QuartzCore                          0x00000001039e2904 -[CALayer layoutSublayers] + 146
17  QuartzCore                          0x00000001039d6526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
18  QuartzCore                          0x00000001039d63a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
19  QuartzCore                          0x0000000103965e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
20  QuartzCore                          0x0000000103992130 _ZN2CA11Transaction6commitEv + 468
21  QuartzCore                          0x0000000103992b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
22  CoreFoundation                      0x0000000102957717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
23  CoreFoundation                      0x0000000102957687 __CFRunLoopDoObservers + 391
24  CoreFoundation                      0x000000010293c038 CFRunLoopRunSpecific + 440
25  UIKit                               0x0000000103b6802f -[UIApplication _run] + 468
26  UIKit                               0x0000000103b6e0d4 UIApplicationMain + 159
27  Pulley                              0x0000000101bd95b7 main + 55
28  libdyld.dylib                       0x0000000109eaa65d start + 1
29  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)


来源: stackexchange

问:
Convert NaN to 0 in JavaScript
Is there a way to convert NaN values to 0 without an if statement? Example:

```<code>if (isNaN(a)) a = 0;
</code>```

It is very annoying to check my variables every time.

答:
    var i = [NaN, 1,2,3];

    var j = i.map(i =>{ return isNaN(i) ? 0 : i});

    console.log(j)```

ContentLicense: CC BY-SA 4.0

Title: Convert NaN to 0 in JavaScript

Body:
Is there a way to convert NaN values to 0 without an if statement? Example:

if (isNaN(a)) a = 0;

It is very annoying to check my variables every time.


问:
Getting the error "cc1plus: error: unrecognized command line option "-std=c++11"" when I run code on Qt creator
I have taken the code from the following source on Github and am trying to run it from Qt on RHEL Red Hat 4.4.7-17:

https://github.com/neveraway/oclJPEGDecoder

I extracted the project folder and ran qmake -projectin it. I opened the files in Qt creator and further modified my .pro file to link OpenCL sources and add the CXX and CFLAGS.

My .pro file looks like this:

```<code>######################################################################
# Automatically generated by qmake (1.07a) Tue Mar 28 14:51:49 2017
######################################################################

TEMPLATE = app
DEPENDPATH += src \
              /usr/local/cuda-7.0/lib64/

INCLUDEPATH += . src \
                /usr/local/cuda-7.0/lib64/\
               /usr/local/cuda-7.0/include/
# Input
HEADERS += src/bitstream.h \
           src/bmp.h \
           src/decoder.h \
           src/huffman.h \
           src/idct.h \
           src/jpeg.h \
           src/macro.h \
           src/stdafx.h \
           src/targetver.h \
           src/zigzag.h

SOURCES += src/bitstream.cpp \
           src/cpuIDCT8x8.cpp \
           src/decoder.cpp \
           src/huffman.cpp \
           src/main.cpp \
           src/oclDCT8x8.cpp \
           src/parser.cpp \
           src/stdafx.cpp \
    src/main.cpp

LIBS += -L/usr/local/cuda-7.0/lib64/ -lOpenCL

QMAKE_CXXFLAGS += -std=c++11

QMAKE_CFLAGS += -std=c99

DISTFILES += \
    src/idct8x8.cl \
    oclJPEGDecoder.sln \
    oclJPEGDecoder.vcxproj \
    oclJPEGDecoder.vcxproj.filters \
    README.md \
    test/JPEG_example_JPG_RIP_050.jpg
</code>```

When I clicked on Run qmake and then Build All, this is what I saw under "Compile Output":

```<code>18:08:23: Configuration unchanged, skipping qmake step.
18:08:23: Starting: "/usr/bin/make"
Makefile:634: warning: overriding commands for target `main.o'
Makefile:603: warning: ignoring old commands for target `main.o'
g++ -c -pipe -std=c++11 -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++ -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [bitstream.o] Error 1
18:08:23: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project oclJPEGDecoder-master (kit: Desktop Qt 5.6.2 GCC 64bit)
When executing step "Make"
18:08:23: Elapsed time: 00:00.
</code>```

My Makefile has the following contents:

```<code>#############################################################################
# Makefile for building: oclJPEGDecoder-master
# Generated by qmake (3.0) (Qt 5.6.2)
# Project:  ../oclJPEGDecoder-master/oclJPEGDecoder-master.pro
# Template: app
# Command: /opt/Qt5.6.2/5.6/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../oclJPEGDecoder-master/oclJPEGDecoder-master.pro
#############################################################################

MAKEFILE      = Makefile

####### Compiler, tools and options

CC            = gcc
CXX           = g++
DEFINES       = -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS        = -pipe -g -Wall -W -D_REENTRANT -fPIC $(DEFINES)
CXXFLAGS      = -pipe -std=c++11 -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC $(DEFINES)
INCPATH       = -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++
QMAKE         = /opt/Qt5.6.2/5.6/gcc_64/bin/qmake
DEL_FILE      = rm -f
CHK_DIR_EXISTS= test -d
MKDIR         = mkdir -p
COPY          = cp -f
COPY_FILE     = cp -f
COPY_DIR      = cp -f -R
INSTALL_FILE  = install -m 644 -p
INSTALL_PROGRAM = install -m 755 -p
INSTALL_DIR   = cp -f -R
DEL_FILE      = rm -f
SYMLINK       = ln -f -s
DEL_DIR       = rmdir
MOVE          = mv -f
TAR           = tar -cf
COMPRESS      = gzip -9f
DISTNAME      = oclJPEGDecoder-master1.0.0
DISTDIR = /root/Downloads/build-oclJPEGDecoder-master-Desktop_Qt_5_6_2_GCC_64bit-Debug/.tmp/oclJPEGDecoder-master1.0.0
LINK          = g++
LFLAGS        = -Wl,-rpath,/opt/Qt5.6.2/5.6/gcc_64/lib
LIBS          = $(SUBLIBS) -L/usr/local/cuda-7.0/lib64/ -lOpenCL -L/opt/Qt5.6.2/5.6/gcc_64/lib -lQt5Gui -L/usr/lib64 -lQt5Core -lGL -lpthread
AR            = ar cqs
RANLIB        =
SED           = sed
STRIP         = strip
</code>```

My .o files look like this:

```<code>####### Compile

bitstream.o: ../oclJPEGDecoder-master/src/bitstream.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/bitstream.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp

cpuIDCT8x8.o: ../oclJPEGDecoder-master/src/cpuIDCT8x8.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o cpuIDCT8x8.o ../oclJPEGDecoder-master/src/cpuIDCT8x8.cpp

decoder.o: ../oclJPEGDecoder-master/src/decoder.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/jpeg.h \
        ../oclJPEGDecoder-master/src/bmp.h \
        ../oclJPEGDecoder-master/src/bitstream.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/zigzag.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o decoder.o ../oclJPEGDecoder-master/src/decoder.cpp

huffman.o: ../oclJPEGDecoder-master/src/huffman.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/bitstream.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o huffman.o ../oclJPEGDecoder-master/src/huffman.cpp

main.o: ../oclJPEGDecoder-master/src/main.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/bitstream.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../oclJPEGDecoder-master/src/main.cpp

oclDCT8x8.o: ../oclJPEGDecoder-master/src/oclDCT8x8.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        /usr/local/cuda-7.0/include/CL/opencl.h \
        /usr/local/cuda-7.0/include/CL/cl.h \
        /usr/local/cuda-7.0/include/CL/cl_platform.h \
        /usr/local/cuda-7.0/include/CL/cl_gl.h \
        /usr/local/cuda-7.0/include/CL/cl_gl_ext.h \
        /usr/local/cuda-7.0/include/CL/cl_ext.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o oclDCT8x8.o ../oclJPEGDecoder-master/src/oclDCT8x8.cpp

parser.o: ../oclJPEGDecoder-master/src/parser.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/jpeg.h \
        ../oclJPEGDecoder-master/src/decoder.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o parser.o ../oclJPEGDecoder-master/src/parser.cpp

stdafx.o: ../oclJPEGDecoder-master/src/stdafx.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o stdafx.o ../oclJPEGDecoder-master/src/stdafx.cpp

main.o: ../oclJPEGDecoder-master/src/main.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/bitstream.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../oclJPEGDecoder-master/src/main.cpp

####### Install

install:  FORCE

uninstall:  FORCE

FORCE:
</code>```

2nd ATTEMPT WITH -std=c++0x:

I changed the CXX_FLAGS command to QMAKE_CXXFLAGS += -std=c++0x and kept everything else unchanged in my .pro file.
When I clicked on Build All after making the change, this is the output I got under "Compile Output":

```<code>18:38:06: Running steps for project oclJPEGDecoder-master...
18:38:06: Configuration unchanged, skipping qmake step.
18:38:06: Starting: "/usr/bin/make"
Makefile:634: warning: overriding commands for target `main.o'
Makefile:603: warning: ignoring old commands for target `main.o'
g++ -c -pipe -std=c++0x -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++ -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp
In file included from ../oclJPEGDecoder-master/src/bitstream.cpp:4:
../oclJPEGDecoder-master/src/bitstream.h:368: error: 'nullptr' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:368: error: ISO C++ forbids initialization of member 'mBitReservoir'
../oclJPEGDecoder-master/src/bitstream.h:368: error: making 'mBitReservoir' static
../oclJPEGDecoder-master/src/bitstream.h:368: error: invalid in-class initialization of static data member of non-integral type 'uint8_t*'
../oclJPEGDecoder-master/src/bitstream.h:369: error: ISO C++ forbids initialization of member 'mCapacity'
../oclJPEGDecoder-master/src/bitstream.h:369: error: making 'mCapacity' static
../oclJPEGDecoder-master/src/bitstream.h:369: error: ISO C++ forbids in-class initialization of non-const static member 'mCapacity'
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::free()':
../oclJPEGDecoder-master/src/bitstream.h:96: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:96: error: 'nullptr' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:98: error: type '<type error>' argument given to 'delete', expected pointer
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::trim()':
../oclJPEGDecoder-master/src/bitstream.h:110: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'bool BitStream::reserve(size_t)':
../oclJPEGDecoder-master/src/bitstream.h:137: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'bool BitStream::frontBit() const':
../oclJPEGDecoder-master/src/bitstream.h:209: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint8_t BitStream::frontFullByte() const':
../oclJPEGDecoder-master/src/bitstream.h:214: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front9b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:219: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front17b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:227: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front25b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:235: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::writeBit(bool)':
../oclJPEGDecoder-master/src/bitstream.h:246: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:248: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'const uint8_t* BitStream::frontData() const':
../oclJPEGDecoder-master/src/bitstream.h:307: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::cachedFrontBits(int)':
../oclJPEGDecoder-master/src/bitstream.h:340: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::moveDataTo(uint8_t*)':
../oclJPEGDecoder-master/src/bitstream.h:398: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.cpp: In member function 'size_t BitStream::append(const uint8_t*, size_t)':
../oclJPEGDecoder-master/src/bitstream.cpp:22: error: 'mBitReservoir' was not declared in this scope
make: *** [bitstream.o] Error 1
18:38:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project oclJPEGDecoder-master (kit: Desktop Qt 5.6.2 GCC 64bit)
When executing step "Make"
18:38:06: Elapsed time: 00:00.
</code>```

I got errors in bitstream.c due to incompatibility with the compiler.

How can I get around this issue? Do I absolutely need to install a new version of g++ to get this code to work? Do I need to include anything in my Makefile?

Please guide me in this matter.

EDIT:

My output for g++ --version:

```<code>g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
</code>```

I typed yum install rpmdevtools rpm-build and it gave me the following response:

```<code>Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security,
              : subscription-manager
Setting up Install Process
Package rpmdevtools-7.5-2.el6.noarch already installed and latest version
Package rpm-build-4.8.0-55.el6.x86_64 already installed and latest version
Nothing to do
</code>```

I wanted to obtain more information about gcc on my system so I typed this command:

```<code>yum list available |grep gcc
</code>```

It gave me this response:

```<code>compat-gcc-34.x86_64              3.4.6-19.el6           rhel-6-workstation-rpms
compat-gcc-34-c++.x86_64          3.4.6-19.el6           rhel-6-workstation-rpms
compat-gcc-34-g77.x86_64          3.4.6-19.el6           rhel-6-workstation-rpms
gcc-gnat.x86_64                   4.4.7-18.el6           rhel-6-workstation-rpms
gcc-java.x86_64                   4.4.7-18.el6           rhel-6-workstation-rpms
gcc-objc.x86_64                   4.4.7-18.el6           rhel-6-workstation-rpms
gcc-objc++.x86_64                 4.4.7-18.el6           rhel-6-workstation-rpms
</code>```

答:
Your 4.4.7 version of gcc is too old to fully enable C++11 features.
You need to upgrade the compiler to a version superior to 4.6 ( at least ) or if it's possible for you, upgrade your distro (let's say RHEL 7) which includes a more recent compiler.  </p>

ContentLicense: CC BY-SA 3.0

Body:
I have taken the code from the following source on Github and am trying to run it from Qt on RHEL Red Hat 4.4.7-17:

https://github.com/neveraway/oclJPEGDecoder

I extracted the project folder and ran qmake -projectin it. I opened the files in Qt creator and further modified my .pro file to link OpenCL sources and add the CXX and CFLAGS.

My .pro file looks like this:

######################################################################
# Automatically generated by qmake (1.07a) Tue Mar 28 14:51:49 2017
######################################################################

TEMPLATE = app
DEPENDPATH += src \
              /usr/local/cuda-7.0/lib64/

INCLUDEPATH += . src \
                /usr/local/cuda-7.0/lib64/\
               /usr/local/cuda-7.0/include/
# Input
HEADERS += src/bitstream.h \
           src/bmp.h \
           src/decoder.h \
           src/huffman.h \
           src/idct.h \
           src/jpeg.h \
           src/macro.h \
           src/stdafx.h \
           src/targetver.h \
           src/zigzag.h

SOURCES += src/bitstream.cpp \
           src/cpuIDCT8x8.cpp \
           src/decoder.cpp \
           src/huffman.cpp \
           src/main.cpp \
           src/oclDCT8x8.cpp \
           src/parser.cpp \
           src/stdafx.cpp \
    src/main.cpp

LIBS += -L/usr/local/cuda-7.0/lib64/ -lOpenCL

QMAKE_CXXFLAGS += -std=c++11

QMAKE_CFLAGS += -std=c99

DISTFILES += \
    src/idct8x8.cl \
    oclJPEGDecoder.sln \
    oclJPEGDecoder.vcxproj \
    oclJPEGDecoder.vcxproj.filters \
    README.md \
    test/JPEG_example_JPG_RIP_050.jpg

When I clicked on Run qmake and then Build All, this is what I saw under "Compile Output":

18:08:23: Configuration unchanged, skipping qmake step.
18:08:23: Starting: "/usr/bin/make"
Makefile:634: warning: overriding commands for target `main.o'
Makefile:603: warning: ignoring old commands for target `main.o'
g++ -c -pipe -std=c++11 -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++ -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [bitstream.o] Error 1
18:08:23: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project oclJPEGDecoder-master (kit: Desktop Qt 5.6.2 GCC 64bit)
When executing step "Make"
18:08:23: Elapsed time: 00:00.

My Makefile has the following contents:

#############################################################################
# Makefile for building: oclJPEGDecoder-master
# Generated by qmake (3.0) (Qt 5.6.2)
# Project:  ../oclJPEGDecoder-master/oclJPEGDecoder-master.pro
# Template: app
# Command: /opt/Qt5.6.2/5.6/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../oclJPEGDecoder-master/oclJPEGDecoder-master.pro
#############################################################################

MAKEFILE      = Makefile

####### Compiler, tools and options

CC            = gcc
CXX           = g++
DEFINES       = -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS        = -pipe -g -Wall -W -D_REENTRANT -fPIC $(DEFINES)
CXXFLAGS      = -pipe -std=c++11 -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC $(DEFINES)
INCPATH       = -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++
QMAKE         = /opt/Qt5.6.2/5.6/gcc_64/bin/qmake
DEL_FILE      = rm -f
CHK_DIR_EXISTS= test -d
MKDIR         = mkdir -p
COPY          = cp -f
COPY_FILE     = cp -f
COPY_DIR      = cp -f -R
INSTALL_FILE  = install -m 644 -p
INSTALL_PROGRAM = install -m 755 -p
INSTALL_DIR   = cp -f -R
DEL_FILE      = rm -f
SYMLINK       = ln -f -s
DEL_DIR       = rmdir
MOVE          = mv -f
TAR           = tar -cf
COMPRESS      = gzip -9f
DISTNAME      = oclJPEGDecoder-master1.0.0
DISTDIR = /root/Downloads/build-oclJPEGDecoder-master-Desktop_Qt_5_6_2_GCC_64bit-Debug/.tmp/oclJPEGDecoder-master1.0.0
LINK          = g++
LFLAGS        = -Wl,-rpath,/opt/Qt5.6.2/5.6/gcc_64/lib
LIBS          = $(SUBLIBS) -L/usr/local/cuda-7.0/lib64/ -lOpenCL -L/opt/Qt5.6.2/5.6/gcc_64/lib -lQt5Gui -L/usr/lib64 -lQt5Core -lGL -lpthread
AR            = ar cqs
RANLIB        =
SED           = sed
STRIP         = strip

My .o files look like this:

####### Compile

bitstream.o: ../oclJPEGDecoder-master/src/bitstream.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/bitstream.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp

cpuIDCT8x8.o: ../oclJPEGDecoder-master/src/cpuIDCT8x8.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o cpuIDCT8x8.o ../oclJPEGDecoder-master/src/cpuIDCT8x8.cpp

decoder.o: ../oclJPEGDecoder-master/src/decoder.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/jpeg.h \
        ../oclJPEGDecoder-master/src/bmp.h \
        ../oclJPEGDecoder-master/src/bitstream.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/zigzag.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o decoder.o ../oclJPEGDecoder-master/src/decoder.cpp

huffman.o: ../oclJPEGDecoder-master/src/huffman.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/bitstream.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o huffman.o ../oclJPEGDecoder-master/src/huffman.cpp

main.o: ../oclJPEGDecoder-master/src/main.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/bitstream.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../oclJPEGDecoder-master/src/main.cpp

oclDCT8x8.o: ../oclJPEGDecoder-master/src/oclDCT8x8.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        /usr/local/cuda-7.0/include/CL/opencl.h \
        /usr/local/cuda-7.0/include/CL/cl.h \
        /usr/local/cuda-7.0/include/CL/cl_platform.h \
        /usr/local/cuda-7.0/include/CL/cl_gl.h \
        /usr/local/cuda-7.0/include/CL/cl_gl_ext.h \
        /usr/local/cuda-7.0/include/CL/cl_ext.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o oclDCT8x8.o ../oclJPEGDecoder-master/src/oclDCT8x8.cpp

parser.o: ../oclJPEGDecoder-master/src/parser.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/jpeg.h \
        ../oclJPEGDecoder-master/src/decoder.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o parser.o ../oclJPEGDecoder-master/src/parser.cpp

stdafx.o: ../oclJPEGDecoder-master/src/stdafx.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o stdafx.o ../oclJPEGDecoder-master/src/stdafx.cpp

main.o: ../oclJPEGDecoder-master/src/main.cpp ../oclJPEGDecoder-master/src/stdafx.h \
        ../oclJPEGDecoder-master/src/targetver.h \
        ../oclJPEGDecoder-master/src/macro.h \
        ../oclJPEGDecoder-master/src/bitstream.h \
        ../oclJPEGDecoder-master/src/huffman.h \
        ../oclJPEGDecoder-master/src/idct.h
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../oclJPEGDecoder-master/src/main.cpp

####### Install

install:  FORCE

uninstall:  FORCE

FORCE:

2nd ATTEMPT WITH -std=c++0x:

I changed the CXX_FLAGS command to QMAKE_CXXFLAGS += -std=c++0x and kept everything else unchanged in my .pro file.
When I clicked on Build All after making the change, this is the output I got under "Compile Output":

18:38:06: Running steps for project oclJPEGDecoder-master...
18:38:06: Configuration unchanged, skipping qmake step.
18:38:06: Starting: "/usr/bin/make"
Makefile:634: warning: overriding commands for target `main.o'
Makefile:603: warning: ignoring old commands for target `main.o'
g++ -c -pipe -std=c++0x -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++ -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp
In file included from ../oclJPEGDecoder-master/src/bitstream.cpp:4:
../oclJPEGDecoder-master/src/bitstream.h:368: error: 'nullptr' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:368: error: ISO C++ forbids initialization of member 'mBitReservoir'
../oclJPEGDecoder-master/src/bitstream.h:368: error: making 'mBitReservoir' static
../oclJPEGDecoder-master/src/bitstream.h:368: error: invalid in-class initialization of static data member of non-integral type 'uint8_t*'
../oclJPEGDecoder-master/src/bitstream.h:369: error: ISO C++ forbids initialization of member 'mCapacity'
../oclJPEGDecoder-master/src/bitstream.h:369: error: making 'mCapacity' static
../oclJPEGDecoder-master/src/bitstream.h:369: error: ISO C++ forbids in-class initialization of non-const static member 'mCapacity'
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::free()':
../oclJPEGDecoder-master/src/bitstream.h:96: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:96: error: 'nullptr' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:98: error: type '<type error>' argument given to 'delete', expected pointer
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::trim()':
../oclJPEGDecoder-master/src/bitstream.h:110: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'bool BitStream::reserve(size_t)':
../oclJPEGDecoder-master/src/bitstream.h:137: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'bool BitStream::frontBit() const':
../oclJPEGDecoder-master/src/bitstream.h:209: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint8_t BitStream::frontFullByte() const':
../oclJPEGDecoder-master/src/bitstream.h:214: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front9b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:219: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front17b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:227: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front25b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:235: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::writeBit(bool)':
../oclJPEGDecoder-master/src/bitstream.h:246: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:248: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'const uint8_t* BitStream::frontData() const':
../oclJPEGDecoder-master/src/bitstream.h:307: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::cachedFrontBits(int)':
../oclJPEGDecoder-master/src/bitstream.h:340: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::moveDataTo(uint8_t*)':
../oclJPEGDecoder-master/src/bitstream.h:398: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.cpp: In member function 'size_t BitStream::append(const uint8_t*, size_t)':
../oclJPEGDecoder-master/src/bitstream.cpp:22: error: 'mBitReservoir' was not declared in this scope
make: *** [bitstream.o] Error 1
18:38:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project oclJPEGDecoder-master (kit: Desktop Qt 5.6.2 GCC 64bit)
When executing step "Make"
18:38:06: Elapsed time: 00:00.

I got errors in bitstream.c due to incompatibility with the compiler.

How can I get around this issue? Do I absolutely need to install a new version of g++ to get this code to work? Do I need to include anything in my Makefile?

Please guide me in this matter.

EDIT:

My output for g++ --version:

g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I typed yum install rpmdevtools rpm-build and it gave me the following response:

Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security,
              : subscription-manager
Setting up Install Process
Package rpmdevtools-7.5-2.el6.noarch already installed and latest version
Package rpm-build-4.8.0-55.el6.x86_64 already installed and latest version
Nothing to do

I wanted to obtain more information about gcc on my system so I typed this command:

yum list available |grep gcc

It gave me this response:

compat-gcc-34.x86_64              3.4.6-19.el6           rhel-6-workstation-rpms
compat-gcc-34-c++.x86_64          3.4.6-19.el6           rhel-6-workstation-rpms
compat-gcc-34-g77.x86_64          3.4.6-19.el6           rhel-6-workstation-rpms
gcc-gnat.x86_64                   4.4.7-18.el6           rhel-6-workstation-rpms
gcc-java.x86_64                   4.4.7-18.el6           rhel-6-workstation-rpms
gcc-objc.x86_64                   4.4.7-18.el6           rhel-6-workstation-rpms
gcc-objc++.x86_64                 4.4.7-18.el6           rhel-6-workstation-rpms


问:
Send data over sockets from Java program to C program
I'm trying to send data over network from a Java program to a C program.
But I don't know which type of data to use. I tried with a char.

Here is my Java code :

```<code>DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
char c = 'c';
dos.writeChar(c);
</code>```

And my C code :

```<code>char buffer[256];
bzero(buffer, 256);
read(newsockfd, buffer, 255);
printf("Here is the message: %c\n", buffer[0]);
</code>```

"Here is the message" print nothing. I don't know if buffer[0] is empty or if the type is not compatible.

答:
in java a char is two bytes, you may use the java type "byte" to just send one byte. Or you have to support the two-byte character (unicode) sent by Java, to be printed in C.

Yet I did not have the time to check the rest of your code, but this might be a start.

Body:
I'm trying to send data over network from a Java program to a C program.
But I don't know which type of data to use. I tried with a char.

Here is my Java code :

DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
char c = 'c';
dos.writeChar(c);

And my C code :

char buffer[256];
bzero(buffer, 256);
read(newsockfd, buffer, 255);
printf("Here is the message: %c\n", buffer[0]);

"Here is the message" print nothing. I don't know if buffer[0] is empty or if the type is not compatible.


问:
Try-catch doesn't wait for async function inside
What I'm trying to do is, after retrying to download file for 5 times in case if download was not successful for some reason, to reset the whole process and turn back to first step: function Try(). If success, then to proceed ProcessSet(3); line

But in my situation, it starts download and without waiting, goes to ProcessSet(3); line.

What am I doing wrong? why next steps after try doesn't wait for await webClient.DownloadFileTaskAsync(new Uri(response.Url), zip_path); to finish?

Here is the code:

```<code>using (WebClient webClient = new WebClient())
{
    webClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

    try
    {
        await webClient.DownloadFileTaskAsync(new Uri(response.Url), zip_path);
    }
    catch (Exception e)
    {
        Thread.Sleep(DelayOnRetry);
        Try();
    }
}
SetProgressBar(40, ProgressBarStyle.Continuous);
ProcessSet(3);
</code>```

And here is the Try() function

```<code>private void Try()
{
    ClearFolder(root_dir);
    Directory.CreateDirectory(root_dir);
    main_timer.Enabled = false;
    ProcessSet(1);
}
</code>```

Here is the whole code:

https://gist.github.com/turalus/8c781b5b0c56f66f7ec17e66a3e120fc

答:
I suggest you to change retry logic:</p>

```<code>var isFileDownloaded = false;
var tryCount = 0;
while (tryCount++ < MAX_TRY_COUNT && !isFileDownloaded) {
     using (WebClient webClient = new WebClient())
     try{
         //do stuff here
         isFileDownloaded = true
     }catch //log exception and Thread.Sleep

}

if (isFileDownloaded){
//        update progress
} else{
//too many retries, exit app
}
</code>```

Body:
What I'm trying to do is, after retrying to download file for 5 times in case if download was not successful for some reason, to reset the whole process and turn back to first step: function Try(). If success, then to proceed ProcessSet(3); line

But in my situation, it starts download and without waiting, goes to ProcessSet(3); line.

What am I doing wrong? why next steps after try doesn't wait for await webClient.DownloadFileTaskAsync(new Uri(response.Url), zip_path); to finish?

Here is the code:

using (WebClient webClient = new WebClient())
{
    webClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

    try
    {
        await webClient.DownloadFileTaskAsync(new Uri(response.Url), zip_path);
    }
    catch (Exception e)
    {
        Thread.Sleep(DelayOnRetry);
        Try();
    }
}
SetProgressBar(40, ProgressBarStyle.Continuous);
ProcessSet(3);

And here is the Try() function

private void Try()
{
    ClearFolder(root_dir);
    Directory.CreateDirectory(root_dir);
    main_timer.Enabled = false;
    ProcessSet(1);
}

Here is the whole code:

https://gist.github.com/turalus/8c781b5b0c56f66f7ec17e66a3e120fc

Body:
I suggest you to change retry logic:

var isFileDownloaded = false;
var tryCount = 0;
while (tryCount++ < MAX_TRY_COUNT && !isFileDownloaded) {
     using (WebClient webClient = new WebClient())
     try{
         //do stuff here
         isFileDownloaded = true
     }catch //log exception and Thread.Sleep

}

if (isFileDownloaded){
//        update progress
} else{
//too many retries, exit app
}


问:
css masonry grid transfer border to the next column
I have a masonry grid to display products and in some cases the first item's border move to the next column. It doesn't happen always and I can't find the reason for this to happen.
Link to the page:
http://en.naaman.b24online.com/b2c-products/tsb-163746/

Thanks.

答:
OK. I found that the height of row of the pins (defined as #columns) is too short. I added the height for the different screen sizes and it seem to work.
Not sure why the row is not taking it's full height.</p>


问:
How to use UPDATE with a SELECT in MySQL
I am using the latest MySQL.

I have two tables: backlinks and pages.

I am trying to update a column called cache_links in the table pages for a certain url. The column should equal the number of rows in backlinks where destination = url.

I could do this in my application language like so, in case what I mean to do isn't clear:

```<code>$myURL = "http://google.com/";

$numLinksResult = mysqli_query($c, "SELECT count(*) AS `num` FROM `backlinks` WHERE `same_domain` = FALSE AND `url` = '$myURL'");
$numLinksRow = mysqli_fetch_assoc($numLinksResult);
$numLinks = $numLinksRow['num'];

mysqli_query($c, "UPDATE `pages` SET `links` = $numLinks WHERE `url` = '$myURL'");
</code>```

The query I've been trying to build currently looks like this:

```<code>UPDATE `pages`, `backlinks` SET pages.`cache_links` = backlinks.count(*)
    WHERE  backlinks.`destination` = pages.`url`
        AND backlinks.`same_domain` = FALSE
        AND pages.`url` = 'http://google.com/'
</code>```

The problem, I think, is at backlinks.count(*). I have no idea what I'm doing wrong. The error I get is:

```<code>#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '*)
WHERE backlinks.`destination` = pages.`url` AND backlinks.`same_' at line 1
</code>```

Any help is greatly appreciated. Thanks a ton!

答:
You can use a correlated sub query.</p>

```<code>UPDATE `pages`
SET    pages.`cache_links` =
       (SELECT COUNT(*)
       FROM    backlinks
       WHERE   backlinks.`destination` = pages.`url`
       AND     backlinks.`same_domain` = FALSE
       )
WHERE  pages.`url` = 'http://google.com/'
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I am using the latest MySQL.

I have two tables: backlinks and pages.

I am trying to update a column called cache_links in the table pages for a certain url. The column should equal the number of rows in backlinks where destination = url.

I could do this in my application language like so, in case what I mean to do isn't clear:

$myURL = "http://google.com/";

$numLinksResult = mysqli_query($c, "SELECT count(*) AS `num` FROM `backlinks` WHERE `same_domain` = FALSE AND `url` = '$myURL'");
$numLinksRow = mysqli_fetch_assoc($numLinksResult);
$numLinks = $numLinksRow['num'];

mysqli_query($c, "UPDATE `pages` SET `links` = $numLinks WHERE `url` = '$myURL'");

The query I've been trying to build currently looks like this:

UPDATE `pages`, `backlinks` SET pages.`cache_links` = backlinks.count(*)
    WHERE  backlinks.`destination` = pages.`url`
        AND backlinks.`same_domain` = FALSE
        AND pages.`url` = 'http://google.com/'

The problem, I think, is at backlinks.count(*). I have no idea what I'm doing wrong. The error I get is:

#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '*)
WHERE backlinks.`destination` = pages.`url` AND backlinks.`same_' at line 1

Any help is greatly appreciated. Thanks a ton!

Body:
You can use a correlated sub query.

UPDATE `pages`
SET    pages.`cache_links` =
       (SELECT COUNT(*)
       FROM    backlinks
       WHERE   backlinks.`destination` = pages.`url`
       AND     backlinks.`same_domain` = FALSE
       )
WHERE  pages.`url` = 'http://google.com/'


问:
how can i query where clause using between date in sphinx
I have this query:

```<code>select * from tabel where last_purchase_categories = 'flight'
 and last_purchase_date between '2016-10-23 11:06:47' and '2016-10-23 11:06:49';
</code>```

it is didnt work in sphinx. i use fulltext search using mysql query browser.
do anyone know how to using date format in sphinx ?

答:
Well sphinx can't do string comparisons like that, at least with between (assuming you have the date in a string attribute). And there isnt a 'datetime' attribute type either.

Can put the date in simple numeric attribute, and do comparisons on that.

a Unix Timestamp might be convenient, can do it in the sphinx config file (using the mysql unix_timestamp() function)

```<code>sql_query = SELECT ..., UNIX_TIMESTAMP(last_purchase_date) AS last_purchase_date FROM ...
sql_attr_uint = last_purchase_date
</code>```

Then query would be something like

```<code>select * from tabel where last_purchase_categories = 'flight'
 and last_purchase_date between 1477217207 and 1477217209;
</code>```

Most programming language have convenient functions for converting dates to a timestamp.

Body:
I have this query:

select * from tabel where last_purchase_categories = 'flight'
 and last_purchase_date between '2016-10-23 11:06:47' and '2016-10-23 11:06:49';

it is didnt work in sphinx. i use fulltext search using mysql query browser.
do anyone know how to using date format in sphinx ?

Body:
Well sphinx can't do string comparisons like that, at least with between (assuming you have the date in a string attribute). And there isnt a 'datetime' attribute type either.

Can put the date in simple numeric attribute, and do comparisons on that.

a Unix Timestamp might be convenient, can do it in the sphinx config file (using the mysql unix_timestamp() function)

sql_query = SELECT ..., UNIX_TIMESTAMP(last_purchase_date) AS last_purchase_date FROM ...
sql_attr_uint = last_purchase_date

Then query would be something like

select * from tabel where last_purchase_categories = 'flight'
 and last_purchase_date between 1477217207 and 1477217209;

Most programming language have convenient functions for converting dates to a timestamp.


问:
What is the preferred way to theme a composed component using styled-components?
Can anyone recommend the best way to compose styled-components that need to be themed?

Here's my code: https://gist.github.com/aaronmcadam/7bfd63a6bc4cfc36f9947a449c6f494a.

I have an Avatar component which composes an Image component, which is itself a styled-component.

If I use Avatar.styled.js with <ThemeProvider>, the theme can be successfully overridden.

If I use Avatar.withTheme.js, the theme can only be overridden if I use withTheme.

Which is the preferred way of doing things like these?

答:
from the official docs: https://github.com/styled-components/styled-components/blob/master/docs/theming.md

We export a  component that takes a theme prop. The
theme you provide there is injected into your styled components via
props.theme

If you ever need to get the current theme outside styled components
(e.g. inside big components), you can use the withTheme Higher Order
Component

```<code>import { withTheme } from 'styled-components'

class MyComponent extends React.Component {
  render() {
    const { theme } = this.props

    console.log('Current theme: ', theme);
    // ...
  }
}

export default withTheme(MyComponent)
</code>```

Body:
from the official docs: https://github.com/styled-components/styled-components/blob/master/docs/theming.md

We export a  component that takes a theme prop. The
theme you provide there is injected into your styled components via
props.theme

If you ever need to get the current theme outside styled components
(e.g. inside big components), you can use the withTheme Higher Order
Component

import { withTheme } from 'styled-components'

class MyComponent extends React.Component {
  render() {
    const { theme } = this.props

    console.log('Current theme: ', theme);
    // ...
  }
}

export default withTheme(MyComponent)


问:
Is there an Android equivalent to iOS´s (swifts) fatalError()?
If something happens in my app I want to kill the app there and then. In swift I can use fatalError(), is there a java equivalent?</p>

答:
I don't there's any method equivalent to fatalError in Android.

If you want to kill the entire process then you can use android.os.Process.killProcess(android.os.Process.myPid());.

To mimic the same behaviour of fatalError you'll probably have to implement it yourself.

The behaviour you'll need to add besides killing the process is

to log a message, you can to this by using Log

print the file and line number, for this you can follow this thread on SO


问:
How to close all opened drivers in Selenium?
I need to close all open Chrome drivers in Selenium. All my methods are closing only one of them. The reason why I need to close all drivers at the same time - in the start of my program I don't know how many drivers I need to open, so I try to open a few drivers with same driver names in cycle.

How I opened these drivers:

```<code>WebDriver driver = new ChromeDriver();
driver.get(firstURL);

driver = new ChromeDriver();
driver.get(secondURL);
</code>```

How I tried to close both drivers:

First try:

```<code>driver.close();
</code>```

Second try:

```<code>driver.quit();
</code>```

Third try:

```<code>driver.close();
driver.close();
</code>```

Fourth try:

```<code>driver.quit();
driver.quit();
</code>```

答:
How did you initialize your driver. Did you initialize more than one driver? If so, then use quit() method for all drivers separately. Otherwise, only driver.quit() should work.

Edit:

Use driver.quit() before each new assignment.

Body:
I need to close all open Chrome drivers in Selenium. All my methods are closing only one of them. The reason why I need to close all drivers at the same time - in the start of my program I don't know how many drivers I need to open, so I try to open a few drivers with same driver names in cycle.

How I opened these drivers:

WebDriver driver = new ChromeDriver();
driver.get(firstURL);

driver = new ChromeDriver();
driver.get(secondURL);

How I tried to close both drivers:

First try:

driver.close();

Second try:

driver.quit();

Third try:

driver.close();
driver.close();

Fourth try:

driver.quit();
driver.quit();


问:
psd to html 1920X1080
I have file .psd  with sizes 1920X1080.
I need to make responsive website that will look good for small and big screens.
I have made from this psd html with pixel perfect technic.
I just don't understand how to make from it design for smaller screens.
Please advise.</p>

答:
Using CCS3 media queries! Example for Desktop first:

```<code>// Your code for Desktop devices

@media only screen and (max-width: 768px) {
  // Here your code for mobile
}
</code>```

or for Mobile First

```<code>// Your code for Mobile devices

@media only screen and (min-width: 768px) {
  // Here your code for tablet
}

@media only screen and (min-width: 992px) {
  // Here your code for Small Desktop
}
</code>```

Different rules:

```<code>@media screen and (max-width: 992px) and (max-height: 700px) {
      // Code
}
</code>```

or:

```<code>@media screen and (max-width: 992px) and (min-height: 400px) {
      // Code
}
</code>```

These are only some example. You must study media queries.

Title: psd to html 1920X1080

Body:
Using CCS3 media queries! Example for Desktop first:

// Your code for Desktop devices

@media only screen and (max-width: 768px) {
  // Here your code for mobile
}

or for Mobile First

// Your code for Mobile devices

@media only screen and (min-width: 768px) {
  // Here your code for tablet
}

@media only screen and (min-width: 992px) {
  // Here your code for Small Desktop
}

Different rules:

@media screen and (max-width: 992px) and (max-height: 700px) {
      // Code
}

or:

@media screen and (max-width: 992px) and (min-height: 400px) {
      // Code
}

These are only some example. You must study media queries.


问:
UDT Type in Stored Procedure: Error - No mapping exists from object type System.Collections.Generic.List`1 to a known managed provider native type
I am passing user defined table type to a stored procedure. But it throws error as "No mapping exists from object type System.Collections.Generic.List`1 to a known managed provider native type."

```<code>UserDefinedTableType:
CREATE TYPE UserQueryAttachmentList AS TABLE
(
[UserQueryId] NVARCHAR(50),
[AttachmentPath] NVARCHAR(200),
[AttachmentName]  NVARCHAR(200),
[AttachmentFor] NVARCHAR(50),
[CreatedBy] NVARCHAR(50)
);

Stored Procedure:
CREATE PROCEDURE PROC_UserQueryAttachment_Insert
(
@Table UserQueryAttachmentList READONLY
)
AS
BEGIN

INSERT INTO dbo.[UserQueryAttachments]
(
    UserQueryId,
    AttachmentPath,
    AttachmentName,
    AttachmentFor,
    CreatedBy,
    CreatedDate
)
SELECT
    UserQueryId,
    AttachmentPath,
    AttachmentName,
    AttachmentFor,
    CreatedBy,
    GETDATE()
FROM
    @Table T

END

C#:
public override bool SaveUserQueryAttachment(List<UserQueryAttachmentToCreate> fileList)
    {

        try
        {
            this.ExecuteStoredProcedureOrQuery<UserQueryAttachmentToCreate>("PROC_UserQueryAttachment_Insert", CommandType.StoredProcedure,
                new SqlParameter("@Table", fileList)
                );
            return true;

        }
        catch (Exception ex)
        {
            return false;
        }
    }
</code>```

Please guide me why this error occuring?

答:
Lists of objects can't be passed to SQL Server directly. Try passing a DataTable like this (code unchecked):</p>

```<code>public override bool SaveUserQueryAttachment(List<UserQueryAttachmentToCreate> fileList)
{
    // TODO: open a SQL connection here

    using (SqlCommand cmd = new SqlCommand("exec PROC_UserQueryAttachment_Insert @table", connection))
    {
        using (var table = new DataTable())
        {
            table.Columns.Add("UserQueryId", typeof(string));
            table.Columns.Add("AttachmentPath", typeof(string));
            table.Columns.Add("AttachmentName", typeof(string));
            table.Columns.Add("AttachmentFor", typeof(string));
            table.Columns.Add("CreatedBy", typeof(string));

            table.Rows.Add(fileList.ToArray());

            var list = new SqlParameter("@table", SqlDbType.Structured);
            list.TypeName = "dbo.UserQueryAttachmentList";
            list.Value = table;

            cmd.Parameters.Add(list);
            cmd.ExecuteReader();
         }
    }

    // TODO: close the SQL connection
}
</code>```

Body:
I am passing user defined table type to a stored procedure. But it throws error as "No mapping exists from object type System.Collections.Generic.List`1 to a known managed provider native type."

UserDefinedTableType:
CREATE TYPE UserQueryAttachmentList AS TABLE
(
[UserQueryId] NVARCHAR(50),
[AttachmentPath] NVARCHAR(200),
[AttachmentName]  NVARCHAR(200),
[AttachmentFor] NVARCHAR(50),
[CreatedBy] NVARCHAR(50)
);

Stored Procedure:
CREATE PROCEDURE PROC_UserQueryAttachment_Insert
(
@Table UserQueryAttachmentList READONLY
)
AS
BEGIN

INSERT INTO dbo.[UserQueryAttachments]
(
    UserQueryId,
    AttachmentPath,
    AttachmentName,
    AttachmentFor,
    CreatedBy,
    CreatedDate
)
SELECT
    UserQueryId,
    AttachmentPath,
    AttachmentName,
    AttachmentFor,
    CreatedBy,
    GETDATE()
FROM
    @Table T

END

C#:
public override bool SaveUserQueryAttachment(List<UserQueryAttachmentToCreate> fileList)
    {

        try
        {
            this.ExecuteStoredProcedureOrQuery<UserQueryAttachmentToCreate>("PROC_UserQueryAttachment_Insert", CommandType.StoredProcedure,
                new SqlParameter("@Table", fileList)
                );
            return true;

        }
        catch (Exception ex)
        {
            return false;
        }
    }

Please guide me why this error occuring?

Body:
Lists of objects can't be passed to SQL Server directly. Try passing a DataTable like this (code unchecked):

public override bool SaveUserQueryAttachment(List<UserQueryAttachmentToCreate> fileList)
{
    // TODO: open a SQL connection here

    using (SqlCommand cmd = new SqlCommand("exec PROC_UserQueryAttachment_Insert @table", connection))
    {
        using (var table = new DataTable())
        {
            table.Columns.Add("UserQueryId", typeof(string));
            table.Columns.Add("AttachmentPath", typeof(string));
            table.Columns.Add("AttachmentName", typeof(string));
            table.Columns.Add("AttachmentFor", typeof(string));
            table.Columns.Add("CreatedBy", typeof(string));

            table.Rows.Add(fileList.ToArray());

            var list = new SqlParameter("@table", SqlDbType.Structured);
            list.TypeName = "dbo.UserQueryAttachmentList";
            list.Value = table;

            cmd.Parameters.Add(list);
            cmd.ExecuteReader();
         }
    }

    // TODO: close the SQL connection
}


问:
Algorithm - A variant of Maximum Bipartite Matching
I am dealing with a variant of the Maximum Bipartite Matching problem.
The original problem is as the following:

There are M job applicants and N jobs. Each applicant has a subset of jobs that he/she is interested in. Each job opening can only accept one applicant and a job applicant can be appointed for only one job. Find an assignment of jobs to applicants in such that as many applicants as possible get jobs.

The additional constraint is that:

Each applicant belongs to a certain group. Now, instead of maximize the number of applicants, we want to maximize of number of happy groups. A happy group is a group in which all of its applicants can get a job.

Any ideas/discussions are welcome!

答:
Connection to Eternity

If you could solve this, you could have won a million pounds on the Eternity puzzle.

In this puzzle you have to fit 209 polygons onto a board.

The reduction is to have one group for each combination of piece and location.

Each group has a leader who is only interested in the job that corresponds to playing his piece.

Each group also has a person for each square in the tile: that person is only interested in the job of filling the corresponding square on the game board.

If you can find a solution with 209 happy groups then you have found a solution to the puzzle!

Connection to Independendent set

This is NP-hard because it can be used to solve maximum independent set which is a known NP-hard problem.

Suppose we have a graph in which we want to find the maximum independent set.

Make a job for each edge.

Make a group for each vertex.

Suppose vertex x is connected to three edges a,b,c.  We would add 3 people to group x.  Each person is only interested in one job.  The first is interested in job a, the second in job b, the third in job c.

Finding the maximum happy groups is then equivalent to the largest independent set.


问:
Distinct() returns duplicates with a user-defined type
I'm trying to write a Linq query which returns an array of objects, with unique values in their constructors.  For integer types, Distinct returns only one copy of each value, but when I try creating my list of objects, things fall apart.  I suspect it's a problem with the equality operator for my class, but when I set a breakpoint, it's never hit.

Filtering out the duplicate int in a sub-expression solves the problem, and also saves me from constructing objects that will be immediately discarded, but I'm curious why this version doesn't work.

UPDATE: 11:04 PM  Several folks have pointed out that MyType doesn't override GetHashCode().  I'm afraid I oversimplified the example.  The original MyType does indeed implement it.  I've added it below, modified only to put the hash code in a temp variable before returning it.

Running through the debugger, I see that all five invocations of GetHashCode return a different value. And since MyType only inherits from Object, this is presumably the same behavior Object would exhibit.

Would I be correct then to conclude that the hash should instead be based on the contents of Value?  This was my first attempt at overriding operators, and at the time, it didn't appear that GetHashCode needed to be particularly fancy.  (This is the first time one of my equality checks didn't seem to work properly.)

```<code>class Program
{
    static void Main(string[] args)
    {
        int[] list = { 1, 3, 4, 4, 5 };
        int[] list2 =
            (from value in list
             select value).Distinct().ToArray();    // One copy of each value.
        MyType[] distinct =
            (from value in list
             select new MyType(value)).Distinct().ToArray(); // Two objects created with 4.

        Array.ForEach(distinct, value => Console.WriteLine(value));
    }
}

class MyType
{
    public int Value { get; private set; }

    public MyType(int arg)
    {
        Value = arg;
    }

    public override int GetHashCode()
    {
        int retval = base.GetHashCode();
        return retval;
    }

    public override bool Equals(object obj)
    {
        if (obj == null)
            return false;

        MyType rhs = obj as MyType;
        if ((Object)rhs == null)
            return false;

        return this == rhs;
    }

    public static bool operator ==(MyType lhs, MyType rhs)
    {
        bool result;

        if ((Object)lhs != null && (Object)rhs != null)
            result = lhs.Value == rhs.Value;
        else
            result = (Object)lhs == (Object)rhs;

        return result;
    }

    public static bool operator !=(MyType lhs, MyType rhs)
    {
        return !(lhs == rhs);
    }
}
</code>```

答:
In you equality method you are still testing for reference equality, rather than semantic equality, eg on this line:

```<code>result = (Object)lhs == (Object)rhs
</code>```

you are just comparing two object references which, even if they hold exactly the same data, are still not the same object.  Instead, your test for equality needs to compare one or more properties of your object.  For instance, if your object had an ID property, and objects with the same ID should be considered semantically equivalent, then you could do this:

```<code>result = lhs.ID == rhs.ID
</code>```

Note that overriding Equals() means you should also override GetHashCode(), which is another kettle of fish, and can be quite difficult to do correctly.

Body:
I'm trying to write a Linq query which returns an array of objects, with unique values in their constructors.  For integer types, Distinct returns only one copy of each value, but when I try creating my list of objects, things fall apart.  I suspect it's a problem with the equality operator for my class, but when I set a breakpoint, it's never hit.

Filtering out the duplicate int in a sub-expression solves the problem, and also saves me from constructing objects that will be immediately discarded, but I'm curious why this version doesn't work.

UPDATE: 11:04 PM  Several folks have pointed out that MyType doesn't override GetHashCode().  I'm afraid I oversimplified the example.  The original MyType does indeed implement it.  I've added it below, modified only to put the hash code in a temp variable before returning it.

Running through the debugger, I see that all five invocations of GetHashCode return a different value. And since MyType only inherits from Object, this is presumably the same behavior Object would exhibit.

Would I be correct then to conclude that the hash should instead be based on the contents of Value?  This was my first attempt at overriding operators, and at the time, it didn't appear that GetHashCode needed to be particularly fancy.  (This is the first time one of my equality checks didn't seem to work properly.)

class Program
{
    static void Main(string[] args)
    {
        int[] list = { 1, 3, 4, 4, 5 };
        int[] list2 =
            (from value in list
             select value).Distinct().ToArray();    // One copy of each value.
        MyType[] distinct =
            (from value in list
             select new MyType(value)).Distinct().ToArray(); // Two objects created with 4.

        Array.ForEach(distinct, value => Console.WriteLine(value));
    }
}

class MyType
{
    public int Value { get; private set; }

    public MyType(int arg)
    {
        Value = arg;
    }

    public override int GetHashCode()
    {
        int retval = base.GetHashCode();
        return retval;
    }

    public override bool Equals(object obj)
    {
        if (obj == null)
            return false;

        MyType rhs = obj as MyType;
        if ((Object)rhs == null)
            return false;

        return this == rhs;
    }

    public static bool operator ==(MyType lhs, MyType rhs)
    {
        bool result;

        if ((Object)lhs != null && (Object)rhs != null)
            result = lhs.Value == rhs.Value;
        else
            result = (Object)lhs == (Object)rhs;

        return result;
    }

    public static bool operator !=(MyType lhs, MyType rhs)
    {
        return !(lhs == rhs);
    }
}

Body:
In you equality method you are still testing for reference equality, rather than semantic equality, eg on this line:

result = (Object)lhs == (Object)rhs

you are just comparing two object references which, even if they hold exactly the same data, are still not the same object.  Instead, your test for equality needs to compare one or more properties of your object.  For instance, if your object had an ID property, and objects with the same ID should be considered semantically equivalent, then you could do this:

result = lhs.ID == rhs.ID

Note that overriding Equals() means you should also override GetHashCode(), which is another kettle of fish, and can be quite difficult to do correctly.


问:
TSQL find number of correspondences
I have the following table:

```<code>SenderName  ReceiverName    NumberOfTime
Ajay          Vijay             1
Anthony       Mark              3
Anthony       John              5
David         Mark              2
David         John              5
David         John              3
David         John              1
John          David             2
John          David             2
John          Anthony           5
Mark          Anthony           1
</code>```

Test Data:

```<code>CREATE TABLE [dbo].[tblMyTempTable](
[SenderName] [varchar](20) NULL,
[ReceiverName] [varchar](10) NULL,
[NumberOfTime] [int] NULL
) ON [PRIMARY]
GO

INSERT [dbo].[tblMyTempTable]
  ([SenderName], [ReceiverName], [NumberOfTime])
VALUES
  (N'David', N'John', 1)
  ,(N'Mark', N'Anthony', 1)
  ,(N'Ajay', N'Vijay', 1)
  ,(N'John', N'David', 2)
  ,(N'Anthony', N'Mark', 3)
  ,(N'David', N'John', 5)
  ,(N'David', N'John', 3)
  ,(N'John', N'David', 2)
  ,(N'David', N'Mark', 2)
  ,(N'John', N'Anthony', 5)
  ,(N'Anthony', N'John', 5)
</code>```

I need to find out how many times correspondence has been between each pair. For example, Anthony has contacted John 5 times, John has contacted Anthony 5 times. So total correspondence between John and Anthony has been 10 times.

Similarly, David has contacted John total of 9 times, John has contacted David 4 times. So total will be 13. I have tried many things including swapping columns using substring, repalce etc. I was wondering if anyone had interesting way to achieve the wanted results. Thanks in advance.

答:
You can use a query like the following:

```<code>;WITH CTE AS (
   SELECT IIF(SenderName < ReceiverName, SenderName, ReceiverName) AS first_name,
          IIF(SenderName >= ReceiverName, SenderName, ReceiverName) AS second_name,
          NumberOfTime
   FROM tblMyTempTable
)
SELECT first_name, second_name, SUM(NumberOfTime) AS total_times
FROM CTE
GROUP BY first_name, second_name
</code>```

The query uses a CTE that contains a version of the table where SenderName and ReceiverName are selected in an alphabetically sorted order.

Demo here

Title: TSQL find number of correspondences

Body:
I have the following table:

SenderName  ReceiverName    NumberOfTime
Ajay          Vijay             1
Anthony       Mark              3
Anthony       John              5
David         Mark              2
David         John              5
David         John              3
David         John              1
John          David             2
John          David             2
John          Anthony           5
Mark          Anthony           1

Test Data:

CREATE TABLE [dbo].[tblMyTempTable](
[SenderName] [varchar](20) NULL,
[ReceiverName] [varchar](10) NULL,
[NumberOfTime] [int] NULL
) ON [PRIMARY]
GO

INSERT [dbo].[tblMyTempTable]
  ([SenderName], [ReceiverName], [NumberOfTime])
VALUES
  (N'David', N'John', 1)
  ,(N'Mark', N'Anthony', 1)
  ,(N'Ajay', N'Vijay', 1)
  ,(N'John', N'David', 2)
  ,(N'Anthony', N'Mark', 3)
  ,(N'David', N'John', 5)
  ,(N'David', N'John', 3)
  ,(N'John', N'David', 2)
  ,(N'David', N'Mark', 2)
  ,(N'John', N'Anthony', 5)
  ,(N'Anthony', N'John', 5)

I need to find out how many times correspondence has been between each pair. For example, Anthony has contacted John 5 times, John has contacted Anthony 5 times. So total correspondence between John and Anthony has been 10 times.

Similarly, David has contacted John total of 9 times, John has contacted David 4 times. So total will be 13. I have tried many things including swapping columns using substring, repalce etc. I was wondering if anyone had interesting way to achieve the wanted results. Thanks in advance.

Body:
You can use a query like the following:

;WITH CTE AS (
   SELECT IIF(SenderName < ReceiverName, SenderName, ReceiverName) AS first_name,
          IIF(SenderName >= ReceiverName, SenderName, ReceiverName) AS second_name,
          NumberOfTime
   FROM tblMyTempTable
)
SELECT first_name, second_name, SUM(NumberOfTime) AS total_times
FROM CTE
GROUP BY first_name, second_name

The query uses a CTE that contains a version of the table where SenderName and ReceiverName are selected in an alphabetically sorted order.

Demo here


问:
keyboard search button enter
i have a employees form that contain button i i start my project when i want to search i have to click by mouse arrow on search can i choose another option by clicking enter button for search for more details for my project i'm using visual studio 2017 c# forms if any detail is missing please just notice

答: You can use this thread and use any keyboard shortcut including "return button"</p>

Title: keyboard search button enter


问:
How to fade part of an image
I have a kind of simple donut chart gradually colored. I want this donut be faded depending on a value. For example if the value is 35 then 35 % of my donut would be not faded and 65 % would be faded. I don't want any animation.

This is an example of what I want to achieve :

The code for the donut without the masking feature :

```<code><ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/donut"
        android:layout_alignTop="@+id/imageView"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"/>
</code>```

答:
You could also use some masking in combination with a semi-transparent image using the following steps.

create a black/white donut up to e.g. 35 %,

mask your semi-transperant with this donut (e.g. make all black parts fully transparent)

use this masked image as overlay for your full coloured donut.

This will leave you with a partly faded donut following the same contours as the original.

I am sorry I don't have any masking-code at hand, but these steps would accomplish the desired result.

Title: How to fade part of an image

Body:
I have a kind of simple donut chart gradually colored. I want this donut be faded depending on a value. For example if the value is 35 then 35 % of my donut would be not faded and 65 % would be faded. I don't want any animation.

This is an example of what I want to achieve :

The code for the donut without the masking feature :

<ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/donut"
        android:layout_alignTop="@+id/imageView"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"/>


问:
Convert CSV to RDD and read with Spark/Scala
I tried to read a file (csv) and print its schema. My problem is that my file has not header to query like SQL.
I tried with this code:

```<code>val logFile = "../resouces/cells.csv"

val dfCells = spark.read
 .format("csv")
 .option("header", "false")
 .option("mode", "DROPMALFORMED")
 .option("delimiter", "|")
 .csv(logFile)

dfCell.printSchema;
</code>```

The file input is:

```<code>ES|15032017|25100|54600||3G|FIBRE|OUTDOOR|COMPANY|MAST|MACRO||47001|DU|41.651834|-4.728534||||||||||||||||
ES|15032017|25101|54601||3G|FIBRE|OUTDOOR|COMPANY|ROOFTOP|MACRO||47001|DU|41.651994|-4.724693||||||||||||||||
ES|15032017|25102|54602||4G|FIBRE|OUTDOOR|COMPANY|ROOFTOP|MICRO||47001|U|41.650912|-4.720648||||||||||||||||
ES|15032017|25103|54603||3G|MICROWAVES|OUTDOOR|COMPANY|ROOFTOP|MACRO||47001|U|41.647312|-4.717118||||||||||||||||
</code>```

The output is:

```<code>|
|
|
</code>```

答: Looks like you have a typo. Use dfCells.printSchema.

Body:
I tried to read a file (csv) and print its schema. My problem is that my file has not header to query like SQL.
I tried with this code:

val logFile = "../resouces/cells.csv"

val dfCells = spark.read
 .format("csv")
 .option("header", "false")
 .option("mode", "DROPMALFORMED")
 .option("delimiter", "|")
 .csv(logFile)

dfCell.printSchema;

The file input is:

ES|15032017|25100|54600||3G|FIBRE|OUTDOOR|COMPANY|MAST|MACRO||47001|DU|41.651834|-4.728534||||||||||||||||
ES|15032017|25101|54601||3G|FIBRE|OUTDOOR|COMPANY|ROOFTOP|MACRO||47001|DU|41.651994|-4.724693||||||||||||||||
ES|15032017|25102|54602||4G|FIBRE|OUTDOOR|COMPANY|ROOFTOP|MICRO||47001|U|41.650912|-4.720648||||||||||||||||
ES|15032017|25103|54603||3G|MICROWAVES|OUTDOOR|COMPANY|ROOFTOP|MACRO||47001|U|41.647312|-4.717118||||||||||||||||

The output is:

|
|
|


问:
Show half of next slide without Center Mode in Slick Slider
What I want is to have a slider that shows 3.5 slides at once, with the right most slide being the one that is only half shown. I have seen something like this done successfully using centerMode and centerPadding with slick slider, but I do not want the slides to be centered. In other words, I want the left most slide to be flush with the side of the window, totally in view, but the right most slide to be half in the window, half off. Is this possible in slick? I've seen people using slidesToShow: 3.5, but this makes the left most slide go half off the screen and I need it on the right.</p>

答:
No need to add "slidesToShow: 3.5 option"

Just call slick:-

```<code>$('.Your-container').slick({
    arrows: false,
});
</code>```

and add following CSS:

```<code>.slick-list{padding:0 20% 0 0 !important;}
</code>```

Either you can give a fixed padding to the right or percentage.

Body:
No need to add "slidesToShow: 3.5 option"

Just call slick:-

$('.Your-container').slick({
    arrows: false,
});

and add following CSS:

.slick-list{padding:0 20% 0 0 !important;}

Either you can give a fixed padding to the right or percentage.


问:
F# remove duplicates from a string [] list
I have a program that results in an [] list, and I'm trying to remove near duplicated arrays from the list. An example of the list is...

```<code>[
   [|
      "Jackson";
      "Stentzke";
      "22";
      "001"
    |];
    [|
      "Jackson";
      "Stentzke";
      "22";
      "002"
    |];
    [|
      "Alec";
      "Stentzke";
      "18";
      "003"
    |]
]
</code>```

Basically I'm trying to write a function that would read over the list and remove all examples of near identical data. So the final returned [] list should look like...

```<code>[
    [|
      "Alec";
      "Stentzke";
      "18";
      "003"
    |]
]
</code>```

I've tried a number of functions to try and get this result or something close to it that can work with. My current attempt is this...

```<code>let removeDuplicates (arrayList: string[]list) =
    let list = arrayList|> List.map(fun aL ->
        let a = arrayList|> List.map(fun aL2 ->
                try
                    match (aL.GetValue(0).Equals(aL2.GetValue(0))) && (aL.GetValue(2).Equals(aL2.GetValue(2))) && (aL.GetValue(3).Equals(aL2.GetValue(3))) with
                    | false -> aL2
                    | _ -> [|""|]
                with
                | ex -> [|""|]
            )
        a
                                              )
    list |> List.concat |> List.distinct
</code>```

But all this returns is the a reversed version on the input []list.

Does anyone know how to remove near duplicated arrays from a list?

答:
You should create a dictionary/map based on the fields you consider identical then just remove any duplicate occurance. Here's a simply and mechanical way, assuming xs is the List you specified above:

```<code>type DataRec = { key:string
                 fname:string
                 lname:string
                 id1:string
                 id2:string}

let dataRecs = xs |> List.map (fun x -> {key=x.[0]+x.[1]+x.[2];fname=x.[0];lname=x.[1];id1=x.[2];id2=x.[3]})

dataRecs |> Seq.groupBy (fun x -> x.key)
         |> Seq.filter (fun x -> Seq.length (snd x) = 1)
         |> Seq.collect snd
         |> Seq.map (fun x -> [|x.fname;x.lname;x.id1;x.id2|])
         |> Seq.toList
</code>```

Output:

val it : string [] list = [[|"Alec"; "Stentzke"; "18"; "003"|]]

It basically creates a key from the first three items, groups by it, filters out anything over 2 counst, and then maps back to an array.

Body:
I have a program that results in an [] list, and I'm trying to remove near duplicated arrays from the list. An example of the list is...

[
   [|
      "Jackson";
      "Stentzke";
      "22";
      "001"
    |];
    [|
      "Jackson";
      "Stentzke";
      "22";
      "002"
    |];
    [|
      "Alec";
      "Stentzke";
      "18";
      "003"
    |]
]

Basically I'm trying to write a function that would read over the list and remove all examples of near identical data. So the final returned [] list should look like...

[
    [|
      "Alec";
      "Stentzke";
      "18";
      "003"
    |]
]

I've tried a number of functions to try and get this result or something close to it that can work with. My current attempt is this...

let removeDuplicates (arrayList: string[]list) =
    let list = arrayList|> List.map(fun aL ->
        let a = arrayList|> List.map(fun aL2 ->
                try
                    match (aL.GetValue(0).Equals(aL2.GetValue(0))) && (aL.GetValue(2).Equals(aL2.GetValue(2))) && (aL.GetValue(3).Equals(aL2.GetValue(3))) with
                    | false -> aL2
                    | _ -> [|""|]
                with
                | ex -> [|""|]
            )
        a
                                              )
    list |> List.concat |> List.distinct

But all this returns is the a reversed version on the input []list.

Does anyone know how to remove near duplicated arrays from a list?

Body:
You should create a dictionary/map based on the fields you consider identical then just remove any duplicate occurance. Here's a simply and mechanical way, assuming xs is the List you specified above:

type DataRec = { key:string
                 fname:string
                 lname:string
                 id1:string
                 id2:string}

let dataRecs = xs |> List.map (fun x -> {key=x.[0]+x.[1]+x.[2];fname=x.[0];lname=x.[1];id1=x.[2];id2=x.[3]})

dataRecs |> Seq.groupBy (fun x -> x.key)
         |> Seq.filter (fun x -> Seq.length (snd x) = 1)
         |> Seq.collect snd
         |> Seq.map (fun x -> [|x.fname;x.lname;x.id1;x.id2|])
         |> Seq.toList

Output:

val it : string [] list = [[|"Alec"; "Stentzke"; "18"; "003"|]]

It basically creates a key from the first three items, groups by it, filters out anything over 2 counst, and then maps back to an array.


问:
Not able to display image from database on webpage
I am not able to display my full image on my webpage from database
my codemy image is goint to database

```<code>$con=  mysqli_connect("localhost", "root", "", "project");

        if(!$con)
       {
           die('not connected');
       }
            $result=  mysqli_query($con, "SELECT addplace, stayamount, foodamount, airlinesamount, noofdays,noofnights,
    SUM(stayamount + foodamount + airlinesamount) AS totalamount,choose
FROM adddetails GROUP BY packageid");

?>
<div class="container">
<CENTER><h2>view packages</h2>
</CENTER>
<table class="table table-bordered">

  <th>place</th>
  <th>stay cost</th>
  <th>food cost</th>
  <th>flight cost</th>
  <th>no of days</th>
  <th>no of nights</th>
  <th>total amount</th>
  <th>image</th>

        <?php

             while($row =mysqli_fetch_array($result))

             {
                 ?>
            <tr>
                <td><?php echo $row['addplace']; ?></td>
                <td><?php echo $row['stayamount']; ?></td>
                <td><?php echo $row['foodamount'] ;?></td>
                <td><?php echo $row['airlinesamount'] ;?></td>
                <td><?php echo $row['noofdays'] ;?></td>
                <td><?php echo $row['noofnights'] ;?></td>
                <td><?php echo $row['totalamount'] ;?></td>
              <td><?php echo '<img src=data:image/jpeg;base64,'.base64_encode( $row['choose'] ).'>'; ?></td>
            </tr>
        <?php
             }
             ?>
             </table>
            </div>
  </div>
</code>```

please rewrite my code and i want my image of 150*150 size to be fitted on my web page in my table

答:
try using this.</p>

```<code><td><img src='".$row['choose']."'/></td>";
</code>```

Body:
I am not able to display my full image on my webpage from database
my codemy image is goint to database

$con=  mysqli_connect("localhost", "root", "", "project");

        if(!$con)
       {
           die('not connected');
       }
            $result=  mysqli_query($con, "SELECT addplace, stayamount, foodamount, airlinesamount, noofdays,noofnights,
    SUM(stayamount + foodamount + airlinesamount) AS totalamount,choose
FROM adddetails GROUP BY packageid");

?>

view packages

  place
  stay cost
  food cost
  flight cost
  no of days
  no of nights
  total amount
  image

        <?php

             while($row =mysqli_fetch_array($result))

             {
                 ?>

                <?php echo $row['addplace']; ?>
                <?php echo $row['stayamount']; ?>
                <?php echo $row['foodamount'] ;?>
                <?php echo $row['airlinesamount'] ;?>
                <?php echo $row['noofdays'] ;?>
                <?php echo $row['noofnights'] ;?>
                <?php echo $row['totalamount'] ;?>
              <?php echo ''; ?>

        <?php
             }
             ?>

please rewrite my code and i want my image of 150*150 size to be fitted on my web page in my table

Body:
try using this.

<td><img src='".$row['choose']."'/></td>";


问:
Updating table with business day and calendar day
I have a table in SQL Server 2012 that is updated manually every month to reflect what date is a file expected to come in.  The date rule already has values but the expected date column is what is updated manually.  If its expected on BD1(Business Day 1) I will update to the first non-weekend day of the month.  If its expected on CD1(Calenday Day 1) I will update to the 1st regardless if it falls on a weekday or a weekend and so forth.  Is it possible to write an update query where it would loop through the values and update automatically?  I'm having trouble figuring out to update to the correct business day.

```
date rule  | March expected date | April expected date |
--------------------------------------------------------
| BD1      | 3/1/2017            | 4/3/2017            |
| BD2      | 3/2/2017            |                     |
| BD3      | 3/3/2017            |                     |
| BD4      | 3/6/2017            |                     |
| BD5      |                     |                     |
| BD6      |                     |                     |
| CD1      | 3/1/2017            |                     |
| CD2      | 3/2/2017            |                     |
| CD3      | 3/3/2017            |                     |
| CD4      | 3/4/2017            |                     |
| CD5      | 3/5/2017            |                     |
| CD6      | 3/6/2017            |                     |

```

I was using the following code to calculate the first business day

```<code>SELECT DATEADD(DAY,
CASE
    (DATEPART(WEEKDAY, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)) + @@DATEFIRST - 1) % 7
    WHEN 6 THEN 2
    WHEN 7 THEN 1
    ELSE 0
END,
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
</code>```

)

but then when it would come to business day 4, it would give me 3/4/2017 which is a saturday instead of 3/6/2017 which is the following monday.  i'm getting stumped in how to tackle this.  I'm thinking a loop update query would be best

答:
IMHO , your table structure is wrong in two way,
i) daterule column should be split in 2 columns like in my CTE.Then calculation will be far easier.

ii) Secondly you don't keep your column in such pivoted manner.this it will keep on increasing.So hope your handling your requirement in correct way.

Keeping your current structure in mind,

```<code>declare @t table(daterule varchar(20),Marchexpected date , Aprilexpected date )
insert into @t VALUES
('BD1','3/1/2017', '4/3/2017')
,('BD2','3/2/2017',  null       )
,('BD3','3/3/2017',    null  )
,('BD4','3/4/2017',    null  )
,('BD5',  null      ,  null  )
,('BD6',  null      ,  null  )
,('CD1','3/1/2017',    null  )
,('CD2','3/2/2017',    null  )
,('CD3','3/3/2017',    null  )
,('CD4','3/4/2017',    null  )
,('CD5','3/5/2017',    null  )
,('CD6','3/6/2017',    null  )
declare @AprilDate date='2017-04-01'
;With CTE as
(
SELECT *
,case when daterule like 'BD%' then 'BD' else 'CD' end ruletype
,cast(replace(replace(daterule,'BD',  '' ),'CD','') as int) ruletypeid
 from @t
)
select daterule,Marchexpected
,case when datename(dw, dateadd(day,(ruletypeid-1),@AprilDate))='Saturday'
then dateadd(day,(ruletypeid+1),@AprilDate)
when datename(dw, dateadd(day,(ruletypeid-1),@AprilDate))='Sunday'
then dateadd(day,(ruletypeid),@AprilDate)
else
dateadd(day,(ruletypeid-1),@AprilDate)
END
Aprilexpected
from cte
where   ruletype='BD'

union ALL

select daterule,Marchexpected
,dateadd(day,(ruletypeid-1),@AprilDate)
from cte
where   ruletype='CD'
</code>```

Body:
I have a table in SQL Server 2012 that is updated manually every month to reflect what date is a file expected to come in.  The date rule already has values but the expected date column is what is updated manually.  If its expected on BD1(Business Day 1) I will update to the first non-weekend day of the month.  If its expected on CD1(Calenday Day 1) I will update to the 1st regardless if it falls on a weekday or a weekend and so forth.  Is it possible to write an update query where it would loop through the values and update automatically?  I'm having trouble figuring out to update to the correct business day.

date rule  | March expected date | April expected date |
--------------------------------------------------------
| BD1      | 3/1/2017            | 4/3/2017            |
| BD2      | 3/2/2017            |                     |
| BD3      | 3/3/2017            |                     |
| BD4      | 3/6/2017            |                     |
| BD5      |                     |                     |
| BD6      |                     |                     |
| CD1      | 3/1/2017            |                     |
| CD2      | 3/2/2017            |                     |
| CD3      | 3/3/2017            |                     |
| CD4      | 3/4/2017            |                     |
| CD5      | 3/5/2017            |                     |
| CD6      | 3/6/2017            |                     |

I was using the following code to calculate the first business day

SELECT DATEADD(DAY,
CASE
    (DATEPART(WEEKDAY, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)) + @@DATEFIRST - 1) % 7
    WHEN 6 THEN 2
    WHEN 7 THEN 1
    ELSE 0
END,
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)

)

but then when it would come to business day 4, it would give me 3/4/2017 which is a saturday instead of 3/6/2017 which is the following monday.  i'm getting stumped in how to tackle this.  I'm thinking a loop update query would be best

Body:
IMHO , your table structure is wrong in two way,
i) daterule column should be split in 2 columns like in my CTE.Then calculation will be far easier.

ii) Secondly you don't keep your column in such pivoted manner.this it will keep on increasing.So hope your handling your requirement in correct way.

Keeping your current structure in mind,

declare @t table(daterule varchar(20),Marchexpected date , Aprilexpected date )
insert into @t VALUES
('BD1','3/1/2017', '4/3/2017')
,('BD2','3/2/2017',  null       )
,('BD3','3/3/2017',    null  )
,('BD4','3/4/2017',    null  )
,('BD5',  null      ,  null  )
,('BD6',  null      ,  null  )
,('CD1','3/1/2017',    null  )
,('CD2','3/2/2017',    null  )
,('CD3','3/3/2017',    null  )
,('CD4','3/4/2017',    null  )
,('CD5','3/5/2017',    null  )
,('CD6','3/6/2017',    null  )
declare @AprilDate date='2017-04-01'
;With CTE as
(
SELECT *
,case when daterule like 'BD%' then 'BD' else 'CD' end ruletype
,cast(replace(replace(daterule,'BD',  '' ),'CD','') as int) ruletypeid
 from @t
)
select daterule,Marchexpected
,case when datename(dw, dateadd(day,(ruletypeid-1),@AprilDate))='Saturday'
then dateadd(day,(ruletypeid+1),@AprilDate)
when datename(dw, dateadd(day,(ruletypeid-1),@AprilDate))='Sunday'
then dateadd(day,(ruletypeid),@AprilDate)
else
dateadd(day,(ruletypeid-1),@AprilDate)
END
Aprilexpected
from cte
where   ruletype='BD'

union ALL

select daterule,Marchexpected
,dateadd(day,(ruletypeid-1),@AprilDate)
from cte
where   ruletype='CD'


问:
How to save a jsoup document as text file
I am trying to save all of the readable words on a web page into one text document while ignoring html markup.
Using JSoup to parse all of the words on a webpage, my only guess of how to seperate the real words from the code is through elements.

Is it possible to convert multiple elements of the jsoup document into a text file?

i.e.:

```<code>        Elements titles = doc.select("title");
        Elements paragraphs = doc.select("p");
        Elements links = doc.select("a[href]");
        Elements smallText = doc.select("a");
</code>```

Currently saving the parse as a document with:

```<code> Document doc = Jsoup.connect("https:// (enter a url)").get();
</code>```

答:
Adding answer because I am unable to comment above.

Replace writer.write(doc.toString()); by  writer.write(doc.select("html").text()); in the above code.

It will give you the text on the page.

Instead of "html" in doc.select("**html**").text() other tags can be used to extract text enclosed in those tags.

Edit: you can also use writer.write(doc.body().text());

Body:
I am trying to save all of the readable words on a web page into one text document while ignoring html markup.
Using JSoup to parse all of the words on a webpage, my only guess of how to seperate the real words from the code is through elements.

Is it possible to convert multiple elements of the jsoup document into a text file?

i.e.:

        Elements titles = doc.select("title");
        Elements paragraphs = doc.select("p");
        Elements links = doc.select("a[href]");
        Elements smallText = doc.select("a");

Currently saving the parse as a document with:

 Document doc = Jsoup.connect("https:// (enter a url)").get();


问:
Remove iOS app when the status is waiting for review
I submitted an updated iOS app. I want to submit another build instead of that.

I removed the binary from review and i deleted the build. No way to upload the same version build again at the time of validation its showing same build already exists.I want to replace this update with another build.

答: Once you have submitted an app for review, you have an option to remove the app which is being reviewed. Just navigate to "App Store" in iTunesConnect you can see the message and link to remove your app. You can change the build number and upload a new build to AppStore again using Xcode or Application loader.</p>


答: driver.quit() will close all (parent+child) browser windows and end the whole session. This should work fine.</p>

Title: How to close all opened drivers in Selenium?

Body:
I need to close all open Chrome drivers in Selenium. All my methods are closing only one of them. The reason why I need to close all drivers at the same time - in the start of my program I don't know how many drivers I need to open, so I try to open a few drivers with same driver names in cycle.

How I opened these drivers:

WebDriver driver = new ChromeDriver();
driver.get(firstURL);

driver = new ChromeDriver();
driver.get(secondURL);

How I tried to close both drivers:

First try:

driver.close();

Second try:

driver.quit();

Third try:

driver.close();
driver.close();

Fourth try:

driver.quit();
driver.quit();