问:
MariaDB Connector/c++ throwing exception
I am trying to connect to my MariaDB instance using the MariaDB Connector/c++. Here is the code where I tried to use the already compiled version of the connector:

```<code>    #include <iostream>
    #include <mariadb/conncpp.hpp>

    int main()
    {
            std::cout << "Hello World!\n";

    try
    {
        // Instantiate Driver
        sql::Driver* driver = sql::mariadb::get_driver_instance();

    // Configure Connection
    sql::SQLString url("jdbc:mariadb://X.X.X.X:3306/myMariaDB");

    sql::Properties properties({
        {"user", "root"},
        {"password", "myPassword"},
        {"useTls", "true"},
        {"tlsCA", "myFile.pem"}
        });

    // Establish Connection
    std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));

    std::cout << "I connected successfully!";

    conn->close();
}
catch (sql::SQLException& e)
{
    std::cerr << "Error Connecting to MariaDB Platform: "
        << e.what() << std::endl;

    // Exit (Failed)
    return 1;
    }

    return 0;
}
</code>```

Running the code throws exception at the //Establish Connection line:

Exception thrown: read access violation.
other.theString._Mypair._Myval2 was 0xFFFFFFFFFFFFFFEF.

Searching the internet people suggested to recompile the connector source which I got from Github https://github.com/mariadb-corporation/mariadb-connector-cpp#readme

I tried to compile the source using VS 2019 and CMake. I have to say that this is my first encounter with CMake and I know very little about it. It seems that both are failing to build the cloned repo. below is the error I get form VS 2019 which is very similar to what I get from CMake. I also get an error in the "Error List" tab in VS 2019 : CMAke Error at libmariadb/cmake/version_info.cmake:15 (STRING):...:

```<code>1> CMake generation started for default configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"
1> Working directory: C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\build\x64-Debug
1> [CMake] -- The CXX compiler identification is MSVC 19.29.30133.0
1> [CMake] -- The C compiler identification is MSVC 19.29.30133.0
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- CMAKE_CXX_FLAGS_DEBUG= /MTd /Zi /Ob0 /Od /RTC1
1> [CMake] -- CMAKE_C_FLAGS_DEBUG= /MTd /Zi /Ob0 /Od /RTC1
1> [CMake] -- CMAKE_CXX_FLAGS_RELEASE= /MT /O2 /Ob2 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_RELEASE= /MT /O2 /Ob2 /DNDEBUG
1> [CMake] -- CMAKE_CXX_FLAGS_RELWITHDEBINFO= /MT /Zi /O2 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_RELWITHDEBINFO= /MT /Zi /O2 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_CXX_FLAGS_MINSIZEREL= /MT /O1 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_MINSIZEREL= /MT /O1 /Ob1 /DNDEBUG
1> [CMake] -- MariaDB Connector ODBC: INSTALL_BINDIR=
1> [CMake] -- MariaDB Connector ODBC: INSTALL_LIBDIR=/mariadb
1> [CMake] -- MariaDB Connector ODBC: INSTALL_PCDIR=/pkgconfig
1> [CMake] -- MariaDB Connector ODBC: INSTALL_INCLUDEDIR=include/mariadb
1> [CMake] -- MariaDB Connector ODBC: INSTALL_DOCDIR=share/doc/mariadbcpp
1> [CMake] -- MariaDB Connector ODBC: INSTALL_LICENSEDIR=share/doc/mariadbcpp
1> [CMake] -- MariaDB Connector ODBC: INSTALL_PLUGINDIR=plugin
1> [CMake] -- Generate MSI package: ON
1> [CMake] -- Sign MSI package: OFF
1> [CMake] -- Setting deafault value for WITH_SSL for libmariadb build to ON
1> [CMake] -- Running C/C cmake scripts
1> [CMake] -- Found Git: C:/Windows/System32/git
1> [CMake] == Configuring MariaDB Connector/C
1> [CMake] CMake Warning (dev) at libmariadb/CMakeLists.txt:19 (PROJECT):
1> [CMake]   Policy CMP0048 is not set: project() command manages VERSION variables.
1> [CMake]   Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
1> [CMake]   command to set the policy and suppress this warning.
1> [CMake]
1> [CMake]   The following variable(s) would be set to empty:
1> [CMake]
1> [CMake]     PROJECT_VERSION
1> [CMake]     PROJECT_VERSION_MAJOR
1> [CMake]     PROJECT_VERSION_MINOR
1> [CMake]     PROJECT_VERSION_PATCH
1> [CMake] This warning is for project developers.  Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
1> [CMake] -- MariaDB Connector C: INSTALL_BINDIR=bin
1> [CMake] -- MariaDB Connector C: INSTALL_LIBDIR=/mariadb
1> [CMake] -- MariaDB Connector C: INSTALL_PCDIR=/pkgconfig
1> [CMake] -- MariaDB Connector C: INSTALL_INCLUDEDIR=include/mariadb
1> [CMake] -- MariaDB Connector C: INSTALL_DOCSDIR=
1> [CMake] -- MariaDB Connector C: INSTALL_PLUGINDIR=plugin
1> [CMake] -- MariaDB Connector C: LIBMARIADB_STATIC_NAME mariadbclient
1> [CMake] -- Looking for include file alloca.h
1> [CMake] -- Looking for include file alloca.h - not found
1> [CMake] -- Looking for include file arpa/inet.h
1> [CMake] -- Looking for include file arpa/inet.h - not found
1> [CMake] -- Looking for include file dlfcn.h
1> [CMake] -- Looking for include file dlfcn.h - not found
1> [CMake] -- Looking for include file fcntl.h
1> [CMake] -- Looking for include file fcntl.h - found
1> [CMake] -- Looking for include file float.h
1> [CMake] -- Looking for include file float.h - found
1> [CMake] -- Looking for include file limits.h
1> [CMake] -- Looking for include file limits.h - found
1> [CMake] -- Looking for include file linux/limits.h
1> [CMake] -- Looking for include file linux/limits.h - not found
1> [CMake] -- Looking for include file pwd.h
1> [CMake] -- Looking for include file pwd.h - not found
1> [CMake] -- Looking for include file sched.h
1> [CMake] -- Looking for include file sched.h - not found
1> [CMake] -- Looking for include file select.h
1> [CMake] -- Looking for include file select.h - not found
1> [CMake] -- Looking for include file signal.h
1> [CMake] -- Looking for include file signal.h - found
1> [CMake] -- Looking for include file stddef.h
1> [CMake] -- Looking for include file stddef.h - found
1> [CMake] -- Looking for include file stdint.h
1> [CMake] -- Looking for include file stdint.h - found
1> [CMake] -- Looking for include file stdlib.h
1> [CMake] -- Looking for include file stdlib.h - found
1> [CMake] -- Looking for include file string.h
1> [CMake] -- Looking for include file string.h - found
1> [CMake] -- Looking for include file strings.h
1> [CMake] -- Looking for include file strings.h - not found
1> [CMake] -- Looking for include file sys/ioctl.h
1> [CMake] -- Looking for include file sys/ioctl.h - not found
1> [CMake] -- Looking for include file sys/select.h
1> [CMake] -- Looking for include file sys/select.h - not found
1> [CMake] -- Looking for include file sys/socket.h
1> [CMake] -- Looking for include file sys/socket.h - not found
1> [CMake] -- Looking for include file sys/types.h
1> [CMake] -- Looking for include file sys/types.h - found
1> [CMake] -- Looking for include file sys/stat.h
1> [CMake] -- Looking for include file sys/stat.h - found
1> [CMake] -- Looking for include file sys/un.h
1> [CMake] -- Looking for include file sys/un.h - not found
1> [CMake] -- Looking for include file unistd.h
1> [CMake] -- Looking for include file unistd.h - not found
1> [CMake] -- Looking for include file utime.h
1> [CMake] -- Looking for include file utime.h - not found
1> [CMake] -- Looking for include file ucontext.h
1> [CMake] -- Looking for include file ucontext.h - not found
1> [CMake] -- Looking for alloca
1> [CMake] -- Looking for alloca - not found
1> [CMake] -- Looking for dlerror
1> [CMake] -- Looking for dlerror - not found
1> [CMake] -- Looking for dlopen
1> [CMake] -- Looking for dlopen - not found
1> [CMake] -- Looking for fcntl
1> [CMake] -- Looking for fcntl - not found
1> [CMake] -- Looking for memcpy
1> [CMake] -- Looking for memcpy - found
1> [CMake] -- Looking for nl_langinfo
1> [CMake] -- Looking for nl_langinfo - not found
1> [CMake] -- Looking for setlocale
1> [CMake] -- Looking for setlocale - found
1> [CMake] -- Looking for poll
1> [CMake] -- Looking for poll - not found
1> [CMake] -- Looking for getpwuid
1> [CMake] -- Looking for getpwuid - not found
1> [CMake] -- Looking for cuserid
1> [CMake] -- Looking for cuserid - not found
1> [CMake] -- Check size of char *
1> [CMake] -- Check size of char * - done
1> [CMake] -- Check size of int
1> [CMake] -- Check size of int - done
1> [CMake] -- Check size of long
1> [CMake] -- Check size of long - done
1> [CMake] -- Check size of long long
1> [CMake] -- Check size of long long - done
1> [CMake] -- Check size of size_t
1> [CMake] -- Check size of size_t - done
1> [CMake] -- Check size of uchar
1> [CMake] -- Check size of uchar - failed
1> [CMake] -- Check size of uint
1> [CMake] -- Check size of uint - failed
1> [CMake] -- Check size of ulong
1> [CMake] -- Check size of ulong - failed
1> [CMake] -- Check size of int8
1> [CMake] -- Check size of int8 - failed
1> [CMake] -- Check size of uint8
1> [CMake] -- Check size of uint8 - failed
1> [CMake] -- Check size of int16
1> [CMake] -- Check size of int16 - failed
1> [CMake] -- Check size of uint16
1> [CMake] -- Check size of uint16 - failed
1> [CMake] -- Check size of int32
1> [CMake] -- Check size of int32 - failed
1> [CMake] -- Check size of uint32
1> [CMake] -- Check size of uint32 - failed
1> [CMake] -- Check size of int64
1> [CMake] -- Check size of int64 - failed
1> [CMake] -- Check size of uint64
1> [CMake] -- Check size of uint64 - failed
1> [CMake] -- Check size of socklen_t
1> [CMake] -- Check size of socklen_t - failed
1> [CMake] -- TLS library/version: Schannel 10.0.19042
1> [CMake] -- SYSTEM_LIBS ws2_32;advapi32;kernel32;shlwapi;crypt32;secur32
1> [CMake] CMake Error at libmariadb/cmake/version_info.cmake:15 (STRING):
1> [CMake]   STRING sub-command REPLACE requires at least four arguments.
1> [CMake] Call Stack (most recent call first):
1> [CMake]   libmariadb/cmake/version_info.cmake:33 (GET_FILE_VERSION)
1> [CMake]   libmariadb/libmariadb/CMakeLists.txt:390 (SET_VERSION_INFO)
1> [CMake] -- SYSTEM processor: AMD64
1> [CMake] -- MariaDB Connector/c configuration:
1> [CMake] -- Static PLUGINS mysql_native_password;mysql_old_password;pvio_socket
1> [CMake] -- Dynamic PLUGINS dialog;client_ed25519;caching_sha2_password;sha256_password;auth_gssapi_client;mysql_clear_password;pvio_npipe;pvio_shmem
1> [CMake] -- CPack generation: ZIP
1> [CMake] -- SSL support: SCHANNEL Libs: secur32
1> [CMake] -- Zlib support: yes (using bundled zlib)
1> [CMake] -- Installation layout: DEFAULT
1> [CMake] -- Include files will be installed in include/mariadb
1> [CMake] -- Libraries will be installed in /mariadb
1> [CMake] -- Binaries will be installed in bin
1> [CMake] -- Documentation included from
1> [CMake] -- Required:
1> [CMake] -- Configuring to install libmariadb to /mariadb
1> [CMake] -- Configuring to install mysql_clear_password to plugin
1> [CMake] -- Configuring to install dialog to plugin
1> [CMake] -- Configuring to install client_ed25519 to plugin
1> [CMake] -- Configuring to install sha256_password to plugin
1> [CMake] -- Configuring to install caching_sha2_password to plugin
1> [CMake] -- Linking Connector/C library statically(mariadbclient)
1> [CMake] -- WiX directory: /bin/
1> [CMake] -- MSI package name mariadb-connector-cpp-1.0.2-win64.msi
1> [CMake] -- Configuring tests framework lib
1> [CMake] -- Configuring C/J junit tests port
1> [CMake] -- Configuring unit tests
1> [CMake] -- Configuring unit tests - examples
1> [CMake] -- Configuring unit tests - connection
1> [CMake] -- Configuring unit tests - databasemetadata
1> [CMake] -- Configuring unit tests - resultsetmetadata
1> [CMake] -- Configuring unit tests - resultset
1> [CMake] -- Configuring unit tests - savepoint
1> [CMake] -- Configuring unit tests - preparedstatement
1> [CMake] -- Configuring unit tests - parametermetadata
1> [CMake] -- Configuring unit tests - statement
1> [CMake] -- Configuring performance test - statement
1> [CMake] -- Configuring bugs test cases - unsorted
1> [CMake] -- Configuring test cases
1> [CMake] -- Package Name: mariadb-connector-cpp-1.0.2-windows-AMD64
1> [CMake] -- License File: C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/COPYING
1> [CMake] -- ReadMe File: C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/README
1> [CMake] -- Source Package Filename: mariadb-connector-cpp-1.0.2-src.ZIP
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/out/build/x64-Debug/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/out/build/x64-Debug/CMakeFiles/CMakeError.log".
1> 'C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"' execution failed with error: ''C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"' returned with exit code: 1'.
</code>```

I have ran out of ideas on how to resolve this. Any help is much appreciated.

答:
In the mariadb c++ connector site(https://github.com/mariadb-corporation/mariadb-connector-cpp)

git clone
git clone https://github.com/MariaDB-Corporation/mariadb-connector-cpp.git

build with debug mode(default is Release with Debug info)
cmake -DCMAKE_BUILD_TYPE=DEBUG -DCONC_WITH_UNIT_TESTS=Off -DCONC_WITH_MSI=OFF -DWITH_SSL=SCHANNEL .
cmake --build . --config DEBUG

replace previous library with debug..

Body:
I am trying to connect to my MariaDB instance using the MariaDB Connector/c++. Here is the code where I tried to use the already compiled version of the connector:

    #include <iostream>
    #include <mariadb/conncpp.hpp>

    int main()
    {
            std::cout << "Hello World!\n";

    try
    {
        // Instantiate Driver
        sql::Driver* driver = sql::mariadb::get_driver_instance();

    // Configure Connection
    sql::SQLString url("jdbc:mariadb://X.X.X.X:3306/myMariaDB");

    sql::Properties properties({
        {"user", "root"},
        {"password", "myPassword"},
        {"useTls", "true"},
        {"tlsCA", "myFile.pem"}
        });

    // Establish Connection
    std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));

    std::cout << "I connected successfully!";

    conn->close();
}
catch (sql::SQLException& e)
{
    std::cerr << "Error Connecting to MariaDB Platform: "
        << e.what() << std::endl;

    // Exit (Failed)
    return 1;
    }

    return 0;
}

Running the code throws exception at the //Establish Connection line:

Exception thrown: read access violation.
other.theString._Mypair._Myval2 was 0xFFFFFFFFFFFFFFEF.

Searching the internet people suggested to recompile the connector source which I got from Github https://github.com/mariadb-corporation/mariadb-connector-cpp#readme

I tried to compile the source using VS 2019 and CMake. I have to say that this is my first encounter with CMake and I know very little about it. It seems that both are failing to build the cloned repo. below is the error I get form VS 2019 which is very similar to what I get from CMake. I also get an error in the "Error List" tab in VS 2019 : CMAke Error at libmariadb/cmake/version_info.cmake:15 (STRING):...:

1> CMake generation started for default configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"
1> Working directory: C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\build\x64-Debug
1> [CMake] -- The CXX compiler identification is MSVC 19.29.30133.0
1> [CMake] -- The C compiler identification is MSVC 19.29.30133.0
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- CMAKE_CXX_FLAGS_DEBUG= /MTd /Zi /Ob0 /Od /RTC1
1> [CMake] -- CMAKE_C_FLAGS_DEBUG= /MTd /Zi /Ob0 /Od /RTC1
1> [CMake] -- CMAKE_CXX_FLAGS_RELEASE= /MT /O2 /Ob2 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_RELEASE= /MT /O2 /Ob2 /DNDEBUG
1> [CMake] -- CMAKE_CXX_FLAGS_RELWITHDEBINFO= /MT /Zi /O2 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_RELWITHDEBINFO= /MT /Zi /O2 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_CXX_FLAGS_MINSIZEREL= /MT /O1 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_MINSIZEREL= /MT /O1 /Ob1 /DNDEBUG
1> [CMake] -- MariaDB Connector ODBC: INSTALL_BINDIR=
1> [CMake] -- MariaDB Connector ODBC: INSTALL_LIBDIR=/mariadb
1> [CMake] -- MariaDB Connector ODBC: INSTALL_PCDIR=/pkgconfig
1> [CMake] -- MariaDB Connector ODBC: INSTALL_INCLUDEDIR=include/mariadb
1> [CMake] -- MariaDB Connector ODBC: INSTALL_DOCDIR=share/doc/mariadbcpp
1> [CMake] -- MariaDB Connector ODBC: INSTALL_LICENSEDIR=share/doc/mariadbcpp
1> [CMake] -- MariaDB Connector ODBC: INSTALL_PLUGINDIR=plugin
1> [CMake] -- Generate MSI package: ON
1> [CMake] -- Sign MSI package: OFF
1> [CMake] -- Setting deafault value for WITH_SSL for libmariadb build to ON
1> [CMake] -- Running C/C cmake scripts
1> [CMake] -- Found Git: C:/Windows/System32/git
1> [CMake] == Configuring MariaDB Connector/C
1> [CMake] CMake Warning (dev) at libmariadb/CMakeLists.txt:19 (PROJECT):
1> [CMake]   Policy CMP0048 is not set: project() command manages VERSION variables.
1> [CMake]   Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
1> [CMake]   command to set the policy and suppress this warning.
1> [CMake]
1> [CMake]   The following variable(s) would be set to empty:
1> [CMake]
1> [CMake]     PROJECT_VERSION
1> [CMake]     PROJECT_VERSION_MAJOR
1> [CMake]     PROJECT_VERSION_MINOR
1> [CMake]     PROJECT_VERSION_PATCH
1> [CMake] This warning is for project developers.  Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
1> [CMake] -- MariaDB Connector C: INSTALL_BINDIR=bin
1> [CMake] -- MariaDB Connector C: INSTALL_LIBDIR=/mariadb
1> [CMake] -- MariaDB Connector C: INSTALL_PCDIR=/pkgconfig
1> [CMake] -- MariaDB Connector C: INSTALL_INCLUDEDIR=include/mariadb
1> [CMake] -- MariaDB Connector C: INSTALL_DOCSDIR=
1> [CMake] -- MariaDB Connector C: INSTALL_PLUGINDIR=plugin
1> [CMake] -- MariaDB Connector C: LIBMARIADB_STATIC_NAME mariadbclient
1> [CMake] -- Looking for include file alloca.h
1> [CMake] -- Looking for include file alloca.h - not found
1> [CMake] -- Looking for include file arpa/inet.h
1> [CMake] -- Looking for include file arpa/inet.h - not found
1> [CMake] -- Looking for include file dlfcn.h
1> [CMake] -- Looking for include file dlfcn.h - not found
1> [CMake] -- Looking for include file fcntl.h
1> [CMake] -- Looking for include file fcntl.h - found
1> [CMake] -- Looking for include file float.h
1> [CMake] -- Looking for include file float.h - found
1> [CMake] -- Looking for include file limits.h
1> [CMake] -- Looking for include file limits.h - found
1> [CMake] -- Looking for include file linux/limits.h
1> [CMake] -- Looking for include file linux/limits.h - not found
1> [CMake] -- Looking for include file pwd.h
1> [CMake] -- Looking for include file pwd.h - not found
1> [CMake] -- Looking for include file sched.h
1> [CMake] -- Looking for include file sched.h - not found
1> [CMake] -- Looking for include file select.h
1> [CMake] -- Looking for include file select.h - not found
1> [CMake] -- Looking for include file signal.h
1> [CMake] -- Looking for include file signal.h - found
1> [CMake] -- Looking for include file stddef.h
1> [CMake] -- Looking for include file stddef.h - found
1> [CMake] -- Looking for include file stdint.h
1> [CMake] -- Looking for include file stdint.h - found
1> [CMake] -- Looking for include file stdlib.h
1> [CMake] -- Looking for include file stdlib.h - found
1> [CMake] -- Looking for include file string.h
1> [CMake] -- Looking for include file string.h - found
1> [CMake] -- Looking for include file strings.h
1> [CMake] -- Looking for include file strings.h - not found
1> [CMake] -- Looking for include file sys/ioctl.h
1> [CMake] -- Looking for include file sys/ioctl.h - not found
1> [CMake] -- Looking for include file sys/select.h
1> [CMake] -- Looking for include file sys/select.h - not found
1> [CMake] -- Looking for include file sys/socket.h
1> [CMake] -- Looking for include file sys/socket.h - not found
1> [CMake] -- Looking for include file sys/types.h
1> [CMake] -- Looking for include file sys/types.h - found
1> [CMake] -- Looking for include file sys/stat.h
1> [CMake] -- Looking for include file sys/stat.h - found
1> [CMake] -- Looking for include file sys/un.h
1> [CMake] -- Looking for include file sys/un.h - not found
1> [CMake] -- Looking for include file unistd.h
1> [CMake] -- Looking for include file unistd.h - not found
1> [CMake] -- Looking for include file utime.h
1> [CMake] -- Looking for include file utime.h - not found
1> [CMake] -- Looking for include file ucontext.h
1> [CMake] -- Looking for include file ucontext.h - not found
1> [CMake] -- Looking for alloca
1> [CMake] -- Looking for alloca - not found
1> [CMake] -- Looking for dlerror
1> [CMake] -- Looking for dlerror - not found
1> [CMake] -- Looking for dlopen
1> [CMake] -- Looking for dlopen - not found
1> [CMake] -- Looking for fcntl
1> [CMake] -- Looking for fcntl - not found
1> [CMake] -- Looking for memcpy
1> [CMake] -- Looking for memcpy - found
1> [CMake] -- Looking for nl_langinfo
1> [CMake] -- Looking for nl_langinfo - not found
1> [CMake] -- Looking for setlocale
1> [CMake] -- Looking for setlocale - found
1> [CMake] -- Looking for poll
1> [CMake] -- Looking for poll - not found
1> [CMake] -- Looking for getpwuid
1> [CMake] -- Looking for getpwuid - not found
1> [CMake] -- Looking for cuserid
1> [CMake] -- Looking for cuserid - not found
1> [CMake] -- Check size of char *
1> [CMake] -- Check size of char * - done
1> [CMake] -- Check size of int
1> [CMake] -- Check size of int - done
1> [CMake] -- Check size of long
1> [CMake] -- Check size of long - done
1> [CMake] -- Check size of long long
1> [CMake] -- Check size of long long - done
1> [CMake] -- Check size of size_t
1> [CMake] -- Check size of size_t - done
1> [CMake] -- Check size of uchar
1> [CMake] -- Check size of uchar - failed
1> [CMake] -- Check size of uint
1> [CMake] -- Check size of uint - failed
1> [CMake] -- Check size of ulong
1> [CMake] -- Check size of ulong - failed
1> [CMake] -- Check size of int8
1> [CMake] -- Check size of int8 - failed
1> [CMake] -- Check size of uint8
1> [CMake] -- Check size of uint8 - failed
1> [CMake] -- Check size of int16
1> [CMake] -- Check size of int16 - failed
1> [CMake] -- Check size of uint16
1> [CMake] -- Check size of uint16 - failed
1> [CMake] -- Check size of int32
1> [CMake] -- Check size of int32 - failed
1> [CMake] -- Check size of uint32
1> [CMake] -- Check size of uint32 - failed
1> [CMake] -- Check size of int64
1> [CMake] -- Check size of int64 - failed
1> [CMake] -- Check size of uint64
1> [CMake] -- Check size of uint64 - failed
1> [CMake] -- Check size of socklen_t
1> [CMake] -- Check size of socklen_t - failed
1> [CMake] -- TLS library/version: Schannel 10.0.19042
1> [CMake] -- SYSTEM_LIBS ws2_32;advapi32;kernel32;shlwapi;crypt32;secur32
1> [CMake] CMake Error at libmariadb/cmake/version_info.cmake:15 (STRING):
1> [CMake]   STRING sub-command REPLACE requires at least four arguments.
1> [CMake] Call Stack (most recent call first):
1> [CMake]   libmariadb/cmake/version_info.cmake:33 (GET_FILE_VERSION)
1> [CMake]   libmariadb/libmariadb/CMakeLists.txt:390 (SET_VERSION_INFO)
1> [CMake] -- SYSTEM processor: AMD64
1> [CMake] -- MariaDB Connector/c configuration:
1> [CMake] -- Static PLUGINS mysql_native_password;mysql_old_password;pvio_socket
1> [CMake] -- Dynamic PLUGINS dialog;client_ed25519;caching_sha2_password;sha256_password;auth_gssapi_client;mysql_clear_password;pvio_npipe;pvio_shmem
1> [CMake] -- CPack generation: ZIP
1> [CMake] -- SSL support: SCHANNEL Libs: secur32
1> [CMake] -- Zlib support: yes (using bundled zlib)
1> [CMake] -- Installation layout: DEFAULT
1> [CMake] -- Include files will be installed in include/mariadb
1> [CMake] -- Libraries will be installed in /mariadb
1> [CMake] -- Binaries will be installed in bin
1> [CMake] -- Documentation included from
1> [CMake] -- Required:
1> [CMake] -- Configuring to install libmariadb to /mariadb
1> [CMake] -- Configuring to install mysql_clear_password to plugin
1> [CMake] -- Configuring to install dialog to plugin
1> [CMake] -- Configuring to install client_ed25519 to plugin
1> [CMake] -- Configuring to install sha256_password to plugin
1> [CMake] -- Configuring to install caching_sha2_password to plugin
1> [CMake] -- Linking Connector/C library statically(mariadbclient)
1> [CMake] -- WiX directory: /bin/
1> [CMake] -- MSI package name mariadb-connector-cpp-1.0.2-win64.msi
1> [CMake] -- Configuring tests framework lib
1> [CMake] -- Configuring C/J junit tests port
1> [CMake] -- Configuring unit tests
1> [CMake] -- Configuring unit tests - examples
1> [CMake] -- Configuring unit tests - connection
1> [CMake] -- Configuring unit tests - databasemetadata
1> [CMake] -- Configuring unit tests - resultsetmetadata
1> [CMake] -- Configuring unit tests - resultset
1> [CMake] -- Configuring unit tests - savepoint
1> [CMake] -- Configuring unit tests - preparedstatement
1> [CMake] -- Configuring unit tests - parametermetadata
1> [CMake] -- Configuring unit tests - statement
1> [CMake] -- Configuring performance test - statement
1> [CMake] -- Configuring bugs test cases - unsorted
1> [CMake] -- Configuring test cases
1> [CMake] -- Package Name: mariadb-connector-cpp-1.0.2-windows-AMD64
1> [CMake] -- License File: C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/COPYING
1> [CMake] -- ReadMe File: C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/README
1> [CMake] -- Source Package Filename: mariadb-connector-cpp-1.0.2-src.ZIP
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/out/build/x64-Debug/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/out/build/x64-Debug/CMakeFiles/CMakeError.log".
1> 'C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"' execution failed with error: ''C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"' returned with exit code: 1'.

I have ran out of ideas on how to resolve this. Any help is much appreciated.


来源: stackexchange

问:
How to pass $this into laravel collection's map()
How can I access/pass $this inside map()? Something like:

```<code>return $this->map(function ($value) use ($this) {
    return Lang::get($value, [], $this);
});
</code>```

I tried the above but I got an error in my IDE stating: Cannot use $this as lexical variable.
This one works but is there a better way to do rather than this:

```<code>$that = $this;
return $this->map(function ($value) use ($that) {
    return Lang::get($value, [], $that);
});
</code>```

答:
In Laravel closures does not have access to outer scope variables, but it has access to $this context and $this context will always be the class where the closure is called.

```<code>return $this->map(function ($value) {
    return Lang::get($value, [], $this);
});
</code>```

Therefor this is valid and accepted by coding guidelines. Your problem is instead that the third parameter of Lang::get(), is not an object but an string there should be an locale, which is defined in the docs.

```<code>return $this->map(function ($value) {
    return Lang::get($value, [], 'en-US');
});
</code>```

So a solution closer to this, is probably what you are looking for, based on you localization settings.

ContentLicense: CC BY-SA 4.0

Body:
How can I access/pass $this inside map()? Something like:

return $this->map(function ($value) use ($this) {
    return Lang::get($value, [], $this);
});

I tried the above but I got an error in my IDE stating: Cannot use $this as lexical variable.
This one works but is there a better way to do rather than this:

$that = $this;
return $this->map(function ($value) use ($that) {
    return Lang::get($value, [], $that);
});

Body:
In Laravel closures does not have access to outer scope variables, but it has access to $this context and $this context will always be the class where the closure is called.

return $this->map(function ($value) {
    return Lang::get($value, [], $this);
});

Therefor this is valid and accepted by coding guidelines. Your problem is instead that the third parameter of Lang::get(), is not an object but an string there should be an locale, which is defined in the docs.

return $this->map(function ($value) {
    return Lang::get($value, [], 'en-US');
});

So a solution closer to this, is probably what you are looking for, based on you localization settings.


问:
Insufficient permissions in vscode
How do I resolve the vs code Insufficient permission issue when saving a file

I've given appropriate permissions to code directory:
chown -R me:staff my-app/

But when I open vscode and try to save a file it says "Insufficient permissions, Retry as admin"

If I launch vscode with sudo from cmd line sudo code . then I dont get that error but then the autocompletion extensions dont seem to work

答:
I encountered this error after executing sudo git pull on ubuntu, The issue was solved by Changing the file/directory persons for the owner, group and others for all the files and the folders for the project by running
sudo chmod -R 770 projectFolder don't run sudo chmod -R 777 projectFolder for security reasons

Title: Insufficient permissions in vscode


问:
HTML .gitignore
I currently have my api keys and list id sitting in my app.js file. I am trying to add those API keys to another file and hide the file using .gitignore. But how do I do that and even if I hide the file in the new secret file how do I get those keys back in my original app.js file</p>

答:
Firstly install a library called dotenv

```<code>npm i dotenv --save

</code>```

Create a file called .env and place your API KEY in it and create .gitignore file place your .env in it

Example

Inside .env :

```<code>API_KEY= YOUR_APIKEY without quotation
</code>```

Inside .gitignore:

```<code>.env

</code>```

To use your API KEY inside app.js

Inside app.js:

```<code>require('dotenv').config()

let API_KEY = process.env.API_KEY;
</code>```

Title: HTML .gitignore

Body:
Firstly install a library called dotenv

npm i dotenv --save

Create a file called .env and place your API KEY in it and create .gitignore file place your .env in it

Example

Inside .env :

API_KEY= YOUR_APIKEY without quotation

Inside .gitignore:

.env

To use your API KEY inside app.js

Inside app.js:

require('dotenv').config()

let API_KEY = process.env.API_KEY;


问:
Getting FlyWay Exception while migrating springboot version
Getting the below exception while migrating my project from Sprinn boot version 1.1.1 to 2.3.12 Release.</p>
```<code>2022-02-08 19:28:15 WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException:
Migration V001_01__create_tables.sql failed
-------------------------------------------
SQL State  : 42001
Error Code : 42001
Message    : Syntax error in SQL statement "CREATE TABLE ICNCCOCN.ICNRQTCV_QUOTATION_COVERAGE (
QTCV_UUID                     VARCHAR(36) NOT NULL,
QTCV_TENANTID                 VARCHAR(2),
QTCV_QTTN_UUID                VARCHAR(36),
QTCV_COVERAGECODE             VARCHAR(36) NOT NULL,
QTCV_CONTINGENT               INTEGER,
QTCV_CHANGED_ON               TIMESTAMP WITH TIME ZONE,
QTCV_CHANGED_BY               VARCHAR(50),
CONSTRAINT ICNSQTCV_P PRIMARY KEY(QTCV_UUID),
)[*]"; expected "identifier"; SQL statement:
</code>```

答: After removing the dangling issue got resolved..</p>

Body:
Getting the below exception while migrating my project from Sprinn boot version 1.1.1 to 2.3.12 Release.

2022-02-08 19:28:15 WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException:
Migration V001_01__create_tables.sql failed
-------------------------------------------
SQL State  : 42001
Error Code : 42001
Message    : Syntax error in SQL statement "CREATE TABLE ICNCCOCN.ICNRQTCV_QUOTATION_COVERAGE (
QTCV_UUID                     VARCHAR(36) NOT NULL,
QTCV_TENANTID                 VARCHAR(2),
QTCV_QTTN_UUID                VARCHAR(36),
QTCV_COVERAGECODE             VARCHAR(36) NOT NULL,
QTCV_CONTINGENT               INTEGER,
QTCV_CHANGED_ON               TIMESTAMP WITH TIME ZONE,
QTCV_CHANGED_BY               VARCHAR(50),
CONSTRAINT ICNSQTCV_P PRIMARY KEY(QTCV_UUID),
)[*]"; expected "identifier"; SQL statement:


问:
How can I display the version number in git for the hash value of a tag?
I am working on the PowerShell right now and would like to display the version and if possible the description of a tag from which I get the hash value. By version I mean something like 55.1.

How can I do this on the PowerShell?

I thank you already for help

答:
You could either:

define an alias for git

or install Posh-Git, which will with tab completion support for common git commands.

In both cases, you will be able to type:

```<code>git show-ref --tags
</code>```

To list tags version and their sha

Or, for a given commit SHA:

```<code>git log --oneline --decorate --tags --no-walk -1 <SHA>
</code>```

Or, as suggested, with git 2.7+:

```<code>git for-each-ref --points-at <commit> --format '%(refname)'
git branch --points-at <commit>
git tag --points-at <commit>
</code>```

Body:
You could either:

define an alias for git

or install Posh-Git, which will with tab completion support for common git commands.

In both cases, you will be able to type:

git show-ref --tags

To list tags version and their sha

Or, for a given commit SHA:

git log --oneline --decorate --tags --no-walk -1 <SHA>

Or, as suggested, with git 2.7+:

git for-each-ref --points-at <commit> --format '%(refname)'
git branch --points-at <commit>
git tag --points-at <commit>


问:
Error when running npx create-react-app myapp on fresh install of node.js
I followed the reactjs.org website for create-react-app to a T

I haven't been able to find this specific error anywhere, and most posts are years old; irrelevant to the specific error in the post anyways.

Has anyone had this happen and what did you do to fix it?

Latest version of Win10 if that helps.
The LTS version v16.14.0 of Node.js

My Node.js installation is just a clean express installation on the OS drive. Any ideas?

The error message is below as-is after runnning npx create-react-app my-app:

```<code>C:\Users\Keith & Vanny>npx create-react-app myapp
'Vanny\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\.bin\' is not recognized as
an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\Users\create-react-app\index.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
</code>```

Update: I installed it locally through npm i create-react-app and tried to create with npm init react-app my-app.

They both yield the same error above. I think it has something to do with that unrecognized command part of the error where a batch script was ran and it failed to parse and do the job, and then the package didn't get installed. So the javascript jargon is telling me I'm missing required packages; my paths for Node are perfect. Clean install and clean of any packages. This's got me stumped. Looks like I'm going to the devs if we can't figure this out.

答:
Creating a local admin account that's just a single string with no symbols or spaces, logging into that account, and then running the npx command worked perfectly.

Installing ReactJs on a Windows machine with a users/ path that contains symbols and spaces, particulary symbols, causes a bug to happen in which npx/npm or even create-react-app can't properly parse the path to the module, therefore throwing a can't find module error.

Lesson learned: never put symbols in your windows username. Pretty bummed I have to develop on the local account for sure though.

Update: Because I refuse to use a dummy admin account to develop on I found the perfect solution working on Win 10 Home in 2022 perfectly fine. Just create a system restore point before you do it. Here's the link! StackExchange solution for properly renaming a faulty conflicting system username. Use the second solution, not the accepted answer.

Just be prepared to spend some hours editing your registry.

Direct link to the solution I'm talking about.

Body:
I followed the reactjs.org website for create-react-app to a T

I haven't been able to find this specific error anywhere, and most posts are years old; irrelevant to the specific error in the post anyways.

Has anyone had this happen and what did you do to fix it?

Latest version of Win10 if that helps.
The LTS version v16.14.0 of Node.js

My Node.js installation is just a clean express installation on the OS drive. Any ideas?

The error message is below as-is after runnning npx create-react-app my-app:

C:\Users\Keith & Vanny>npx create-react-app myapp
'Vanny\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\.bin\' is not recognized as
an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\Users\create-react-app\index.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Update: I installed it locally through npm i create-react-app and tried to create with npm init react-app my-app.

They both yield the same error above. I think it has something to do with that unrecognized command part of the error where a batch script was ran and it failed to parse and do the job, and then the package didn't get installed. So the javascript jargon is telling me I'm missing required packages; my paths for Node are perfect. Clean install and clean of any packages. This's got me stumped. Looks like I'm going to the devs if we can't figure this out.


问:
help in uniquely identifying combine columns
How can I uniquely identify two or more columns, that I have used table named address in the database, now address is has fields like street name, suite name and street num.

strnum   | strnam  |  sutname

1        | xyz     | 32

1        | xyz     | 32

now how can I uniquely these three columns. That is I want to check whether these three column are already inserted or not. If any field valus is changed than its ok, it will insert new one. but in case all three similar field..Help me to combinely identify these three fields.

答:
```<code>$query = "SELECT * FROM `address` WHERE `strnum` = '$strnum' AND `strnam` = '$strnam' AND `sutname` = '$sutname' LIMIT 1";
$result = mysql_query($query);
if (!mysql_num_rows($result)) {
    // If you get to here, there is no existing record
    $query = "INSERT INTO `address` (`strnum`,`strnam`,`sutname`) VALUES ('$strnum','$strnam','$sutname')";
    if (!mysql_query($query)) print('Insert failed!');
} else print('Record already exists!');
</code>```

EDIT I just added a missing ; so this parses...

ContentLicense: CC BY-SA 3.0

Body:
$query = "SELECT * FROM `address` WHERE `strnum` = '$strnum' AND `strnam` = '$strnam' AND `sutname` = '$sutname' LIMIT 1";
$result = mysql_query($query);
if (!mysql_num_rows($result)) {
    // If you get to here, there is no existing record
    $query = "INSERT INTO `address` (`strnum`,`strnam`,`sutname`) VALUES ('$strnum','$strnam','$sutname')";
    if (!mysql_query($query)) print('Insert failed!');
} else print('Record already exists!');

EDIT I just added a missing ; so this parses...


问:
Python to Powerpoint: Export svg to a pptx file
I was experimenting with the python-pptx library to automate the process of adding images to my presentations. I used code such as:

```<code>from pptx import Presentation
import os

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[8])
placeholder = slide.placeholders[1]
picture = placeholder.insert_picture('pie.png')
prs.save("ESEMPIO.pptx")
</code>```

This works just fine, but it was noted that when zooming in the pie chart contained in pie.png becomes quite pixelated. Someone suggested to use SVG format, so I saved the image as an SVG (unfortunately, I can't seem to add the SVG file here). Now, if I try to do:

```<code>from pptx import Presentation
import os

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[8])
placeholder = slide.placeholders[1]
picture = placeholder.insert_picture('pie.svg')
prs.save("ESEMPIO.pptx")
</code>```

I get the following error: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f38da87c350>, which I guess is because it does not like the SVG format. Is there any workaround to get an SVG into a PowerPoint presentation?

PNG pie chart

答:
In md2pptx we automate the conversion of SVG to .PNG under the covers. It uses CairoSVG to do it.

md2pptx relies heavily on python-pptx to convert Markdown to .pptx.

You can get md2pptx here:

https://github.com/MartinPacker/md2pptx

Sorry if this seems like an advert. I just wanted you to know there is automation available.

Body:
I was experimenting with the python-pptx library to automate the process of adding images to my presentations. I used code such as:

from pptx import Presentation
import os

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[8])
placeholder = slide.placeholders[1]
picture = placeholder.insert_picture('pie.png')
prs.save("ESEMPIO.pptx")

This works just fine, but it was noted that when zooming in the pie chart contained in pie.png becomes quite pixelated. Someone suggested to use SVG format, so I saved the image as an SVG (unfortunately, I can't seem to add the SVG file here). Now, if I try to do:

from pptx import Presentation
import os

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[8])
placeholder = slide.placeholders[1]
picture = placeholder.insert_picture('pie.svg')
prs.save("ESEMPIO.pptx")

I get the following error: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f38da87c350>, which I guess is because it does not like the SVG format. Is there any workaround to get an SVG into a PowerPoint presentation?

PNG pie chart


问:
Vimeo API: Play button and multiple videos
I'm having some trouble. I just discovered that you can control vimeo with js, and now I'm trying to create a play button that will start playing a vimeo video.

The problem I'm having is that I have multiple videos on the same page. I took the example/playground file (from here http://player.vimeo.com/playground / https://github.com/vimeo/player-api/tree/master/javascript) and removed the functionality that I don't require, however, I can't understand how I connect the play button with a certain video.

This is what I have so far

HTML:

```<code><iframe id="player_1" src="http://player.vimeo.com/video/7100569?api=1&player_id=player_1" width="540" height="304" frameborder="0"></iframe>
<div class="intro">
     <span class="hide">Play 1</span>
</div>
<iframe id="player_2" src="http://player.vimeo.com/video/7100569?api=1&player_id=player_2" width="540" height="304" frameborder="0"></iframe>
<div class="intro">
    <span class="hide">Play 2</span>
</div>
</code>```

JS:

```<code>            var vimeoPlayers = document.querySelectorAll('iframe'),
                player;

            for (var i = 0, length = vimeoPlayers.length; i < length; i++) {
                player = vimeoPlayers[i];
                $f(player).addEvent('ready', ready);
            }

            function addEvent(element, eventName, callback) {
                if (element.addEventListener) {
                    element.addEventListener(eventName, callback, false);
                }
                else {
                    element.attachEvent(eventName, callback, false);
                }
            }

            function ready(player_id) {
                // Keep a reference to Froogaloop for this player
                var container = document.getElementById(player_id).parentNode.parentNode,
                    froogaloop = $f(player_id);

                function setupSimpleButtons() {
                    var buttons = container.querySelector('div.intro'),
                        playBtn = buttons.querySelector('.hide');

                    // Call play when play button clicked
                    addEvent(playBtn, 'click', function() {
                        froogaloop.api('play');
                    }, false);

                }

                setupSimpleButtons();
            }
        })();
</code>```

If I have code that is unnecessary please help me remove it.
Many thanks.

答:
I figured out a way to do this much easier, you can see an example here:
http://labs.funkhausdesign.com/examples/vimeo/froogaloop2-api-basics.html</p>

Body:
I'm having some trouble. I just discovered that you can control vimeo with js, and now I'm trying to create a play button that will start playing a vimeo video.

The problem I'm having is that I have multiple videos on the same page. I took the example/playground file (from here http://player.vimeo.com/playground / https://github.com/vimeo/player-api/tree/master/javascript) and removed the functionality that I don't require, however, I can't understand how I connect the play button with a certain video.

This is what I have so far

HTML:

     Play 1

    Play 2

JS:

            var vimeoPlayers = document.querySelectorAll('iframe'),
                player;

            for (var i = 0, length = vimeoPlayers.length; i < length; i++) {
                player = vimeoPlayers[i];
                $f(player).addEvent('ready', ready);
            }

            function addEvent(element, eventName, callback) {
                if (element.addEventListener) {
                    element.addEventListener(eventName, callback, false);
                }
                else {
                    element.attachEvent(eventName, callback, false);
                }
            }

            function ready(player_id) {
                // Keep a reference to Froogaloop for this player
                var container = document.getElementById(player_id).parentNode.parentNode,
                    froogaloop = $f(player_id);

                function setupSimpleButtons() {
                    var buttons = container.querySelector('div.intro'),
                        playBtn = buttons.querySelector('.hide');

                    // Call play when play button clicked
                    addEvent(playBtn, 'click', function() {
                        froogaloop.api('play');
                    }, false);

                }

                setupSimpleButtons();
            }
        })();

If I have code that is unnecessary please help me remove it.
Many thanks.


问:
Where is the problem when I try to changed the class string to bytes in python?
```<code>def write(self,vals):
        for record in self:

            emp_id = record.employee_name
            user = self.env['res.users'].search([("email",'=',record.mail)])
            if vals.get('unit_icon'):

                if vals.get('unit_name'):

                    members = self.env['team.works'].search([('unit_name.id','=',vals.get('unit_name'))])
                else:
                    members = self.env['team.works'].search([('unit_name.id','=',record.unit_name['id'])])
                    #print("---------------------------1")
                    #print(type(vals.get('unit_icon')))
                    b = bytes(vals.get('unit_icon'), 'utf-8') #This line the give the error
                    #print(b)
                    #print("---------------------------2")
                    for i in members:
                        #print("---------------------------3")
                        #print(type(i['unit_icon']))
                        #print(i['unit_icon'])
                        i['unit_icon'] = b
                        #print("---------------------------4")```

Hi everyone. I am working on the in odoo project.If the logo is changed, I want to updated logo of other members but there is a problem.Changed logo class is a string.Updated logo other members logo class is bytes other member logo.I am trying to string to bytes to achive this

```<code>b = bytes(vals.get('unit_icon'), 'utf-8')```

After changed class but it give me the error "TypeError: encoding without a string argument". What is the problem of the code ?

答:
if vals.get('unit_icon') is string then Pythonic way is:</p>
```<code>b = vals.get('unit_icon').encode()  # encode defaults to 'utf-8'
</code>```

Body:
def write(self,vals):
        for record in self:

            emp_id = record.employee_name
            user = self.env['res.users'].search([("email",'=',record.mail)])
            if vals.get('unit_icon'):

                if vals.get('unit_name'):

                    members = self.env['team.works'].search([('unit_name.id','=',vals.get('unit_name'))])
                else:
                    members = self.env['team.works'].search([('unit_name.id','=',record.unit_name['id'])])
                    #print("---------------------------1")
                    #print(type(vals.get('unit_icon')))
                    b = bytes(vals.get('unit_icon'), 'utf-8') #This line the give the error
                    #print(b)
                    #print("---------------------------2")
                    for i in members:
                        #print("---------------------------3")
                        #print(type(i['unit_icon']))
                        #print(i['unit_icon'])
                        i['unit_icon'] = b
                        #print("---------------------------4")

Hi everyone. I am working on the in odoo project.If the logo is changed, I want to updated logo of other members but there is a problem.Changed logo class is a string.Updated logo other members logo class is bytes other member logo.I am trying to string to bytes to achive this

b = bytes(vals.get('unit_icon'), 'utf-8')

After changed class but it give me the error "TypeError: encoding without a string argument". What is the problem of the code ?

Body:
if vals.get('unit_icon') is string then Pythonic way is:

b = vals.get('unit_icon').encode()  # encode defaults to 'utf-8'


问:
React-tooltip displays twice when using MUI icon
Whenever I add a tooltip to an SVG (using react-toolip), the tooltip shows twice:

The Code:

```<code><HelpIcon data-tip='This field represents all sales (or revenues) generated by the company.'></HelpIcon>
<ReactTooltip effect='solid' place='left' multiline={true}/>
</code>```

While using the HelpIcon from @mui:

```<code>import HelpIcon from '@mui/icons-material/Help';
import ReactTooltip from 'react-tooltip';
</code>```

答:
You can use Material UI tooltip also Its easy to manage and also long text can be used easily</p>
```<code>import { Tooltip } from '@mui/material';

<Tooltip title='your tooltip title' >
   <HelpIcon>
</Tooltip>
</code>```

Body:
Whenever I add a tooltip to an SVG (using react-toolip), the tooltip shows twice:

The Code:

<HelpIcon data-tip='This field represents all sales (or revenues) generated by the company.'></HelpIcon>
<ReactTooltip effect='solid' place='left' multiline={true}/>

While using the HelpIcon from @mui:

import HelpIcon from '@mui/icons-material/Help';
import ReactTooltip from 'react-tooltip';

Body:
You can use Material UI tooltip also Its easy to manage and also long text can be used easily

import { Tooltip } from '@mui/material';

<Tooltip title='your tooltip title' >
   <HelpIcon>
</Tooltip>


问:
error gradle when update to bumblebee android studio version
today, i update to bumblebee android version, and i create new project and i import some lib, include dagger-hilt.
in build.gradle (module) i insert:

```<code>plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'androidx.navigation.safeargs'
}

dependencies {
...
 implementation "com.google.dagger:hilt-android:2.38.1"
    kapt "com.google.dagger:hilt-compiler:2.38.1"
    androidTestImplementation  "com.google.dagger:hilt-android-testing:2.38.1"
    kaptAndroidTest "com.google.dagger:hilt-compiler:2.38.1"
    testImplementation "com.google.dagger:hilt-android-testing:2.38.1"
    kaptTest "com.google.dagger:hilt-compiler:2.38.1"
}
</code>```

and in build.gradle (project) i insert:

```<code>plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'androidx.navigation.safeargs.kotlin' version '2.4.0-beta02' apply false
    id 'dagger.hilt.android.plugin' version '2.38.1' apply false
}
</code>```

but android studio build fail:

Build file 'H:\AndroidProject\WMTWorkmanagerTodolist\build.gradle' line: 7

Plugin [id: 'dagger.hilt.android.plugin', version: '2.38.1', apply: false] was not found in any of the following sources:

Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'dagger.hilt.android.plugin', version: '2.38.1', apply: false] was not found in any of the following sources:

Gradle Core Plugins (plugin is not in 'org.gradle' namespace)

Plugin Repositories (could not resolve plugin artifact 'dagger.hilt.android.plugin:dagger.hilt.android.plugin.gradle.plugin:2.38.1')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo

why? how do i can fix it. Thank for support.

答:
enter image description here
I copied the old version and it works fine

Body:
today, i update to bumblebee android version, and i create new project and i import some lib, include dagger-hilt.
in build.gradle (module) i insert:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'androidx.navigation.safeargs'
}

dependencies {
...
 implementation "com.google.dagger:hilt-android:2.38.1"
    kapt "com.google.dagger:hilt-compiler:2.38.1"
    androidTestImplementation  "com.google.dagger:hilt-android-testing:2.38.1"
    kaptAndroidTest "com.google.dagger:hilt-compiler:2.38.1"
    testImplementation "com.google.dagger:hilt-android-testing:2.38.1"
    kaptTest "com.google.dagger:hilt-compiler:2.38.1"
}

and in build.gradle (project) i insert:

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'androidx.navigation.safeargs.kotlin' version '2.4.0-beta02' apply false
    id 'dagger.hilt.android.plugin' version '2.38.1' apply false
}

but android studio build fail:

Build file 'H:\AndroidProject\WMTWorkmanagerTodolist\build.gradle' line: 7

Plugin [id: 'dagger.hilt.android.plugin', version: '2.38.1', apply: false] was not found in any of the following sources:

Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'dagger.hilt.android.plugin', version: '2.38.1', apply: false] was not found in any of the following sources:

Gradle Core Plugins (plugin is not in 'org.gradle' namespace)

Plugin Repositories (could not resolve plugin artifact 'dagger.hilt.android.plugin:dagger.hilt.android.plugin.gradle.plugin:2.38.1')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo

why? how do i can fix it. Thank for support.


问:
Gradle A problem occurred starting process 'command 'npm'' on Mac
I have MacOS with IntelliJ Idea installed. I'm using Gradle (gradle-4.10.2) for building the project. I have NodeJS and NPM installed on the Mac and available from the shell.

```<code>node -v
v16.14.0
npm -v
8.1.0
</code>```

When running Gradle task that uses NODE/NPM, it fails with the following error (in current example it is NPM).

```<code>doFirst {
        if(isDevelopment == "N") {
            tasks.uiBuilderInstall.execute()
            tasks.uiBuild.execute()
        }
        tasks.uiDeploy.execute()
    }
</code>```

--

```<code>Build file '/Users/bhpark/dev/automation/build.gradle' line: 102

Execution failed for task ':uiBuilderInstall'.
> A problem occurred starting process 'command 'npm''

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
</code>```

The error stack trace from Gradle is the following.

```<code>* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':uiBuilderInstall'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
    at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:402)
    at org.gradle.api.internal.TaskInternal$execute.call(Unknown Source)
    at build_1fub0dnl18bp9886qo0wrdb8f$_run_closure5$_closure21.doCall(/Users/bhpark/dev/automation/build.gradle:102)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:739)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:712)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
    at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'npm''
    at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:231)
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:209)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:355)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:85)
    at org.gradle.internal.operations.CurrentBuildOperationPreservingRunnable.run(CurrentBuildOperationPreservingRunnable.java:42)
    ... 3 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'npm'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:67)
    ... 4 more
Caused by: java.io.IOException: Cannot run program "npm" (in directory "/Users/bhpark/dev/automation/src/ui"): error=2, No such file or directory
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 5 more
Caused by: java.io.IOException: error=2, No such file or directory
    ... 6 more
</code>```

Gradle "... occurred starting process 'command 'npm''" on Mac

I looked at the above article and implemented it, but there was no big change.
Is there any other way?

答:
It worked fine in ide too.
I found the problem.
On Mac, it is run through the launch pad, but when executing Command Line commands through Gradle, the installation location of brew could not be referenced.

For nodeJS installed via brew the path is /opt/homebrew/Cellar
you need to add location

```<code>sudo launchctl config user path /opt/homebrew/Cellar:/opt/Cellar:/Cellar
</code>```

Rebooting after entering the command solved the problem.

Body:
I have MacOS with IntelliJ Idea installed. I'm using Gradle (gradle-4.10.2) for building the project. I have NodeJS and NPM installed on the Mac and available from the shell.

node -v
v16.14.0
npm -v
8.1.0

When running Gradle task that uses NODE/NPM, it fails with the following error (in current example it is NPM).

doFirst {
        if(isDevelopment == "N") {
            tasks.uiBuilderInstall.execute()
            tasks.uiBuild.execute()
        }
        tasks.uiDeploy.execute()
    }

--

Build file '/Users/bhpark/dev/automation/build.gradle' line: 102

Execution failed for task ':uiBuilderInstall'.
> A problem occurred starting process 'command 'npm''

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

The error stack trace from Gradle is the following.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':uiBuilderInstall'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
    at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:402)
    at org.gradle.api.internal.TaskInternal$execute.call(Unknown Source)
    at build_1fub0dnl18bp9886qo0wrdb8f$_run_closure5$_closure21.doCall(/Users/bhpark/dev/automation/build.gradle:102)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:739)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:712)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
    at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'npm''
    at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:231)
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:209)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:355)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:85)
    at org.gradle.internal.operations.CurrentBuildOperationPreservingRunnable.run(CurrentBuildOperationPreservingRunnable.java:42)
    ... 3 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'npm'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:67)
    ... 4 more
Caused by: java.io.IOException: Cannot run program "npm" (in directory "/Users/bhpark/dev/automation/src/ui"): error=2, No such file or directory
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 5 more
Caused by: java.io.IOException: error=2, No such file or directory
    ... 6 more

Gradle "... occurred starting process 'command 'npm''" on Mac

I looked at the above article and implemented it, but there was no big change.
Is there any other way?

Body:
It worked fine in ide too.
I found the problem.
On Mac, it is run through the launch pad, but when executing Command Line commands through Gradle, the installation location of brew could not be referenced.

For nodeJS installed via brew the path is /opt/homebrew/Cellar
you need to add location

sudo launchctl config user path /opt/homebrew/Cellar:/opt/Cellar:/Cellar

Rebooting after entering the command solved the problem.


问:
Powershell: How to iterate and set Sound Playback and Sound Input device?
Well, one of the things that is worse in Win11 is that it is now several clicks to change audio playback device (where in Win10 it was two or three clicks).

Time to script it.

What is the method in powershell to:

List audio output and input devices

Set/change the audio output and input devices

答:
I am not sure if its gonna work on Windows 11 but its worth a try.

There is a module in powershell that can be used to manage sound devices and volume level. Try AudioDeviceCmdlets module from the PSGallery https://www.powershellgallery.com/packages/AudioDeviceCmdlets/3.0.0.4

Then you can use Get-AudioDevice -List to see the available audio devices, and Set-AudioDevice <AudioDevice> -index 1 to set the desired "AudioDevice" to be the default input/output.

More on the module here - https://github.com/frgnca/AudioDeviceCmdlets


问:
Hide SliverAppBar when when app is started
I want to open SliverAppBar only when I pull down, SliverAppBar is hiding automatically when scrolling down, but when I open the app, I want the appbar to hide, and only appear when I pull down.

```<code>    body: CustomScrollView(
            slivers: [
              SliverAppBar(
                title: Text('Pull down to create item'),
                floating: false,
                pinned: false,
              ),
             ]
</code>```

答:
Set floating: true, on SliverAppBar

SliverAppBar(
  title: Text('Pull down to create item'),
  floating: true,
  pinned: false,
),
```

Body:
I want to open SliverAppBar only when I pull down, SliverAppBar is hiding automatically when scrolling down, but when I open the app, I want the appbar to hide, and only appear when I pull down.

    body: CustomScrollView(
            slivers: [
              SliverAppBar(
                title: Text('Pull down to create item'),
                floating: false,
                pinned: false,
              ),
             ]


问:
Is it possible to have multiple receivers inside elements.xml?
I have a feature for a site APC and it has event handlers for custom lists, which is working perfectly.
Now I want to add event handlers for my announcements within the same site. Can I add it inside the elements.xml as a second receivers node having listtemplateid=104??

Thanks in advance.
janejanejane

答: Yes, definitely you can. Its supported by sharepoint.</p>


问:
Xamarin : Application not installed issue
When I install my application in debugging mode on my Android mobile device, it seems to be installed.

However, after signing the application and publishing it, it's not installed on my phone. (Release mode)

It says: Application not installed.
I tried a few things but cannot resolve this problem. I also tested with another Keystore but it still cannot be installed.

I verified Xamarin Studio options but everything is OK, does anyone have an idea?

答:
You may encounter this issue if you have installed then uninstalled the same app from your phone.

In Visual Studio, go to

Tools > Android > Android Adb Command Prompt

Ensure your phone is connected and debugging is enabled on your phone. If this is done properly, the name of your phone should show in Visual Studio next to the run button.

In the adb command prompt, enter this command:

adb uninstall [your package name]

E.g.

adb uninstall com.mypackage

You should then be able to install your APK


问:
Custom TextField in Flutter: add superscript
Is it possible in flutter to develop custom TextField  to input numbers with superscript like  102  ?

答:
Well, there has to be a way for the user to specify that he is getting into (and out of) superscript mode (say using a specific key). Using a TextInputFormatter to 'trap' these locations - there should be a way to then display the text the way you wanted.

Alternatively, as in stackoverflow where we use ``` to highlight code and there is a display-only section that shows how the text looks, you can do all sorts of text display for formatting the text as per the codes in the typed text without needing to use the TextInputFormatter method.


问:
ARIMA dependency on google colab not working
I am working on a time series problem and wanted to try ARIMA model for it.

But while working I am stuck at pmdarima not getting installed onto Google Colaboratory.

This command is running forever and neither it is throwing any error nor it is completing its execution.

答:
I solved the same problem by running pip install statsmodels just before pip install pmdarima.

It looks like a versions conflict.


问:
Efficiently mask shapes using createGraphics in p5.js
I am trying to create various shapes in p5.js and fill them with specific patterns/drawings. Each shape will have a unique pattern generated using createGraphics. Since my different shapes won't cover all of my base canvas, I am thinking of creating smaller-sized graphics for my patterns to improve performance. For example, if my base canvas is 1000 * 1000 pixels and my shape only takes 50 * 50 pixels and I want to fill it with a rectangular pattern, I do not see the point in creating a 1000 * 1000 pixels pattern graphics and masking it with my 50 * 50 pixels shape.

I am trying to work on a proof of concept using a single shape and pattern:

Determine the width and height of a rectangle that would contain my entire shape. Note that I know what my shape will look like before drawing it (pre-determined points to draw vertices).

Create my pattern graphics using the dimensions determined in 1.

Create my shape.

Mask the pattern graphics created in 2 with the shape created in 3.

Display the resulting image in my base canvas.

Please also note that a shape can be located at any position within my base canvas and that its position is determined by the first point used to draw the shape. The process will have to be repeated many times to generate the desired output.

```<code>function setup() {

    createCanvas(1000, 1000);
    background(200, 255, 255);

    var ptrn;
    var myShape;
    var msk;

    let ptrn_w = 1000;
    let ptrn_h = 1000;

    ptrn = createGraphics(ptrn_w, ptrn_h);
    ptrn.background(120, 0, 150);
    ptrn.fill(255, 255, 255);
    ptrn.noStroke();

    for (let i = 0; i < 500; i++){
        let x = random(0, ptrn_w);
        let y = random(0, ptrn_h);
        ptrn.rect(x, y, 20, 5);
    }

    msk = createGraphics(ptrn_w, ptrn_h);
    msk.beginShape();
    msk.vertex(250, 920);
    msk.vertex(300, 15);
    msk.vertex(325, 75);
    msk.vertex(350, 840);
    msk.endShape(CLOSE);

    ( myShape = ptrn.get() ).mask( msk.get() );

    image(myShape, 0, 0);

}

function draw() {

}
</code>```

The code listed above works since ptrn_w and ptrn_h are equal to the width and height of the base canvas. However, we are generating patterns/graphics for the whole canvas and a high % of that area is not used. If we are generating hundreds of different shapes with complex patterns, I can see how limiting the area in which we generate our patterns could be beneficial from a performance standpoint.

Changing ptrn_w and ptrn_h to ptrn_w = 100 and ptrn_h = 905 is problematic since the mask would be applied outside of the pattern graphics ptrn.

Is there a way to translate the position of ptrn so that it aligns with the position of msk? Would image(myShape, 0, 0) be problematic if we are zeroing the position of our image?

Another idea I had was to zero the position of my mask and reposition it when calling image(myShape, x_pos, y_pos).

What is the best approach to achieve such behavior? Any creative ideas are welcomed.

答:
I believe the most efficient way to do this would be to use the underlying CanvasRenderingContext2D's globalCompositeOperation. By setting this to 'source-in' you can do a sort of reverse mask operation without the need to use a p5.Image object. Additional as shown in the example bellow you can do some simple calculations on your list of vertices to determine the width and height and to draw your shape on a minimally sized buffer.

let vertices = [
  [10, 15],
  [150, 40],
  [100, 120],
  [25, 75]
];

let ptrn;
let myShape;

let shapeTop, shapeLeft;

function setup() {
  createCanvas(windowWidth, windowHeight);

  // Calculate the rage of vertices values
  let shapeBottom, shapeRight;
  for (const [x, y] of vertices) {
    if (shapeTop === undefined || y < shapeTop) {
      shapeTop = y;
    }
    if (shapeBottom === undefined || y > shapeBottom) {
      shapeBottom = y;
    }
    if (shapeLeft === undefined || x < shapeLeft) {
      shapeLeft = x;
    }
    if (shapeRight === undefined || x > shapeRight) {
      shapeRight = x;
    }
  }

  // Determine the minimum width and height to fit the shape
  let w = shapeRight - shapeLeft,
    h = shapeBottom - shapeTop;

  // Generate the pattern
  ptrn = createGraphics(w, h);
  ptrn.background(120, 0, 150);
  ptrn.noStroke();
  for (let i = 0; i < 100; i++) {
    ptrn.fill(random(255), random(255), random(255));
    let x = random(0, w);
    let y = random(0, h);
    ptrn.rect(x, y, 5);
  }

  // Draw the shape
  myShape = createGraphics(w, h);
  myShape.fill(255);
  myShape.noStroke();
  myShape.beginShape();
  for (const [x, y] of vertices) {
    myShape.vertex(x - shapeLeft, y - shapeTop);
  }
  myShape.endShape(CLOSE);

  // See: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  // The 'source-in' composite operation will output the drawn content (ptrn)
  // only in place of existing pixels that are not transparent.
  // The output of each pixel is basically: color(r2, g2, b3, min(a1, a2))
  myShape.drawingContext.globalCompositeOperation = 'source-in';
  myShape.image(ptrn, 0, 0)
}

function draw() {
  background(200, 255, 255);
  image(myShape, mouseX + shapeLeft, mouseY + shapeTop);
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>html, body { margin: 0; padding: 0; overflow: hidden }</code>```

```

Body:
I am trying to create various shapes in p5.js and fill them with specific patterns/drawings. Each shape will have a unique pattern generated using createGraphics. Since my different shapes won't cover all of my base canvas, I am thinking of creating smaller-sized graphics for my patterns to improve performance. For example, if my base canvas is 1000 * 1000 pixels and my shape only takes 50 * 50 pixels and I want to fill it with a rectangular pattern, I do not see the point in creating a 1000 * 1000 pixels pattern graphics and masking it with my 50 * 50 pixels shape.

I am trying to work on a proof of concept using a single shape and pattern:

Determine the width and height of a rectangle that would contain my entire shape. Note that I know what my shape will look like before drawing it (pre-determined points to draw vertices).

Create my pattern graphics using the dimensions determined in 1.

Create my shape.

Mask the pattern graphics created in 2 with the shape created in 3.

Display the resulting image in my base canvas.

Please also note that a shape can be located at any position within my base canvas and that its position is determined by the first point used to draw the shape. The process will have to be repeated many times to generate the desired output.

function setup() {

    createCanvas(1000, 1000);
    background(200, 255, 255);

    var ptrn;
    var myShape;
    var msk;

    let ptrn_w = 1000;
    let ptrn_h = 1000;

    ptrn = createGraphics(ptrn_w, ptrn_h);
    ptrn.background(120, 0, 150);
    ptrn.fill(255, 255, 255);
    ptrn.noStroke();

    for (let i = 0; i < 500; i++){
        let x = random(0, ptrn_w);
        let y = random(0, ptrn_h);
        ptrn.rect(x, y, 20, 5);
    }

    msk = createGraphics(ptrn_w, ptrn_h);
    msk.beginShape();
    msk.vertex(250, 920);
    msk.vertex(300, 15);
    msk.vertex(325, 75);
    msk.vertex(350, 840);
    msk.endShape(CLOSE);

    ( myShape = ptrn.get() ).mask( msk.get() );

    image(myShape, 0, 0);

}

function draw() {

}

The code listed above works since ptrn_w and ptrn_h are equal to the width and height of the base canvas. However, we are generating patterns/graphics for the whole canvas and a high % of that area is not used. If we are generating hundreds of different shapes with complex patterns, I can see how limiting the area in which we generate our patterns could be beneficial from a performance standpoint.

Changing ptrn_w and ptrn_h to ptrn_w = 100 and ptrn_h = 905 is problematic since the mask would be applied outside of the pattern graphics ptrn.

Is there a way to translate the position of ptrn so that it aligns with the position of msk? Would image(myShape, 0, 0) be problematic if we are zeroing the position of our image?

Another idea I had was to zero the position of my mask and reposition it when calling image(myShape, x_pos, y_pos).

What is the best approach to achieve such behavior? Any creative ideas are welcomed.

Body:
I believe the most efficient way to do this would be to use the underlying CanvasRenderingContext2D's globalCompositeOperation. By setting this to 'source-in' you can do a sort of reverse mask operation without the need to use a p5.Image object. Additional as shown in the example bellow you can do some simple calculations on your list of vertices to determine the width and height and to draw your shape on a minimally sized buffer.

let vertices = [
  [10, 15],
  [150, 40],
  [100, 120],
  [25, 75]
];

let ptrn;
let myShape;

let shapeTop, shapeLeft;

function setup() {
  createCanvas(windowWidth, windowHeight);

  // Calculate the rage of vertices values
  let shapeBottom, shapeRight;
  for (const [x, y] of vertices) {
    if (shapeTop === undefined || y < shapeTop) {
      shapeTop = y;
    }
    if (shapeBottom === undefined || y > shapeBottom) {
      shapeBottom = y;
    }
    if (shapeLeft === undefined || x < shapeLeft) {
      shapeLeft = x;
    }
    if (shapeRight === undefined || x > shapeRight) {
      shapeRight = x;
    }
  }

  // Determine the minimum width and height to fit the shape
  let w = shapeRight - shapeLeft,
    h = shapeBottom - shapeTop;

  // Generate the pattern
  ptrn = createGraphics(w, h);
  ptrn.background(120, 0, 150);
  ptrn.noStroke();
  for (let i = 0; i < 100; i++) {
    ptrn.fill(random(255), random(255), random(255));
    let x = random(0, w);
    let y = random(0, h);
    ptrn.rect(x, y, 5);
  }

  // Draw the shape
  myShape = createGraphics(w, h);
  myShape.fill(255);
  myShape.noStroke();
  myShape.beginShape();
  for (const [x, y] of vertices) {
    myShape.vertex(x - shapeLeft, y - shapeTop);
  }
  myShape.endShape(CLOSE);

  // See: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  // The 'source-in' composite operation will output the drawn content (ptrn)
  // only in place of existing pixels that are not transparent.
  // The output of each pixel is basically: color(r2, g2, b3, min(a1, a2))
  myShape.drawingContext.globalCompositeOperation = 'source-in';
  myShape.image(ptrn, 0, 0)
}

function draw() {
  background(200, 255, 255);
  image(myShape, mouseX + shapeLeft, mouseY + shapeTop);
}

html, body { margin: 0; padding: 0; overflow: hidden }

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>