text:
Q: Different errors in ConnectionFactory.php on line 245 - Laravel 5.4 I've updated the question a couple of times but left the original question mostly intact so my thought process is easier to follow. I've added a short summary for everyone to decide if they might be able to help with this. Any help is much appreciated.
Summary

*

*An error rarely (once every 2-4 weeks) occurs.

*After the error occurs once every further request that accesses the database also crashes with the same error

*Error seems to happen in the creation of MySqlConnector in laravel/framework

*Error has so far only occurred on our live server of this application, so we couldn't leave the error and start debugging but had to hot-fix it to maintain up-time.

*We did have some issues with connections breaking up randomly (rarely). This started around the same moment. Maybe the issue is a connection breaking up while building the PDO connection?

Stack

*

*Apache 2.4.32

*PHP 7.1.15

*MariaDB 10.2.6

Detailed question
We've encountered the following error on one of our laravel projects:
[2018-05-29 11:02:05] production.ERROR:
Symfony\Component\Debug\Exception\FatalThrowableError: Illegal offset type in C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php:245
Stack trace:
#0 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php(183): Illuminate\Database\Connectors\ConnectionFactory->createConnector(Array)
#1 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#2 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(883): call_user_func(Object(Closure))
#3 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(445): Illuminate\Database\Connection->getPdo()
#4 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(640): Illuminate\Database\Connection->Illuminate\Database\{closure}('insert into `lo...', Array)
#5 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(607): Illuminate\Database\Connection->runQueryCallback('insert into `lo...', Array, Object(Closure))
#6 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(450): Illuminate\Database\Connection->run('insert into `lo...', Array, Object(Closure))
#7 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(404): Illuminate\Database\Connection->statement('insert into `lo...', Array)
#8 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Query\Processors\Processor.php(32): Illuminate\Database\Connection->insert('insert into `lo...', Array)
#9 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(2138): Illuminate\Database\Query\Processors\Processor->processInsertGetId(Object(Illuminate\Database\Query\Builder), 'insert into `lo...', Array, 'id')
#10 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(1251): Illuminate\Database\Query\Builder->insertGetId(Array, 'id')
#11 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(684): Illuminate\Database\Eloquent\Builder->__call('insertGetId', Array)
#12 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(649): Illuminate\Database\Eloquent\Model->insertAndSetId(Object(Illuminate\Database\Eloquent\Builder), Array)
#13 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(518): Illuminate\Database\Eloquent\Model->performInsert(Object(Illuminate\Database\Eloquent\Builder))
#14 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(734): Illuminate\Database\Eloquent\Model->save()
#15 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Support\helpers.php(950): Illuminate\Database\Eloquent\Builder->Illuminate\Database\Eloquent\{closure}(Object(App\Error))
#16 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(735): tap(Object(App\Error), Object(Closure))
#17 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1357): Illuminate\Database\Eloquent\Builder->create(Array)
#18 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1369): Illuminate\Database\Eloquent\Model->__call('create', Array)
#19 C:\Webserver\Websites\www.somedomain.com\webroot\app\Exceptions\Handler.php(246): Illuminate\Database\Eloquent\Model::__callStatic('create', Array)
#20 C:\Webserver\Websites\www.somedomain.com\webroot\app\Exceptions\Handler.php(217): App\Exceptions\Handler->logErrorAndNotify(Array, Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#21 C:\Webserver\Websites\www.somedomain.com\webroot\app\Exceptions\Handler.php(106): App\Exceptions\Handler->logThenRenderServerException(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalThrowableError), 500)
#22 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(326): App\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#23 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(124): Illuminate\Foundation\Http\Kernel->renderException(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#24 C:\Webserver\Websites\www.somedomain.com\webroot\public\index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#25 {main}

Once this error occurred for the first time all requests to the website triggered the exact same error.
Googling the issue all i found was the following 2 solutions:

*

*run php artisan config:cache or php artisan config:clear

*restart the web server

One example of where these solutions were found can be found here
Now restarting the web server worked, but within an hour we had the same issue come up again. Did another restart and it seems to work for now, but i'd like to know what causes this and how can we prevent it?
Some more information:

*

*We're using Redis to cache everything including the config.

*Hosting is done using a custom apache stack.

*The website has ran months with some reboots but never encountering this issue.

*The first time the issue occurred today the server had filled it's memory capacity, the 2nd time it happened it had 15 GB of memory left over.

Any clues or advice would be much appreciated. If more information is needed to answer the question i'll try and expand the question when asked for it.
Update:
So we had the error occur again, same line but different error. I think that something goes wrong with building the PDO connection and this connection then gets stored to be used again for all future requests for some period of time?
This is the new stack trace:
[2018-06-25 15:27:38] production.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Undefined class constant 'PDO::ATTR_CASE' in C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php:245
Stack trace:
#0 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php(183): Illuminate\Database\Connectors\ConnectionFactory->createConnector(Array)
#1 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#2 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(883): call_user_func(Object(Closure))
#3 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(904): Illuminate\Database\Connection->getPdo()
#4 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(392): Illuminate\Database\Connection->getReadPdo()
#5 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(318): Illuminate\Database\Connection->getPdoForSelect(true)
#6 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(640): Illuminate\Database\Connection->Illuminate\Database\{closure}('select * from `...', Array)
#7 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(607): Illuminate\Database\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#8 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php(326): Illuminate\Database\Connection->run('select * from `...', Array, Object(Closure))
#9 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1710): Illuminate\Database\Connection->select('select * from `...', Array, true)
#10 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1695): Illuminate\Database\Query\Builder->runSelect()
#11 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(462): Illuminate\Database\Query\Builder->get(Array)
#12 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(446): Illuminate\Database\Eloquent\Builder->getModels(Array)
#13 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Concerns\BuildsQueries.php(75): Illuminate\Database\Eloquent\Builder->get(Array)
#14 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(391): Illuminate\Database\Eloquent\Builder->first(Array)
#15 C:\Webserver\Websites\www.somedomain.com\webroot\app\Http\Controllers\Webshop\HomeController.php(268): Illuminate\Database\Eloquent\Builder->firstOrFail()
#16 [internal function]: App\Http\Controllers\Webshop\HomeController->showArticleDetail('BOSAL-287-273-1...')
#17 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(55): call_user_func_array(Array, Array)
#18 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(44): Illuminate\Routing\Controller->callAction('showArticleDeta...', Array)
#19 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Route.php(203): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\Webshop\HomeController), 'showArticleDeta...')
#20 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Route.php(160): Illuminate\Routing\Route->runController()
#21 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Router.php(574): Illuminate\Routing\Route->run()
#22 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#23 C:\Webserver\Websites\www.somedomain.com\webroot\app\Http\Middleware\Localization.php(43): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#24 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): App\Http\Middleware\Localization->handle(Object(Illuminate\Http\Request), Object(Closure))
#25 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#27 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#28 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(65): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#31 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#33 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 C:\Webserver\Websites\www.somedomain.com\webroot\app\Http\Middleware\ConfigureBugsnap.php(36): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#36 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): App\Http\Middleware\ConfigureBugsnap->handle(Object(Illuminate\Http\Request), Object(Closure))
#37 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#39 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#40 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#41 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#42 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#43 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#44 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#45 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#46 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#47 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#48 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Router.php(576): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#49 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Router.php(535): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#50 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Router.php(513): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#51 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#52 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#53 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\spatie\laravel-robots-middleware\src\RobotsMiddleware.php(14): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#54 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Spatie\RobotsMiddleware\RobotsMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#55 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#56 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#57 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#58 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#59 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#60 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#61 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#62 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#63 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#64 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#65 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#66 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(148): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#67 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#68 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#69 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#70 C:\Webserver\Websites\www.somedomain.com\webroot\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#71 C:\Webserver\Websites\www.somedomain.com\webroot\public\index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#72 {main}

The error line is once again on line 245 of ConnectionFactory from laravel/framework. This line is the return new MySQLConnector; line from the function below:
/**
 * Create a connector instance based on the configuration.
 *
 * @param  array  $config
 * @return \Illuminate\Database\Connectors\ConnectorInterface
 *
 * @throws \InvalidArgumentException
 */
public function createConnector(array $config)
{
    if (! isset($config['driver'])) {
        throw new InvalidArgumentException('A driver must be specified.');
    }

    if ($this->container->bound($key = "db.connector.{$config['driver']}")) {
        return $this->container->make($key);
    }

    switch ($config['driver']) {
        case 'mysql':
            return new MySqlConnector;
        case 'pgsql':
            return new PostgresConnector;
        case 'sqlite':
            return new SQLiteConnector;
        case 'sqlsrv':
            return new SqlServerConnector;
    }

    throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]");
}

The class MySqlConnector extends the class Connector. The first few lines of Connecter are:
<?php

namespace Illuminate\Database\Connectors;

use PDO;
use Exception;
use Illuminate\Support\Arr;
use Doctrine\DBAL\Driver\PDOConnection;
use Illuminate\Database\DetectsLostConnections;

class Connector
{
    use DetectsLostConnections;

    /**
     * The default PDO connection options.
     *
     * @var array
     */
    protected $options = [
        PDO::ATTR_CASE => PDO::CASE_NATURAL,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
        PDO::ATTR_STRINGIFY_FETCHES => false,
        PDO::ATTR_EMULATE_PREPARES => false,
    ];

It seems like PDO::ATTR_CASE should be set. Or maybe PDO::CASE_NATURAL is also not set? I'm not totally understanding what exactly happens, but somewhere in the creation of a new MySqlConnecter object, or the creation of the underlying Connector it returns the error that this is not set. First i thought it had to do with some of the functions in the class. But seeing that the Trace stops at the creation means that the error can't really come from any of the functions.
So something has to go wrong in using the PDO class i think? Connecter.php also has the following line at the start: 'use Doctrine\DBAL\Driver\PDOConnection;' which extends PDO as well.
Once this happens every further request for each user gives back the same error with stack trace until we restart Apache, this i don't understand at all. It seems like it could happen if somehow the PDO file was not available but i'm unsure why it keeps happening then and why a restart of Apache solves it.
Below are the subquestions that might help solve the issue:

*

*What causes this error to show up?

*If the above can't be easily answered, what can i do to get better understand this issue? It has only rarely occured on our live environment, so we have not had the chance to just put dd's everywhere to go through it step by step. And had to reach for the quickfix everytime which is just restarting Apache.

*Why does every request after the initial failure fail as well with the same error?

A: Our last try we restarted MySQL Server, as well as Apache. (in that order) That seemed to have solved the issue. Just in case we did reboot the server that evening as well.
This solved it for us, but if someone has a better answer with some actual knowledge about what causes the issue i hope they share their knowledge!
Edit: still not fixed, seems to be a temporary fix.

A: Three suggestions here so far:

*

*make sure your database config is set up correctly and persists this way (thus nothing changes in the variables being read on the server side... not only from the .env file). This may have something to do with some kind of conflict between cached and current database settings. Have a detailed look;

*make sure your php version suits the requirements of laravel 5.4, because that type of error may easily be caused by unexisting syntax in the current php version that's being used somewhere in the background at some given point, from which on the backside server work is being corrupted;

*This might as well have something to do with the availability of your MySQL PDO driver for the php version you're using, so given function pieces regarding the stuff inside the PDO classes are not accessible. And this sounds most reasonable to me, so you could dig up deeper in that matter. Focus on certain PHP being used and settings around the PDO modules.

Furthermore, a serverside configuration error (like with apache or the server administration) should be concerned as false input is likely to be passed to basic laravel layers and cause unexpected behavior. Unfortunately the stack trace and the information around the error are insufficient to diagnose the issue precisely. Keep me tuned though, it seems interesting.


text:
Q: Bluetooth Headset's microphone recognized as keyboard I have a fresh install of Ubuntu 20.04. I'm connecting my bluetooth headset, which works perfectly on the old laptop with 18.04, and it seems to be recognized as a keyboard. I also tried with my colleagues' headsets, always bluetooth, but the problem persists.
The audio is fine, but the microphone is not working.
This is the log:
Aug  3 10:05:46 mob-agabellini bluetoothd[773]: /org/bluez/hci0/dev_00_6A_8E_16_D1_34/sep1/fd1: fd(38) ready
Aug  3 10:05:46 mob-agabellini rtkit-daemon[1062]: Supervising 14 threads of 2 processes of 2 users.
Aug  3 10:05:46 mob-agabellini rtkit-daemon[1062]: Successfully made thread 6108 of process 1743 owned by '1000' RT at priority 5.
Aug  3 10:05:46 mob-agabellini rtkit-daemon[1062]: Supervising 15 threads of 2 processes of 2 users.
Aug  3 10:05:47 mob-agabellini kernel: [  746.539326] input: BH-M9 (AVRCP) as /devices/virtual/input/input25
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) config/udev: Adding input device BH-M9 (AVRCP) (/dev/input/event19)
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (**) BH-M9 (AVRCP): Applying InputClass "libinput keyboard catchall"
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) Using input driver 'libinput' for 'BH-M9 (AVRCP)'
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1025]: (II) config/udev: Adding input device BH-M9 (AVRCP) (/dev/input/event19)
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1025]: (**) BH-M9 (AVRCP): Applying InputClass "libinput keyboard catchall"
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1025]: (II) Using input driver 'libinput' for 'BH-M9 (AVRCP)'
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) systemd-logind: got fd for /dev/input/event19 13:83 fd 94 paused 0
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (**) BH-M9 (AVRCP): always reports core events
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (**) Option "Device" "/dev/input/event19"
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (**) Option "_source" "server/udev"
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) event19 - BH-M9 (AVRCP): is tagged by udev as: Keyboard
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) event19 - BH-M9 (AVRCP): device is a keyboard
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) event19 - BH-M9 (AVRCP): device removed
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (**) Option "config_info" "udev:/sys/devices/virtual/input/input25/event19"
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) XINPUT: Adding extended input device "BH-M9 (AVRCP)" (type: KEYBOARD, id 21)
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (**) Option "xkb_model" "pc105"
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (**) Option "xkb_layout" "it"
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (WW) Option "xkb_variant" requires a string value
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (WW) Option "xkb_options" requires a string value
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1025]: (II) systemd-logind: got fd for /dev/input/event19 13:83 fd 30 paused 1
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1025]: (II) systemd-logind: releasing fd for 13:83
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) event19 - BH-M9 (AVRCP): is tagged by udev as: Keyboard
Aug  3 10:05:47 mob-agabellini /usr/lib/gdm3/gdm-x-session[1837]: (II) event19 - BH-M9 (AVRCP): device is a keyboard
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 31 with keysym 31 (keycode a).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 32 with keysym 32 (keycode b).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 33 with keysym 33 (keycode c).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 34 with keysym 34 (keycode d).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 35 with keysym 35 (keycode e).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 38 with keysym 38 (keycode 11).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 39 with keysym 39 (keycode 12).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 36 with keysym 36 (keycode f).
Aug  3 10:05:47 mob-agabellini gnome-shell[2048]: Window manager warning: Overwriting existing binding of keysym 37 with keysym 37 (keycode 10).

Is there anything I can do? Is it a possible bug?
Thank you,
Andrew

redpajama_set_name: RedPajamaStackExchange


text:
Q: Overlining text in listing environment without changing the font In short, I would like to place a line over some characters in a listing environment.
I am aware of this answer, but am trying to achieve something a bit different.
The following:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{%
    escapeinside={(*}{*)},%
}
\begin{document}
    \begin{lstlisting}[basicstyle=\ttfamily,%
                       language=Java,%
                       keywordstyle = \color{blue}]
        class new (*$\overline{new}$*)
    \end{lstlisting}
\end{document}

produces:

What can I do to make sure listing treats the overlined "new" as a keyword and apply the keyword style to it?
I would be accepting a solution that uses minted if it exists.


text:
Q: Implement XOR in terms of ADD, SUB, AND and branch on equal / not-equal? I had an interview question about implementing XOR in terms of ADD/SUB and branches:

Implement Xor operation between two numbers using the following commands only:

*

*Add

*Sub

*Branch if equal

*Branch if not equal

*And

You can use registers r3 and r4 as extra space. Assume that register r1 stores the first number and r2 stores the second number

A: Since a + b can be expanded to (a ^ b) + ((a & b) << 1), if +, -, &-operators are available, the following holds:
a ^ b == a + b - (a & b) - (a & b).
In fact, gcc 8.2.1 optimizes the following c-function
unsigned foo(unsigned a, unsigned b)
{
   return a + b - (a & b) - (a & b);
}

to the following x86-64 assembly with -O3:
foo:
    movl    %edi, %eax
    xorl    %esi, %eax
    ret

Consequently, neither of the branch-instructions are required, nor more than three registers (following is pseudo-assembly):
$r1 = a          //first argument
$r2 = b          //second argument
$r3 = $r1 & $r2  //one temp register is enough
$r1 = $r1 + $r2
$r1 = $r1 - $r3
$r1 = $r1 - $r3  //$r1 is the return value

A: With SUB you can get NOT
~a = ~0 - a

or if two's complement is used
~a = -a - 1

From AND and NOT you get NAND which is functional complete, thus you can do any logic functions easily. There are various ways to get XOR from those. One of them is

t = a NAND b
a ^ b = (a NAND t) NAND (b NAND t)

Alternatively

a ^ b = (b NAND ~a) NAND (a NAND ~b)

which can be translated to something like this
r3 = ~0 - r1  # ~a
r4 = r2 & r3  # b & ~a
r4 = ~r4      # b NAND ~a
r2 = ~0 - r2  # ~b
r2 = r2 & r1  # a & ~b
r2 = ~r2      # a NAND ~b
r1 = r2 & r4
r1 = ~r1      # a ^ b

but it won't be as efficient as utilizing the adder's property directly
You can find many other ways from exclusive or's equivalences
a ^ b = (a | b) & ~(a & b) = ~(~a & ~b) & ~(a & b)
a ^ b = ~(a & b) & (a | b) = ~(a & b) & ~(~a & ~b)

See Is XOR a combination of AND and NOT operators?
Related: XOR from only OR and AND


text:
Q: Firebase Cloud Messaging: Send notification with profile photo Starting with iOS 15 I have noticed more and more chat apps sending push notifications in a new style. Instead of showing a regular notification with a square profile picture on the right side, the image is shown as a circle on the left side, replacing the app icon and the app icon is in the lower right corner of the image.

I first noticed this with messages and assumed it was just something Apple could do but now Snapchat and WhatsApp have those notifications as well. Today TikTok stated sending notifications in the same way and I'm determined to find out how I can do this in my apps. Although I have seen a few articles talking about apps that have these notifications, I have not found any information on how to implement them. Is this exclusive to certain apps? Also, if this is available for all apps, is there a way to send these trough Firebase Cloud Messaging?


text:
Q: Merging partially overlapping sheets in Excel while keeping columns separate? I have sheets with partially overlapping records for each month:
Person      Jan
Alice       $20
Bob         $10
Charlie     $30

and
 Person     Feb
 Alice      $15
 Charlie    $10
 Dave       $40

I want to combine them into a single sheet like so:
 Person     Jan    Feb
 Alice      $20    $15
 Bob        $10    $0
 Charlie    $30    $10
 Dave       $0     $40

Is there a convenient way to do this in Excel? I've looked into the consolidate feature, but that seems to combine the columns, which I don't want.

A: You can use a pivot table with multiple ranges:  https://support.office.com/en-us/article/consolidate-multiple-worksheets-into-one-pivottable-3ae257d2-ca94-49ff-a481-e9fc8adeeeb5
If you right-click the pivot table and select PivotTable Options, you can customise it to hide bits you don't want and set 0 value for empty cells.

Hide headings and total rows you don't want to see:

Manually hide the first row (ie Sum of Value).
Then select the figure columns and format to display with $.
The only thing I couldn't do was edit to add "Person" heading, if you keep this as a pivot table which you can update. But you could just select your formatted pivot table and copy and paste to a new sheet and it is no longer a pivot table, just text.


text:
Q: Multiple associations in same table with multiple potential foreign keys I want to do some seemingly simple associations:
class OrderWizard < ActiveRecord::Base
  belongs_to :buyer_wizard,     :class_name => MiniWizard.name
  belongs_to :seller_wizard,    :class_name => MiniWizard.name
end

class MiniWizard < ActiveRecord::Base
   has_one :order_wizard, :foreign_key = '????' # Could be buyer_wizard_id or seller_wizard_id

   def is_buyer_wizard?
     ??
   end

   def is_seller_wizard?
     ??
   end
end

*

*An associated MiniWizard needs to know who is connecting to it.  Assuming has_many :through best way to go?  If so, how would the models look?

*A MiniWizard instance needs to know if it's a buyer or seller.  Stuck on how to do this.

A: You actually probably want two associations, for example, something like this might represent the relationships more accurately:
class MiniWizard < ActiveRecord::Base
   has_one :bought_order_wizard, :foreign_key => 'buyer_wizard_id', :class_name => 'MiniWizard'
   has_one :sold_order_wizard, :foreign_key => 'seller_wizard_id', :class_name => 'MiniWizard'

  def order_wizard
    bought_order_wizard || sold_order_wizard
  end

  def is_buyer_wizard?
    !bought_order_wizard.nil?
  end

  def is_seller_wizard?
    !sold_order_wizard.nil?
  end
end


text:
Q: Launch Twitter with selected user from wp8 application I am trying to launch twitter with selected user from my WP8 application and it does not work so good.
In my click event for the button that will do the job the code looks like this:
private void Button_Click_3(object sender, System.Windows.RoutedEventArgs e)
{
   Windows.System.Launcher.LaunchUriAsync(new Uri("twitter:@user"));
}

When I click the button I get a message that asks if I want to search the app in the store but i have Twitter installed so what is happening.

A: Are you sure that the twitter app supports app to app coms? this might be your issue ill look into it later


text:
Q: How to detect the end of a get sequence in a proxy object? In order to avoid error when accessing deeply nested properties, I wrote a proxy-returning function:
const safe_access = obj =>
  new Proxy(obj, {
    get: (o, k) =>
      o[k] == null
        ? safe_access({})
        : typeof o[k] === 'object'
          ? safe_access(o[k])
          : o[k] });

Here's an example:
const a = safe_access({});
a.x.y.z; // no TypeError

However in its current form safe_access is unable to tell when it has reached the end of the path. Meaning that it cannot return undefined to signify that the property truly doesn't exist. This also means that you cannot have default values:
const a = safe_access({});
a.x.y.z || 42; // not 42

const {x: {y: {z = 42}}} = a;
z; // not 42

How can my proxy object detect the end of a property lookup?

A: This answer more or less applies here, for the same reasons.
You can't detect the end of an access chain because nothing makes it any different from the preceding accesses. At runtime, the following code is effectively identical to let r = a.x.y.z.
let r = a;
{
    r = r.x;
    r = r.y;
    r = r.z
}

If you actually want to use this sort of safe navigation in code you're writing, the best is to use the optional chaining (?.) and nullish coalescing (??) operators added to the Javascript standard in 2020. They provide a neater, less confusing way to do this sort of thing, and are supported by all modern browsers.
let r = a?.x?.y?.z ?? 42;

If you need to support legacy browsers, you can get these operators from these two Babel plugins: ([1], [2]).

However, if you really want to implement "safe" access yourself, there are a few tricks you can use to get around this.
One trick, that probably requires the least additional work is to reserve one name to indicate the end of the safe access chain. (I've done something similar in Python in the past.)
function safe_access(value) {
    let obj = (typeof(value) === 'object') ? value : {};

    return new Proxy(obj, {
        value: value,
        get: function(target, property) {
            if (property === "$")
                return this.value;
            else
                return safe_access(target[property]);
        }
    });
}

let a = {'x': {'y': 123}};
// a.x.y is a proxy object
a.x.y.$ === 123
a.x.y.z.$ === undefined

Another trick is detailed in this blog post.

A: An interesting option is to work with Promises. Comlink has an interesting usage of this.
Expanding on jirassimok's answer, if everything is async, then the termination token becomes "then".
function safe_access(value) {
    let obj = (typeof value === 'object') ? value : {};

    return new Proxy(obj, {
        value: value,
        get: function(target, property) {
            if (property === "then")
                return this.value;
            else
                return safe_access(target[property]);
        }
    });
}

async function main() {
  let a = safe_access({'x': {'y': 123}});
  // a.x.y is a proxy object
  (await a.x.y) === 123
  (await a.x.y.z) === undefined
}

main();

This wasn't immediately obvious to me, as I've been using async/await for a long time now.


text:
Q: Why doesnt the onClickListener do anything? Following a tutorial, I did set up onClick-Listeners before.
Now I am trying to make a simple app for listening to one stream, but my onClickListener doesn't do anything.
I created a new very simple app in android studio 3.3.2 to find out what is happening. I guess it is something very basic.
package com.example.musicplay;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the content of the activity to use the activity_main.xml layout file
        setContentView(R.layout.activity_main);

        final Button play_button = findViewById(R.id.play_button);
        Log.i("Button found","this one: " + play_button.getText());

        play_button.setOnClickListener(new View.OnClickListener() {

            // The code in this method will be executed when the play button is clicked on.
            @Override
            public void onClick(View view) {

                Toast.makeText(MainActivity.this, "A click happened!", Toast.LENGTH_SHORT).show();

            }
        });

        setContentView(R.layout.activity_main);
    }
}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/play_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/play_button"/>

</LinearLayout>

The toast message should appear when the button is clicked, but nothing happens.

A: You are calling setContentView twice.  This will replace the view hierarchy set up by the first call.  Remove the second call to setContentView.


text:
Q: Change installation directory of XQuartz on Mountain Lion Mountain Lion doesn't include X11 any more, and XQuartz is the substitute.  Having installed it, I see that XQuartz 2.7.2 installs in the non-standard (though commonly used) directory /opt.  It also installs symlinks from /usr/X11 to /opt/X11.
I would prefer having XQuartz only use /usr/X11 and not create /opt/X11.
Is there a way to change the installation directory of XQuartz on Mountain Lion?

A: Get the sources and compile it yourself, setting the paths you prefer.


text:
Q: Pass data to server side from Javascript code I'm trying to send data from client-side to server-side (asp.net c#), if you really want to know, I want to send the window.name property.
First I thought about having a asp:HiddenField and on the OnSubmit event have some JS write the value in the hidden field. The only problem is that I can access the hidden field value (according to this) only from PreLoad event to PreRenderComplete event. The project that I'm working on has a lot of code in the OnInit event, and unfortunately I cannot move it and I need to use the window.name value here.
The other ideas that I have is to add a custom HTTP Header windowId or on the OnSubmit event have a JS that appends a parameter to the document.location.href.
I managed to write to the header from JS with the XMLHttpRequest setRequestHeader, but, maybe I did something wrong in my implementation, this generates 2 requests, the first one is the normal, expected one(clicking a button/link ...) and the second is from the XMLHttpRequest. I find this behavior very unnatural. Do you have any sugestions? (see code snippet below). I do not what to use AJAX.
    var oReq = new window.XMLHttpRequest;
    oReq.open('POST', document.location, false);
    oReq.setRequestHeader("windowId", window.name);
    oReq.send(null);

For the OnSubmit hook idea, i haven't spent to much time on it, but i think I have to append the # character before i append my windowId parameter with it's value, so that the page doesn't reload. I might be wrong about this. Any way, I have to remove this from the URL after I take the value, so that the user doesn't see the nasty URL. Do you have any sugestions?
Ok so what are your ideas?
Thank you for reading all my blabbering, and thank you, in advance, for you answers.

A: I would recommend the <asp:HiddenField /> (e.g., <asp:HiddenField ID="hfWindowName" runat="server" />. In OnInit you can still access its value by using Request.Form:
string windowName = Request.Form(hfWindowName.UniqueID);


text:
Q: How to run tests in a django view without affecting the database I am trying to run the functional tests (using Selenium in python/django) directly from the django views by using management.call_command, in order to allow the user to run the test from the web site. The django view is something like:
class MyView():
    def get(self):
        output = call_command('test', 'folder.tests.MyTest')
        # doing ./manage.py test folder.tests.MyTest
        test_result = 'Test result: ' + output
        return something_http_with_test_result

What is the best way to do this in order to do not affect the current user data? MyTest is going to create a lot of object in the database but the user must not see them.
Thank you

A: The best way I found to run it properly is to use os.system :
import os
dir = 'your_absolute_path_to_project'
class MyView:
    def some_func_called():
        os.system(dir + '/manage.py test >' + dir + '/log.txt')

The project and firefox have to have the same owner and results will be in log.txt.


text:
Q: Trying to implement CLLocationManager: Getting compile time error I'm trying to implement a CLLocationManager into my app and I'm getting the following compile time error.
Code in the view controller's viewDidLoad method:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

Errors:
_OBJ_CLASS_$_CLLocationManager," referenced from Obj-c-class-ref in AboutLocationViewController.o

_kCLLocationAccuracyBest," referenced from:
-[AboutLocationViewController viewDidLoad] in AboutLocationViewController.o

Symbol(s)not found for architecture arm7
Collect2: Id returned 1 exit status

A: You probably have not added the CoreLocation.framework inside the Frameworks folder. As a result the linker can't find the CLLocationManager class.


text:
Q: Collada file mirrored when created with qgis2threejs in QGIS 2.18 When I export a Collada file from QGIS 2.18.23 using the amazing QGIS2threejs plugin version 1.4.2, my Collada file comes into Blender and Sketchup with the East West mirrored. This is not the case in the browser or when I export an .obj.
I don't know of a way to fix it in Sketchup or Blender because it would require being both flipped and turned insideout. I know I could use Blender to convert the .obj to a .dae but I need my students who will have QGIS and Sketchup installed but not Blender to be able to export and use a Collada file.
The .dae is a of a lidar derived DEM in MA State Plane Feet.
In QGIS 3 the plugin has been updated and .gltf is the only export option.
An alternative conversion process that results in a .dae would be acceptable.


text:
Q: Does adding an object to a nested field reindex? With nested objects you have an array of objects:
comments: [
   {field1, field2, ..}
]

When you want to add a new object to the comments, does ElasticSearch reindex the whole document?
comments: [
   {field1, field2, ..},
   {newField1, newField2, ...}
]

A: you have two options

*

*either Updating a Whole Document (reindex it) https://www.elastic.co/guide/en/elasticsearch/guide/current/update-doc.html or

*perform partial update https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-updates.html
in above mention both options elasticsearch internally manages the same "retrieve-change-reindex" process


text:
Q: How can I safely create a partition to an already bootable drive I already asked this question on Apple's community forum, right here, so I'll post the answer here if something comes up there first.
This is my problem :
I recently bought an external drive of 500Gb with the intent to use it to store large files that I use on my Mac and to use it as a bootable drive for Windows.
I followed this tutorial to make the drive bootable on Windows 10, everything works well for that part.
Now I want to be able to partition the drive so that I can have 2 parts for Windows (1 part that contains the infos for the boot, 1 that contains Windows) and 1 part that I can use on the Mac side to store files. I thought that I could simple use the partition operation on the Disk Utility app, but the operation is greyed out. I found many answers on forums, but none of them is exactly what I'm looking for. Any idea how I can can achieve it ?
The actual state of the drive :
/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE          IDENTIFIER
   0:     FDisk_partition_scheme                        *500.1 GB   disk2
   1:                 DOS_FAT_32 WINBOOT                 209.7 MB   disk2s1
   2:               Windows_NTFS BOOTCAMP                499.9 GB   disk2s2

Thanks in advance and have a good day !

A: Ok, after spending the afternoon looking how to solve this, I found that the easy way was to create a new partition from Windows' side in exFat format. And since the format exFat is modifiable on Mac, unlike NTFS, I can then erase it and then change the format to whichever I want.


text:
Q: Why does `md5sum` not give the same hash as the Internet does? I want to find the md5 hash of the string "a", but running echo "a" | md5sum gives me another hash than what I get if I search the internet (for example using DuckDuckGo or the first search result I found).
Running echo "a" | md5sum gives me "60b725f10c9c85c70d97880dfe8191b3", but it should be "0cc175b9c0f1b6a831c399e269772661".
If I make a reverse hash lookup for "60b725f10c9c85c70d97880dfe8191b3", I do however get "a".

A: The reason for the hashes being different is that echo includes a newline at the end of the output string to make it pretty. This can be prohibited by the -n flag (if your implementation of echo supports it), or by using another program (like printf):
> echo "a" | md5sum
60b725f10c9c85c70d97880dfe8191b3  -

> echo -n "a" | md5sum
0cc175b9c0f1b6a831c399e269772661  -

> printf "a" | md5sum
0cc175b9c0f1b6a831c399e269772661  -


text:
Q: How do I group a new variable based on a variables first letter? I have a variable that is alphanumeric, ex: A890. I have over 1 million records and all 26 letters of the alphabet are used to start the variable, and I would like to know how to many of these records (the count) start with a given letter. Ideally creating a table would be great. Ex:
A - 2,900
B - 784,090
Etc.

Could anyone please help me with this?

A: Is this something you can use?
x <- c("A1234", "A234", "B7654", "A76768", "C980", "A767", "Z90898")

library(stringr)
table(str_extract(x, "^[A-Z]"))

A B C Z
4 1 1 1

Here you extract the upper-case letter occurring in first position in the string and tabulate the result.

A: Does this answer:
> df <- data.frame(name = c('A123','A2321','B32','B3232','C098','A989','C321','D233','D123','B2132'),
+                  value = round(rnorm(10,100,2),2))
> df %>% group_by(substr(name,1,1)) %>% summarise(occurances = n())
`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 4 x 2
  `substr(name, 1, 1)` occurances
  <chr>                     <int>
1 A                             3
2 B                             3
3 C                             2
4 D                             2
>

A: A dplyr solution
library(dplyr)

df2 <- data.frame(alphanumeric = c(rep("A890", 5), rep("B2011", 8)))

df2 %>%
   mutate(starter = substr(x = alphanumeric, 1, 1)) %>%
   group_by(starter) %>%
   tally

#> # A tibble: 2 x 2
#>   starter     n
#>   <chr>   <int>
#> 1 A           5
#> 2 B           8


text:
Q: Two Dimensional Arrays C++ So I need to be able to read integers from a file into a two dimensional array. The numbers are sorted as follows:
3 3 4 5
6 3 5 6 7 8 9
and so on and so forth.
My issue is I'm not sure how to start because the first number in each row indicates the amount of numbers that are going to be read into array[i][j] where j would equal either 3 or 6. I also don't know how how many rows are going to be in the file to be tested later.

A: As others pointed out you really should use std::vector for this. But if it have to be an array you could either store everything into a vector anyway and copy the content of that vector into an new array afterwards. Or you read the file line by line until the end such that you know the number of rows and then you can allocate and fill an array.
And for the size of the second dimension of this array: it should always be 7, except each and every row starts with 3 (where the size would be 4).


text:
Q: Change in a git commit of a file disappears after merge I was developing in a feature branch. At that moment I'd made some other changes which are already merged into develop branch through PR in github and I needed those changes in my feature branch. So I decided to merge develop branch into my feature branch. I'd deleted some code in a file and committed in the feature branch. After merging develop into the feature branch, I found that the change of deletion code in the commit of the file disappeared and the deleted part was added back due to the merge operation. I would like to ask: under what circumstances does this happen? Thanks!
UPDATED:
I use github to view the history. Here is the example:
This is the history of agent.go at the commit 80d82ee in the feature branch OWL-1697. This is the whole history of this file in feature branch OWL-1697. After the merge operation, the change of 80d82ee for this file disappeared.

A: I would not recommend using GitHub to view commit and file history.  (GitHub may have some nice and/or fancy way to view these, but as a very causal user of GitHub, I do not know of one.  The command line tools have extensive flags, although you must be something of a Git expert to know which to use, and when.)
TL;DR summary of why the merge went wrong
After you work through the text below, pay particular attention to these last few lines of the git log output:
* | | | | | 80d82eef [OWL-1730][common][nqm-mng] Code refactoring
* | | | | | 2438360a [OWL-1667][common][nqm-mng] From `hbs` to `nqm-mng`
| |_|/ / /
|/| | | |
* | | | | b598349a Merge pull request #295 from masato25/OWL-1724

In commit 2438360a, you added some lines, and then in commit 80d82eef, you took them out again.
However, you put the same added lines in via commit d04492d9:
| | * | d04492d9 [OWL-1667][common][nqm-mng] From `hbs` to `nqm-mng`

a bit higher up.  You did this on the same day as the added lines in 2438360a.  You took the lines out, in 80d82eef, much later ... but in a different branch.  In topological order, you took the change out almost immediately after you put it in ... while also leaving the change in a separate branch.  You then brought those into another branch via e1d369d0, which you brought into another branch, and so on until you brought them right back into the branch you thought you had taken them out of.
Viewing the commit graph
If I clone your repository and use git log --all --decorate --oneline --graph to view it, I see this, in part, which includes commit 80d82eef (at the bottom):
* aeecad13 (origin/OWL-1697) [OWL-1730][nqm-mng] Update debug message
* f0797f8e [OWL-1730][nqm-mng] Fix the proble from merge
* 5aaba93b [OWL-1730][nqm-mng] Drop gin's "gopkg.in" paths

[mass snip]

* | | | d2d4debd [OWL-1730][nqm-mng] Tests
* | | | e1037c28 [OWL-1730][nqm-mng] Queue service
* | | |   a847d783 Merge branch 'OWL-1677' into OWL-1697
|\ \ \ \
| * \ \ \   ea916618 Merge branch 'develop' into OWL-1677
| |\ \ \ \
| | |/ / /
| * | | | 056a7442 [OWL-1677] Refactoring testing to usage of Ginkgo
| * | | | 800c3f09 [OWL-1677] Add utilities for testing by Ginkgo framework
| * | | |   85deb914 Merge branch 'develop' into OWL-1677
| |\ \ \ \
| * | | | | c830da0f [OWL-1677] Fix tests
| * | | | | 14d8571c [OWL-1677] Refactoring test to Ginkgo
| * | | | | 8538306f [OWL-1677] Re-write testing to Ginkgo framework
* | | | | | 906741cd [OWL-1730][nqm-mng] Rename types and methods
* | | | | | 80d82eef [OWL-1730][common][nqm-mng] Code refactoring

We can see that the commit is in fact still there, not deleted by the merge.
Finding commits that affect a file: --full-history
Now, the file you care about here is named modules/nqm-mng/restful/agent.go in commit 80d82eef.  As we can see from the --decorate otuput, a branch name that leads here is origin/OWL-1697.  The commits that modify this particular file, however, are a bit tricky to find.
The first bit of magic to know is to use --full-history when restricting git log to path names (I suspect there is no way to get GitHub to do this).  The reason is that if a merge has undone something you wanted done, Git's "history simplification", which removes commits that don't contribute to the final version of the source, makes it impossible to find out which merge removed that contribution.
The second bit of magic to know is that when looking at merge commits, we may want -m to make Git "split" the merge into the two halves.
I also use --topo-order to force Git to show commits in a topologically sensible order (usually not necessary, but generally a good idea here).
Who did what
We might take a look at precisely what 80d82eef does to the file of interest at this point:
$ git show 80d82eef -- modules/nqm-mng/restful/agent.go
commit 80d82eef9606800c094858ac0d60f27ef9ad1307
Author: chyeh <chyeh@cepave.com>
Date:   Fri May 19 11:34:09 2017 +0800

    [OWL-1730][common][nqm-mng] Code refactoring

    Move some code from `common/` to `modules/nqm-mng/` as the preparation
    of the following development.

diff --git a/modules/nqm-mng/restful/agent.go b/modules/nqm-mng/restful/agent.go
index 3ba34901..f21afd05 100644
--- a/modules/nqm-mng/restful/agent.go
+++ b/modules/nqm-mng/restful/agent.go
@@ -124,10 +124,3 @@ func clearCachedTargetsOfAgentById(
        r := commonNqmDb.DeleteCachedTargetsOfAgentById(q.AgentID)
        return mvc.JsonOutputOrNotFound(r)
 }
-
-func nqmAgentHeartbeat(
-       req *commonNqmModel.AgentHeartbeatRequest,
-) mvc.OutputBody {
-       r := commonNqmDb.AgentHeartbeat(req)
-       return mvc.JsonOutputBody(r)
-}

Now we can run this rather long command (I've broken it into two lines for display purposes):
$ git log --full-history -m -p --topo-order \
    origin/OWL-1697 -- modules/nqm-mng/restful/agent.go

Note the three extra options (full history, merge split, and topological order).
The output is long so I won't quote it all, but the commits displayed are:

*

*f0797f8e1e2e5a41db30225f4e72dc987b055ac8, in which you re-delete the lines brought back by the failed merge;

*7e00e309f0ed5750f6b7b052e77431ec4797d601 (vs its first parent d2d4debd), which re-adds the lines you did not want);

*648a324e1333814968a09e4b0277fc0774b4fce6 (vs its first parent 447ac685), which affects just an import line;

*ccbad82029c50040250a48180caeacfcc57044bd (vs its second parent da0dcde6), which also re-adds the lines you did not want;

*dfa34ab98170d62e1bb6d624c2d09f9e4e7e0b57 (vs its second parent 5571dc2c);

*219347a6f1649ccfee8e69b481e3166d8d310fe0 (vs its second parent 1a60e4aa);

*b11d41be75700c450280a4a5e0edb12381045303 (vs its second parent 28176808);

*8f5a0e242fd7c7ded6cdcc4517c33c793b96f8ea (vs its second parent 5178acdb);

*e1d369d06a49846f39661642bdfb7c0c81a86b8e (vs its first parent 8b1d4f0f);

*d04492d986fdf1257cb93a5524f2501e767bd564: this is an ordinary commit that you made on 2 May, in which you added the lines you do not want;

*80d82eef9606800c094858ac0d60f27ef9ad1307: this is the ordinary commit you made on 19 May, in which you deleted the lines you do not want;

*2438360a653e5c158b366f313bf771db4f294147: this is an ordinary commit that you made on 2 May, in which you added the lines you do not want;

*and then numerous irrelevant commits that do not affect the lines you care about, all predating these changes.

Putting these in context
Depending on how you do your merges, the "most interesting" ones tend to be the first parent ones.  This is the case above.
It's also a good idea to look at the merge base of the merge that brought back the changes you did not want.  To do this, we need to run git merge-base on the two hash IDs of the two parents of that merge.  As a reminder, that merge's hash ID is 7e00e309 (or 7e00e309f0ed5750f6b7b052e77431ec4797d601 in full).  So let's run git merge-base on the two parents:
$ git merge-base --all 7e00e309^1 7e00e309^2
b598349a0ba6d6901ef812440746e2dc633c4cdc

Commits "below" this point tend not to be of interest.
We can now use:
git log --decorate --oneline --graph origin/OWL-1697

to view all of these in their complete context, although matching up the hash IDs is quite difficult and painful.  Or, we can run:
git log --decorate --oneline --graph origin/OWL-1697 \
    --full-history -- modules/nqm-mng/restful/agent.go

to strip this display down to just commits that touch that file, when compared to any of their parent commits.  The result is still quite long, but is now follow-able.  Let's follow it down to the merge base, i.e., the commit starting with b598349a:
* f0797f8e [OWL-1730][nqm-mng] Fix the proble from merge
*   7e00e309 Merge branch 'develop' into OWL-1697
|\
| *   648a324e Merge pull request #306 from Cepave/OWL-1771
| |\
| | * 4d722f8d [OWL-1771] Change `gin`'s import paths
| * |   447ac685 Merge branch 'roby-testing' into develop
| |\ \
| * | | ee1daba9 Merge pull request #305 from masato25/OWL-1674_ma
| | |/
| |/|
| * |   ccbad820 Merge pull request #303 from masato25/OWL-1740
| |\ \
| * \ \   69a9ee6e Merge pull request #302 from masato25/OWL-1765
| |\ \ \
| | * \ \   9e9d1a55 Merge branch 'develop' into OWL-1765
| | |\ \ \
| | |/ / /
| |/| / /
| | |/ /
| * | |   dfa34ab9 Merge pull request #300 from masato25/OWL-1740
| |\ \ \
| | |/ /
| * | |   219347a6 Merge pull request #301 from masato25/OWL-1755
| |\ \ \
| | |/ /
| * | |   b11d41be Merge pull request #299 from masato25/OWL-1755
| |\ \ \
| | |/ /
| | | /
| | |/
| |/|
| * |   8f5a0e24 Merge pull request #298 from humorless/OWL-1644-c
| |\ \
| * \ \   e1d369d0 Merge pull request #286 from Cepave/OWL-1667
| |\ \ \
| | |/ /
| |/| |
| | * | d04492d9 [OWL-1667][common][nqm-mng] From `hbs` to `nqm-mng`
| * | |   8b1d4f0f Merge pull request #297 from hitripod/develop
| |\ \ \
| * | | | 05e45dc8 Merge pull request #296 from masato25/OWL-1765
| | |_|/
| |/| |
* | | |   a847d783 Merge branch 'OWL-1677' into OWL-1697
|\ \ \ \
| * \ \ \   ea916618 Merge branch 'develop' into OWL-1677
| |\ \ \ \
| | |/ / /
| |\ \ \ \
| | |/ / /
| * | | |   85deb914 Merge branch 'develop' into OWL-1677
| |\ \ \ \
* | | | | | 80d82eef [OWL-1730][common][nqm-mng] Code refactoring
* | | | | | 2438360a [OWL-1667][common][nqm-mng] From `hbs` to `nqm-mng`
| |_|/ / /
|/| | | |
* | | | | b598349a Merge pull request #295 from masato25/OWL-1724
| |_|/ /
[snip]

This output contains all the reasons why your merge went wrong.  As far as Git is concerned, adding and then immediately removing those lines, in commits 2438360a and 80d82eef, was quite irrelevant.  What mattered was the independent and never-undone adding of those same lines in d04492d9.  That's the source of the change brought in by a series of merges, and ultimately brought in by merge 7e00e309.  All Git could tell is that those lines were supposed to be there, because they were added by one "side" of the merge, and the other side did nothing to the file!

A: Since your file changes which you made in feature branch is not yet committed, while merging you probably stashed them. so while merge in operation those changes added back.


text:
Q: Strange and unknown error while compiling QT code I don't know why I am getting error or these statements. The same code works fine when I compile it for x86_64 system but when I changed target to Beaglebone Black and switched to angstrom tool chain the QTcreator started giving error in these lines.
//connect(process, &QProcess::readyReadStandardError, [=]{
ui->textBrowser->append(process->readAllStandardError());
});
connect(process, &QProcess::readyReadStandardOutput, [=]{
ui->textBrowser->append(process->readAllStandardOutput());
});

Errors are for the expression "[=]". Infact I don't know why this error is coming. Could this be related to version, bcoz BBB is have qt4-embedded. Any help would be appreciated.

A: The syntax for connecting signal to c++11 lambda has been added to Qt 5. Since previous version (Qt4) doesn't define the right signature for connect(), you can't use it. You should transform your code to match the correct syntax:
connect(process, SIGNAL(readyReadStandardError()), receiver, SLOT(yourCustomSlot()) );

With a slot declared as follow:
class MyReceiverClass {

slots:
    void yourCustomSlot() {
        ui->textBrowser->append(process->readAllStandardOutput());
    }
};


text:
Q: Babel hyphenation not working I am having trouble using the babel (2016/04/23 3.9r) package. For some reason, soft babelhyphen or the "- shorthand only add a breaking opportunity but no hyphen is displayed in case a word is broken. This is undesired and results in the following output. Am I doing something wrong, is this a decision by design or just a bug in the update-to-date babel/MiKTeX?
Update
After reducing the parbox space, I receive the following output. The "-shorthand is working but babelhyphen not.

\documentclass{article}

\usepackage[ngerman]{babel}

\begin{document}

    \bigskip
    \parbox{1em}{$n$\babelhyphen{soft}dimensional}

    \bigskip
    \parbox{1em}{$n$"-dimensional}

    \bigskip
    \parbox{1em}{$n$\-dimensional}

    \bigskip
    \parbox{1em}{$n$\babelhyphen{nobreak}dimensional}

\end{document}

First Version

MWE
\documentclass{article}

\usepackage[ngerman]{babel}

\begin{document}

    \bigskip
    \parbox{3em}{n\babelhyphen{soft}dimensional}

    \bigskip
    \parbox{3em}{n"-dimensional}

    \bigskip
    \parbox{3em}{n\-dimensional}

    \bigskip
    \parbox{3em}{n\babelhyphen{nobreak}dimensional}

\end{document}


text:
Q: Why "using sleep()" makes the result of the same code being different? I wrote a program that create a string array which contains random strings, and the rand_str() is to make a string of 20 length long. When I use sleep(), the result is exactly what I want. However, I think sleep() shouldn't appear in my code. Removing sleep(), the random strings created are totally different. I am really confused about this. Could someone help to explain why this happens?
#include <iostream>
#include <string.h>
#include <random>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <stdlib.h>
#include <array>
#define show(w) for(auto val:w){cout<<val<< " ";}cout<<endl;
using namespace std;

char *rand_str(char *str,const int len);

int main(){
    const int len = 10;
    char *a[len];
    string c[len];
    array<string,len> ar;char b[len][21];
    for (int i = 0; i < len; ++i) {
        ar[i] = rand_str(b[i], 21);
        fflush(stdin);
//      Sleep(1000);
    }
    show(ar);
    return 0;
}
char *rand_str(char *str,const int len){
    srand(time(NULL));
    int i;
    for(i=0;i<len;++i)
    {
        switch((rand()%3))
        {
            case 1:
                str[i]='A'+rand()%26;
                break;
            case 2:
                str[i]='a'+rand()%26;
                break;
            default:
                str[i]='0'+rand()%10;
                break;
        }
    }
    str[len - 1]='\0';
    return str;
}

Not using sleep() :

Using sleep() :

A: The program you've written executes quickly enough that it is extremely likely that every single loop of rand_str will occur in the span of a single second. This is important because your method for generating strings involves calls to time, because time returns a time_t object, which is specified in the C-standard as:

The encoding of calendar time in time_t is unspecified, but most systems conform to POSIX specification and return a value of integral type holding the number of seconds since the Epoch. Implementations in which time_t is a 32-bit signed integer (many historical implementations) fail in the year 2038.
—time, C++ Reference

So if the entire program executes in under a second, every single call to time in that span will return the same value, seeding your random numbers with the same value each time, and producing identical output on each loop. Conversely, when you Sleep for 1000 milliseconds (1 second), you nearly guarantee that each execution will have a different seed, and thus different output.
In general, you should only seed the random numbers once, at the start of your program. Alternatively, you should consider leaning how to use the <random> library, since it contains far better mechanisms for generating Random Numbers.

A: rand_str most likely has some kind of time-dependence associated with it. The one you present has a seed set to srand(time(NULL)); so it certainly does.
And Sleep(1000) (which will be a minimum sleep of 1000 units) is enough to change the result.
Removing the sleep call and your program execution is fast enough for the time-dependence of rand_str to be unobservable.

A: Your rand_str function re-seeds the PRNG on every single call, and it does so using the current time in seconds. It then pulls out the "first" number in that sequence and returns it.
That means you only get a different pseudo-random sequence for function calls for different seconds in time. If you make multiple function calls within the same second, you keep re-seeding with the same seed, which results in the same sequence, and the first number in that same sequence is the same number always returned. That's why the sleep makes a difference: it changes the seed.
You should only seed once, at the start of your program, then just use the resulting sequence as needed.
Incidentally, this entire methodology is outdated. Since C++11, we do random numbers like this.

A: This is most likely due to the fact that computers cannot produce truly random numbers.
Hence, there exists a concept called a seed. And the most common seed for pseudo-random number generation is the time.
Making your program wait a bit will make it run the random generator with a different seed.


text:
Q: webClient Bot - Multithreading I'm making bot for online game.
It works, but it is singlethread application.
I want to make it multithread application.
I know how background worker works.
To all my tasks I use one WebClient with added Cookie support.
My for example needs to open one page, wait 10 min and do next instruction.
I also want to be able to stop bot at any time.
Do I have to pass my WebClient object to background worker to work with?
What is the best way to update controls on my Form?
I have one class that has all the values that I want to show on Main Form.
Should I fire some event when property changes? If yes, can you give me example?

UPDATE:
This is my Special WebClient:
using System;
using System.Net;

namespace Game_Bot
{
    class WebClientEx : WebClient
    {
        public CookieContainer CookieContainer { get; private set; }

        public WebClientEx()
        {
            CookieContainer = new CookieContainer();
        }

        public void ClearCookies()
        {
            CookieContainer = new CookieContainer();
        }

        protected override WebRequest GetWebRequest(Uri address)
        {

            var request = base.GetWebRequest(address);
            if (request is HttpWebRequest)
            {
                (request as HttpWebRequest).CookieContainer = CookieContainer;
            }
            return request;
        }
    }

}

Is this good way of updating UI? Or is there any beter?
    public void SetStatus(string status)
    {
        if (TransferLeftLabel.Dispatcher.Thread == Thread.CurrentThread)
        {
            TransferLeftLabel.Text = status;
        }
        else
        {
            TransferLeftLabel.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
            (Action)(() => {  SetStatus(string status); }));
        }
    }

A: This is how I would do it:
First:
I like to manage threads manually instead of using the BackgroundWorker control when making multithreads applications like the one you want to modify.
To start a new thread, it is as simple as:
public void SomeMethod() {
    var thread = new Thread(MyMethod);
    thread.Start(); //Will start the method
}

public void MyMethod() {
    //Do whatever you want inside the thread here
}

You can get as many Thread instances as you want, store them in a list, and manage how you prefer. However, it isn't true that the more threads the better. Search in Google.
About opening pages and keeping Cookies.
I think you could have an instance of a class in your Form, or where you have the logic (some place that threads can access), (let's name it WebUtils) with a method like: GoToUrl(<url here>) or something like that, and a CookieCollection as a field in that class to keep cookies.
Something you should take in count:
When calling GoToUrl, you might need to do lock when accessing the cookies variable, to avoid inconsistency.
About updating controls:
You can create an event inside the class WebUtils, and everytime the page is accessed you can fire this event. Before starting the threads, you must subscribe to the event in your Form, you can do something similar with lock when updating/accessing/modifying controls in your form.
Now, how to avoid the message Control ____ accessed from a thread other than the thread it was created...?
Here's an example:
If you want to modify property Text of the control textBox1, instead of just doing:
textBox1.Text = "Ey, I accessed the site
you can do:
MethodInvoker m = () => { textBox1.Text = "Ey, I accessed the site" };
if (InvokeRequired)
    BeginInvoke(m);
else
    m.Invoke()

Make sure all the modifications are done like that.
This is just an overview. I'm not a thread expert.
Here is good reference about threadings in general: Threading in C#
Edit:
Take a look at the IsBackground property of threads. That could be the cause of application freezes when you just want to cose it.
I suggested creating a class WebUtils, or however you want to name, because that's how I've created it in the past.
Something like:
public class WebUtils {
    CookieContainer _cookies;

    public WebUtils() {
        _cookies = new CookieContainer();
    }

    public void AccessPage(string url) {
        //Here I create a new instance of a HttpWebRequest class, and assign `_cookies` to its `Cookie` property.
        //Don't really know if `WebClient` has something similar
    }
}


text:
Q: Mistakes in FAQ for some SE sites I like the new "format" of the FAQ, but it looks like a few things broke:

Furthermore, clicking on the "What kind of questions should I not ask here?" link doesn't do anything.

Added by @kiamlaluno:
Similar issue is present on meta.drupal.SE/faq, and meta.english.SE/faq.

To make a comparison, the same issue is not present on drupal.SE/faq, even though both drupal.SE and meta.drupal.SE are using the same software revision.

A: The encoding issue will be fixed in the next build.
Clicking the "What kind of questions should I not ask here?" does actually do something even for non-expanding sections - it changes the URL hash in your address bar.  We want to expose as many ways as possible to allow linking to particular sections of the faq.  When you arrive at any section of a site's FAQ except the first (whatever that happens to be) we copy and highlight that section up top.
You can test it out here: https://meta.stackoverflow.com/faq#howtoask


text:
Q: Updating Perl date functions? Date::Datecalc.pm not found I'm migrating a Perl script to a new system and am running into problems.  I ran "pear install date" and installed the Date module but this script is expecting some subroutines that seem to no longer be available?
When I run the script I get:
Can't locate Date/DateCalc.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./script.pl line 23.

I'm using these two functions which seem to not be available on this new system.
use Date::DateCalc qw(day_of_week dates_difference);

Is there a new library I need to install or change the reference to these functions in order to access them?

A: Date::DateCalc isn't a Perl library that I recognise. It's not available on CPAN, so I assume it's a library that is written in-house or something that your project has acquired from elsewhere. You'll need to find out where it came from and see if you reinstall it from there. It may be possible to copy it from the old server onto the new one - but that can sometimes be a tricky undertaking.
For several years, Time::Piece and Time::Seconds have been included in the standard Perl library. Neither of them have the specific subroutines that you ask for, but it would be simple to write them both based on these modules.
If you tell us what the input and output of these subroutines are, then someone here might write them for you.


text:
Q: ASP.NET Webforms routing - how to stop trailing slash being routed? Given the following code, in my ASP.NET webform app;
void foo(RouteCollection routes){
   routes.MapPageRoute(string.Empty, "testroute", "~/hello.aspx", false);
}

The problem is, while http://localhost/testroute routes to hello.aspx, http://localhost/testroute/ also routes to hello.aspx.
Is there anyway to prevent this?

A: The best thing to do here, in my opinion, is simply to make sure your website uses consistent URLs in its <a> tags. Don't worry about extraneous paths into your routing mechanism, but instead concentrate on being sure to use only the desired URL pattern for your links.
For example, make sure your website does not contain any <a> tags with href="/testroute/", and it won't matter that it responds to that.
As I noted in the comments, it's actually standard that a trailing slash at the end of the path portion of a URL has no effect; you can include it, or not. This means two 'different' URLs can load the same page: /page.aspx and /page.aspx/ both load the same thing. But there's also another longstanding tradition here that is similar, with default documents; that is, / and /default.aspx will tend to load the same thing.
The solution in that case is, of course, the same as the solution here: Just be sure that your <a> tags use a consistent, single version of the URLs you want to use.

For the record, you could do something that detects the trailing slash and issues a 301 redirect, but I think it's much easier just to make sure you are consistent with the URLs.


text:
Q: Net core 2.2: OperationCanceledException instead of TaskCanceledException on HttpClient timeout In our project we have an HttpClient for outgoing connection with a strict timeout, and previously, I dealt with the timeout situation like all the tutorials suggested: by catching the TaskCanceledException. And it worked. But since recently (can't say the exact time, but about a month), the timeout started to cause the OperationCanceledException.
System.OperationCanceledException: The operation was canceled.
   at System.Net.Http.HttpClient.HandleFinishSendAsyncError(Exception e, CancellationTokenSource cts)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   <buisness-logic traceback>
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware`1.Invoke(HttpContext context)
   at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
   at NSwag.AspNetCore.Middlewares.SwaggerDocumentMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

It's not a big problem to change all the catches to OperationCanceledException, but I'd like to know why?  Does anybody know why HttpClient could switch the exception? I deploy the application locally using the VS2019 16.4.3 and IIS express. Net core 2.2

A: I found it.
https://github.com/dotnet/corefx/issues/33957
Basically, in case of short timeouts there is a race condition that can cause OCE to happen. What it means is "we do not really know what exactly happen, and we do not care, so you shouldn't too".


text:
Q: If statement omits a condition I am trying to create a program in C that takes in any date and returns the zodiac sign.I have a function that is supposed to validate if the date is possible (day >0,month>0, if month ==x ,day <31 etc ) Thing is that on the part where it is supposed to validate the month and determine if it is a 30 month or a 31 month it only accepts one part of the conditions making it either a definite 30 day for all months or a 31 day for all months.
the function name is fnValidacion()
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

/*
Programa : Signo Zodiaco.
Autor    : Samir Fersobe 1063021
Fecha    : Marzo 28, 2015
*/
const char *signo[12] = {"Aries","Tauro","Geminis","Cancer","Leo","Virgo","Libra","Escorpio",
                        "Sagitario","Capricornio","Acuario","Piscis"};//Arreglo de Signos Zodiacales

int Ano,Mes,Dia   ;//Variables de Ano , Mes y Dia.
int aprovacion = 0;//Determina si la funcion sigue o no.
int bisiesto = 1  ;//determina si el año es bisiesto.
int type          ;//determina la estacion.
//Funciones
void fnFecha()     ;//Consigue la fecha
void fnBisiesto()  ;//Define si el año es bisiesto.
void fnValidacion();//Determina si la fecha es valida.
void fnSigno()     ;//Determina el signo zodiacal.
void fnDevuelta()  ;//Devuelve la respuesta.
int main(int argc, char** argv)
{
    fnFecha();
    fnBisiesto();
    fnValidacion();
    fnSigno();
    fnDevuelta();

}
void fnDevuelta()
{/*determinar si la funcion sigue o no, y devuelve el resultado al usuario */
    switch (aprovacion){
        case 1:
            printf("El Signo Zodiacal es %s",signo[type]);
            break;
        default:
            printf("\n Intente de nuevo con otra fecha.");
            break;
                       }
}
void fnSigno()
{/*Determina el signo zodiacal*/
    switch(Mes){
            case 12:
                if (Dia < 22)
                    type = 8;
                else
                    type = 9;
                break;
            case 1:
                if (Dia < 20)
                    type = 9;
                else
                    type = 10;
                break;
            case 2:
                 if (Dia < 18)
                    type = 10;
                else
                    type = 11;
                break;
            case 3:
                if (Dia < 20)
                    type = 11;
                else
                    type = 0;
                break;
            case 4:
                 if (Dia < 20)
                    type = 0;
                else
                    type = 1;
                break;
            case 5:
                 if (Dia < 21)
                    type = 1;
                else
                    type = 2;
                break;

            case 6:
                if (Dia < 21)
                    type = 2;
                else
                    type = 3;
                break;
            case 7:
                if (Dia < 23)
                    type = 3;
                else
                    type = 4;
                break;
            case 8:
                if (Dia < 28)
                    type = 4;
                else
                    type = 5;
                break;
            case 9:
                if (Dia < 23)
                    type = 5;
                else
                    type = 6;
                break;
            case 10:
                if (Dia < 23)
                    type = 6;
                else
                    type = 7;
                break;
            case 11:
                if (Dia < 22)
                    type = 7;
                else
                    type = 8;
                break;

    }
}
void fnBisiesto()
{/*determina si el ano es bisiesto */
    if ((Ano%4 != 0) || ((Ano%100 == 0) && (Ano%400 != 0)))
        bisiesto = 0;
}
void fnValidacion()
{/*Esta parte determina si la fecha es valida*/
    if  (
        (Ano < 0) || (Dia <0) || (Mes < 1) || (Mes > 12)  ||//Ano,Dia,Mes No negativo.Mes entre 1 y 12.
        (Dia > 31) || ((Mes == 4,6,9,11) && (Dia > 30))   ||//Dia no mayor que 31.Si mes es de 30, Dia no mayor que 30.
        ((bisiesto == 0) && (Mes == 2) && (Dia > 28))     ||//Si no es bisiesto febrero no mayor que 28.
        ((bisiesto == 1) && (Mes == 2) && (Dia > 29))       //Si es bisiesto febrero no mayor que 29.
        )
        printf("Esta fecha no es Valida.");                 //Explica al usuario que fecha no es valida.
    else
        return aprovacion = 1;
}
void fnFecha()
{/*Adquiere la fecha del usuario */
    printf("Inserte el Ano: ");
    scanf("%d", &Ano);
    printf("Inserte el Mes: ");
    scanf("%d", &Mes);
    printf("Inserte el Dia: ");
    scanf("%d", &Dia);
    return ;
}

A: I think, your problem is in
(Mes == 4,6,9,11)

You have to write all the conditions individually, maybe something like
((Mes == 4) || (Mes == 6) || (Mes == 9) || (Mes ==11))

Otherwise, as per the operator precedence,  your code will look like
 ((Mes == 4), 6,9,11)

where (Mes == 4) producing either 0 or 1. Next, as per the , operator property, <#>

The left operand of a comma operator is evaluated as a void expression; there is a
  sequence point between its evaluation and that of the right operand. Then the right
  operand is evaluated; the result has its type and value.

So, finally, your expression becomes (11), which is a true value for if condition or logical operator.

[@Quoted from C11 standard, chapter §6.5.17].


text:
Q: How to plot points with ggplot2 using a « for » loop? I started to learn « ggplot2 » and loops since some times. So now, I try to plot some points with « ggplot2 » using a « for » loop. But, I don't really know how to do it, and I don't really know if it's a good idea. I checked over the similar questions and I just don't understand. Maybe, I need more explications.
I've been surfing on stack overflow for a while and it helped me a lot. However, it's my first question here and if it miss some informations or if the script is not correctly exposed, just tell me what's wrong and I'll take care it for the next time.
Here's my script with geom_point() :
    library(tidyverse)
    data("CO2")

    ggplot(data = CO2, mapping = aes(x = conc, y = uptake)) +            # I think that I must do this.

      for (i in 1:nrow(CO2)) {                                           # For each line of the dataset.
        if(CO2$Type[i] == "Quebec" & CO2$Treatment[i] == "nonchilled") { # Test these conditions.
          geom_point(mapping = aes(x = CO2$conc[i], y = CO2$uptake[i]))  # If they are true, add the point using geom_point.
        }                                                                # And eventually, I would like to add more « for » loops.
      }

And I also try with annotate() :
    ggplot(data = CO2, mapping = aes(x = conc, y = uptake)) +

      for (i in 1:nrow(CO2)) {
        if(CO2$Type[i] == "Quebec" & CO2$Treatment[i] == "nonchilled") {
          annotate(geom = "point", x = CO2$conc[i], y = CO2$uptake[i])
        }
      }

The points just don't appear. I also try to stock the values in vectors and assigned them to the « x » et « y » arguments.
Is someone knows how to do that simply, and if it's common to do that.
If it's not, why?
And what are the alternatives?
Thank you and have a good day!

A: I believe the other answers solve the stated question well, but if you plan to make multiple graphs using the different levels of Type & Treatment, you might try using facet_grid:
CO2 %>%
  ggplot(mapping = aes(x = conc, y = uptake)) +
  geom_point() +
  facet_grid(. ~ Type + Treatment)

A: I agree with Rui Barradas, I would do something like this:
CO2 %>%
  filter(Type == "Quebec" & Treatment == "nonchilled") %>% # Get nonchilled Quebec data
  ggplot(aes(x = conc, y = uptake)) +                      # Plot concentration and uptake
    geom_point()                                           # Plot as points

A: I don't think you'll want to have the for loop within the ggplot function. I would recommend filtering your dataframe to the conditions you want before, and then plotting all those points.
You'll have to come up with a list of all the conditions you want and filter out to make a dataframe of only those observations you want to plot. See below:
CO2_quebec <- CO2 %>%
  filter(Type=="Quebec") %>% #Filters out Type only in 'Quebec'
  filter(Treatment == "nonchilled") #Filters out Treatment only for 'nonchilled'

ggplot(data = CO2_quebec, mapping = aes(x = conc, y = uptake)) +
  geom_point() #Note, your geom_point takes your x and y based on your ggplot line above unless otherwise specified

A: It is a very common usage of ggplot.
Here is what you are probably looking for :
gg<- ggplot(data = CO2[CO2$Type=="Quebec" & CO2$Treatment=="nonchilled",], mapping = aes(x = conc, y = uptake))  +
  geom_point()
gg

First of all, you should filter your data before doing the plot. It will make your life easier (as I did).
Then, ggplot is a clever package : you don't need to precise every point you want to plot. If you don't tell him anything, it will understand that you want to plot everything (that's why it is useful to filter before).
Moreover, here is something you will probably appreciate :
gg<- ggplot(data = CO2[CO2$Treatment=="nonchilled",], mapping = aes(x = conc, y = uptake, group=Type,color=Type))  +
  geom_point()
gg

A: You're over complicating this. Try filter:
  library(tidyverse)
  data("CO2")

  CO2 %>% filter(Type == 'Quebec' & Treatment == 'nonchilled') %>%
  ggplot(aes(x = conc, y = uptake)) +
    geom_point()


text:
Q: Least squares coordinates when changing basis Suppose I have two sets of $p$ vectors for a basis of a subspace of $\mathbb{R}^n$.  Arranging these vectors into matrices, I have $X$ and $Z$.  Each row of $Z$ can be obtained by a linear transformation of the  rows of $X$,  so
$$ Z = X \Omega $$
Suppose I solve a least squares problem using both $X$ and $Z$.  The corresponding coordinates of the solution in each basis might be $\hat{\beta}$ and $\hat{w}$ respectively, so
$$ \hat{y} = X \hat{\beta} $$
$$ \hat{y} = Z \hat{w} $$
Because the bases are in general different from one another ($\Omega \neq I_p$), then $\hat{\beta} \neq \hat{w}$.  However, simple manipulation of the hat matrix yields that
$$ \hat{\beta} = \Omega \hat{w}$$
Question:
Why should this be the case?  Why are the least squares coordinates in the old basis simply the same transformation of the coordinates in the new basis?


text:
Q: Is there a option to set Simple code blocks in one line across IDE's in Prettier? We want to use with different IDE's like VSCode and Intellij. To keep the code styles as close as possible we started now using prettier.
Unfortunately for easy code blocks prettier seems to work pretty differently between Intellij and VSCode.
Happens with Prettier in Intellij
public dispatch() {
}

vs. happens with prettier in VSCode
public dispatch() {}

I know there is the flag in Intellij "Simple blocks in one line" but it will be overwritten by the Prettier Plug-in.
Now I would ask if there is an option flag for the .prettierrc that can manage this behaviour? How would you solve this issue?


text:
Q: Assigning promise to a variable I'm using https://www.npmjs.com/package/react-native-link-preview this library to fetch meta data from url's. I have tried it and it's working for me. I'm trying to assign the value in the promise to a variable but i cannot get it to work. How can it to a variable.
My code
 if(this.videoUrl != null){

        LinkPreview.getPreview(this.videoUrl)
            .then(data =>
                console.log("previewData ",data)
            );

    }

Here i want to use the values in data . I've tried declaring a variable and assign the value to it. But it was getting a null value. So how can i do it.
My approach
 var previewData = '';

        if(this.videoUrl != null){

            LinkPreview.getPreview(this.videoUrl)
                .then(data =>

                    previewData = data,
                    console.log("previewData ",previewData)

                );

        }


text:
Q: How to convert a ONNX network (generated by MatLab) to a caffemodel? I built a Network in Matlab and exported as ONNX but I need a caffemodel. How can I convert it? I found this
https://github.com/MTlab/onnx2caffe
but it does not work at all

A: Unfortunately there is no currently supported solution to convert an ONNX model to a Caffe model.
There is the Caffe -> ONNX direction, using both onnxmltools and coremltools.


text:
Q: How to revert local code to previous revision svn I would like to revert only the local code to previous versions.
For extra points, what i would like to do is to revert a folder to a previous version (only locally) and generate a file of differences from the version after it.
e.g. say I have version 100. I want version 99 and a diff between that and 100, then 98 and 99 etc.

A: svn checkout url://repository/path@1234

to check out rev no 1234.
svn revert -R

to revert local modifications.
check here for more

A: svn update -r 99
svn diff -r 100

A: I recently had to revert to a particular revision to debug an older build and this worked like magic:
svn up -r 3340 (or whatever your desired revision number)
I had to resolve all conflicts using "tc" option as I did not care about local changes (checked in everything I cared about prior to reverting)
To get back to head revision was simple too:
svn up
Note: a Better way to revert to a previous SVN revision of a file.