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 / dbt2.patch
Last active November 17, 2023 22:00
Downloads and runs the DBT2 benchmark for MySQL.
From 664f364c5c08a4bcb51d8ebdda2f72b9e8f8d491 Mon Sep 17 00:00:00 2001
From: Benjamin Morel <benjamin.morel@gmail.com>
Date: Sun, 17 Sep 2023 14:50:28 +0200
Subject: [PATCH] Patch
---
scripts/mysql/mysql_load_db.sh | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/scripts/mysql/mysql_load_db.sh b/scripts/mysql/mysql_load_db.sh
@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 / innodb-realtime-stats.php
Last active April 21, 2023 17:10
Quick script to display InnoDB inserts/updates/deletes/reads per second in real time
<?php
/**
* Quick script to display InnoDB inserts/updates/deletes/reads per second in real time.
*
* Sample output:
*
* Inserts 40,368.63 /s
* Updates 19.98 /s
* Deletes 9.99 /s
@BenMorel
BenMorel / generate-jit-php-ini.php
Last active January 15, 2023 00:03
Generates a php.ini file compatible with PHP JIT compiler
<?php
/**
* Generates a php.ini file from runtime ini directives, excluding extensions incompatible with JIT.
* I did not find a way to disable an extension from the command line, so this script is a workaround.
*
* Use it this way:
*
* php generate-jit-php-ini.php > php.ini
* php -n -c php.ini
@BenMorel
BenMorel / stream.php
Last active September 7, 2022 13:46
Stream a file that is being written to by another process
<?php
/**
* This script streams a file that is being written to by another process.
* It will continue fread()ing past EOF until explicitly stopped with CTRL+C.
*
* The script will exit with a status code of 0 if and only if the stream is stopped *after* EOF has been reached,
* i.e. if actual EOF *MAY* have been reached.
*
* The output of the streamed file is sent to STDOUT, and the output of the script is sent to STDERR,
<?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 / errorLevelToConstants.php
Last active March 25, 2022 09:45
Returns constants matching an error level
<?php
/**
* Examples:
*
* errorLevelToConstants(E_WARNING) => ['E_WARNING', 'E_ALL']
* errorLevelToConstants(3) => ['E_ERROR', 'E_WARNING', 'E_ALL']
*
* @return string[]
*/
@BenMorel
BenMorel / viewport-units-ios.scss
Last active March 11, 2022 13:15
SCSS mixin to support vh and vw units on all iOS Safari versions. Based on an idea by Patrick Burtchaell's: https://gist.github.com/pburtchaell/e702f441ba9b3f76f587
/**
* Fix for vw, vh, vmin, vmax on iOS 7.
* http://caniuse.com/#feat=viewport-units
*
* This fix works by replacing viewport units with px values on known screen sizes.
*
* iPhone 6 and 6 Plus cannot run iOS 7, so are not targeted by this fix.
* Target devices running iOS 8+ will incidentally execute the media query,
* but this will still produce the expected result; so this is not a problem.
@BenMorel
BenMorel / server.php
Created August 27, 2017 12:15
(Medium) Sample PHP server
<?php
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($sock, '0.0.0.0', 10000);
for (;;) {
socket_recvfrom($sock, $message, 1024, 0, $ip, $port);
$reply = str_rot13($message);
socket_sendto($sock, $reply, strlen($reply), 0, $ip, $port);
}
@BenMorel
BenMorel / symfony-deserialize-json-to-dto.php
Created January 2, 2022 22:50
Symfony Serializer: deserializing JSON to DTO example
<?php
require 'vendor/autoload.php';
use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;