Snippets populaires

replace url by links in a text

  static function urlMe($text){
    $pattern = "@(http://|https://){1}((www\.?)[a-zA-Z0-9\-\.]+\.[a-z]{2,6})/?([^\s]*)@";
    preg_match_all($pattern,' '.$text.' ',$matches);
    foreach($matches[2] as $offset => $link){
      $text = str_replace($matches[0][$offset],'<a href="'.$matches[0][$offset].'" title="'.$matches[0][$offset].'">'.$link.'</a>',$text);
    }
    return($text);
  }
by Leroux de Lens Amaury on 2009-11-18, tagged links  regexp  tools 
(2 comments)

Supprimer les espaces des noms de fichier

Pour supprimer tous les espaces des noms de fichier récursivement :

$ find . -type f -regex ".*\ .*" \
       -exec bash -c 'echo "$1";mv "$1" "${1// /-}"' '{}' '{}'  \;

(via maboite.org)

by Nicolas Perriault on 2008-04-08, tagged bash  cli  find 

Corriger l'encodage d'un fichier MYSql

Pour corriger les caractères bizarres qui peuvent apparaitre à la place des accents après une remontée d'un fichier de dump, il est possible de fixer l'encodage pour la connexion en rajoutant au début du fichier la ligne :

SET CHARACTER SET <encodage>;

J'utilise notamment souvent UTF8 dans ce cas, le fichier provenant d'un dump effectué sous linux, et remontant dans une base en latin1.

by gameplayer on 2007-06-08, tagged mysql  sysadmin 

Vérifier l'empreinte md5 d'une image ISO

Avec md5sum :

$ md5sum feisty-desktop-i386.iso

Comparer l'empreinte de l'image ISO avec celle du CD gravé :

Trouver le périphérique à vérifier :

$ cat /etc/fstab | grep cdrom

Vérification :

$ md5sum /dev/hdb
by Nicolas Perriault on 2007-02-17, tagged cdrom  cli  debian  iso  linux  md5  ubuntu 

Mirrorer un répertoire d'une machine à une autre via SSH

Pour synchroniser un répertoire d'une machine A vers une machine B en passant par SSH (avec preservation des droits) :

$ rsync -avz -e ssh someuser@server1.example.com:/var/www/ /var/www/

Utile également pour migrer une machine vers une autre.

by Nicolas Perriault on 2006-11-01, tagged linux  mirroring  rsync  server  sysadmin  ubuntu 

Trouver le nombre de slots mémoires disponibles/occupés sous Linux

Sous linux :

$ dmidecode | grep -i "size"

Ce qui renvoie un truc du genre :

Size: 512 MB
Size: 512 MB
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed

Donc là on a 6 slots occupés par deux barrettes de 512Mo.

by Nicolas Perriault on 2006-10-26, tagged bash  cli  hardware  infos  linux 

Hello World !

Hi all, this is just a test :

<?php
abstract class HelloWorld {
  static public function sayIt()
  {
    echo 'Hello World !';
  }
}
 
HelloWorld::sayIt();
?>
by Nicolas Perriault on 2006-10-09, tagged php  test 

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
by Nicolas Perriault on 2007-01-11, tagged bash  cli  filesystem  linux 

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
by gameplayer on 2007-01-11, tagged bash  debian  linux  sysadmin  ubuntu 
(2 comments)

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.)

by Nicolas Perriault on 2007-01-02, tagged sysadmin  ubuntu