Skip to content

Instantly share code, notes, and snippets.

View Raphhh's full-sized avatar

Raphaël Lefebvre Raphhh

View GitHub Profile
@Raphhh
Raphhh / ContextualOptionsFormListener.php
Last active August 2, 2023 13:45
Symfony form: set options according to the data
<?php
namespace AppBundle\Form\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class ContextualOptionsFormListener implements EventSubscriberInterface
{
/**
@Raphhh
Raphhh / chromedriver_get_version.sh
Last active October 26, 2021 19:04
Get the version of chromedriver according to a chrome version. Usage `$ google-chrome --version | ./chromedriver_get_version.sh`. See https://chromedriver.chromium.org/downloads/version-selection
#!/bin/bash
chrome_version=$(cat <&0 | grep -o '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*')
wget -O- -q "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_version" | grep -o '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*'
@Raphhh
Raphhh / .scrutinizer.yml
Last active October 16, 2017 07:53
Scrutinizer PSR config
filter:
excluded_paths: [vendor/*, tests/*]
tools:
external_code_coverage: true
checks:
php:
verify_property_names: true
verify_argument_usable_as_reference: true
verify_access_scope_valid: true
variable_existence: true
@Raphhh
Raphhh / killCurrentWindow.js
Created February 6, 2017 18:30
Close the current window in javascript
function killMe(event) {
if (event.data === 'kill_me') {
event.source.close();
}
}
if (window.addEventListener){
addEventListener('message', killMe, false);
} else {
@Raphhh
Raphhh / delegateFormInNewWindow.js
Created February 6, 2017 18:04
Open a new window in Javascript on form submit
function delegateFormInNewWindow(form, width, height) {
var left = (screen.width/2)-(width/2);
var top = (screen.height/2)-(height/2);
var dialog = window.open(form.action, '_form', 'resizable,width='+width+',height='+height+',top='+top+',left='+left );
form.target='_form';
return dialog;
}
$(function() {
@Raphhh
Raphhh / validation.js
Created January 26, 2017 17:03
Display error messages of the html validation in a symphony form
$('input,select,textarea', $context).on('invalid', function(evt) {
var $this = $(this);
setErrorMessage($this, $this.data('validation-message') || this.validationMessage);
});
function setErrorMessage($field, message) {
var $parent = $field.closest('div:not(.input-group)');
var $messageContainer = $parent.find('.help-block');
if (!$messageContainer.length) {
$messageContainer = $('<span class="help-block"><ul class="list-unstyled"></ul></span>');
@Raphhh
Raphhh / .gitconfig
Last active March 10, 2016 11:29
.gitconfig
[user]
name = Raphaël Lefebvre
email = raphael@raphaellefebvre.be
[core]
excludesfile = c:/Users/Raphaël/.gitignore_global
autocrlf = input
[ui]
color = auto
[grep]
extendedRegexp = true
@Raphhh
Raphhh / .bash_aliases
Last active February 16, 2016 13:53
set some aliases on linux
alias xphp='php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1'
alias dumpath='echo $PATH | tr ":" "\n"'
alias adduserpath='echo 'PATH="$1:$PATH"' >> ~/.profile'
@Raphhh
Raphhh / PHPStorm-code-template.md
Last active January 28, 2016 08:53
Templates for getter and setter in PHPStorm

#PHP getter method

/**
 * Getter of $${PARAM_NAME}
 *
 * @return ${TYPE_HINT}
 */
#if (${TYPE_HINT} == "bool" || ${TYPE_HINT} == "boolean")
public ${STATIC} function ${PARAM_NAME}()