Skip to content

Instantly share code, notes, and snippets.

View Pierstoval's full-sized avatar
🌖

Alex Rock Pierstoval

🌖
View GitHub Profile
@Pierstoval
Pierstoval / pre-receive.bash
Last active September 9, 2021 07:46
Git pre-receive example to use a bare repo to deploy an ap
#!/bin/bash
########################################################################
################################ README ################################
########################################################################
#
# This script is here to allow the use of "git push prod v1.2.3" commands or similar.
#
# Push a tag to a bare repository having this file as pre-receive hook,
# and you'll be able to deploy directly from command line in your local environment,
@Pierstoval
Pierstoval / remove_windows_dir_from_wsl.bash
Last active March 14, 2021 18:32
Remove Windows directories from WSL's PATH
# Remove Windows directories from WSL's PATH
export PATH=$(echo $PATH \
| sed 's/:/\n/g' \
| sort -u \
| grep -v -e'/mnt/[a-z]/' \
| sed -z 's/\n/:/g' \
| sed 's/:$//'
)
@Pierstoval
Pierstoval / Makefile
Last active March 2, 2021 14:38
"Check requirements" command for your Makefile
# Use it like this:
#
# $ printf $(_TITLE) "Something in green" "The message"
#
# This will output something like this:
#
# [Something in green] The message
#
# (of course, with proper colors)
_TITLE := "\033[32m[%s]\033[0m %s\n" # Green text
(function(){
let list=document.querySelectorAll('.event--vote-stars');
let score = 0;
for (let i=0,l=list.length;i<l;i++) {
let el=list[i];
score+=el.querySelectorAll('a.star.is-selected').length;
}
console.info(score/list.length);
})();

Native mocks versus PHPUnit mocks

Mock type Tests duration
Native mocks 160.10 seconds
Mockery 177.01 seconds (+10%)
PHPUnit mocks 232.29 seconds (+45%)
Prophecy 3868.80 seconds (+2416%)
@Pierstoval
Pierstoval / FormLoginAuthenticator.php
Last active February 4, 2020 16:32
(for stackoverflow)
<?php
/**
* This file is part of the corahn_rin package.
*
* (c) Alexandre Rock Ancelet <alex@orbitale.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@Pierstoval
Pierstoval / imagemagick_geometry.php
Last active January 9, 2020 15:24
This enormous regexp matches any "Geometry" parameter for ImageMagick. See the docs about this: http://www.imagemagick.org/script/command-line-processing.php#geometry
<?php
$number = "\d*(?:\.\d+)?"; // It's a reference to use in other cases that matches any kind of number/float
$width = "(?<w>(?:$number)?%?)?"; // This is the first part, the width
$height = "(?:x(?<h>(?:$number)?%?))?"; // Here is the height, the same as "width" but starting with an "x"
$aspect = "[!><@^]"; // These are the different filters one can use to stretch, shrink, etc.
$size = "$width$height"; // To match any size we need width and height at least (aspect comes later)
@Pierstoval
Pierstoval / _ChromeSnippets.md
Last active August 8, 2019 15:14
Chrome snippets

My Chrome snippets

<?php
declare(strict_types=1);
namespace Tests;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase as BaseWebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
# Change the current background according to a distant URL.
# Needs the "feh" package to work.
DISPLAY=:0 XAUTHORITY=$HOME/.Xauthority feh --bg-center http://rammb.cira.colostate.edu/ramsdis/online/images/latest/himawari-8/full_disk_ahi_natural_color.jpg
# Source: https://twitter.com/docteur_klein/status/1130730930031779840