Skip to content

Instantly share code, notes, and snippets.

View vyspiansky's full-sized avatar

Ihor Vyspiansky vyspiansky

View GitHub Profile
@vyspiansky
vyspiansky / add-remove-query-param-using-response.md
Last active April 15, 2025 19:24
Add new query parameter to URL using Symfony Response
// Create a request object or parse the URL
$request = \Symfony\Component\HttpFoundation\Request::create($urlWithoutToken);

// or get the current request.
// $request = $event->getRequest();

Add new query parameter to URL

@vyspiansky
vyspiansky / concurrent_http_requests.md
Last active March 18, 2025 12:12
Concurrent HTTP requests in PHP 8.1+

cURL Multi

Native cURL multi-handle API for parallel requests.

Using separate cURL requests

<?php
// File: separate_curl_requests.php
@vyspiansky
vyspiansky / simple_generator.php
Last active March 18, 2025 10:52
Simple generator in PHP
<?php
declare(strict_types=1);
function simpleGenerator() {
echo "The generator begins\n";
for ($i = 0; $i < 3; ++$i) {
yield $i;
echo "Yielded $i\n";
@vyspiansky
vyspiansky / max_allowed_packet-size-in-mysql.md
Last active March 6, 2025 20:26
Set max_allowed_packet size in MySQL

Update MySQL's maximum packet size configuration

We're going to fix the following issue

The query length of 118146958 bytes is larger than max_allowed_packet size (33554432).

First of all, let's check the current size

@vyspiansky
vyspiansky / file_extension_by_contents.md
Last active February 21, 2025 13:40
PHP: retrieve a file extension by its contents

Using Symfony's MimeTypes

use Symfony\Component\Mime\MimeTypes;

function getFileExtension(string $fileContent): ?string
{
    $mimeType = (new \finfo(FILEINFO_MIME_TYPE))->buffer($fileContent);

 $mimeTypes = new MimeTypes();
@vyspiansky
vyspiansky / move_file_to_directory_in_drupal.php
Last active March 18, 2025 10:52
Move file to directory in Drupal 10
<?php
use Drupal\Core\File\FileSystemInterface;
$directory = '/path/to/processed';
\Drupal::service('file_system')
->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
\Drupal::service('file_system')
@vyspiansky
vyspiansky / password_validation_message_in_drupal_10.md
Last active March 19, 2025 07:36
Change client-side password validation message in Drupal 10

We are going to replace "Make it at least 8 characters" from the user core modules (core/modules/user/user.module) with "Make it at least 12 characters".

/**
 * Implements hook_element_info_alter().
 */
function <your_module>_element_info_alter(array &$types): void
{
    if (isset($types['password_confirm'])) {
 $types['password_confirm']['#process'][] = 'users_form_process_password_confirm';
@vyspiansky
vyspiansky / ngrok_notes.md
Last active March 19, 2025 07:37
ngrok: create a tunnel from the public internet to your local machine

ngrok notes

ngrok creates a tunnel from the public internet to your local machine.

Install

Sign up for an ngrok account https://dashboard.ngrok.com/

brew install ngrok/ngrok/ngrok
@vyspiansky
vyspiansky / error_messages_visibility_in_drupal_10.md
Last active March 20, 2025 09:09
Visibility of error messages in Drupal 10

To configure the error messages visibility, set an appropriate configuration in the settings.php file

// Show all error messages, including notices and coding standards warnings.
$config['system.logging']['error_level'] = 'verbose';

File: /path/to/docroot/sites/<SITE_NAME>/settings.php.

Then clear the Drupal cache.