Skip to content

Instantly share code, notes, and snippets.

View MagePsycho's full-sized avatar

magepsycho MagePsycho

View GitHub Profile
@Tjitse-E
Tjitse-E / rector.php
Created January 29, 2024 13:50
Add missing dynamic properties using RectorPHP
<?php
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
// Define directories to check
$directories = [
@ProcessEight
ProcessEight / automated-refactoring.md
Last active May 3, 2024 20:34
Discussion of automated refactoring processes to bring legacy codebases up to date
@peterjaap
peterjaap / identify.php
Last active September 6, 2023 08:12
Identify used Magento 2 frontend extensions in a Luma install
<?php
// Run with the URL pointing to a require-config.js as the first argument;
// php identify.php http://magento2demo.firebearstudio.com/pub/static/frontend/Magento/luma/en_US/requirejs-config.js
$content = file_get_contents($argv[1]);
preg_match_all(
'/(?P<quote>\'|")(?P<extension>[[:alnum:]]+_[[:alnum:]]+)\/js\/.+?(?P=quote)/m',
$content,
$matches
@m-radzikowski
m-radzikowski / script-template.sh
Last active May 4, 2024 04:13
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@thibaut-decherit
thibaut-decherit / Symfony - Serve Private File.md
Created February 20, 2020 17:21
Symfony - Serve Private File

Symfony - Serve Private File

Following example demonstrates how to:

  • display a private file download prompt to the user (here for a PDF file)
  • serve a private image or PDF which will be displayed on a webpage

See https://symfony.com/doc/4.4/components/http_foundation.html#serving-files

Host these files in a directory outside of /public, so they can be accessed only through the controller and its @Security() authorization. For example you could create a /private-uploads directory at the root of your project.

<?php
/**
* @author Raj KB <magepsycho@gmail.com>
* @website https://www.magepsycho.com
*
*/
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
@k1paris
k1paris / Law-of-Demeter-with-PHP.md
Last active April 13, 2024 05:49
Law of Demeter with PHP (LoD)

Law of Demeter with PHP (LoD)

Law of Demeter or principle of least knowledge is a design guideline, that is using to make code more simple and stable.

Rules for module

  • Each unit should have only limited knowledge about other units: only units "closely" related to the current unit.
  • Each unit should only talk to his friends; don't talk to strangers.
  • Only talk to your immediate friends.
@cubedtear
cubedtear / script.sh
Last active July 7, 2023 04:37
Self-updating bash script
#!/usr/bin/env bash
VERSION="0.0.2"
SCRIPT_URL='https://gist.github.com/cubedtear/54434fc66439fc4e04e28bd658189701/raw'
SCRIPT_DESCRIPTION=""
SCRIPT_LOCATION="${BASH_SOURCE[@]}"
rm -f updater.sh
function update()
{
@ivanvermeyen
ivanvermeyen / HOWTO.md
Last active January 14, 2024 03:02
Multiple MySQL versions on MacOS with Homebrew

Update - 4 september 2020

Making multiple MySQL versions work with Homebrew was tricky to say the least. Fortunately there are 2 new easy ways that I learned of to achieve this.

DBngin app

As @4unkur and @henrytirla commented below, there is this extremely easy to use app called DBngin, which lets you setup multiple databases (not only MySQL) simultaneously using different ports:

https://dbngin.com/

@atillay
atillay / DemoController.php
Last active October 11, 2022 07:25
Symfony 4 Pagination Service
<?php
namespace App\Controller;
use App\Entity\Demo;
use App\Service\PaginationService;
use Symfony\Component\HttpFoundation\Request;
class DemoController extends AdminController
{