Derniers snippets
Réduire le coût de performances de require_once
La fonction require_once étant assez coûteuse en PHP, il peut être intéressant de tester l'existence de l'objet que le fichier définit avant de le charger d'emblée :
class_exists('sfCache') or require_once($sf_symfony_lib_dir.'/cache/sfCache.class.php');
[Symfony] Traiter les OR sql avec Propel
Voici comment gérer les "ou" SQL dans Propel :
$criteria = new Criteria(); $criteria->add(TotoPeer::NAME, 'Gérard Bouchard'); $criterion = $criteria->getNewCriterion ( TotoPeer::ID, 5 )->addOr($criteria->getNewCriterion ( TotoPeer::ID, 10 )); $criteria->addAnd($criterion); TotoPeer::doSelect($criteria);
Ceci donnera quelque chose comme :
SELECT * FROM toto WHERE toto.NAME = 'Gérard Bouchard' AND ( toto.ID = 5 OR toto.ID = 10 );
Changer les caractères <CR> en <LF>
Convertir rapidement et simplement les caractères \r en \n :
$ perl -pi -e 's#\r#\n#gs' /path/to/file
Effacer les fichiers trop volumineux
Find est un outil magnifiquement simple et puissant. Par exemple, pour supprimer tous les fichiers de plus de 500Kb dans le répertoire courant :
$ find . -type f -size +500 | xargs rm
Turn on Bash Smart Completion
Just edit /etc/bash.bashrc
Uncomment the following lines, by removing the # in the beginning of the lines:
#if [ -f /etc/bash_completion ]; then # . /etc/bash_completion #fi
Now, resource the modified file :
$ source /etc/bash.bashrc
Then try to tape apt-cache [TAB][TAB]
You will have this result in replacement of the habitual list of files and directories of your current path :
$ apt-cache
add dotty dumpavail pkgnames rdepends show showsrc unmet
depends dump gencaches policy search showpkg stats xvcg
It works with a lot of functions like cd (it will provide only directories), apt-get,...
It also enable code completion when using the sudo command.
Isn't it useful ?
Nota : The tip I give here is to activate Smart Completion for all users. If you want to activate it for only one user (or if you want to activate it but doesn't have write rights to /etc/bash.bashrc) you can modify your ~/.bashrc file and uncomment the same lines as described upper and resource it with
$ source ~/.bashrc
Can't start server: Bind on TCP/IP port: Cannot assign requested address
Des fois, MySQL c'est chiant. Merci IRC !
<n1k0> help <n1k0> je dois installer un server mysql5 sur une ubuntu lts server toute fraiche <n1k0> apt-get install mysql-server-5.0 <n1k0> et là c'est le drâme <n1k0> il me sort ...failed or took more than 6s. <n1k0> Please take a look at the syslog. <n1k0> /usr/bin/mysqladmin: connect to server at 'localhost' failed <n1k0> error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' <n1k0> Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists! <n1k0> dans le syslog, j'ai : <n1k0> [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address <n1k0> netstat, ps et lsof me montrent qu'aucun autre mysql ne tourne <n1k0> j'ai tenté --reinstall --purge, rien n'y fait <Yann2> et si t'essaie de démarrer le serveur? <david`bgk> port utilisé ? <n1k0> j'ai même rebooté la machine (!) <n1k0> port 3306 libre <Yann2> avec sudo /etc/init.d/ ? <n1k0> rien n'y fait <Yann2> meme message d'erreur? <n1k0> ouais <david`bgk> et /var/run/mysqld/mysqld.sock existe ? <n1k0> non justement <n1k0> mais d'ou vient le bleme ?? <worf|work> dans /etc/mysql/my.cnf regarde quel est le bind-adress <worf|work> si y en a un etc... <n1k0> j'ai aussi ^G/usr/bin/mysqladmin: connect to server at 'localhost' failed <[NikO]> j'adore les boulets sur msn, ils m'ajoutent dans leur contact, et ils me font 't'es ki ?' <n1k0> dans le syslog <worf|work> netstat -an | grep 3306 <worf|work> regarde si y a un truc qui listen aussi <n1k0> bind-address : 127.0.0.1 <worf|work> il doit servir qu'en local ce mysql ? <worf|work> ou d'autres machines devront s'y connecter ? <n1k0> rien n'ecoute <n1k0> non c'est du local pur <worf|work> dans ps y a aucun mysqld ? <n1k0> non <worf|work> tapes : safe_mysqld <worf|work> ou mysqld_safe <worf|work> (si ça existe) <n1k0> command not found <n1k0> ah <n1k0> Starting mysqld daemon with databases from /var/lib/mysql <n1k0> mysqld_safe[4716]: started <n1k0> STOPPING server from pid file /var/run/mysqld/mysqld.pid <n1k0> mysqld_safe[4729]: ended <n1k0> gné <worf|work> ls -la /var/lib/mysql <n1k0> total 20532 <n1k0> drwxr-xr-x 3 mysql mysql 4096 2007-01-10 13:35 . <n1k0> drwxr-xr-x 22 root root 4096 2007-01-10 13:21 .. <n1k0> -rw-r--r-- 1 root root 0 2007-01-10 13:21 debian-5.0.flag <n1k0> -rw-rw---- 1 mysql mysql 10485760 2007-01-10 13:35 ibdata1 <n1k0> -rw-rw---- 1 mysql mysql 5242880 2007-01-10 13:35 ib_logfile0 <n1k0> -rw-rw---- 1 mysql mysql 5242880 2007-01-10 13:21 ib_logfile1 <n1k0> drwxr-xr-x 2 mysql root 4096 2007-01-10 13:21 mysql <worf|work> ça m'a l'air pourtant pas mal <n1k0> Le truc qui m'inquiète c'est : <worf|work> chown mysql:mysql /var/lib/mysql <n1k0> http://www.debianforum.de/forum/viewtopic.php?t=59014&sid=f89fc839052a659222b63b77b55572d5 <n1k0> et surtout http://www.linuxforums.org/forum/servers/41668-mysql-problems-_-solved-_.html <n1k0> Genre personne y comprend rien <n1k0> le chown a rien changé <worf|work> dans ton my.cnf vire ton bind-adresse <n1k0> ok <n1k0> ça marche ! <n1k0> bouarf <worf|work> ton interface loopback est pas en bon état :) <n1k0> yep <worf|work> ferme ton 3306 avec un firewall <worf|work> et pi toute façon quand tu fais tes GRANT restreint les ensuite à l'ip de la machine. <Rik24d> david`bgk: je parlais bien évidemment des négo entre apple et les opérateurs <worf|work> ifconfig lo <worf|work> ça dit quoi ? <n1k0> lo Link encap:Local Loopback <n1k0> LOOPBACK MTU:16436 Metric:1 <n1k0> RX packets:0 errors:0 dropped:0 overruns:0 frame:0 <n1k0> TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 <n1k0> collisions:0 txqueuelen:0 <n1k0> RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) <worf|work> c le script réso qui pue <worf|work> ifconfig lo UP <Rik24d> n1k0: http://paste.inertie.org ;) <david`bgk> paste.inertie.org :p <david`bgk> arf <n1k0> Rik24d, flemme + mode panic = excusez moi <neuro`> Quelqu'un qui torche en rewrite rules ici ? <david`bgk> c'est juste que c'est nouveau mais personne l'utilise ;) <n1k0> YEAH <n1k0> merci mille fois worf|work <worf|work> verifie tes scripts de démarrage <n1k0> I owe you a beer, quand tu veux <worf|work> c'est pas normal que lo soit pas UP <worf|work> et ça doit etre ça qui merde, pas mysql <n1k0> yep <n1k0> mais là le truc tourne, je peux installer ma demo <n1k0> je ferai un gros check up cet aprem <n1k0> merci encore <worf|work> de rien
Utiliser la JVM de Sun au lieu de GCJ
Vérifier la présence de la mchine virtuelle Java de Sun :
$ update-java-alternatives -l
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-gcj 1041 /usr/lib/jvm/java-gcj
La mettre par défaut :
$ sudo update-java-alternatives -s java-1.5.0-sun
Puis :
$ sudo vi /etc/jvm
Écrire tout en haut du fichier :
/usr/lib/jvm/java-1.5.0-sun
[Edgy] Sources.list bien cool
De quoi subvenir à la plupart des besoins.
# Ubuntu officials deb http://archive.ubuntu.com/ubuntu/ edgy main restricted multiverse universe deb http://archive.ubuntu.com/ubuntu/ edgy-updates main restricted multiverse universe deb http://archive.ubuntu.com/ubuntu/ edgy-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu edgy-security main restricted multiverse universe # Ubuntu commercials deb http://archive.canonical.com/ubuntu edgy-commercial main # Beryl deb http://ubuntu.beryl-project.org edgy main # Asher deb http://asher256-repository.tuxfamily.org edgy main dupdate french deb http://asher256-repository.tuxfamily.org ubuntu main dupdate french # Medibuntu deb http://medibuntu.sos-sts.com/repo/ edgy free deb http://medibuntu.sos-sts.com/repo/ edgy non-free # Wine deb http://wine.budgetdedicated.com/apt edgy main # Geany deb http://gauvain.tuxfamily.org/repos edgy contrib
Trouver tous les fichiers modifiés récemment
To find files modified between the last x days and the last y days (x > y) in the current directory (x and y are integers) :
$ find ./ -ctime -x -ctime +y
Lancer un script au démarrage sur Ubuntu
Write a script and put it in the /etc/init.d/ directory.
Lets say you called it FOO. You then run :
$ sudo update-rc.d FOO defaults
You also have to make the file you created, FOO, executable, using
$ sudo chmod +x FOO
You can check out :
$ sudo man update-rc.d
... for more information. It is a Debian utility to install scripts.
The option "defaults" puts a link to start FOO in run levels 2, 3, 4 and 5. (and puts a link to stop FOO into 0, 1 and 6.)




