Skip to content

Instantly share code, notes, and snippets.

@Crell
Crell / benchmark.php
Last active Dec 30, 2020 — forked from olleharstedt/benchmark.js
Clone benchmark
View benchmark.php
<?php
const ITERS = 1000000;
class QueryBuilder {
public $select;
public $from;
public $where;
public function withSelect($sel) {
View error.txt
FetchError: request to http://solr.internal:8080/solr/maincore/update? failed, reason: connect ECONNREFUSED 169.254.143.220:8080
at ClientRequest.<anonymous> (/app/node_modules/node-fetch/lib/index.js:1455:11)
at ClientRequest.emit (events.js:314:20)
at Socket.socketErrorListener (_http_client.js:469:9)
at Socket.emit (events.js:314:20)
at emitErrorNT (internal/streams/destroy.js:100:8)
at emitErrorCloseNT (internal/streams/destroy.js:68:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
type: 'system',
errno: 'ECONNREFUSED',
View Enum1.php
enum Option {
case None = new class {};
case Some = new class($val) {
public function __construct(private $val) {}
public function value() { return $val; }
};
public function value{} { throw new TypeError; }
}
View plugins.sh
echo "Installing Additional Plugins"
cd plugins
file="../plugins.txt"
while read -r line; do
[ "$line" = "\#*" ] && continue
git clone --depth=1 $line
done < grep -v -- "^#" "$file"
cd ..
View zend_compile.c
void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
{
zend_ast *name_ast = ast->child[0];
zend_ast *args_ast = ast->child[1];
znode name_node;
// If this is a partial function call, convert it to a special partial opcode.
zend_ast_list *arglist = zend_ast_get_list(args_ast);
for (int i; i < arglist->children; ++i) {
@Crell
Crell / after.php
Created Mar 24, 2020
Constructor promotion
View after.php
<?php
class Doer
{
public function __construct(protected Connection $database) {}
}
@Crell
Crell / 1_single-attribute.php
Last active Mar 9, 2020
3 test implementations of PHP Attributes for Tukio
View 1_single-attribute.php
<?php
class ProviderBuilder {
public function addListenerService(string $serviceName, string $methodName, string $type, int $priority = 0, string $id = null): string
{
// ...
}
public function addSubscriber(string $class, string $serviceName): void
View command line
$ php -d ffi.enable=preload -d opcache.preload="dummy-preload.php" dummy-test.php
PHP Fatal error: Uncaught FFI\Exception: Failed loading scope 'DUMMY' in /home/crell/temp/php-ffi-test/dummy.php:11
Stack trace:
#0 /home/crell/temp/php-ffi-test/dummy.php(11): FFI::scope()
#1 /home/crell/temp/php-ffi-test/dummy-test.php(7): Dummy->__construct()
#2 {main}
thrown in /home/crell/temp/php-ffi-test/dummy.php on line 11
@Crell
Crell / DoctrineProjectLoad.php
Created Aug 14, 2019
Is this too clever for its own good?
View DoctrineProjectLoad.php
<?php
declare(strict_types=1);
namespace App\EventListener;
use App\Entity\Project;
use App\PlatformClient;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\MessageBusInterface;
View RegionType.php
<?php
declare(strict_types=1);
namespace App\Form\Type;
use App\PlatformClient;
use Platformsh\Client\Model\Region;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;