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 / 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 / bench.php
Last active December 16, 2021 22:03
(Medium) BulkInserter benchmark
<?php
/**
* Benchmarks BulkInserter at various batch sizes.
*
* Before running this script, make sure to:
*
* - set your PDO parameters in this file
* - run composer install
* - import setup.sql into your database
@BenMorel
BenMorel / remove-mysql-root-password.sh
Last active June 3, 2018 19:43
(Medium) Remove MySQL root password *DO NOT USE THIS ON A PRODUCTION SERVER*
password=$(grep -oP 'temporary password(.*): \K(\S+)' /var/log/mysqld.log)
mysqladmin --user=root --password="$password" password aaBB@@cc1122
mysql --user=root --password=aaBB@@cc1122 -e "UNINSTALL PLUGIN validate_password;"
mysqladmin --user=root --password="aaBB@@cc1122" password ""
@BenMorel
BenMorel / convert-eol.php
Created March 2, 2018 16:55
PHP line breaks converter
<?php
/**
* Converts a string using CR, LF, CRLF, or possibly a mix of these, to the given EOL character(s).
*
* @param string $text The text to convert.
* @param string $eol The line break character(s).
*
* @return string
*/
<?php
use Brick\DateTime\LocalDate;
use Brick\DateTime\LocalTime;
use Brick\DateTime\LocalDateTime;
/**
* Formatter for date-time classes.
*/
class DateTimeFormatter
@BenMorel
BenMorel / solve.php
Last active May 20, 2018 12:33
Solve 2 equations with 2 unknowns in PHP
<?php
/**
* Solves the following equations:
*
* a·x + b·y = c
* d·x + e·y = f
*
* Returns an array with [x, y]
*/
@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 / Font-Awesome-4-to-5-Migration.php
Last active November 15, 2018 13:23
Automatically migrates Font Awesome 4 class names to Font Awesome 5 class names
<?php
/**
* Automatically migrates Font Awesome 4 class names to Font Awesome 5 class names.
*
* WARNING: THIS WILL REWRITE YOUR FILES.
* BACK UP YOUR FILES BEFORE RUNNING THIS SCRIPT.
* YOU HAVE BEEN WARNED.
*
* Note: the migration CSV file was parsed from the official migration documentation:
@BenMorel
BenMorel / remove-mysql-8-root-password.sh
Created November 9, 2018 13:24
(Medium) Remove MySQL root password *DO NOT USE THIS ON A PRODUCTION SERVER*
password=$(grep -oP 'temporary password(.*): \K(\S+)' /var/log/mysqld.log)
mysqladmin --user=root --password="$password" password aaBB@@cc1122
mysql --user=root --password=aaBB@@cc1122 -e "UNINSTALL COMPONENT 'file://component_validate_password';"
mysqladmin --user=root --password="aaBB@@cc1122" password ""
@BenMorel
BenMorel / doctrine-dbal-travis-matrix-builder.php
Last active October 20, 2020 18:20
Builds the Travis CI job matrix for Doctrine DBAL - See doctrine/dbal#3347
<?php
/**
* This script builds the .travis.yml build matrix, around these variables:
*
* - PHP versions
* - database drivers
* - platform versions
*
* With the following requirements: