Skip to content

Instantly share code, notes, and snippets.

@grandmanitou
grandmanitou / select2-height-fixer.css
Created February 16, 2014 08:07
Adjust select2 height when there are more than one line of tags
.select2-container.form-control {
height: auto !important;
}
@grandmanitou
grandmanitou / age-from-birthdate.php
Created March 20, 2014 09:17
Get age from birthdate
<?php
function age($date)
{
$d = strtotime($date);
//echo strftime('%a %d %b %Y', $d).' > ';
return (int) ((time() - $d) / 3600 / 24 / 365.242);
}
?>
@grandmanitou
grandmanitou / InvoicesController.php
Created March 25, 2014 15:22
Add vendor class to CakePHP 2.x - e.g. HTML2PDF
<?php
App::uses('AppController', 'Controller');
class InvoicesController extends AppController {
public $uses = array();
public function pdf($id = null) {
$this->autoRender = false;
$this->layout = null;
/**
* Calculate Greatest Common Divisor of 2 integers.
* The result is always positive even if either of, or both, input operands are negative.
* By Aurélien Millet
* http://aurelien-dev-notes.blogspot.fr/2012/07/php-calcul-du-plus-grand-commun-diviseur.html
*
* @param int $a
* @param int $b
* @return int
*/
<?php
// Input group
echo $this->Form->input('test', array(
'beforeInput' => '<div class="input-group">',
'afterInput' => '<span class="input-group-addon">.00</span></div>'
));
?>
@grandmanitou
grandmanitou / chmod.sh
Created April 12, 2014 12:32
Recursively chmod files starting from a specific folder
find ./ -type f -name '*.*' -exec chmod 644 '{}' \+
@grandmanitou
grandmanitou / gist:10607174
Created April 13, 2014 23:57
Compile PHP 5.1.11 for Plesk 11.5 on Ubuntu
Download PHP 5.5.11
wget http://fr2.php.net/get/php-5.5.11.tar.gz/from/this/mirror -O /usr/local/src/php-5.5.11.tar.gz
Extract and change to the directory
tar xzvf /usr/local/src/php-5.5.11.tar.gz -C /usr/local/src/
cd /usr/local/src/php-5.5.11/
Configure PHP 5.5.11
./configure --with-libdir=/lib/x86_64-linux-gnu --cache-file=./config.cache --prefix=/usr/local/php-5.5.11 --with-config-file-path=/usr/local/php-5.5.11/etc --disable-debug --with-pic --disable-rpath --with-bz2 --with-curl=/usr/lib/x86_64-linux-gnu/ --with-freetype-dir=/usr/local/php-5.5.11 --with-png-dir=/usr/local/php-5.5.11 --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr/local/php-5.5.11 --with-openssl --with-pspell --with-pcre-regex --with-zlib --enable-exif --enable-ftp --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-wddx --with-kerberos --with-unixODBC=/usr --enable-shmop --enable-calendar --with-libxml-dir=/usr/local/php-5.5.11 --enable-pcntl --with-imap-ssl -
@grandmanitou
grandmanitou / NewsController.php
Created April 25, 2014 15:45
CakePHP Paginate HABTM with conditions
<?php
public function index() {
$this->paginate = array(
'conditions' => array('NewsProfiles.profile_id' => $this->authUser['profile_id']),
'joins' => array(
array(
'alias' => 'NewsProfiles',
'table' => 'news_profiles',
'type' => 'INNER',
'conditions' => 'News.id = NewsProfiles.news_id'
@grandmanitou
grandmanitou / ExtractionsController.php
Created May 5, 2014 10:29
CakePHP - Download file
<?php
App::uses('AppController', 'Controller');
/**
* Extractions Controller
*
* @property Extraction $Extraction
* @property PaginatorComponent $Paginator
* @property SessionComponent $Session
*/
class ExtractionsController extends AppController {
@grandmanitou
grandmanitou / cakephp_date_input_formatting_with_boostcake.php
Last active August 29, 2015 14:01
CakePHP Date Input nice formatting with BoostCake
<?php
echo $this->Form->input('end', array(
'label' => array('text' => 'Date de fin'),
'type' => 'date',
'dateFormat' => 'DMY',
'minYear' => date('Y'),
'style' => 'width: 100px; display: inline-block;'
));
echo $this->Form->input('end', array(
'label' => array('text' => 'Heure de fin'),