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 / 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
@dg
dg / composer-frontline.php
Last active February 13, 2023 14:14
Composer Frontline: Updates all the version constraints of dependencies in the composer.json file to their latest version.
<?php
declare(strict_types=1);
// Updates all the version constraints of dependencies in the composer.json file to their latest version.
//
// usage: composer-frontline.php (updates all Nette packages)
// composer-frontline.php doctrine/* (updates all Doctrine packages)
// composer-frontline.php * (updates all packages)
<?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
*/
@jamesgmarks
jamesgmarks / gist:56502e46e29a9576b0f5afea3a0f595c
Last active March 12, 2024 19:30
MySQL/MariaDB BIN_TO_UUID and UUID_TO_BIN Polyfill
DELIMITER //
CREATE FUNCTION BIN_TO_UUID(b BINARY(16))
RETURNS CHAR(36)
BEGIN
DECLARE hexStr CHAR(32);
SET hexStr = HEX(b);
RETURN LOWER(CONCAT(
SUBSTR(hexStr, 1, 8), '-',
SUBSTR(hexStr, 9, 4), '-',

NOT UP TO DATE!

Things in this document might not work or be broken nowadays

my laptop:

I'm writing this here because a few things in here are spesific to this model laptop.
Dell XPS 15 9560 (4k) touch screen

Some notes:

Most things after setup are not specific for this laptop
# = run as root

@nikic
nikic / objects_arrays.md
Last active April 12, 2024 17:05
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@cecilemuller
cecilemuller / get_combinations.php
Created February 1, 2013 03:13
PHP: Get all combinations of multiple arrays (preserves keys)
<?php
function get_combinations($arrays) {
$result = array(array());
foreach ($arrays as $property => $property_values) {
$tmp = array();
foreach ($result as $result_item) {
foreach ($property_values as $property_value) {
$tmp[] = array_merge($result_item, array($property => $property_value));
}
@BenMorel
BenMorel / coding-standard.md
Last active December 11, 2015 23:28
Coding standard draft for the Doctrine project
  • Code must follow PSR-2.
  • Classes must have a docblock documentation describing their purpose.
  • Class methods must have a docblock documentation, in this order:
    • A mandatory one-line short description.
    • An optional multi-line long description.
    • A mandatory @param annotation for each parameter: @param [type] [name] [description]
      • [type] is the type of the variable, primitive or class.
      • [name] is the name of the parameter, including the leading $.
      • [description] is a short description of the parameter. If the description spans multiple lines, all lines must be indented by the same number of spaces as the first line.
  • The indentation must be such as types, names and descriptions for all parameters of a single method start on the same column.
hr {
border: 0;
height: 1px;
background-image: linear-gradient(left , rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.3) 50%, rgba(0, 0, 0, 0.1) 100%);
background-image: -o-linear-gradient(left , rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.3) 50%, rgba(0, 0, 0, 0.1) 100%);
background-image: -moz-linear-gradient(left , rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.3) 50%, rgba(0, 0, 0, 0.1) 100%);
background-image: -webkit-linear-gradient(left , rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.3) 50%, rgba(0, 0, 0, 0.1) 100%);
background-image: -ms-linear-gradient(left , rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.3) 50%, rgba(0, 0, 0, 0.1) 100%);
background-image: -webkit-gradient(