Skip to content

Instantly share code, notes, and snippets.

View vyspiansky's full-sized avatar

Ihor Vyspiansky vyspiansky

View GitHub Profile
@vyspiansky
vyspiansky / assemble_sql_query_in_drupal.php
Created June 9, 2026 08:45
Assemble SQL query in Drupal 10
<?php
/** @var \Drupal\Core\Database\Query\ExtendableInterface $query */
$sql = $query->__toString();
$args = $query->getArguments();
foreach ($args as $placeholder => $value) {
$quoted = is_numeric($value) ? (string) $value : "'" . addslashes($value) . "'";
$sql = str_replace($placeholder, $quoted, $sql);
}
@vyspiansky
vyspiansky / mariadb_improving_performance.md
Last active May 22, 2026 14:56
MariaDB performance profiling

Enable query log temporarily

Inside the MySQL prompt:

SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = '/tmp/mariadb_general.log';

Or use one-liner from terminal

@vyspiansky
vyspiansky / php_8_4_macos.md
Last active March 4, 2026 13:27
Install PHP 8.4 on macOS (Intel Mac) terminal

Install PHP 8.4 on macOS (Intel Mac) terminal

Open Zsh configuration file:

nano ~/.zshrc

Scroll to the bottom and paste these exact lines:

@vyspiansky
vyspiansky / jpeg_batch_converter_macos_terminal.md
Last active December 11, 2025 14:39
JPEG batch converter (macOS Terminal)

Convert images to JPEG with quality control via macOS Terminal.

Bash script

File ./convert_to_jpeg.sh content:

#!/bin/bash

# This script converts various image types to JPEG with 75% quality.
@vyspiansky
vyspiansky / function_caller_in_php.md
Last active October 23, 2025 10:24
Determine which function called the current function in PHP

To do this we can use debug_backtrace:

// $backtrace = debug_backtrace();
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);

// $caller = isset($backtrace[1]['function']) ? $backtrace[1]['function'] : 'unknown';
$caller = $backtrace[1]['function'] ?? 'unknown';
@vyspiansky
vyspiansky / monkey-patch-gtm-push.md
Last active October 6, 2025 12:50
Wrap (monkey-patch) Google Tag Manager push method

To console.log every argument pushed to Google Tag Manager, use

window.dataLayer = window.dataLayer || [];

// Save the original push method
const originalPush = window.dataLayer.push;

// Monkey patch push
window.dataLayer.push = function() {
@vyspiansky
vyspiansky / sd-card-write-access-macos.md
Created May 23, 2025 07:55
Enable write access to an SD card on macOS

To list mounted volumes use the following command in the Terminal (Applications > Utilities):

ls -la /Volumes/

For instance, our SD card is mounted as NO NAME.

Let's check extended attributes

@vyspiansky
vyspiansky / largest-tables-in-mysql.sql
Last active May 6, 2025 12:23
Top 10 largest tables in a MySQL database
-- Top 10 largest tables in a MySQL database
-- MySQL 5.7.29
SELECT
table_schema AS `Database`,
table_name AS `Table`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`,
ROUND(data_length / 1024 / 1024, 2) AS `Data Size (MB)`,
ROUND(index_length / 1024 / 1024, 2) AS `Index Size (MB)`,
table_rows as 'Rows'
@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