<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <title>Latest snippets by user Nicolas Perriault</title>
  <link rel="alternate" href="http://snippets.prendreuncafe.com/snippets/from/NiKo/order_by/date"></link>
  <id>http://snippets.prendreuncafe.com/snippets/from/NiKo/order_by/date</id>
  <updated>2008-05-26T15:34:00Z</updated>
  <author>
    <name>Symfony</name>
    <author_email>noreply@symfony-project.com</author_email>
  </author>
<entry>
  <title>[Symfony] Effacer partiellement le cache d'une application</title>
  <link href="http://snippets.prendreuncafe.com/snippet/94"></link>
  <updated>2008-05-26T15:34:00Z</updated>
  <id>94</id>
  <summary type="html">Toujours utile depuis un contexte d'application différent de celui visé :

[code=php]
sfToolkit::clearGlob(sfConfig::get('sf_cache_dir').'/frontend/*/all/*/templates/toto.cache');
[/code]</summary>
</entry>
<entry>
  <title>Gestion des tags en SQL</title>
  <link href="http://snippets.prendreuncafe.com/snippet/93"></link>
  <updated>2008-05-15T22:06:43Z</updated>
  <id>93</id>
  <summary type="html">Un schema classique de gestion de tags :

[code=sql]
CREATE TABLE Project ( 
  project_id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
  name VARCHAR(50) NOT NULL, 
  url TEXT NOT NULL, 
  PRIMARY KEY (project_id) 
) ENGINE=MyISAM;

CREATE TABLE Tags ( 
  tag_id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
  tag_text VARCHAR(50) NOT NULL, 
  PRIMARY KEY (tag_id), 
  INDEX (tag_text) 
) ENGINE=MyISAM; 

CREATE TABLE Tag2Project ( 
  tag INT UNSIGNED NOT NULL, 
  project INT UNSIGNED NOT NULL, 
  PRIMARY KEY (tag, project), 
  INDEX rv_primary (project, tag) 
) ENGINE=MyISAM;
[/code]

Pour récupérer tous les projets taggué `php` **ou** `mysql` :

[code=sql]
SELECT p.name 
FROM Project p 
  INNER JOIN Tag2Project t2p 
    ON p.project_id = t2p.project 
  INNER JOIN Tag t 
    ON t2p.tag = t.tag_id 
WHERE t.tag_text IN ('mysql', 'php');
[/code]

Pour récupérer tous les projets taggué `php` **et** `mysql` :

[code=sql]
SELECT p.name 
FROM Project p 
  CROSS JOIN Tag t1 
  CROSS JOIN Tag t2 
  INNER JOIN Tag2Project t2p 
    ON p.project_id = t2p.project 
      AND t2p.tag = t1.tag_id 
  INNER JOIN Tag2Project t2p2 
    ON t2p.project = t2p2.project 
      AND t2p2.tag = t2.tag_id 
WHERE t1.tag_text = &quot;php&quot; 
  AND t2.tag_text = &quot;mysql&quot;;
[/code]

Tiré et adapté de la présentation [Join-fu de Jay Pipes](http://jpipes.com/presentations/joinfu/joinfu.pdf)</summary>
</entry>
<entry>
  <title>Cross apps url helper for symfony 1.0</title>
  <link href="http://snippets.prendreuncafe.com/snippet/92"></link>
  <updated>2008-05-15T15:50:14Z</updated>
  <id>92</id>
  <summary type="html">Here's a helper that allow to generate cross apps urls in symfony 1.0

[code=php]
/**
 * Generates cross-apps urls in symfony 1.0
 *
 * @param  string  the app we want to go to
 * @param  string  the route in the app. Must be valid
 * @param  array   the arguments required by the route. Optional
 * @return string
 */
function cross_app_url($app, $route, $args = null)
{
  $host = sfContext::getInstance()-&gt;getRequest()-&gt;getHost() ;
  $env = sfConfig::get('sf_environment');
  $appRoutingFile = SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'routing.yml' ;
  $route = substr($route, 1, strlen($route)) ;
  if (file_exists($appRoutingFile))
  {
    $yml = sfYaml::load($appRoutingFile) ;
    $routeUrl = $yml[$route]['url'] ;
    if ($args)
    {
      foreach ($args as $k =&gt; $v)
      {
        $routeUrl = str_replace(':' . $k, $v, $routeUrl) ;
      }
    }
    if (strrpos($routeUrl, '*') == strlen($routeUrl) - 1)
    {
      $routeUrl = substr($routeUrl, 0, strlen($routeUrl) - 2) ;
    }
  }
  return sprintf('http://%s/%s/%s',
                 $host,
                 ($env == 'dev' ? $app . '_dev.php' : ($app != $main_app) ? $app : ''),
                 $routeUrl);
}
[/code]

Adapted from [here](http://www.symfony-project.org/forum/index.php/mv/msg/7460/31105/)</summary>
</entry>
<entry>
  <title>Logger compatible Firebug et Opera Console</title>
  <link href="http://snippets.prendreuncafe.com/snippet/90"></link>
  <updated>2008-05-10T12:16:48Z</updated>
  <id>90</id>
  <summary type="html">Une petite fonction qui permet de logguer dans la console de Firebug ou d'Opera, sans déclencher d'erreur si ces derniers sont indisponibles.

[code=javascript]
function log() {
  try {
    console.log.apply(console, arguments);
  } catch(e) {
    try {
      opera.postError.apply(opera, arguments);
    } catch(e) {
    }
  }
}

log(&quot;Voici un objet: %o&quot;, {toto: &quot;tata&quot;, coucou: true});
[/code]</summary>
</entry>
<entry>
  <title>Extraire toutes les chaînes d'un fichier binaire</title>
  <link href="http://snippets.prendreuncafe.com/snippet/89"></link>
  <updated>2008-04-23T14:36:03Z</updated>
  <id>89</id>
  <summary type="html">En fait, c'est tout bête (mais qu'est ce que ça peut être utilie !) :

[code]
$ strings /usr/bin/iconv 
Written by %s.
char
UCS-4
conversion from %s unsupported
conversion to %s unsupported
conversion from %s to %s unsupported
try '%s -l' to get the list of supported encodings
[...]
[code]</summary>
</entry>
<entry>
  <title>Convertir un timestamp unix en ligne de commande</title>
  <link href="http://snippets.prendreuncafe.com/snippet/88"></link>
  <updated>2008-04-18T21:41:13Z</updated>
  <id>88</id>
  <summary type="html">C'est bête mais ça peut toujours servir.

[code]
$ date -r 1204748227
Wed Mar  5 12:17:07 PST 2008
[/code]</summary>
</entry>
<entry>
  <title>Créer un patch SVN et l'appliquer</title>
  <link href="http://snippets.prendreuncafe.com/snippet/87"></link>
  <updated>2008-04-11T09:23:03Z</updated>
  <id>87</id>
  <summary type="html">Pour mémoire, voici la méthode pour créer un patch depuis un dépôt subversion et l'appliquer sur un autre checkout de ce même dépôt :

[code]
$ cd /path/to/instance/1
$ svn diff /tmp/diff.patch
$ cd /path/to/instance/2
$ patch -p0 -i /tmp/diff.patch
[/code]</summary>
</entry>
<entry>
  <title>Supprimer les espaces des noms de fichier</title>
  <link href="http://snippets.prendreuncafe.com/snippet/86"></link>
  <updated>2008-04-08T11:42:29Z</updated>
  <id>86</id>
  <summary type="html">Pour supprimer tous les espaces des noms de fichier récursivement :

[code]
$ find . -type f -regex &quot;.*\ .*&quot; \
       -exec bash -c 'echo &quot;$1&quot;;mv &quot;$1&quot; &quot;${1// /-}&quot;' '{}' '{}'  \;
[/code]

(via maboite.org)</summary>
</entry>
<entry>
  <title>Déplacement récursif SVN avec xargs </title>
  <link href="http://snippets.prendreuncafe.com/snippet/85"></link>
  <updated>2008-04-07T16:47:32Z</updated>
  <id>85</id>
  <summary type="html">Pour déplacer n fichiers php d'un dépôt subversion :

[code]
$ find . -name *.php | xargs -I % svn mv &quot;%&quot; trunk/
[/code]

On notera qu'on peut appliquer le principe pour toute commande dont l'ordre des arguments est exotique.</summary>
</entry>
<entry>
  <title>Lire les mails en texte brut sous OS X avec Mail.app</title>
  <link href="http://snippets.prendreuncafe.com/snippet/84"></link>
  <updated>2008-04-02T14:29:49Z</updated>
  <id>84</id>
  <summary type="html">Ouvrir un terminal et taper :

[code]
$ defaults write com.apple.mail PreferPlainText -bool TRUE
[/code]</summary>
</entry>
</feed>