Skip to content

Instantly share code, notes, and snippets.

View Raphhh's full-sized avatar

Raphaël Lefebvre Raphhh

View GitHub Profile
@Raphhh
Raphhh / pre-commit
Created December 7, 2015 12:33
Git pre-commit hook for PHP project
#!/bin/sh
# running the tests
./bin/test
echo ""
STATUS_CODE=$?
exit $STATUS_CODE
@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 / ContextualOptionsFormListener.php
Last active October 23, 2024 12:23
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 / 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 / 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 / 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 / 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:]]*'