Derniers snippets latest snippets

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
by gameplayer on 2007-01-03, tagged files  linux  sysadmin 

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 

Générer la PHPDoc d'un projet

$ sudo apt-get install php-pear
$ sudo pear install PhpDocumentor
$ phpdoc -d /path/to/project/sources -t /path/to/project/doc
by Nicolas Perriault on 2006-12-26, tagged pear  php  phpdoc  ubuntu 

Multiton en PHP5

class Multiton
{
  private $instances = array();
 
  public function getInstance($var1, $var2, $var3)
  {
    $uid = md5((string)$var1.(string)$var2.(string)$var3);
    if (!isset(self::$instances[$uid])) 
    { 
      self::$instances[$uid] = new Multiton($var1, $var2, $var3);
    }
    return self::$instances[$uid];
  }
 
}
by Nicolas Perriault on 2006-12-26, tagged pattern  php 

Lire le @#!$% de format mp3 sous Ubuntu Edgy

Après avoir installé la moitié des packages universe ou autres medibuntu, c'était en fait un simple :

$ sudo apt-get install gstreamer0.10-ffmpeg

Now, banshee rocks.

by Nicolas Perriault on 2006-12-24, tagged codecs  mp3  ubuntu 

Downgrader un package sous Ubuntu

On peut forcer la version d'un paquet à installer :

$ sudo aptitude install nomdupaquet=1.2.3-version2
by Nicolas Perriault on 2006-12-21, tagged apt  debian  linux  sysadmin  ubuntu 

Récupérer la taille d'une vidéo en PHP avec ffmpeg

On a besoin de http://ffmpeg-php.sourceforge.net/, puis :

extension_loaded('ffmpeg') or die('ffmpeg extension not loaded');
 
$ffmpegInstance = new ffmpeg_movie('/path/to/movie.avi');
$ffmpegInstance->getDuration(); // Gets the duration in secs.
$ffmpegInstance->getVideoCodec(); // What type of compression/codec used
by Nicolas Perriault on 2006-12-21, tagged audio  ffmpeg  php  video 

Redirect HTTP -> HTTPS requests in a VirtualHost

<VirtualHost 100.101.102.103:80>
 
  ServerName    subdomain.domain.tld
  DocumentRoot  /path/to/docroot
 
  <IfModule mod_rewrite.c>
    RewriteEngine   on
    RewriteLog      /var/log/apache2/https_rewrite.log
    RewriteLogLevel 1
    RewriteCond     %{SERVER_PORT} !^443$
    RewriteCond     %{SERVER_NAME} ^subdomain.domain.tld$
    RewriteRule     ^/(.*) https://%{SERVER_NAME}/$1 [L,R]
  </IfModule>
 
</VirtualHost>
 
<VirtualHost 100.101.102.103:443>
 
  ServerName    subdomain.domain.tld
  DocumentRoot  /path/to/docroot
 
  SSLEngine On
  SSLCertificateFile     /etc/apache2/ssl_conf/myservicename.crt
  SSLCertificateKeyFile  /etc/apache2/ssl_conf/myservicename.key
 
 
</VirtualHost>
by Nicolas Perriault on 2006-12-19, tagged apache  http  https  server  sysadmin 

Changer l'éditeur par défaut sous Ubuntu

$ sudo update-alternatives --config editor

Et là, choisir vi :-)

by Nicolas Perriault on 2006-12-12, tagged debian  editor  ubuntu  vi  vim 

Effacer les lignes vides d'un fichier

$ sed '/^$/d' fichier.txt
by Nicolas Perriault on 2006-12-09, tagged cli  linux  sed  string