Skip to content

Instantly share code, notes, and snippets.

View vyspiansky's full-sized avatar

Ihor Vyspiansky vyspiansky

View GitHub Profile
@vyspiansky
vyspiansky / jpeg_batch_converter_macos_terminal.md
Last active November 21, 2025 09:20
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
@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();