Skip to content

Instantly share code, notes, and snippets.

View Raphhh's full-sized avatar

Raphaël Lefebvre Raphhh

View GitHub Profile
@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 / 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 / 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 / .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 / 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 / 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}()
@Raphhh
Raphhh / php-lib-check-list.md
Last active August 29, 2015 14:07
PHP lib check list

PHP lib check list

Git

  1. .gitignore is versionned.
  2. .gitignore does not contain any IDE or system exclusions.

Files format

  1. Files are encoded in UTF-8 without BOM (PSR-1).
  2. End of lines are LF (PSR-2).