<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>piouPiouM's dev</title>
	
	<link>http://pioupioum.fr</link>
	<description>Bloc-note d'un développeur web</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:47:44 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.pioupioum.fr/pioupioum-dev-blog" /><feedburner:info uri="pioupioum-dev-blog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><item>
		<title>Bundle License Helper pour TextMate</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/hVh3seY_ZSA/license-helper-textmate-bundle.html</link>
		<comments>http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html#comments</comments>
		<pubDate>Thu, 29 Jul 2010 16:29:29 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[projet]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=426</guid>
		<description><![CDATA[Parce que j&#8217;en avais ma claque de chercher le texte des licences à ajouter en en-tête de mes sources1, voici un bundle TextMate pour palier à cette répétitive perte de temps.



Table des matières


Installation
Utilisation du bundle
Personnaliser le sélecteur des licences
Corriger le formatage de la licence
Licences supportées
Développement


Installation

Depuis les sources, avec Git

cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/piouPiouM/license-helper.tmbundle.git "License Helper.tmbundle"
osascript [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Parce que j&#8217;en avais ma claque de chercher le texte des licences à ajouter en en-tête de mes sources<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>, voici un <strong><a href="http://pioupioum.fr/tag/textmate/" title="Archives pour le tag TextMate – piouPiouM&#039;s dev">bundle TextMate</a></strong> pour palier à cette répétitive perte de temps.</p>

<p><img src="http://assets1.pioupioum.fr/uploads/2010/07/License-Helper-Textmate-Bundle.png" alt="License Helper Textmate Bundle" title="License Helper Textmate Bundle" width="610" height="385" class="aligncenter size-full wp-image-431" /><span id="more-426"></span></p>

<h2 id="toc">Table des matières</h2>

<ol>
<li><a href="#installer">Installation</a></li>
<li><a href="#usage">Utilisation du bundle</a></li>
<li><a href="#personnaliser">Personnaliser le sélecteur des licences</a></li>
<li><a href="#formatage">Corriger le formatage de la licence</a></li>
<li><a href="#licenses">Licences supportées</a></li>
<li><a href="#developpement">Développement</a></li>
</ol>

<h2 id="installer">Installation</h2>

<h3>Depuis les sources, avec Git</h3>

<pre><code>cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/piouPiouM/license-helper.tmbundle.git "License Helper.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'
</code></pre>

<h3>Depuis les sources, sans Git</h3>

<pre><code>cd ~/Library/Application\ Support/TextMate/Bundles
wget http://github.com/piouPiouM/license-helper.tmbundle/tarball/master
tar zxf license-helper.tmbundle.tar.gz
rm license-helper.tmbundle.tar.gz
mv license-helper.tmbundle "License Helper.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'
</code></pre>

<h3>Téléchargement direct</h3>

<div class="download box">
    <a href="http://github.com/piouPiouM/license-helper.tmbundle/tarball/master" title="Téléchargement depuis les serveurs de GitHub"><span>Télécharger la dernière version du bundle License Helper pour TextMate</span></a>
</div>

<p>Après récupération, décompressez l&#8217;archive, renommez le dossier en <code>License Helper.tmbundle</code>. Acceptez le changement d&#8217;extension. Il ne reste plus qu&#8217;à installer le bundle d&#8217;un double-clic sur le fichier.</p>

<h2 id="usage">Utilisation du bundle</h2>

<p>Utilisez le lanceur <code>license⇥</code> pour <strong>sélectionner une licence</strong> <em>via</em> la boîte de dialogue qui s&#8217;affiche.</p>

<p><div id="attachment_427" class="wp-caption aligncenter" style="width: 349px"><img src="http://assets1.pioupioum.fr/uploads/2010/07/license-helper-textmate-bundle-dialog.png" alt="Choix d&#039;une licence – License Helper Textmate Bundle" title="license-helper-textmate-bundle-dialog" width="339" height="384" class="size-full wp-image-427" /><p class="wp-caption-text">Choix d&#8217;une licence – License Helper Textmate Bundle</p></div></p>

<p>Un bloc de licence est inséré en tant que Snippet. Utilisez la touche de tabulation pour vous déplacez sur les différents placeholders.</p>

<h3>Liste des variables d&#8217;environnement utilisées</h3>

<p>Déclarez dans votre projet les variables d&#8217;environnement qui suivent pour auto-compléter les blocs de licence à insérer&#160;:</p>

<ul>
<li><code>TM_PROJECT_YEAR</code>. L&#8217;année de production. Par défaut&#160;: l&#8217;année courante.</li>
<li><code>TM_PROJECT_COPYRIGHT_HOLDERS</code> ou <code>TM_AUTHOR</code> ou <code>TM_ORGANIZATION_NAME</code>. Les détenteurs du copyright.</li>
<li><code>TM_ORGANIZATION_EMAIL</code>. Adresse mail de l&#8217;organisation détentrice du copyright.</li>
<li><code>TM_PROJECT_DESCRIPTION</code>. Description brève du projet.</li>
</ul>

<p>Notez que les variables sont utilisées en fonction de la licence choisie et qu&#8217;il n&#8217;est pas nécessaire de toutes les renseigner si vous n&#8217;en avez pas l&#8217;usage.</p>

<p>Vous pouvez fixer la licence de votre projet en ajoutant la variable d&#8217;environnement de projet <code>TM_PROJECT_LICENSE</code>. Ainsi, vous n&#8217;aurez plus à la sélectionner.</p>

<h2 id="personnaliser">Personnaliser le sélecteur des licences</h2>

<p>La commande accessible depuis le menu <em>License Helper → Edit licenses order</em> lance l&#8217;édition du fichier de configuration du bundle.<br />
Modifiez l&#8217;ordre des licences déclarées selon vos préférences d&#8217;apparition dans le sélecteur de licences.</p>

<h2 id="formatage">Corriger le formatage de la licence</h2>

<p>Il est possible qu&#8217;avec certains langages, le rendu des blocs de licences ne corresponde pas à vos attentes. Si tel est le cas, définissez votre propre format&#160;:</p>

<ol>
<li>Bundles → Bundle Editor</li>
<li>Dans l&#8217;entrée <strong>License Helper</strong>, créez une nouvelle Preference et donnez-lui le nom du langage.</li>
<li>Remplissez le champ Scope Selector avec le scope approprié – i.e. <code>source.java</code> pour les sources java.</li>
<li>Définissez les shellVariables <code>TM_LICENSE_HELPER_HEADER</code> (début du bloc de commentaire) et <code>TM_LICENSE_HELPER_FOOTER</code> (fin du bloc de commentaire), comme suit&#160;:</li>
</ol>

<pre>{  shellVariables = (
        {   name = 'TM_LICENSE_HELPER_HEADER';
            value = '/*';
        },
        {   name = 'TM_LICENSE_HELPER_FOOTER';
            value = '*/';
        },
    );
}</pre>

<p><strong>Note&#160;:</strong> chacune des lignes de la licence peut être préfixée de la variable <code>TM_LICENSE_HELPER_LINE</code>.</p>

<h2 id="licenses">Licences supportées</h2>

<p>La liste des licences prises en charge par le plugin n&#8217;est pas figée. N&#8217;hésitez pas à me <a href="#developpement">soumettre</a> celles qui vous font défaut.</p>

<ul>
<li><a href="http://www.opensource.org/licenses/agpl-v3.html" title="GNU AFFERO GENERAL PUBLIC LICENSE v3 | Open Source Initiative">Affero GNU Public License 3.0</a></li>
<li><a href="http://www.opensource.org/licenses/apache2.0.php" title="Open Source Initiative OSI - Apache License, Version 2.0:Licensing | Open Source Initiative">Apache license 2.0</a></li>
<li><a href="http://www.cecill.info/" title="CeCILL">CeCILL license</a></li>
<li><a href="http://sam.zoy.org/wtfpl/" title="WTFPL - Do What The Fuck You Want To Public License">Do What The Fuck You Want To Public License</a></li>
<li><a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" title="GNU General Public License v2.0 - GNU Project - Free Software Foundation (FSF)">GNU General Public License version 2</a></li>
<li><a href="http://www.gnu.org/licenses/gpl-3.0.html" title="The GNU General Public License - GNU Project - Free Software Foundation (FSF)">GNU General Public License version 3</a></li>
<li><a href="http://www.gnu.org/licenses/lgpl.html" title="GNU Lesser General Public License - GNU Project - Free Software Foundation (FSF)">GNU Lesser General Public License version 3</a></li>
<li><a href="http://www.opensource.org/licenses/mit-license.html" title="Open Source Initiative OSI - The MIT License:Licensing | Open Source Initiative">MIT license</a></li>
<li><a href="http://www.opensource.org/licenses/bsd-license.php" title="Open Source Initiative OSI - The BSD License:Licensing | Open Source Initiative">New and Simplified BSD licenses</a></li>
<li><a href="http://www.opensource.org/licenses/bsd-license.php" title="Open Source Initiative OSI - The BSD License:Licensing | Open Source Initiative">Original BSD license</a></li>
<li><a href="http://www.opensource.org/licenses/postgresql" title="The PostgreSQL Licence (TPL) | Open Source Initiative">PostgreSQL license</a></li>
</ul>

<h2 id="developpement">Développement</h2>

<p>Distribué sous <a href="http://www.opensource.org/licenses/mit-license.html" title="Open Source Initiative OSI - The MIT License:Licensing | Open Source Initiative">license MIT</a>, le <a href="http://github.com/piouPiouM/license-helper.tmbundle" title="piouPiouM's license-helper.tmbundle at master - GitHub">code source du bundle</a> est accessible sur GitHub.</p>

<p>Une suggestion, une amélioration, une critique ou un bug à me soumettre&#160;? Ça se passe du côté du <a href="http://github.com/piouPiouM/license-helper.tmbundle/issues" title="Issues - piouPiouM/license-helper.tmbundle - GitHub">bugtracker</a> associé.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li><li><a href='http://pioupioum.fr/developpement/jslint-console-rhino.html' title='Une console JSLint pour aider vos validations JavaScript'>Une console JSLint pour aider vos validations JavaScript</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>exception faite des projets pour lesquels j&#8217;utilise un builder qui l&#8217;ajoute comme un grand à ma place.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/hVh3seY_ZSA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html</feedburner:origLink></item>
		<item>
		<title>JavaScript : optimiser le calcul de l’intersection de tableaux de grandes tailles</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/MhVIsCsiVuc/javascript-array-intersection.html</link>
		<comments>http://pioupioum.fr/developpement/javascript-array-intersection.html#comments</comments>
		<pubDate>Tue, 13 Jul 2010 13:31:38 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=408</guid>
		<description><![CDATA[Trouver sur la toile une fonction JavaScript de calcul d&#8217;intersection de tableaux qui soit efficace sur des tableaux dépassant les 50 entrées relève de l&#8217;impossible. C&#8217;est bien simple, les différentes solutions que j&#8217;ai pu rencontrer réalisent des calculs linéaires donc autant dire qu&#8217;à partir d&#8217;un certain seuil leurs performances deviennent catastrophiques.

C&#8217;est pourquoi je vous propose [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Trouver sur la toile une fonction <strong>JavaScript</strong> de calcul d&#8217;<strong>intersection de tableaux</strong> qui soit efficace sur des tableaux dépassant les 50 entrées relève de l&#8217;impossible. C&#8217;est bien simple, les différentes solutions que j&#8217;ai pu rencontrer réalisent des calculs linéaires donc autant dire qu&#8217;à partir d&#8217;un certain seuil <em>leurs performances deviennent catastrophiques</em>.</p>

<p>C&#8217;est pourquoi je vous propose ici une fonction de recherche des intersections pour un nombre arbitraire de grands tableaux plus efficace que ce que j&#8217;ai pu tester,  <a href="http://pioupioum.fr/sandbox/javascript-array-intersect-benchmark/" title="JavaScript Big Arrays Intersection - JSpeedmus Benchmark Suite">benchmarks</a> à l&#8217;appui. Est également disponible la suite des <a href="http://pioupioum.fr/sandbox/javascript-array-intersect-benchmark/qunit.html" title="JavaScript Big Arrays Intersection - Unit tests">tests unitaires</a>.</p>

<p><div id="attachment_418" class="wp-caption aligncenter" style="width: 620px"><a href="http://assets1.pioupioum.fr/uploads/2010/07/JavaScript-Big-Arrays-Intersection-JSpeedmus-Benchmark-Suite.png"><img src="http://assets1.pioupioum.fr/uploads/2010/07/JavaScript-Big-Arrays-Intersection-JSpeedmus-Benchmark-Suite-610x238.png" alt="Benchmark réalisé sous Google Chrome 5.0.375.99 / Mac Pro 2 x 3 Ghz Quad-Core Intel Xeon / Mac OS X 10.5.8" title="JavaScript Big Arrays Intersection - JSpeedmus Benchmark Suite" width="610" height="238" class="size-medium wp-image-418" /></a><p class="wp-caption-text">Benchmark réalisé sous Google Chrome 5.0.375.99 / Mac Pro 2 x 3 Ghz Quad-Core Intel Xeon sous Mac OS X 10.5.8</p></div>
<span id="more-408"></span></p>

<h2>La fonction array_big_intersect()</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Compute the intersection of big arrays.
 *
 * @author  Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @license http://www.opensource.org/licenses/mit-license.php MIT License.
 * @see     http://pioupioum.fr/developpement/javascript-array-intersection.html
 * @version 1.0.1
 *
 * @param  {Array} arr1 First array.
 * @param  {Array} arr2 Second array.
 * @param  {Array} [arr3[, arr4[, ...]]] Optional arrays.
 * @return {Array} A new array containing elements common to the arrays passed
 *                 in arguments, with no duplicates.
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> array_big_intersect <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> args <span style="color: #339933;">=</span> Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">slice</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      aLower <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      aStack <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      count<span style="color: #339933;">,</span>
      i<span style="color: #339933;">,</span>
      nArgs<span style="color: #339933;">,</span>
      nLower<span style="color: #339933;">,</span>
      oRest <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      oTmp <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      value<span style="color: #339933;">,</span>
      compareArrayLength <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> b.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      indexes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> oStack<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
            value<span style="color: #339933;">,</span>
            nArr <span style="color: #339933;">=</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">,</span>
            oTmp <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> nArr <span style="color: #339933;">&gt;</span> i<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          value <span style="color: #339933;">=</span> array<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            oStack<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>oStack<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// counter</span>
            oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">return</span> oStack<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  args.<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span>compareArrayLength<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  aLower <span style="color: #339933;">=</span> args.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  nLower <span style="color: #339933;">=</span> aLower.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span> <span style="color: #339933;">===</span> nLower<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> aStack<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  nArgs <span style="color: #339933;">=</span> args.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
  i <span style="color: #339933;">=</span> nArgs<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    oRest <span style="color: #339933;">=</span> indexes<span style="color: #009900;">&#40;</span>args.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> oRest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> nLower <span style="color: #339933;">&gt;</span> i<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    value <span style="color: #339933;">=</span> aLower<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    count <span style="color: #339933;">=</span> oRest<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nArgs <span style="color: #339933;">===</span> count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        aStack.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> aStack<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<h2>Un gain de performances</h2>

<p>Le gain de performances tient à peu de choses. En premier lieu, l&#8217;ordre d&#8217;analyse des tableaux est un point à ne pas négliger. Par définition, l&#8217;ensemble des valeurs constituant l&#8217;intersection se retrouve dans le plus petit des tableaux. De ce fait, je me base sur le plus petit d&#8217;entre-eux pour effectuer les comparaisons de présence d&#8217;une valeur dans les ensembles restants.</p>

<p>Aussi, la fonction crée un Hash de toutes les valeurs uniques et stocke leur fréquence d&#8217;apparition. Si une valeur apparaît autant de fois qu&#8217;il y a de tableaux, c&#8217;est qu&#8217;une intersection est trouvée.</p>

<p>Et c&#8217;est tout <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>Petit avertissement, si vous avez à travailler sur des tableaux de petites tailles, je vous conseille plutôt d&#8217;utiliser la fonction <a href="http://www.jslab.dk/library/Array.intersect" title="JavaScript Lab - Library - Array.intersect">Array#intersect()</a> de la librairie <a href="http://www.jslab.dk/library/" title="JavaScript Lab - Library">JSLab</a> qui s&#8217;avère être des plus performantes.</p>

<h2>Anecdote</h2>

<p>Anecdote (ou pas), mon benchmark met en évidence des erreurs de calcul de la part des librairies <a href="http://prototypejs.org/" title="Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications">Prototype</a> et <a href="http://www.thegrubbsian.com/2009/01/25/useful-javascript-extensions/" title="Useful JavaScript Extensions &mdash; The Grubbsian">Extensions</a>. La seconde ayant moins d&#8217;impact car peu propagée, il en est tout autre pour Prototype. En effet, cette dernière exclue <strong>systématiquement</strong> la valeur <code>0</code> (zéro) du tableau résultant. Ce qui est plus qu&#8217;embarrassant, pourtant le <a href="https://prototype.lighthouseapp.com/projects/8886/tickets/841-arrayintersect-return-wrong-result-if-array-values-has-0">bug</a> est connu depuis fin 2009.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/jslint-console-rhino.html' title='Une console JSLint pour aider vos validations JavaScript'>Une console JSLint pour aider vos validations JavaScript</a></li><li><a href='http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/MhVIsCsiVuc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/javascript-array-intersection.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/javascript-array-intersection.html</feedburner:origLink></item>
		<item>
		<title>Une console JSLint pour aider vos validations JavaScript</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/B2_fK8hyDdY/jslint-console-rhino.html</link>
		<comments>http://pioupioum.fr/developpement/jslint-console-rhino.html#comments</comments>
		<pubDate>Thu, 03 Jun 2010 20:07:49 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSLint]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[Rhino]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=395</guid>
		<description><![CDATA[J&#8217;ai pris l&#8217;habitude de valider mon code JavaScript à l&#8217;aide de JSLint. Outil d&#8217;analyse statique de code, JSLint permet de m&#8217;assurer du niveau de qualité de mon code avant toute déploiement en production.

Cependant la console accompagnant l&#8217;outil ne me convenait pas, et ce pour plusieurs raisons&#160;:


L&#8217;élément window n&#8217;est pas défini via les options passées à [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>J&#8217;ai pris l&#8217;habitude de valider mon code <a href="http://pioupioum.fr/tag/javascript/" title="Archives pour le tag JavaScript – piouPiouM&#039;s dev">JavaScript</a> à l&#8217;aide de <strong><a href="http://www.jslint.com/" title="JSLint, The JavaScript Code Quality Tool">JSLint</a></strong>. Outil d&#8217;<a href="http://fr.wikipedia.org/wiki/Analyse_statique_de_programmes" title="Analyse statique de programmes - Wikipédia">analyse statique</a> de code, <strong>JSLint</strong> permet de m&#8217;assurer du niveau de qualité de mon code avant toute déploiement en production.</p>

<p>Cependant la <a href="http://www.jslint.com/rhino/rhino.js">console</a> accompagnant l&#8217;outil ne me convenait pas, et ce pour plusieurs raisons&#160;:</p>

<ol>
<li>L&#8217;élément <code>window</code> n&#8217;est pas défini <em>via</em> les options passées à <code>JSLINT</code> ce qui m&#8217;oblige à le déclarer, à l&#8217;aide de l&#8217;instruction <code>/*@global</code>, dans une majorité de mes scripts.</li>
<li>Dans le même esprit, j&#8217;utilise couramment certaines options — comme <code>browser: true</code> — non présentes dans l&#8217;appel à <code>JSLINT</code>.</li>
<li>La présentation du résultat ne me convient guère.</li>
</ol>

<p>Vous trouverez dans les lignes qui suivent la console que j&#8217;utilise en remplacement.</p>

<p><span id="more-395"></span></p>

<h2>Table des matières</h2>

<ol>
<li><a href="#source">Code source</a></li>
<li><a href="#prerequis">Prérequis</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="changelog">Historique des versions et changelog</a></li>
</ol>

<h2 id="source">Code source</h2>

<div class="box file-js">
    <a href="http://static.pioupioum.fr/code/jslint-console.js" title="Télécharger"><span>jslint-console.js (4&nbsp;Ko)</span></a>
</div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*global JSLINT */</span>
<span style="color: #009966; font-style: italic;">/*jslint white: true, rhino: true */</span>
<span style="color: #006600; font-style: italic;">/**
 * @fileOverview Provides a JSLint console for Rhino.
 * &lt;p&gt;Usage: &lt;code&gt;java -jar lib/js.jar lib/jslint-console.js lib/fulljslint.js src/testFile1.js src/testFile2.js&lt;/code&gt;&lt;/p&gt;
 * @author Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @version 0.1.1 (2010-06-24)
 */</span>
<span style="color: #006600; font-style: italic;">/**
 * @license Copyright (c) 2010 Mehdi Kabab &lt;http://pioupioum.fr/&gt;.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the &quot;Software&quot;), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Loads the JSLint script given as first argument.</span>
load<span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>scripts<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">,</span>
        indentLen <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Returns the string repeated multiplier times.
     * @param {Number} multiplier Number of time the string should be repeated.
     * @this {String}
     * @return Returns the repeated string.
     * @type String
     * @addon
     */</span>
    String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">repeat</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>multiplier<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span> <span style="color: #339933;">&gt;</span> multiplier<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            multiplier <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">+</span> multiplier<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Cleans evidence message and assign &lt;code&gt;identLen&lt;/code&gt;.
     * @private
     * @param {String} str The full message.
     * @param {String} p1 Possible identation.
     * @param {String} p2 The message content.
     * @returns The message content
     * @type String
     */</span>
    <span style="color: #003366; font-weight: bold;">function</span> cleanEvidence<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> p1<span style="color: #339933;">,</span> p2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        indentLen <span style="color: #339933;">=</span> p1.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> p2<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// cleanEvidence</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Check quality code of the given script.
     * @private
     * @param {String} jsfile File to check.
     * @requires JSLINT
     * @requires String#repeat()
     */</span>
    <span style="color: #003366; font-weight: bold;">function</span> lint<span style="color: #009900;">&#40;</span>jsfile<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">,</span>
            input<span style="color: #339933;">,</span>
            e<span style="color: #339933;">,</span>
            errLen<span style="color: #339933;">,</span>
            errTag <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;[ERROR] &quot;</span><span style="color: #339933;">,</span>
            found <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Running JSLint on: &quot;</span> <span style="color: #339933;">+</span> jsfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        input <span style="color: #339933;">=</span> readFile<span style="color: #009900;">&#40;</span>jsfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>errTag <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;Couldn't open file.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            quit<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>JSLINT<span style="color: #009900;">&#40;</span>input<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> browser<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> rhino<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> laxbreak<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            onevar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> undef<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> nomen<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> eqeqeq<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> bitwise<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            regexp<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> newcap<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            predef<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'window'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'escape'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'unescape'</span><span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> errLen <span style="color: #339933;">=</span> JSLINT.<span style="color: #660066;">errors</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> errLen<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                e <span style="color: #339933;">=</span> JSLINT.<span style="color: #660066;">errors</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    found <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;% scanned).&quot;</span> <span style="color: #339933;">!==</span> e.<span style="color: #660066;">reason</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">11</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>errTag <span style="color: #339933;">+</span> e.<span style="color: #660066;">reason</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\.$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                            <span style="color: #3366CC;">&quot; on line &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">line</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; character &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">character</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">!==</span> e.<span style="color: #660066;">evidence</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span>.<span style="color: #660066;">repeat</span><span style="color: #009900;">&#40;</span>errTag.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                                <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">evidence</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^(\s*)(\S*(\s+\S+)*)\s*$/</span><span style="color: #339933;">,</span> cleanEvidence<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span>.<span style="color: #660066;">repeat</span><span style="color: #009900;">&#40;</span>errTag.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                                <span style="color: #3366CC;">&quot;.&quot;</span>.<span style="color: #660066;">repeat</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">character</span> <span style="color: #339933;">-</span> indentLen <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;^&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>errTag <span style="color: #339933;">+</span> e.<span style="color: #660066;">reason</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;=&gt; &quot;</span> <span style="color: #339933;">+</span> found <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; error(s) found.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            quit<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;OK<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// lint</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>scripts<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Usage: jslint-console.js fulljslint.js file1.js[ file2.js]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        quit<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> scripts.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        lint<span style="color: #009900;">&#40;</span>scripts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<h2 id="prerequis">Prérequis</h2>

<p>Les prérequis sont simples&#160;:</p>

<ul>
<li><a href="http://www.mozilla.org/rhino/download.html" title="Rhino Downloads">Télécharger Rhino</a> et récupérer le fichier <code>js.jar</code>.</li>
<li>Récupérer la version <a href="http://www.jslint.com/rhino/fulljslint.js">complète</a> ou <a href="http://www.jslint.com/rhino/jslint.js">minifiée</a> de JSLint. Attention cependant, il vous faudra supprimer la fonction anonyme embarquée <code>rhino.js</code> (en fin de script).</li>
</ul>

<h2 id="usage">Usage</h2>

<p>Dans un shell, exécutez <code>jslint-console.js</code> à l&#8217;aide de <strong><a href="http://www.mozilla.org/rhino/" title="Rhino - JavaScript for Java">Rhino</a></strong>, comme suis&#160;:</p>

<pre>$ java -jar lib/rhino/js.jar lib/jslint/jslint-console.js lib/jslint/fulljslint.js src/*.js</pre>

<p>Ici, deux arguments sont passés à la <strong>console jslint</strong>&#160;:</p>

<ul>
<li>Le script JSLint, <code>lib/jslint/fulljslint.js</code>, à fournir en premier argument. Je ne le charge pas en dur dans <code>jslint-console.js</code> afin de conserver une souplesse d&#8217;implémentation (<em>via</em> une tâche <a href="http://pioupioum.fr/tag/ant/" title="Archives pour le tag ant – piouPiouM&#039;s dev">Ant</a> par exemple).</li>
<li>La liste des fichiers sources <strong>JavaScript</strong> à analyser.</li>
</ul>

<p>Voici un exemple de sortie de la console&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="" style="font-family:monospace;">$ java -jar lib/rhino/js-1.7R2.jar lib/jslint/jslint-console.js lib/jslint/fulljslint.js src/*.js
Running JSLint on: src/jsfile1.js
OK
&nbsp;
Running JSLint on: src/jsfile2.js
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> Expected '===' and instead saw '==' on line <span style="">52</span> character 23.
        if <span class="br0">&#40;</span>false == test<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        ..........^
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> Unexpected dangling '_' in '_ob' on line <span style="">74</span> character 17.
        var _ob = window.ob;
        ....^
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> 'ob' is not defined on line <span style="">80</span> character 39.
        if <span class="br0">&#40;</span>'function' !== typeof ob.getVariables<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        ..........................^
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> 'ob' is not defined on line <span style="">83</span> character 26.
        params = ob.getVariables<span class="br0">&#40;</span><span class="br0">&#41;</span>.sequence;
        .........^
=&gt; <span style="">4</span> error<span class="br0">&#40;</span>s<span class="br0">&#41;</span> found.</pre></td></tr></table></div>


<h2 id="changelog">Historique des versions et changelog</h2>

<h3>0.1.1 (2010-06-24)</h3>

<ul>
<li>Forcer un multiplieur positif dans String.prototype.repeat</li>
</ul>

<h3>0.1 (2010-06-03)</h3>

<ul>
<li>Version initiale.</li>
</ul>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=B2_fK8hyDdY:G7gyMmjCOYQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=B2_fK8hyDdY:G7gyMmjCOYQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=B2_fK8hyDdY:G7gyMmjCOYQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=B2_fK8hyDdY:G7gyMmjCOYQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=B2_fK8hyDdY:G7gyMmjCOYQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=B2_fK8hyDdY:G7gyMmjCOYQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=B2_fK8hyDdY:G7gyMmjCOYQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=B2_fK8hyDdY:G7gyMmjCOYQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=B2_fK8hyDdY:G7gyMmjCOYQ:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/B2_fK8hyDdY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/jslint-console-rhino.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/jslint-console-rhino.html</feedburner:origLink></item>
		<item>
		<title>TextMate : commande “Export words”</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/hVU9VmImBXM/textmate-commande-exporter-mots-word-wrap.html</link>
		<comments>http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html#comments</comments>
		<pubDate>Sun, 16 May 2010 14:30:47 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=380</guid>
		<description><![CDATA[À l&#8217;intérieur du code source d&#8217;une classe PHP, je souhaite stocker dans un tableau la liste des mots de la version populaire de l&#8217;incontournable texte Lorem ipsum. Jusque là rien de bien sorcier. Mais pour des raisons de lisibilité et de conventions de codage je veux obtenir des lignes formées par un maximum de 72 [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>À l&#8217;intérieur du code source d&#8217;une classe PHP, je souhaite stocker dans un tableau la liste des mots de la version populaire de l&#8217;incontournable texte <em><a href="http://fr.wikipedia.org/wiki/Faux-texte#Lorem_ipsum_.28version_populaire.29" title="Faux-texte - Wikipédia">Lorem ipsum</a></em>. Jusque là rien de bien sorcier. Mais pour des raisons de lisibilité et de conventions de codage je veux obtenir des lignes formées par un maximum de 72 caractères.</p>

<p>Certes je peux <em>m&#8217;amuser</em> à le faire à la main, mais pourquoi me fatiguer quand un langage de script tel que <strong>PHP</strong> me tend la main pour automatiser la procédure&#160;? Et, cerise sur le gâteau, si en plus je peux l&#8217;intégrer à mon éditeur préféré, <a href="http://pioupioum.fr/tag/textmate/" title="Archives pour le tag TextMate – piouPiouM&#039;s dev">TextMate</a>.</p>

<p><div id="attachment_386" class="wp-caption aligncenter" style="width: 458px"><a href="http://assets1.pioupioum.fr/uploads/2010/05/export-words.png"><img src="http://assets1.pioupioum.fr/uploads/2010/05/export-words-448x350.png" alt="Exemple d&#039;action de la commande TextMate Export words" title="TextMate Export words" width="448" height="350" class="size-medium wp-image-386" /></a><p class="wp-caption-text">Exemple d&#8217;action de la commande TextMate Export words</p></div><span id="more-380"></span></p>

<h2>Intégration dans Textmate</h2>

<ol>
<li>Allez dans le menu <span lang="en">Bundles</span> > <span lang="en">Bundle Editor</span> > <span lang="en">Show Bundle Editor</span> puis créez une nouvelle commande à l&#8217;aide de l&#8217;action <span lang="en">New Command</span>.</li>
<li>Donnez à la commande le nom <span lang="en">Export words</span>.</li>
<li>Veillez à ce que <span lang="en">Save</span> soit défini à <span lang="en">Nothing</span>.</li>
<li>Sélectionnez pour <span lang="en">Input</span> les options <span lang="en">Selected Text or Nothing</span>.</li>
<li>Placez <span lang="en">Output</span> à <span lang="en">Replace Selected Text</span>.</li>
<li>Choisissez une <span lang="en">Activation</span> de type <span lang="en">Key Equivalent</span> et définnez un raccourci. J&#8217;ai opté pour la séquence <kbd>⌥⇧W</kbd>.</li>
<li>Laissez vide le champ <span lang="en">Scope Selector</span> afin de pouvoir jouir de la commande depuis n&#8217;importe quel type de fichier et scope.</li>
<li>Enfin, copiez-collez le code ci-dessous dans le champ <span lang="en">Command(s)</span>.</li>
</ol>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/env php -n
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Export a wrapped representation of the words of a text.
 *
 * Optional parameters in a line that follows the text:
 *      l&lt;size&gt;. The column width. Default: 72.
 *      s&lt;characters&gt;. Characters to remove. Default: punctuation.
 *      o&lt;asc|desc&gt;. Sort order. Default: none.
 */</span>
<span style="color: #666666; font-style: italic;">/*
# ***** BEGIN LICENSE BLOCK *****
#
# Copyright (C) 2010 Mehdi Kabab &lt;http://pioupioum.fr/&gt;
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the &quot;Software&quot;), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# ***** END LICENSE BLOCK ***** */</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">version_compare</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">PHP_VERSION</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'5.0.0'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You must have PHP &gt;= 5.0.0!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$lenght</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">72</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// the default column width.</span>
<span style="color: #000088;">$strip</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'\p{P}'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// removes the ponctuation</span>
<span style="color: #000088;">$sort</span>   <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// no sorting</span>
&nbsp;
<span style="color: #000088;">$raw</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://filter/read=string.tolower/resource=php://stdin'</span><span style="color: #339933;">,</span>
            FILE_IGNORE_NEW_LINES <span style="color: #339933;">|</span> FILE_SKIP_EMPTY_LINES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_pop</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^(?:\s{0,}(?:l(?&lt;lenght&gt;\d+)|s(?&lt;strip&gt;.*)|o(?&lt;sort&gt;asc|desc))\s{0,})+$#u'</span><span style="color: #339933;">,</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lenght'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lenght'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$lenght</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lenght'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'strip'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'strip'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$strip</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'|'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'strip'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$sort</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sort'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$raw</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$raw</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Removes punctuation and user characters</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$strip</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$strip</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'\#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$strip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$raw</span>   <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#('</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$strip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">')#u'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$raw</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Estimating indent</span>
<span style="color: #000088;">$start_index</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TM_INPUT_START_LINE_INDEX'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$start_index</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TM_INPUT_START_LINE_INDEX'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'YES'</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TM_SOFT_TABS'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$tab</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TM_TAB_SIZE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$tab</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$tab_count</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_index</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TM_TAB_SIZE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$extra_spaces</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start_index</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TM_TAB_SIZE'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tabs</span>         <span style="color: #339933;">=</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tab</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tab_count</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$extra_spaces</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tabs_len</span>     <span style="color: #339933;">=</span> <span style="color: #000088;">$tab_count</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TM_TAB_SIZE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$extra_spaces</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Extracting words now!</span>
<span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#\s+#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$raw</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_map</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'trim'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// removes empty fields</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sort</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">natsort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'desc'</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$sort</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_reverse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%s\'%s\''</span><span style="color: #339933;">,</span>
                 <span style="color: #000088;">$tabs</span><span style="color: #339933;">,</span>
                 <span style="color: #990000;">wordwrap</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;', '&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lenght</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$tabs_len</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #006699; font-weight: bold;">$tabs</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$start_index</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ltrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;''&quot;</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$words</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$words</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<h2>Utilisation de la commande TextMate <strong>Export words</strong></h2>

<p>Sélectionnez le texte à transformer. La transformation du texte se contrôle en ajoutant à la suite une ligne d&#8217;arguments <strong>optionnels</strong>&#160;:</p>

<ul>
<li><strong><code>l&lt;size&gt;</code></strong>. Ajuster la longueur de ligne. Exemple&#160;: <code>l80</code> pour effectuer une coupure à la colonne 80. Défaut&#160;: 72.</li>
<li><strong><code>s&lt;characters&gt;</code></strong>. Exemple&#160;: <code>slorem|ipsum</code> pour exclure les mots <em>lorem</em> et <em>ipsum</em>. Défaut&#160;: toute ponctuation.</li>
<li><strong><code>o&lt;asc|desc&gt;</code></strong>. Trier la sortie selon les ordres <code>asc</code>endant et <code>desc</code>endant. Défaut&#160;: aucun tri n&#8217;est réalisé.</li>
</ul>

<p>Notez que si votre sélection est précédée par une indentation, alors le script va appliquer cette dernière à chacune des lignes générées en se conformant aux options courantes de TextMate&#160;: il générera des espaces si le mode <span lang="en">Soft Tabs</span> est activé. Sinon des tabulations complétées d&#8217;éventuels espaces.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVU9VmImBXM:JKaWyis8IRY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVU9VmImBXM:JKaWyis8IRY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVU9VmImBXM:JKaWyis8IRY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVU9VmImBXM:JKaWyis8IRY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVU9VmImBXM:JKaWyis8IRY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVU9VmImBXM:JKaWyis8IRY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVU9VmImBXM:JKaWyis8IRY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVU9VmImBXM:JKaWyis8IRY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVU9VmImBXM:JKaWyis8IRY:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/hVU9VmImBXM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html</feedburner:origLink></item>
		<item>
		<title>PHP : installer APC sous Mac OS X Leopard</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/LMCacpcXiUI/php-installer-apc-macosx.html</link>
		<comments>http://pioupioum.fr/snippets/php-installer-apc-macosx.html#comments</comments>
		<pubDate>Thu, 06 May 2010 18:47:30 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[APC]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=376</guid>
		<description><![CDATA[Sous Mac OS X Leopard, l&#8217;installation du système de cache APC via PECL est en carton. Pour faire simple, l&#8217;extension n&#8217;est disponible que pour la version CLI de PHP.

Il est cependant possible d&#8217;y remédier1 et ainsi disposer d&#8217;APC avec la configuration de base fourni par Apple.

Récupérer la dernière version d&#8217;APC

$ curl http://pecl.php.net/get/APC -o ~/Downloads/APC-latest.tgz
$ tar [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Sous Mac OS X Leopard, l&#8217;installation du système de cache <a href="http://php.net/manual/fr/book.apc.php" title="PHP: APC - Manual">APC</a> <em>via</em> <a href="http://pecl.php.net/" title="PECL :: The PHP Extension Community Library">PECL</a> est en carton. Pour faire simple, l&#8217;extension n&#8217;est disponible que pour la version CLI de PHP.</p>

<p>Il est cependant possible d&#8217;y remédier<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> et ainsi disposer d&#8217;<strong>APC</strong> avec la configuration de base fourni par Apple.</p>

<h2>Récupérer la dernière version d&#8217;APC</h2>

<pre>$ curl http://pecl.php.net/get/APC -o ~/Downloads/APC-latest.tgz
$ tar -zxf !$ -C ~/Downloads/
$ cd ~/Downloads/APC-3.1.3p1/</pre>

<p>La version utilisée ici est la 3.1.3p1.</p>

<h2>Préparer l&#8217;environnement de compilation</h2>

<pre>$ /usr/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519</pre>

<p><span id="more-376"></span></p>

<h2>Lancer la compilation</h2>

<p>Copier-coller dans la commande qui suit dans son intégralité. Attention à ne pas inclure de retours à la ligne.</p>

<pre>MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure</pre>

<p>Puis un coup de <code>make</code>&#160;:</p>

<pre>$ make
...
----------------------------------------------------------------------
Libraries have been installed in:
   /Users/mehdi/Downloads/APC-3.1.3p1/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.</pre>

<p>Et pour finir, on installe l&#8217;extension APC.</p>

<pre>$ sudo make install
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20060613/</pre>

<h2>Activer l&#8217;extension APC pour PHP</h2>

<p>Éditer le fichier <code>php.ini</code> pour ajouter la configuration qui suit&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">extension</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> apc.so</span>
apc.enabled <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 1</span>
apc.enable_cli <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 1</span>
apc.mmap_file_mask <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /tmp/apc.XXXXXX</span>
apc.num_files_hint <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 1024</span>
apc.shm_segments <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 1</span>
apc.shm_size <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 128</span>
apc.ttl <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 7200</span>
apc.user_ttl <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 7200</span></pre></div></div>


<p>Relancer Apache pour qu&#8217;il prenne en compte la nouvelle extension.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li><li><a href='http://pioupioum.fr/snippets/apache-rotation-logs.html' title='Rotation des logs Apache'>Rotation des logs Apache</a></li><li><a href='http://pioupioum.fr/snippets/convertir-icone-icns-png.html' title='Convertir une icône ICNS en une image PNG'>Convertir une icône ICNS en une image PNG</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>Source&#160;: <a href="http://discussions.apple.com/thread.jspa?threadID=1578979" title="Apple - Support - Discussions - Entropy php5 with GD support and APC ...">Forum du support Apple</a>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=LMCacpcXiUI:fg3hEzb73Fc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=LMCacpcXiUI:fg3hEzb73Fc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=LMCacpcXiUI:fg3hEzb73Fc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=LMCacpcXiUI:fg3hEzb73Fc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=LMCacpcXiUI:fg3hEzb73Fc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=LMCacpcXiUI:fg3hEzb73Fc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=LMCacpcXiUI:fg3hEzb73Fc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=LMCacpcXiUI:fg3hEzb73Fc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=LMCacpcXiUI:fg3hEzb73Fc:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/LMCacpcXiUI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/php-installer-apc-macosx.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/snippets/php-installer-apc-macosx.html</feedburner:origLink></item>
		<item>
		<title>TextMate : convertir une couleur hexadécimale en notation RGBA</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/XQ-u468gROY/textmate-convertir-couleur-hexadecimale-html-rgba.html</link>
		<comments>http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html#comments</comments>
		<pubDate>Thu, 15 Apr 2010 10:19:56 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[couleur]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[rgba]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=367</guid>
		<description><![CDATA[CSS supporte divers formats de description des couleurs, le plus utilisé étant la notation héxadécimale #RRGGBB. L&#8217;introduction du support des couleurs RGBA par CSS 3 a été l&#8217;occasion pour certains de découvrir les notations rgba(255, 255, 255, 1) et sa version sans gestion de l&#8217;opacité rgb(255, 255, 255).

Il faut avouer que si nous disposons d&#8217;une [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>CSS supporte divers formats de description des couleurs, le plus utilisé étant la <strong>notation héxadécimale</strong> <code>#RRGGBB</code>. L&#8217;introduction du support des <a href="http://pioupioum.fr/tag/rgba/" title="Archives pour le tag rgba – piouPiouM&#039;s dev">couleurs RGBA</a> par CSS 3 a été l&#8217;occasion pour certains de découvrir les notations <code>rgba(255, 255, 255, 1)</code> et sa version sans gestion de l&#8217;opacité <code>rgb(255, 255, 255)</code>.</p>

<p>Il faut avouer que si nous disposons d&#8217;une palette d&#8217;outils d&#8217;aide à la saisie de couleurs en notation hexadécimale, il en est rien pour insérer une couleur au format <code>rgb[a]</code>, et cela peut <a href="http://twitter.com/br1o/status/12041847261" title="une réaction sur twitter">agacer</a>. Mais c&#8217;était sans compter sur <a href="http://pioupioum.fr/tag/textmate/" title="Archives pour le tag TextMate – piouPiouM&#039;s dev">TextMate</a>&#160;!<span id="more-367"></span></p>

<h2>Convertir une couleur héxadécimale en notation RGBA</h2>

<p>La commande TextMate <strong>Convert Hex to RGB(A) color</strong> va vous permettre de convertir <em>via</em> le raccourci clavier <kbd>⌘⇧X</kbd> une couleur héxadécimale en son équivalent RGB(A).</p>

<h3>Installation</h3>

<p>Après avoir téléchargé le fichier qui suit, installez la commande d&#8217;un simple double-clique.</p>

<div class="box textmate-command">
    <a title="Télécharger" href="http://assets1.pioupioum.fr/uploads/2010/04/Convert-Hex-to-RGBA-color.tmCommand"><span>Convert Hex to RGB(A) color.tmCommand (4&#160;Ko)</span></a>
</div>

<p>La nouvelle commande est maintenant disponible dans le bundle <strong>Source</strong>.</p>

<p>Pourquoi l&#8217;installer dans le bundle <strong>Source</strong> au lieu du bundle <strong>CSS</strong>&#160;? Parce qu&#8217;elle peut être utile dans d&#8217;autre languages, comme JavaScript et sera ainsi disponible à tout moment, qu&#8217;importe le bundle actif.</p>

<h3>Usage</h3>

<p>Simple d&#8217;utilisation, positionnez-vous sur une couleur et activez la commande pour obtenir son équivalent en notation RGB&#160;:</p>

<pre>#6633ff => rgb(102, 51, 255)
#63F    => rgb(102, 51, 255)</pre>

<p>Ajoutez à une couleur héxadécimale la composante d&#8217;opacité pour remplacer la couleur par sa forme RGBA&#160;:</p>

<pre>#6633FF80 => rgba(102, 51, 255, .50)
#63FA     => rgba(102, 51, 255, .67)
#63F0     => rgba(102, 51, 255, 0)</pre>

<p>Vous pouvez également sélectionner une couleur (avec le sharp <code>#</code> initial) et lancer la convertion. Cela se révèle être particulièrement utile avec une sélection en colonne.</p>

<h3>Code source</h3>

<p>Voici le <a href="http://gist.github.com/366816" title="gist: 366816 - Source code of a TextMate Command- GitHub">code</a> ruby<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> utilisé au sein de la commande.
<script src="http://gist.github.com/366816.js?file=hex2rgba.rb"></script></p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/jquery-color-plugin-animation-rgba-support.html' title='Du RGBA dans vos animations avec le plugin jQuery Color'>Du RGBA dans vos animations avec le plugin jQuery Color</a></li><li><a href='http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html' title='JavaScript : tester le support des couleurs RGBA'>JavaScript&#160;: tester le support des couleurs RGBA</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>Toute remarque ou conseil est le bienvenu. Il s&#8217;agit de mon premier script ruby…&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=XQ-u468gROY:AVFp4E64uMk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=XQ-u468gROY:AVFp4E64uMk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=XQ-u468gROY:AVFp4E64uMk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=XQ-u468gROY:AVFp4E64uMk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=XQ-u468gROY:AVFp4E64uMk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=XQ-u468gROY:AVFp4E64uMk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=XQ-u468gROY:AVFp4E64uMk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=XQ-u468gROY:AVFp4E64uMk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=XQ-u468gROY:AVFp4E64uMk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/XQ-u468gROY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html</feedburner:origLink></item>
		<item>
		<title>Optimiser le chargement des AdSense</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/it4ebgIdA9A/optimiser-rapidite-chargement-adsense-jquery.html</link>
		<comments>http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html#comments</comments>
		<pubDate>Thu, 11 Mar 2010 16:48:57 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[optimiser]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=357</guid>
		<description><![CDATA[Il n&#8217;y a rien de plus horripilant que d&#8217;attendre que des publicités chargent pour accéder au contenu d&#8217;un article. C&#8217;est malheureusement une situation que l&#8217;on rencontre fréquemment. La faute en incombe au fonctionnement des blocs AdSense des publicitaires.

En effet, ils nécessitent que nous insérerions le code correspondant à un bloc à l&#8217;endroit où il sera [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Il n&#8217;y a rien de plus horripilant que d&#8217;attendre que des publicités chargent pour accéder au contenu d&#8217;un article. C&#8217;est malheureusement une situation que l&#8217;on rencontre fréquemment. La faute en incombe au fonctionnement des blocs <strong>AdSense</strong> des publicitaires.</p>

<p>En effet, ils nécessitent que nous insérerions le code correspondant à un bloc à l&#8217;endroit où il sera affiché. Cela pour deux raisons notamment&#160;:</p>

<ol>
<li>Des variables globales identifiants l&#8217;annonce sont déclarées.</li>
<li>Le script qui va charger l&#8217;annonce est immédiatement exécuté et fait appel à des actions d&#8217;écriture dans le flux <em>via</em> <a href="https://developer.mozilla.org/fr/DOM/document.write">write</a>.</li>
</ol>

<p>Le deuxième point oblige le navigateur à traiter le code de l&#8217;adsense dès qu&#8217;il le rencontre puisque ce dernier n&#8217;utilise pas de gestionnaire de chargement. En plus d&#8217;écrire dans le flux courant, le système du publicitaire va charger des éléments extérieurs. Pour peu que la latence des réponses soit élevée, l&#8217;impression de <strong>ralentissement du chargement de la page</strong> augmente.</p>

<p>S&#8217;est ainsi que si un article est précédé d&#8217;un encart publicitaire, l&#8217;utilisateur devra patiemment attendre le chargement de ce dernier avant de pouvoir accéder au contenu désiré.<br />
L&#8217;expérience utilisateur s&#8217;en trouve dégradée.</p>

<h2>En finir avec les ralentissements de chargement des pages</h2>

<p>Vous l&#8217;aurez peut-être remarqué, mais sur <a href="http://pioupioum.fr/" title="piouPiouM&#8217;s dev : bloc-note d&#8217;un développeur web. PHP, git, shell, plugins WordPress, SPIP, jQuery">piouPiouM&#8217;s dev</a>, le <strong>chargement des blocs publicitaires</strong> est comme <strong>temporisé</strong>, ne gênant ainsi en rien la navigation sur le site.<br />
Voyons dans la suite du billet comment y parvenir, en prenant pour exemple le service <a href="https://www.google.com/adsense/">Google Adsense</a>.
<span id="more-357"></span></p>

<h2 id="integration-maquette">Intégration dans une maquette</h2>

<p>On commence par définir les emplacements des encarts publicitaires. Cela vous permet ainsi d&#8217;intégrer les annonces dans vos maquettes <abbr title="Hyper Text Markup Language">HTML</abbr>, tout en vous assurant que cette apparence sera conservée pour les utilisateurs n&#8217;ayant pas JavaScript d&#8217;activé, ou qui bloquent les annonces publicitaires.<br />
Je prend ici le parti d&#8217;annoncer la couleur, en précisant la mention <em>Publicité</em>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;ads-[ads_id]&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ads [ads_format]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    Publicité
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<p>En sommes, il s&#8217;agit d&#8217;un simple élément <code>&lt;div&gt;</code> ayant pour attributs&#160;:</p>

<ul>
<li>un identifiant <strong>[ads_id]</strong>&#160;: un identifiant unique qui va servir de point d&#8217;ancrage au contenu de l&#8217;adsense. Vous pouvez par exemple, dans le cas de Google Adsense, utiliser le nom du critère personnalisé en notation CamelCase.</li>
<li>une classe <strong>ads</strong>&#160;: le style des encarts de pub lorsque celles-ci sont en attente de chargement.</li>
<li>une classe <strong>[ads_format]</strong>&#160;: le format de l&#8217;encart publicitaire. Par exemple, <code>square250</code> pour une annonce de 250px de côtés ou encore <code>banner468</code> pour une bannière au format 468 x 60.</li>
</ul>

<p>Appliquez les styles <abbr title="Cascading Style Sheets">CSS</abbr> qui suivent.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* @group Tools */</span>
&nbsp;
<span style="color: #6666ff;">.hide</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* @end   Tools */</span>
<span style="color: #808080; font-style: italic;">/* @group Adsense */</span>
&nbsp;
<span style="color: #6666ff;">.ads</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#F4F4F4</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#666666</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">11px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-transform</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">uppercase</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.square250</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.banner468</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">468px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* @end   Adsense */</span></pre></td></tr></table></div>


<h2 id="ads-code-annonceur">Insertion du code de l&#8217;annonceur</h2>

<p>Insérez en fin de page les différents codes donnés par votre annonceur (ici, Google Adsense).</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;hide&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Ads --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;adsref-[ads_id]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
google_ad_client = &quot;pub-[client_id]&quot;;
google_ad_slot   = &quot;[slot_id]&quot;;
google_ad_width  = 250;
google_ad_height = 250;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<p><strong>Chaque annonce</strong> est incluse dans un élément ayant pour identifiant <code>adsref-[ads_id]</code> (voir <a href="#integration-maquette">Intégration de la maquette</a>) qui fait le lien avec l&#8217;emplacement final de la publicité.</p>

<p>Le tout étant masqué à l&#8217;aide d&#8217;un <code>div.hide</code>. Il serait en effet désagréable d&#8217;afficher les annonces publicitaires en bas de page, même si ce n&#8217;est que pour une poignée de [micro]secondes.</p>

<h2 id="jquery-ads-loader">Un Adsense Loader avec jQuery</h2>

<p>Il ne reste plus qu&#8217;à déplacer à l&#8217;aide de JavaScript les blocs AdSense aux endroits souhaités. Avec <a href="http://pioupioum.fr/tag/jquery/" title="Archives pour le tag jQuery – piouPiouM&#039;s dev">jQuery</a> cela donne&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> $ads<span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div[id^=&quot;adsref-&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>          <span style="color: #006600; font-style: italic;">// pour chaque bloc d'annonce #adsref-[ads_id]</span>
        $ads <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ads-'</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// supprimer de #ads-[ads_id] tout éventuel contenu</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ins:first'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$ads<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>           <span style="color: #006600; font-style: italic;">// déplacer l'annonce dans #ads-[ads_id]</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Bien évidemment, et comme vous êtes sensible aux bonnes pratiques liées à la <a href="http://performance.survol.fr/" title="Performance web">performance web</a>, vous insérerez naturellement ce code en fin de page <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li><li><a href='http://pioupioum.fr/developpement/jslint-console-rhino.html' title='Une console JSLint pour aider vos validations JavaScript'>Une console JSLint pour aider vos validations JavaScript</a></li><li><a href='http://pioupioum.fr/developpement/jquery-color-plugin-animation-rgba-support.html' title='Du RGBA dans vos animations avec le plugin jQuery Color'>Du RGBA dans vos animations avec le plugin jQuery Color</a></li><li><a href='http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html' title='JavaScript : tester le support des couleurs RGBA'>JavaScript&#160;: tester le support des couleurs RGBA</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-autoriser-upload-media-format-inconnu.html' title='WordPress : autoriser l&#8217;upload de fichiers au format non-supporté'>WordPress&#160;: autoriser l&#8217;upload de fichiers au format non-supporté</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=it4ebgIdA9A:lxx2bTJ3IRo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=it4ebgIdA9A:lxx2bTJ3IRo:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=it4ebgIdA9A:lxx2bTJ3IRo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=it4ebgIdA9A:lxx2bTJ3IRo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=it4ebgIdA9A:lxx2bTJ3IRo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=it4ebgIdA9A:lxx2bTJ3IRo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=it4ebgIdA9A:lxx2bTJ3IRo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=it4ebgIdA9A:lxx2bTJ3IRo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=it4ebgIdA9A:lxx2bTJ3IRo:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/it4ebgIdA9A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html</feedburner:origLink></item>
		<item>
		<title>PHP : convertir un DATETIME en un timestamp UNIX</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/j1drFlo1fes/php-convertir-datetime-unix-timestamp.html</link>
		<comments>http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html#comments</comments>
		<pubDate>Tue, 09 Mar 2010 23:28:01 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=346</guid>
		<description><![CDATA[Mise à jour à 10:57
Plus simple, rapide, intégré, toussa&#160;: utiliser strtotime tout simplement.
Merci à Éric Daspet et à Oncle Tom pour le rappel.

Une fonction utilitaire1 pour convertir une chaîne de type DATETIME ou DATE en un timestamp UNIX.
Les formats pris en charges en entrée sont AAAA-MM-JJ HH:MM:SS et AA-MM-JJ HH:MM:SS. L&#8217;heure étant optionnelle dans le [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><strong>Mise à jour à 10:57</strong><br />
Plus simple, rapide, intégré, toussa&#160;: utiliser <a href="http://php.net/manual/fr/function.strtotime.php">strtotime</a> tout simplement.<br />
Merci à <a href="http://twitter.com/edasfr/status/10264669320" title="réaction sur twitter">Éric Daspet</a> et à <a href="http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html#comment-1187" title="réaction dans les commentaires">Oncle Tom</a> pour le rappel.</p>

<p>Une fonction utilitaire<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> pour convertir une chaîne de type <strong>DATETIME</strong> ou <strong>DATE</strong> en un <strong>timestamp UNIX</strong>.<br />
Les formats pris en charges en entrée sont <code>AAAA-MM-JJ HH:MM:SS</code> et <code>AA-MM-JJ HH:MM:SS</code>. L&#8217;heure étant optionnelle dans le cas de la conversion d&#8217;une date.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Get UNIX timestamp for a date or date time.
 *
 * Example:
 * &lt;code&gt;
 * &lt;?php
 * unix_timestamp('2010-03-09 22:43:46'); # 1268171026
 * unix_timestamp('10-03-09 22:43:46');   # 1268171026
 * unix_timestamp('2010-03-09');          # 1268089200
 * ?&gt;
 * &lt;/code&gt;
 *
 * @author    Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @copyright 2010 Mehdi Kabab
 * @license   http://www.opensource.org/licenses/mit-license.html MIT License
 * @link      http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html
 *
 * @param string The date or datetime to convert.
 * @return int The UNIX timestamp corresponding to the datetime.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> unix_timestamp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">':'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$c</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$c</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">array_pad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">array_walk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'intval'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>vous allez dire qu&#8217;il en existe pléthore, mais je les trouve toutes trop lourdes (conditions, strlen, multiples explode, etc) pour le peu à faire. Sans parler du fait qu&#8217;elles ne supportent uniquement que le format DATETIME.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=j1drFlo1fes:TzRk52FGggo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=j1drFlo1fes:TzRk52FGggo:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=j1drFlo1fes:TzRk52FGggo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=j1drFlo1fes:TzRk52FGggo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=j1drFlo1fes:TzRk52FGggo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=j1drFlo1fes:TzRk52FGggo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=j1drFlo1fes:TzRk52FGggo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=j1drFlo1fes:TzRk52FGggo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=j1drFlo1fes:TzRk52FGggo:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/j1drFlo1fes" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html</feedburner:origLink></item>
		<item>
		<title>Bash : convertir un string en entier</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/gdyfIqjQ3kk/bash-convertir-string-to-integer.html</link>
		<comments>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html#comments</comments>
		<pubDate>Sat, 06 Mar 2010 19:06:25 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=340</guid>
		<description><![CDATA[Bash n&#8217;offre pas de fonction pour convertir une chaîne de caractères ou un nombre flottant en un entier.
Cela n&#8217;est toute fois pas impossible, il suffit de faire appel à printf1 et le tour est joué&#160;!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash
# string_to_int.sh - Shell script to convert a string or float number
# to an integer.
&#160;
function string_to_int &#40;&#41;
&#123;
    [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><a href="http://fr.wikipedia.org/wiki/Bourne-Again_shell" title="Bourne-Again shell - Wikipédia">Bash</a> n&#8217;offre pas de fonction pour convertir une chaîne de caractères ou un nombre flottant en un entier.<br />
Cela n&#8217;est toute fois pas impossible, il suffit de faire appel à <code>printf</code><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> et le tour est joué&#160;!</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;"># string_to_int.sh - Shell script to convert a string or float number</span>
<span style="color: #666666; font-style: italic;"># to an integer.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> string_to_int <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">LANG</span>=C
    <span style="color: #007800;">d</span>=<span style="color: #800000;">${1##*.}</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${#1}</span> <span style="color: #660033;">-eq</span> <span style="color: #800000;">${#d}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">d</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #007800;">e</span>=<span style="color: #800000;">${1%.*}</span>
    <span style="color: #007800;">e</span>=<span style="color: #800000;">${e//,/}</span>
    <span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #000000; font-weight: bold;">%</span>.0f <span style="color: #ff0000;">&quot;<span style="color: #007800;">$e</span>.<span style="color: #007800;">$d</span>&quot;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">not_int</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;12.652&quot;</span> <span style="color: #ff0000;">&quot;-12.652&quot;</span> <span style="color: #000000;">12.652</span> <span style="color: #000000;">14</span> <span style="color: #ff0000;">&quot;12,652&quot;</span> foo <span style="color: #ff0000;">&quot;1,254.8&quot;</span> <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> <span style="color: #ff0000;">&quot;125,160,254.8&quot;</span> <span style="color: #ff0000;">&quot;125,160,254&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> value <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${not_int[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Convert <span style="color: #007800;">$value</span> to int: <span style="color: #007800;">$(string_to_int $value)</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>


<p>Ce qui nous donne&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>string_to_int.sh 
Convert <span style="color: #000000;">12.652</span> to int: <span style="color: #000000;">13</span>
Convert -<span style="color: #000000;">12.652</span> to int: <span style="color: #660033;">-13</span>
Convert <span style="color: #000000;">12.652</span> to int: <span style="color: #000000;">13</span>
Convert <span style="color: #000000;">14</span> to int: <span style="color: #000000;">14</span>
Convert <span style="color: #000000;">12</span>,<span style="color: #000000;">652</span> to int: <span style="color: #000000;">12652</span>
Convert foo to int: <span style="color: #000000;">0</span>
Convert <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">1255</span>
Convert <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">1255</span>
Convert <span style="color: #000000;">125</span>,<span style="color: #000000;">160</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">125160255</span>
Convert <span style="color: #000000;">125</span>,<span style="color: #000000;">160</span>,<span style="color: #000000;">254</span> to int: <span style="color: #000000;">125160254</span></pre></div></div>


<p>Voir <a href="http://gist.github.com/324313">sur Github</a>.</p>

<p><strong>Mis à jour le 7 mars 2010</strong><br />
Prise en charge de la notation US. Merci à <a href="http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html#comment-1159">patpro</a>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li><li><a href='http://pioupioum.fr/snippets/convertir-icone-icns-png.html' title='Convertir une icône ICNS en une image PNG'>Convertir une icône ICNS en une image PNG</a></li><li><a href='http://pioupioum.fr/snippets/leopard-rechercher-nom-reel-utilisateur.html' title='Rechercher le nom réel d&#8217;un utilisateur sous Leopard'>Rechercher le nom réel d&#8217;un utilisateur sous Leopard</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>une substitution du séparateur des décimals <code>.</code> en <code>,</code> est nécessaire avant de faire appel à <code>printf</code>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=gdyfIqjQ3kk:qrOzovIx4V4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=gdyfIqjQ3kk:qrOzovIx4V4:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=gdyfIqjQ3kk:qrOzovIx4V4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=gdyfIqjQ3kk:qrOzovIx4V4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=gdyfIqjQ3kk:qrOzovIx4V4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=gdyfIqjQ3kk:qrOzovIx4V4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=gdyfIqjQ3kk:qrOzovIx4V4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=gdyfIqjQ3kk:qrOzovIx4V4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=gdyfIqjQ3kk:qrOzovIx4V4:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/gdyfIqjQ3kk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html</feedburner:origLink></item>
		<item>
		<title>PHP : fonction uncamel() pour inverser une notation en CamelCase</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/-DSzO8Mawwo/php-uncamel-fonction-convertir-camel-case.html</link>
		<comments>http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html#comments</comments>
		<pubDate>Sun, 28 Feb 2010 18:17:12 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=336</guid>
		<description><![CDATA[Une fonction PHP utilitaire pour convertir une chaîne en notation CamelCase en mots réunis par un séparateur (par défaut, le caractère underscore _).

La fonction uncamel() supporte indifféremment, en entrée, les notations lowerCamelCase et UpperCamelCase.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
&#60;?php
/**
 * Reverse a CamelCase string.
 *
 * Examples:
 *     uncamel('lowerCamelCase') === 'lower_camel_case'
 *     [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Une fonction <strong><a href="http://fr.wikipedia.org/wiki/PHP" title="PHP: Hypertext Preprocessor - Wikipédia">PHP</a></strong> utilitaire pour convertir une chaîne en notation <strong><a href="http://fr.wikipedia.org/wiki/CamelCase" title="CamelCase - Wikipédia">CamelCase</a></strong> en mots réunis par un séparateur (par défaut, le caractère <em>underscore</em> <code>_</code>).</p>

<p>La fonction <strong><code>uncamel()</code></strong> supporte indifféremment, en entrée, les notations <strong>lowerCamelCase</strong> et <strong>UpperCamelCase</strong>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Reverse a CamelCase string.
 *
 * Examples:
 *     uncamel('lowerCamelCase') === 'lower_camel_case'
 *     uncamel('UpperCamelCase') === 'upper_camel_case'
 *     uncamel('ThisIsAString') === 'this_is_a_string'
 *     uncamel('notcamelcase') === 'notcamelcase'
 *     uncamel('lowerCamelCase', ' | ') === 'lower | camel | case'
 *
 * @author    Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @copyright 2010 Mehdi Kabab
 * @license   http://www.opensource.org/licenses/mit-license.html MIT License
 * @link      http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html
 *
 * @param  string $content The CamelCase string.
 * @param  string $separator The glue for the compound words. Defaults to '_'.
 * @return string
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> uncamel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$separator</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'_'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#(?&lt;=[a-zA-Z])([A-Z])(?=[a-zA-Z])#e'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;'<span style="color: #006699; font-weight: bold;">$separator</span>' . strtolower('<span style="color: #006699; font-weight: bold;">$1</span>')&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<p>Le <a href="http://gist.github.com/317702" title="gist: 317702 -  GitHub">forker (gist)</a>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=-DSzO8Mawwo:3RAfaz7FBRg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=-DSzO8Mawwo:3RAfaz7FBRg:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=-DSzO8Mawwo:3RAfaz7FBRg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=-DSzO8Mawwo:3RAfaz7FBRg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=-DSzO8Mawwo:3RAfaz7FBRg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=-DSzO8Mawwo:3RAfaz7FBRg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=-DSzO8Mawwo:3RAfaz7FBRg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=-DSzO8Mawwo:3RAfaz7FBRg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=-DSzO8Mawwo:3RAfaz7FBRg:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/-DSzO8Mawwo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 3.125 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-08-01 04:32:09 -->
