Skip to content

Instantly share code, notes, and snippets.

View elenakondrateva's full-sized avatar

Elena Kay elenakondrateva

View GitHub Profile
@elenakondrateva
elenakondrateva / mariadb-escape-regexp.php
Last active July 11, 2023 20:52
Escape REGEXP for MariaDB query
<?php
// MariaDB uses the C escape syntax in strings (for example, "\n" to represent the newline character),
// we must double any "\" that we use in REGEXP strings (see https://mariadb.com/kb/en/regexp/)
// PHP's preg_quote() won't work here as it adds single slashes so use a special regular expression here
$string = 'My [string] {with} ~regexp~ |special| /characters/+.';
$pattern = '/(\+|-|\||&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
$replacement = '\\\\\\\\${1}';
$stringEscaped = preg_replace($pattern, $replacement, $string);
@elenakondrateva
elenakondrateva / VerifyCsrfToken.php
Created June 15, 2020 02:12
Enable Postman requests in Laravel (exception for CSRF Middleware)
<?php
namespace App\Http\Middleware;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
@elenakondrateva
elenakondrateva / LaravelBackpackObjectUpdateTest.php
Created May 27, 2020 01:24
To test Laravel Backpack edit/update action we need to pass some extra parameters
<?php
namespace Tests\Feature;
use App\Models\Permission;
use App\Models\Role;
use Tests\TestCase;
/**
* Class RoleTest
@elenakondrateva
elenakondrateva / Topmenu.php
Created June 29, 2017 23:39
Move Magento2 top menu categories under second level
<?php
namespace Acme\Topmenu\Plugin\Theme\Block\Html;
use Magento\Framework\Data\Tree\NodeFactory;
use Magento\Framework\Data\TreeFactory;
use Magento\Framework\Data\Tree\Node;
use Magento\Framework\Data\Tree;
class Topmenu
{
@elenakondrateva
elenakondrateva / patch.sh
Last active June 28, 2017 00:09
Magento2 deployment script sample
#!/bin/bash
echo "Patching out... Do you want to continue? (y/n)"
read CONFIRMATION
if [[ "$CONFIRMATION" != "y" && "$CONFIRMATION" != "Y" ]]; then
echo No worries.
exit 1
fi
@elenakondrateva
elenakondrateva / package.json
Last active August 6, 2019 20:00
Magento 2 Post CSS Autoprefixer
{
"name": "Project",
"author": "Vendor",
"description": "Node modules dependencies for local development",
"version": "2.0.0",
"license": "(OSL-3.0 OR AFL-3.0)",
"repository": {
"type": "git",
"url": "https://github.com/magento/magento2.git"
},
@elenakondrateva
elenakondrateva / OneOffSyncUploads.php
Last active March 8, 2020 20:12
Synchronise OctoberCMS media files with AWS S3 cloud
<?php
namespace Acme\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Storage;
class OneOffSyncUploads extends Command
@elenakondrateva
elenakondrateva / ImportFromCSVCommand.php
Last active June 27, 2017 02:45
Symfony Command Import from CSV abstract class
<?php
namespace Acme\CoreBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@elenakondrateva
elenakondrateva / Tinyint.php
Last active June 28, 2023 00:21
Custom Doctrine DBAL type 'tinyint' for Symfony
<?php
namespace AppBundle\Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class Tinyint extends Type
{
const TINYINT = 'tinyint';