Skip to content

Instantly share code, notes, and snippets.

use Amp\Loop;
use Amp\Mysql\ConnectionConfig;
use Amp\Mysql\Pool;
use Amp\Mysql\ResultSet;
use Amp\Mysql\TimeoutConnector;
use Amp\Socket\ClientTlsContext;
use Illuminate\Support\Collection;
class AsyncMySql {
private const DEFAULT_MAX_CONNECTIONS = 20;
$dbConfig = [
'driver' => <data>,
'host' => <data>,
'port' => <data>,
'database' => <data>,
'username' => <data>,
'password' => <data>,
'charset' => <data>,
'collation' => <data>,
'prefix' => '',
$sslOption = null;
if(isset($dbConfig['options'][\PDO::MYSQL_ATTR_SSL_CA])) {
$sslOption = new ClientTlsContext();
$sslOption->withCaFile($dbConfig['options'][\PDO::MYSQL_ATTR_SSL_CA]);
}
$host = $dbConfig['host'];
$port = $dbConfig['port'];
$user = $dbConfig['username'];
@plankes-projects
plankes-projects / exception
Created April 12, 2018 09:30
DNS fail on local windows machine
#0 C:\htdocs\import\vendor\amphp\dns\lib\BasicResolver.php(138): Amp\Dns\ResolutionException: All query attempts failed
#1 (0): Amp\Dns\{closure}()
#2 C:\htdocs\import\vendor\amphp\amp\lib\Coroutine.php(71): throw(Amp\MultiReasonException#1
(
[Amp\MultiReasonException:reasons] => array
(
[0] => Am...)
#3 C:\htdocs\import\vendor\amphp\amp\lib\Failure.php(26): Amp\{closure}(Amp\MultiReasonException#1
(
[Amp\MultiReasonException:reasons] => array
@plankes-projects
plankes-projects / exception
Created April 12, 2018 09:29
Crypto negotiation failed on windows server
#0 C:\htdocs\vendor\amphp\mysql\src\Internal\Processor.php(201): Amp\Mysql\ConnectionException: Connection went away... unable to fulfil this deferred ... It's unknown whether the query was executed...
#1 C:\htdocs\vendor\amphp\amp\lib\Internal\Placeholder.php(127): Amp\Mysql\Internal\{closure}(null, null)
#2 C:\htdocs\vendor\amphp\amp\lib\Coroutine.php(79): resolve(null)
#3 C:\htdocs\vendor\amphp\amp\lib\Internal\Placeholder.php(127): Amp\{closure}(null, null)
#4 C:\htdocs\vendor\amphp\amp\lib\Deferred.php(41): resolve(null)
#5 C:\htdocs\vendor\amphp\byte-stream\lib\ResourceInputStream.php(177): resolve()
#6 C:\htdocs\vendor\amphp\byte-stream\lib\ResourceInputStream.php(165): free()
#7 C:\htdocs\vendor\amphp\socket\src\Socket.php(104): close()
#8 C:\htdocs\vendor\amphp\mysql\src\Internal\Processor.php(1073): close()
#9 C:\htdocs\vendor\amphp\mysql\src\Internal\Processor.php(1354): close()
package DeepLearning4J.example
import java.io.File;
import java.util.Arrays;
import java.util.List;
import org.canova.api.records.reader.RecordReader;
import org.canova.api.split.FileSplit;
import org.canova.image.loader.BaseImageLoader;
import org.canova.image.loader.NativeImageLoader;
while (dataIter.hasNext()) {
dsNext = dataIter.next();
network.fit(dsNext);
}
@plankes-projects
plankes-projects / AlexNetTrainer.java
Last active May 27, 2016 13:31
AlexNet configuration for DeepLearning4j
package trainer;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.GradientNormalization;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.Updater;
import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.LocalResponseNormalization;
@plankes-projects
plankes-projects / predict.java
Last active September 28, 2016 14:08
How to predict one image with a model from DeepLearning4j
INDArray predict(MultiLayerNetwork model, File imageFile) throws Exception {
ImageLoader imageLoader = new ImageLoader(Config.IMAGE_WIDTH, Config.IMAGE_HEIGHT, Config.CHANNELS);
INDArray image = imageLoader.asRowVector(imageFile);
return model.output(image);
}
@plankes-projects
plankes-projects / train.java
Last active May 27, 2016 13:32
How to train a DeepLearning4j model with custom images. 'new File("directory")' is the directory wich has 1 subdirectory with images for each category you have.
RecordReader recordReader = new ImageRecordReader(Config.IMAGE_WIDTH, Config.IMAGE_HEIGHT, Config.CHANNELS, true);
recordReader.initialize(new FileSplit(new File("directory"), BaseImageLoader.ALLOWED_FORMATS));
DataSetIterator dataIter = new RecordReaderDataSetIterator(recordReader, batchSize, -1, numLabels);
while (dataIter.hasNext()) {
dsNext = dataIter.next();
dsNext.scale();
network.fit(dsNext);
}