Skip to content

Instantly share code, notes, and snippets.

@grandmanitou
grandmanitou / gist:7993601
Created December 16, 2013 20:15
Dump all databases from mysql - one file per database - then compress to zip
mysql -s -r -uadmin -p`cat /etc/psa/.psa.shadow` -e 'show databases' | while read db; do mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` $db -r ${db}.sql; [[ $? -eq 0 ]] && zip ${db}.zip ${db}.sql -r9; done
@grandmanitou
grandmanitou / gist:7993667
Last active December 31, 2015 13:29
Log into MySQL with root / admin account via command line
# classic connection
mysql -uadmin -p`cat /etc/psa/.psa.shadow`
# classic dump
mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` viacombi_eu_forum > viacombi_eu_forum.sql
@grandmanitou
grandmanitou / gist:7994542
Created December 16, 2013 21:13
Upload recursively a wholde directory structure to a remote FTP server via command line. Requires lftp
lftp ftp://user:[email protected] -e "mirror -e -R /local/folder /remote/folder ; quit"
@grandmanitou
grandmanitou / gist:8093911
Created December 23, 2013 09:16
Delete all .DS_Store recursively
find . -name '*.DS_Store' -type f -delete
@grandmanitou
grandmanitou / gist:8521246
Created January 20, 2014 14:57
PHP convert numbers to capital letters (useful to create excel tables)
function num2alpha($n) {
$r = '';
for ($i = 1; $n >= 0 && $i < 10; $i++) {
$r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) . $r;
$n -= pow(26, $i);
}
return $r;
}
@grandmanitou
grandmanitou / AppController.php
Created January 28, 2014 15:59
CakePHP v2.x validate HABTM
public function beforeRender() {
// Enable HABTM validation
$model = Inflector::singularize($this->name);
foreach($this->{$model}->hasAndBelongsToMany as $k=>$v) {
if(isset($this->{$model}->validationErrors[$k]))
{
$this->{$model}->{$k}->validationErrors[$k] = $this->{$model}->validationErrors[$k];
}
}
@grandmanitou
grandmanitou / gist:8773691
Created February 2, 2014 19:44
PHP highlight words in text using regex
function highlight($text, $words) {
preg_match_all('~\w+~', $words, $m);
if(!$m)
return $text;
$re = '~\\b(' . implode('|', $m[0]) . ')\\b~';
return preg_replace($re, '<b>$0</b>', $text);
}
$text = '
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
@grandmanitou
grandmanitou / gist:8859378
Created February 7, 2014 09:02
Cakephp 2.x validation of french phone number
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'phone_number_1' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
@grandmanitou
grandmanitou / gist:8859900
Created February 7, 2014 09:51
Convert first page of PDF to JPG using ImageMagick through command line
convert source.pdf[0] output.jpeg
@grandmanitou
grandmanitou / gist:8863248
Created February 7, 2014 14:10
Place multiple markers with infowindow on Google Maps API v3, use external links to trigger click and center map on desired location.
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?language=fra&amp;sensor=false"></script>
<script type="text/javascript">
var map;
var Markers = {};
var infowindow;
var locations = [
[
'Samsung Store Madeleine',
'<strong>Samsung Store Madeleine</strong><p>5 Boulevard Malesherbes, 75008 Paris<br>10h – 20h</p>',
48.8701925,