Skip to content

Instantly share code, notes, and snippets.

View BenMorel's full-sized avatar
🤝
Open to work. Drop me an email!

Benjamin Morel BenMorel

🤝
Open to work. Drop me an email!
View GitHub Profile
@BenMorel
BenMorel / bootstrap.php
Last active May 3, 2023 21:36
The first lines of any decent PHP quick script
<?php
declare(strict_types=1);
error_reporting(E_ALL);
set_error_handler(function ($severity, $message, $file, $line) {
if ((error_reporting() & $severity) === 0) {
return false;
}
@BenMorel
BenMorel / dump.php
Created November 23, 2020 13:24
Example of using the benmorel/smartdump PHP API instead of the CLI
<?php
/**
* Example valid with benmorel/smartdump~0.2.0
*
* https://github.com/BenMorel/smartdump
*/
use BenMorel\SmartDump\Configuration\DumpConfiguration;
use BenMorel\SmartDump\Configuration\TargetTable;
<?php
/**
* This script downloads the list of releases of a project via the GitHub API,
* and generates a changelog out of it.
*
* Example, to generate a changelog for brick/math:
*
* php changelog-from-github-api.php brick/math > CHANGELOG.md
*/
@BenMorel
BenMorel / pecl-versions.php
Last active October 25, 2020 15:28
Adds "PECL <package name>" in front of versions in php.net docs changelogs.
<?php
/**
* Adds "PECL <package name>" in front of versions in php.net docs changelogs.
* Used for https://github.com/php/doc-en/pull/162
*/
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/reference'));
foreach ($files as $file) {
@BenMorel
BenMorel / generate-wildcard-certificate.sh
Created October 13, 2020 16:40 — forked from PowerKiKi/generate-wildcard-certificate.sh
Generate self-signed wildcard SSL certificate for development environment
#!/usr/bin/env bash
# print usage
DOMAIN=$1
if [ -z "$1" ]; then
echo "USAGE: $0 domain.lan"
echo ""
echo "This will generate a non-secure self-signed wildcard certificate for given domain."
echo "This should only be used in a development environment."
@BenMorel
BenMorel / benchmark.csv
Created September 21, 2020 08:06
[medium] innodb_io_capacity benchmark
innodb_io_capacity innodb_io_capacity_max NOTPM
200 200 88208
200 300 88857
200 400 88547
200 500 88671
200 750 88850
200 1000 88433
200 1500 89293
200 2000 89644
200 3000 92469
@BenMorel
BenMorel / benchmark.md
Created September 17, 2020 12:25
[medium] Filesystem benchmark
Filesystem default (128M) 10G 20G
ext4 39952 71552 70907
XFS 40311 69782 70147
@BenMorel
BenMorel / DoctrineCompilerPass.php
Created January 28, 2020 21:11
A Symfony compiler pass to set the default transaction isolation level on Doctrine\DBAL\Connection
<?php
declare(strict_types=1);
namespace App;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\TransactionIsolationLevel;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@BenMorel
BenMorel / JsonCanonicalizer.php
Created January 27, 2020 23:45
Simple canonicalization of a JSON string.
<?php
/**
* Simple canonicalization of a JSON string.
*
* - removes formatting
* - sorts object properties
*/
class JsonCanonicalizer
{
@BenMorel
BenMorel / iptables-config-script
Created October 17, 2019 22:57 — forked from LouWii/iptables-config-script
Bash script to configure iptables for a web server. Some rules can be removed depending on used services.
#!/bin/sh
# Empty all rules
sudo iptables -t filter -F
sudo iptables -t filter -X
# Set up default rules
sudo iptables -t filter -P INPUT DROP
sudo iptables -t filter -P FORWARD DROP
sudo iptables -t filter -P OUTPUT ACCEPT