Skip to content

Instantly share code, notes, and snippets.

View pounard's full-sized avatar
💭
What's happening?

Pierre pounard

💭
What's happening?
View GitHub Profile
<?php
function usage($programeName) {
echo <<<EOT
Usage:
{$programeName} TRACE_FILE
EOT;
}
/**
* @see \Symfony\Component\HttpKernel\Controller\ErrorController
*/
final class ErrorController
{
private bool $debug = false;
private ErrorRendererInterface $errorRenderer;
private Environment $twig;
/**
@pounard
pounard / serializer-type-map.php
Last active April 9, 2020 08:24
Symfony serializer type map decorator
<?php
/**
* Maps PHP native types to normalized names
*/
interface TypeMap
{
const TYPE_ARRAY = 'array';
const TYPE_NULL = 'null';
const TYPE_STRING = 'string';
@pounard
pounard / user_rights.sh
Last active November 29, 2018 15:12
User rights restoration script for Symfony/D7/D8
#!/bin/bash
if [ "`id -u`" != "0" ]; then
echo "Script must be run as root"
exit 1
fi
IGNORE_BIN=0
ROOT_PATH=`pwd`
@pounard
pounard / iban-input-mask-not-working.js
Created October 18, 2018 09:51
IBAN input mask that does not work
function applyIBANMaks(input) {
var mask = '____ ____ ____ ____ ____ ____ ____'.split('');
var cursorPositionDelta = 0;
function strip(value) {
return value.split('').filter(function (chr) {
return /[a-zA-Z\d]/.test(chr);
});
}
@pounard
pounard / normalize-path.php
Last active June 26, 2018 11:24
Path normalization, equivalent of Python's os.path.normpath() and os.path.absath()
<?php
// Generate test data for performance test
$testData = [];
$words = ['..', 'test', 'pouet', '/', '..', '', 'usr', 'bin', 'firefox', 'do not', 'panic', 'secret', 'perso', 'private', 'foo', '/', '..', '', 'hyper long word', 'word with space', 'some56457', '@ert', '.ezrzer', 'cassoulet', '/', '..', ''];
for ($i = 0; $i < 100; ++$i) {
$value = [];
$count = rand(0, 20);
for ($j = 1; $j < $count; ++$j) {
$value[] = $words[rand(0, count($words) - 1)];
commit f3c67888421b31f71ae0a8cabb5259676150baa4
Author: Pierre Rineau <pierre.rineau@makina-corpus.com>
Date: Wed Mar 28 22:24:01 2018 +0200
https://www.drupal.org/sa-core-2018-002 backport from Drupal 7
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 23179ca98d..c14d966d86 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@pounard
pounard / dump_opcodes.sh
Last active March 13, 2018 08:33
Dumps a PHP file's generated OPCodes
phpdbg -np* file.php
@pounard
pounard / panic.php
Last active January 6, 2022 09:32
Drupal panic script (complete)
#!/usr/bin/php
<?php
function panic_bootstrap_database($site_host = null, $incomming_host = null) {
$_SERVER['REMOTE_ADDR'] = $incomming_host ? $incomming_host : '127.0.0.1';
$_SERVER['HTTP_HOST'] = $site_host ? $site_host : '127.0.0.1';
$_SERVER['SCRIPT_NAME'] = '/index.php';
define('DRUPAL_ROOT', __DIR__ . '/../html');